Skip to main content
summaryrefslogtreecommitdiffstats
blob: d9f25154ed4444bbc3b97a2323851f91e249522f (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
/*******************************************************************************
 * Copyright (c) 2017 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.core.util;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.ats.api.IAtsServices;
import org.eclipse.osee.ats.api.ai.IAtsActionableItem;
import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
import org.eclipse.osee.ats.api.team.IAtsTeamDefinition;
import org.eclipse.osee.ats.api.util.IAtsChangeSet;
import org.eclipse.osee.ats.api.workflow.IAttribute;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.ArtifactToken;
import org.eclipse.osee.framework.core.data.AttributeTypeToken;
import org.eclipse.osee.framework.jdk.core.util.Strings;

/**
 * @author Donald G. Dunne
 */
public class ConvertAtsConfigGuidAttributesOperations {

   public static final AttributeTypeToken TeamDefinition =
      AtsAttributeTypes.createType(1152921504606847201L, "Team Definition");
   public static final AttributeTypeToken ActionableItem = AtsAttributeTypes.createType(1152921504606847200L,
      "Actionable Item", "Actionable Items that are impacted by this change.");

   public static void convertActionableItemsIfNeeded(IAtsChangeSet changes, ArtifactToken art, IAtsServices services) {
      // convert guids to id
      Collection<ArtifactId> currentAiRefIds =
         services.getAttributeResolver().getAttributeValues(art, AtsAttributeTypes.ActionableItemReference);

      List<ArtifactId> neededAiRefIds = new LinkedList<>();
      for (IAttribute<?> attr : services.getAttributeResolver().getAttributes(art, ActionableItem)) {
         String aiArtGuid = (String) attr.getValue();
         IAtsActionableItem ai = services.getConfigItem(aiArtGuid);
         if (ai == null) {
            services.getLogger().error("AI not found for aiArtGuid " + aiArtGuid + " for art " + art.toStringWithId());
         } else if (!currentAiRefIds.contains(ai.getId())) {
            neededAiRefIds.add(ai.getStoreObject());
         }
      }

      for (ArtifactId need : neededAiRefIds) {
         changes.addArtifactReferencedAttribute(art, AtsAttributeTypes.ActionableItemReference, need);
      }

      // convert id to guid
      Collection<IAttribute<Object>> aiGuidAttrs = services.getAttributeResolver().getAttributes(art, ActionableItem);
      List<String> currentAiGuidIds = new LinkedList<>();
      for (IAttribute<Object> aiRefAttr : aiGuidAttrs) {
         currentAiGuidIds.add(aiRefAttr.getValue().toString());
      }

      List<String> neededAiGuidIds = new LinkedList<>();
      Collection<Object> aiArts =
         services.getAttributeResolver().getAttributeValues(art, AtsAttributeTypes.ActionableItemReference);
      for (Object obj : aiArts) {
         IAtsActionableItem ai = null;
         if (obj instanceof ArtifactId) {
            ai = services.getConfigItem((ArtifactId) obj);
         } else {
            ai = services.getConfigItem(Long.valueOf((String) obj));
         }
         if (ai == null) {
            services.getLogger().error("AI not found for id " + obj + " for art " + art.toStringWithId());
         } else if (!currentAiGuidIds.contains(ai.getStoreObject().getGuid())) {
            neededAiGuidIds.add(ai.getStoreObject().getGuid());
         }
      }

      for (String guid : neededAiGuidIds) {
         changes.addAttribute(art, ActionableItem, guid);
      }
   }

   public static void convertTeamDefinitionIfNeeded(IAtsChangeSet changes, ArtifactToken art, IAtsServices services) {
      // convert guid to id
      String teamDefId = services.getAttributeResolver().getSoleAttributeValueAsString(art,
         AtsAttributeTypes.TeamDefinitionReference, null);
      if (!Strings.isNumeric(teamDefId)) {
         String teamDefGuid = services.getAttributeResolver().getSoleAttributeValue(art, TeamDefinition, "");
         if (Strings.isValid(teamDefGuid)) {
            IAtsTeamDefinition teamDef = services.getConfigItem(teamDefGuid);
            changes.addArtifactReferencedAttribute(art, AtsAttributeTypes.TeamDefinitionReference,
               teamDef.getStoreObject());
         }
      }
      // convert id to guid
      String teamDefGuid = services.getAttributeResolver().getSoleAttributeValue(art, TeamDefinition, "");
      if (!Strings.isValid(teamDefGuid)) {
         teamDefId = services.getAttributeResolver().getSoleAttributeValueAsString(art,
            AtsAttributeTypes.TeamDefinitionReference, null);
         if (Strings.isNumeric(teamDefId)) {
            ArtifactId artifact = services.getArtifact(Long.valueOf(teamDefId));
            if (artifact != null) {
               changes.setSoleAttributeValue(art, TeamDefinition, artifact.getGuid());
            }
         }
      }
   }

}

Back to the top