Skip to main content
summaryrefslogtreecommitdiffstats
blob: 76e789c56b71720e94f96380e4b46c1e030e6347 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.manager.servlet.data;

import org.eclipse.osee.framework.core.enums.BranchArchivedState;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.database.core.ConnectionHandler;

/**
 * @author Roberto E. Escobar
 */
public class ArtifactUtil {

   private static final String DEFAULT_ATTRIBUTE_DATA_PROVIDER = "%DefaultAttributeDataProvider";

   private static String URI_BY_GUID_PREFIX =
      "SELECT attr1.uri FROM osee_artifact art1, osee_attribute attr1, osee_attribute_type attyp1, osee_attribute_provider_type oapt1, %s txs1";

   private static String URI_BY_GUID_AND_BRANCH_ID =
      URI_BY_GUID_PREFIX + " WHERE art1.art_id = attr1.art_id AND attr1.attr_type_id = attyp1.attr_type_id AND oapt1.attr_provider_type_id = attyp1.attr_provider_type_id AND attr1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1 AND art1.guid = ? AND NOT oapt1.attribute_provider_class LIKE ? AND txs1.branch_id = ?";

   private static String URI_BY_GUID_AND_BRANCH_NAME =
      URI_BY_GUID_PREFIX + ", osee_branch ob1 WHERE art1.art_id = attr1.art_id AND attr1.attr_type_id = attyp1.attr_type_id AND oapt1.attr_provider_type_id = attyp1.attr_provider_type_id AND attr1.gamma_id = txs1.gamma_id AND txs1.branch_id = ob1.branch_id AND txs1.tx_current = 1 AND art1.guid = ? AND NOT oapt1.attribute_provider_class LIKE ? AND ob1.branch_name = ?";

   private static String URI_BY_GUID_AND_BRANCH_GUID =
      URI_BY_GUID_PREFIX + ", osee_branch ob1 WHERE art1.art_id = attr1.art_id AND attr1.attr_type_id = attyp1.attr_type_id AND oapt1.attr_provider_type_id = attyp1.attr_provider_type_id AND attr1.gamma_id = txs1.gamma_id AND txs1.branch_id = ob1.branch_id AND txs1.tx_current = 1 AND art1.guid = ? AND NOT oapt1.attribute_provider_class LIKE ? AND ob1.branch_guid = ?";

   public static String getUri(String guid, int branchId) throws OseeDataStoreException {
      BranchArchivedState state = isArchived(branchId);
      return getUri(state, URI_BY_GUID_AND_BRANCH_ID, guid, DEFAULT_ATTRIBUTE_DATA_PROVIDER, branchId);
   }

   public static String getUri(String guid, String branchName) throws OseeDataStoreException {
      BranchArchivedState state = isArchived(branchName);
      return getUri(state, URI_BY_GUID_AND_BRANCH_NAME, guid, DEFAULT_ATTRIBUTE_DATA_PROVIDER, branchName);
   }

   public static String getUriByGuids(String branchGuid, String artifactGuid) throws OseeDataStoreException {
      BranchArchivedState state = isArchivedBranchGuid(branchGuid);
      return getUri(state, URI_BY_GUID_AND_BRANCH_GUID, artifactGuid, DEFAULT_ATTRIBUTE_DATA_PROVIDER, branchGuid);
   }

   private static BranchArchivedState isArchivedBranchGuid(String branchGuid) throws OseeDataStoreException {
      return BranchArchivedState.valueOf(ConnectionHandler.runPreparedQueryFetchInt(0,
         "Select archived from osee_branch where branch_guid = ?", branchGuid));
   }

   private static BranchArchivedState isArchived(int branchId) throws OseeDataStoreException {
      return BranchArchivedState.valueOf(ConnectionHandler.runPreparedQueryFetchInt(0,
         "Select archived from osee_branch where branch_id = ?", branchId));
   }

   private static BranchArchivedState isArchived(String branchName) throws OseeDataStoreException {
      return BranchArchivedState.valueOf(ConnectionHandler.runPreparedQueryFetchInt(0,
         "Select archived from osee_branch where branch_name like ?", branchName));
   }

   private static String getUri(BranchArchivedState state, String query, Object... dataBindings) throws OseeDataStoreException {
      String sql = String.format(query, getTransactionTable(state));
      return ConnectionHandler.runPreparedQueryFetchString("", sql, dataBindings);
   }

   private static String getTransactionTable(BranchArchivedState state) {
      return state.isUnArchived() ? "osee_txs" : "osee_txs_archived";
   }
}

Back to the top