Skip to main content
summaryrefslogtreecommitdiffstats
blob: b1c805762281fb8df64130f748bb19db8b9617a1 (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
/*
 * Created on Jun 4, 2012
 *
 * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
 */
package org.eclipse.osee.ats.core.config;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.osee.ats.core.model.IAtsActionableItem;
import org.eclipse.osee.ats.core.model.IAtsConfigObject;
import org.eclipse.osee.ats.core.model.IAtsTeamDefinition;
import org.eclipse.osee.framework.core.enums.Active;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Collections;

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

   private static String TopActionableItemGuid = "AAABER+37QEA8O7WSQaqJQ";

   public static Collection<String> getNames(Collection<? extends IAtsActionableItem> aias) {
      ArrayList<String> names = new ArrayList<String>();
      for (IAtsActionableItem named : aias) {
         names.add(named.getName());
      }
      return names;
   }

   public static List<String> toGuids(Collection<? extends IAtsActionableItem> aias) {
      List<String> guids = new ArrayList<String>(aias.size());
      for (IAtsActionableItem artifact : aias) {
         guids.add(artifact.getGuid());
      }
      return guids;
   }

   /**
    * Recurses default hierarchy and collections children of parentArtifact that are of type class
    */
   @SuppressWarnings("unchecked")
   public static <A extends IAtsActionableItem> void getChildrenOfType(IAtsActionableItem parentArtifact, Collection<A> children, Class<A> clazz, boolean recurse) throws OseeCoreException {
      for (IAtsActionableItem child : parentArtifact.getChildrenActionableItems()) {
         if (child.getClass().equals(clazz)) {
            children.add((A) child);
            if (recurse) {
               getChildrenOfType(child, children, clazz, recurse);
            }
         }
      }
   }

   public static Set<IAtsActionableItem> getAIsFromItemAndChildren(IAtsActionableItem aia) throws OseeCoreException {
      Set<IAtsActionableItem> aias = new HashSet<IAtsActionableItem>();
      aias.add(aia);
      for (IAtsActionableItem art : aia.getChildrenActionableItems()) {
         aias.addAll(getAIsFromItemAndChildren(art));
      }
      return aias;
   }

   public static Set<IAtsTeamDefinition> getTeamsFromItemAndChildren(IAtsActionableItem aia) throws OseeCoreException {
      return TeamDefinitions.getTeamsFromItemAndChildren(aia);
   }

   public static Set<IAtsActionableItem> getActionableItemsFromItemAndChildren(IAtsActionableItem aia) throws OseeCoreException {
      Set<IAtsActionableItem> aias = new HashSet<IAtsActionableItem>();
      getActionableItemsFromItemAndChildren(aia, aias);
      return aias;
   }

   public static void getActionableItemsFromItemAndChildren(IAtsActionableItem aia, Set<IAtsActionableItem> aiaTeams) throws OseeCoreException {
      for (IAtsActionableItem art : aia.getChildrenActionableItems()) {
         aiaTeams.add(art);
         for (IAtsActionableItem childArt : aia.getChildrenActionableItems()) {
            getActionableItemsFromItemAndChildren(childArt, aiaTeams);
         }
      }
   }

   public static Set<IAtsActionableItem> getActionableItems(Collection<String> actionableItemNames) {
      Set<IAtsActionableItem> aias = new HashSet<IAtsActionableItem>();
      for (String actionableItemName : actionableItemNames) {
         for (IAtsActionableItem aia : AtsConfigCache.get(IAtsActionableItem.class)) {
            if (aia.getName().equals(actionableItemName)) {
               aias.add(aia);
            }
         }
      }
      return aias;
   }

   public static Collection<IAtsTeamDefinition> getImpactedTeamDefs(Collection<IAtsActionableItem> aias) throws OseeCoreException {
      return TeamDefinitions.getImpactedTeamDefs(aias);
   }

   public static List<IAtsActionableItem> getActionableItems(Active active) {
      return Collections.castAll(getActive(AtsConfigCache.get(IAtsActionableItem.class), active));
   }

   public static String getNotActionableItemError(IAtsConfigObject configObject) {
      return "Action can not be written against " + configObject.getName() + " \"" + configObject + "\" (" + configObject.getHumanReadableId() + ").\n\nChoose another item.";
   }

   public static IAtsActionableItem getTopActionableItem() {
      return AtsConfigCache.getSoleByGuid(TopActionableItemGuid, IAtsActionableItem.class);
   }

   public static List<IAtsActionableItem> getActionableItemsAll() {
      return getActionableItems(Active.Both);
   }

   public static List<IAtsActionableItem> getTopLevelActionableItems(Active active) throws OseeCoreException {
      IAtsActionableItem topAi = getTopActionableItem();
      if (topAi == null) {
         return java.util.Collections.emptyList();
      }
      return Collections.castAll(getActive(getChildren(topAi, false), active));
   }

   public static List<IAtsActionableItem> getActive(Collection<IAtsActionableItem> teamDefs, Active active) {
      List<IAtsActionableItem> results = new ArrayList<IAtsActionableItem>();
      for (IAtsActionableItem aia : teamDefs) {
         if (active == Active.Both) {
            results.add(aia);
         } else {
            // assume active unless otherwise specified
            boolean attributeActive = aia.isActive();
            if (active == Active.Active && attributeActive) {
               results.add(aia);
            } else if (active == Active.InActive && !attributeActive) {
               results.add(aia);
            }
         }
      }
      return results;
   }

   public static Set<IAtsActionableItem> getChildren(IAtsActionableItem topActionableItem, boolean recurse) throws OseeCoreException {
      Set<IAtsActionableItem> children = new HashSet<IAtsActionableItem>();
      for (IAtsActionableItem child : topActionableItem.getChildrenActionableItems()) {
         children.add(child);
         if (recurse) {
            children.addAll(getChildren(child, recurse));
         }
      }
      return children;
   }

}

Back to the top