Skip to main content
summaryrefslogtreecommitdiffstats
blob: ae6860cdc8b7de7bf9e0d2d756cbdbcb020aca0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 * Copyright (c) 2010 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.core.message;

import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.osee.framework.core.enums.BranchArchivedState;
import org.eclipse.osee.framework.core.enums.BranchState;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.enums.StorageState;
import org.eclipse.osee.framework.core.message.internal.DatabaseService;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.jdk.core.util.Strings;

public final class BranchRow {
   private final long branchUuid;

   private final String branchName;
   private final BranchType branchType;
   private final BranchState branchState;
   private final BranchArchivedState branchArchived;
   private StorageState storageState;
   private final boolean inheritAccessControl;

   // TODO remove
   public void setStorageState(StorageState storageState) {
      this.storageState = storageState;
   }

   public BranchRow(long branchUuid, String branchName, BranchType branchType, BranchState branchState, BranchArchivedState branchArchived, StorageState storageState, boolean inheritAccessControl) {
      this.branchUuid = branchUuid;
      this.branchName = branchName;
      this.branchType = branchType;
      this.branchState = branchState;
      this.branchArchived = branchArchived;
      this.storageState = storageState;
      this.inheritAccessControl = inheritAccessControl;
   }

   public long getBranchId() {
      return branchUuid;
   }

   public String getBranchName() {
      return branchName;
   }

   public BranchType getBranchType() {
      return branchType;
   }

   public BranchState getBranchState() {
      return branchState;
   }

   public BranchArchivedState getBranchArchived() {
      return branchArchived;
   }

   public StorageState getStorageState() {
      return storageState;
   }

   public boolean isInheritAccessControl() {
      return inheritAccessControl;
   }

   public String[] toArray() {
      if (isOseeUsingGuidsForAppServerMessaging()) {
         return new String[] {
            getBranchArchived().name(),
            getBranchGuidLegacy(getBranchId()),
            String.valueOf(getBranchId()),
            getBranchName(),
            getBranchState().name(),
            getBranchType().name(),
            getStorageState().name(),
            Boolean.toString(isInheritAccessControl())};
      } else {
         return new String[] {
            getBranchArchived().name(),
            String.valueOf(getBranchId()),
            getBranchName(),
            getBranchState().name(),
            getBranchType().name(),
            getStorageState().name(),
            Boolean.toString(isInheritAccessControl())};
      }
   }

   public static BranchRow fromArray(String[] data) {
      BranchArchivedState archived = BranchArchivedState.valueOf(data[0]);
      long branchUuid = 0;
      boolean inheritAccessControl = false;
      String branchName = null;
      BranchState branchState = null;
      BranchType branchType = null;
      StorageState storageState = null;
      if (isOseeUsingGuidsForAppServerMessaging()) {
         // skip guid
         branchUuid = Long.valueOf(data[2]);
         branchName = data[3];
         branchState = BranchState.valueOf(data[4]);
         branchType = BranchType.valueOf(data[5]);
         storageState = StorageState.valueOf(data[6]);
      } else {
         branchUuid = Long.valueOf(data[1]);
         branchName = data[2];
         branchState = BranchState.valueOf(data[3]);
         branchType = BranchType.valueOf(data[4]);
         storageState = StorageState.valueOf(data[5]);
         inheritAccessControl = Boolean.parseBoolean(data[6]);
      }
      return new BranchRow(branchUuid, branchName, branchType, branchState, archived, storageState,
         inheritAccessControl);
   }

   // Temporary cache till all code uses branch uuid. Remove after 0.17.0
   private static final String SELECT_OSEE_INFO =
      "select osee_value from osee_info where osee_key = 'osee.using.guids.for.app.server.messaging'";
   private static Boolean oseeUsingGuidsForAppServerMessaging = null;

   public static boolean isOseeUsingGuidsForAppServerMessaging() {
      if (oseeUsingGuidsForAppServerMessaging == null) {
         oseeUsingGuidsForAppServerMessaging =
            DatabaseService.getDatabaseService().runPreparedQueryFetchObject("", SELECT_OSEE_INFO).equals("true");
      }
      return oseeUsingGuidsForAppServerMessaging;
   }

   private static final String SELECT_BRANCH_GUID_BY_ID = "select branch_guid from osee_branch where branch_id = ?";
   // Temporary cache till all code uses branch uuid. Remove after 0.17.0
   private static final ConcurrentHashMap<Long, String> longToGuidCache = new ConcurrentHashMap<Long, String>(50);

   /**
    * Temporary method till all code uses branch uuid. Remove after 0.17.0
    */
   public static String getBranchGuidLegacy(long branchUuid) {
      String guid = longToGuidCache.get(branchUuid);
      if (!Strings.isValid(guid)) {
         guid =
            DatabaseService.getDatabaseService().runPreparedQueryFetchObject("", SELECT_BRANCH_GUID_BY_ID, branchUuid);
         Conditions.checkExpressionFailOnTrue(!Strings.isValid(guid), "Error getting branch_guid for branch: [%d]",
            branchUuid);
         longToGuidCache.putIfAbsent(branchUuid, guid);
      }
      return guid;
   }

   // Temporary cache till all code uses branch uuid. Remove after 0.17.0
   private static final String SELECT_BRANCH_ID_BY_GUID = "select branch_id from osee_branch where branch_guid = ?";
   // Temporary cache till all code uses branch uuid. Remove after 0.17.0
   private static final ConcurrentHashMap<String, Long> guidToLongCache = new ConcurrentHashMap<String, Long>(50);

   /**
    * Temporary method till all code uses branch uuid. Remove after 0.17.0
    */
   public static long getBranchIdLegacy(String branchGuid) {
      Long longId = guidToLongCache.get(branchGuid);
      if (longId == null) {
         if (branchGuid.equals("-1")) {
            longId = -1L;
         } else {
            longId =
               DatabaseService.getDatabaseService().runPreparedQueryFetchObject(0L, SELECT_BRANCH_ID_BY_GUID,
                  branchGuid);
            Conditions.checkExpressionFailOnTrue(longId <= 0, "Error getting branch_id for branch: [%s]", branchGuid);
         }
         guidToLongCache.putIfAbsent(branchGuid, longId);
      }
      return longId;
   }

}

Back to the top