Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8904c3e37149278c2e6363fa3a99952749bfe315 (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
/*******************************************************************************
 * 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.skynet.core.artifact.search;

import java.util.List;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.services.IdentityService;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.internal.Activator;

/**
 * @author Jeff C. Phillips
 */
public class OrphanArtifactSearch implements ISearchPrimitive {
   private static final String LABEL = "Orphan Search: ";
   private static final String tables = "osee_artifact";
   private static final String sql =
      "art_type_id =? AND art_id NOT in (SELECT t2.art_id FROM osee_relation_link t1, osee_artifact t2, osee_txs t4, (SELECT Max(t1.gamma_id) AS gamma_id, t1.rel_link_id, t2.branch_id FROM osee_relation_link t1, osee_txs t2 WHERE t1.gamma_id = t2.gamma_id AND t2.branch_id = ? GROUP BY t1.rel_link_id, t2.branch_id) t6 WHERE t1.rel_link_type_id =? AND t1.b_art_id = t2.art_id AND t1.gamma_id = t4.gamma_id AND t1.rel_link_id = t6.rel_link_id AND t4.branch_id = t6.branch_id AND t1.gamma_id = t6.gamma_id AND t4.mod_type <> " + ModificationType.DELETED.getValue() + " GROUP BY t2.art_id)";
   private final IArtifactType aritfactType;
   private final int relationTypeId;

   public OrphanArtifactSearch(IArtifactType aritfactType) throws OseeCoreException {
      this.aritfactType = aritfactType;
      this.relationTypeId =
         Activator.getInstance().getIdentityService().getLocalId(CoreRelationTypes.Default_Hierarchical__Child);
   }

   @Override
   public String getCriteriaSql(List<Object> dataList, IOseeBranch branch) throws OseeCoreException {
      IdentityService identityService = Activator.getInstance().getIdentityService();
      dataList.add(identityService.getLocalId(aritfactType));
      dataList.add(BranchManager.getBranchId(branch));
      dataList.add(relationTypeId);

      return sql;
   }

   @Override
   public String getArtIdColName() {
      return "art_id";
   }

   @Override
   public String getTableSql(List<Object> dataList, IOseeBranch branch) {
      return tables;
   }

   @Override
   public String toString() {
      return LABEL + aritfactType.getName();
   }

   public static OrphanArtifactSearch getPrimitive(String storageString) {
      storageString = storageString.replace(LABEL, "");
      if (storageString.endsWith(";")) {
         storageString = storageString.substring(0, storageString.length() - 1);
      }
      OrphanArtifactSearch search = null;
      try {
         ArtifactType artifactType = ArtifactTypeManager.getType(storageString);
         search = new OrphanArtifactSearch(artifactType);
      } catch (OseeCoreException ex) {
         throw new IllegalStateException("Value for " + OrphanArtifactSearch.class.getSimpleName() + " not parsable");
      }
      return search;
   }

   @Override
   public String getStorageString() {
      return LABEL + aritfactType.getName() + ";";
   }
}

Back to the top