Skip to main content
summaryrefslogtreecommitdiffstats
blob: d17b41050abd4c984f6099e5146920ea3cc08fe3 (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
/*******************************************************************************
 * Copyright (c) 2013 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.ats.impl.internal.workdef;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.ats.api.data.AtsArtifactToken;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinitionStore;
import org.eclipse.osee.ats.core.util.AtsUtilCore;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.QueryOption;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.data.ArtifactReadable;

/**
 * @author Donald G. Dunne
 */
public class AtsWorkDefinitionStoreImpl implements IAtsWorkDefinitionStore {

   private static OrcsApi orcsApi;

   public static void setOrcsApi(OrcsApi orcsApi) {
      AtsWorkDefinitionStoreImpl.orcsApi = orcsApi;
   }

   public void start() throws OseeCoreException {
      Conditions.checkNotNull(orcsApi, "OrcsApi");
      System.out.println("ATS - AtsWorkDefinitionStoreImpl started");
   }

   @Override
   public List<Pair<String, String>> getWorkDefinitionStrings() throws OseeCoreException {
      List<Pair<String, String>> nameToWorkDefStr = new ArrayList<Pair<String, String>>(15);
      for (ArtifactReadable workDefArt : orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andTypeEquals(
         AtsArtifactTypes.WorkDefinition).getResults()) {
         nameToWorkDefStr.add(
            new Pair<String, String>(workDefArt.getName(), loadWorkDefinitionFromArtifact(workDefArt)));
      }
      return nameToWorkDefStr;
   }

   @Override
   public String loadWorkDefinitionString(String workDefId) throws OseeCoreException {
      return loadWorkDefinitionFromArtifact(workDefId);
   }

   @Override
   public boolean isWorkDefinitionExists(String workDefId) throws OseeCoreException {
      return loadWorkDefinitionString(workDefId) != null;
   }

   private String loadWorkDefinitionFromArtifact(String name) throws OseeCoreException {
      ArtifactReadable artifact = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andTypeEquals(
         AtsArtifactTypes.WorkDefinition).and(CoreAttributeTypes.Name, name,
            QueryOption.EXACT_MATCH_OPTIONS).getResults().getExactlyOne();
      return loadWorkDefinitionFromArtifact(artifact);
   }

   private String loadWorkDefinitionFromArtifact(ArtifactReadable artifact) throws OseeCoreException {
      String modelText = null;
      if (artifact != null) {
         modelText = artifact.getSoleAttributeAsString(AtsAttributeTypes.DslSheet);
      }
      return modelText;
   }

   @SuppressWarnings("unchecked")
   @Override
   public String loadRuleDefinitionString() throws OseeCoreException {
      ArtifactReadable artifact = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIds(
         AtsArtifactToken.RuleDefinitions).getResults().getOneOrNull();
      if (artifact != null) {
         return artifact.getSoleAttributeValue(AtsAttributeTypes.DslSheet, null);
      } else {
         return null;
      }
   };

}

Back to the top