Skip to main content
summaryrefslogtreecommitdiffstats
blob: bf33efcee455e5a7d4773160917520763c5b1c31 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*******************************************************************************
 * 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.core.client.internal.workflow;

import java.util.Collection;
import org.eclipse.osee.ats.api.IAtsObject;
import org.eclipse.osee.ats.api.IAtsWorkItem;
import org.eclipse.osee.ats.api.review.IAtsAbstractReview;
import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition;
import org.eclipse.osee.ats.api.workdef.IStateToken;
import org.eclipse.osee.ats.api.workdef.WidgetResult;
import org.eclipse.osee.ats.api.workflow.IAtsAction;
import org.eclipse.osee.ats.api.workflow.IAtsTask;
import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow;
import org.eclipse.osee.ats.api.workflow.IAtsWorkData;
import org.eclipse.osee.ats.api.workflow.IAtsWorkItemService;
import org.eclipse.osee.ats.api.workflow.transition.ITransitionListener;
import org.eclipse.osee.ats.core.client.internal.AtsClientService;
import org.eclipse.osee.ats.core.client.internal.IAtsWorkItemArtifactService;
import org.eclipse.osee.ats.core.client.review.ReviewManager;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.core.client.validator.AtsXWidgetValidateManagerClient;
import org.eclipse.osee.ats.core.client.workflow.AbstractWorkflowArtifact;
import org.eclipse.osee.ats.core.client.workflow.AtsWorkData;
import org.eclipse.osee.ats.core.client.workflow.transition.TransitionListeners;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.attribute.AttributeTypeManager;

/**
 * @author Donald G. Dunne
 */
public class AtsWorkItemServiceImpl implements IAtsWorkItemService {

   private final IAtsWorkItemArtifactService workItemArtifactProvider;

   public AtsWorkItemServiceImpl(IAtsWorkItemArtifactService workItemArtifactProvider) {
      this.workItemArtifactProvider = workItemArtifactProvider;
   }

   @Override
   public IAtsWorkData getWorkData(IAtsWorkItem workItem) throws OseeCoreException {
      return new AtsWorkData((AbstractWorkflowArtifact) workItemArtifactProvider.get(workItem));
   }

   @Override
   public IArtifactType getArtifactType(IAtsWorkItem workItem) throws OseeCoreException {
      return workItemArtifactProvider.get(workItem).getArtifactType();
   }

   @Override
   public Collection<Object> getAttributeValues(IAtsObject workItem, IAttributeType attributeType) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(workItem);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", workItem.toString());

      IAttributeType attrType = AttributeTypeManager.getType(attributeType);
      if (attrType == null) {
         throw new OseeArgumentException(String.format("Can't resolve Attribute Type [%s]", attributeType));
      }

      return artifact.getAttributeValues(attributeType);
   }

   @Override
   public boolean isOfType(IAtsWorkItem workItem, IArtifactType matchType) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(workItem);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", workItem.toString());
      return artifact.isOfType(matchType);
   }

   @Override
   public IAtsTeamWorkflow getParentTeamWorkflow(IAtsWorkItem workItem) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(workItem);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", workItem.toString());
      if (artifact instanceof AbstractWorkflowArtifact) {
         AbstractWorkflowArtifact awa = (AbstractWorkflowArtifact) artifact;
         return awa.getParentTeamWorkflow();
      }
      return null;
   }

   @Override
   public int getTransactionNumber(IAtsWorkItem workItem) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(workItem);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", workItem.toString());
      return artifact.getTransactionNumber();
   }

   @Override
   public Collection<IAtsTeamWorkflow> getTeams(IAtsAction action) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(action);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", action.toString());
      return action.getTeamWorkflows();
   }

   @Override
   public IStateToken getCurrentState(IAtsWorkItem workItem) throws OseeCoreException {
      IStateToken state = null;
      Artifact artifact = workItemArtifactProvider.get(workItem);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", workItem.toString());
      if (artifact instanceof AbstractWorkflowArtifact) {
         AbstractWorkflowArtifact awa = (AbstractWorkflowArtifact) artifact;
         state = awa.getStateDefinitionByName(awa.getCurrentStateName());
      }
      return state;
   }

   @Override
   public Collection<IAtsTask> getTasks(IAtsTeamWorkflow atsObject, IStateToken relatedToState) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(atsObject);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", atsObject.toString());
      return Collections.castAll(((TeamWorkFlowArtifact) atsObject).getTaskArtifacts());
   }

   @Override
   public Collection<IAtsAbstractReview> getReviews(IAtsTeamWorkflow atsObject) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(atsObject);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", atsObject.toString());
      return Collections.castAll(ReviewManager.getReviews((TeamWorkFlowArtifact) atsObject));
   }

   @Override
   public Collection<IAtsAbstractReview> getReviews(IAtsTeamWorkflow atsObject, IStateToken state) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(atsObject);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", atsObject.toString());
      return Collections.castAll(ReviewManager.getReviews((TeamWorkFlowArtifact) atsObject, state));
   }

   @Override
   public Collection<IAtsTask> getTasks(IAtsTeamWorkflow iAtsTeamWorkflow) throws OseeCoreException {
      Artifact artifact = workItemArtifactProvider.get(iAtsTeamWorkflow);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", iAtsTeamWorkflow.toString());
      return Collections.castAll(((TeamWorkFlowArtifact) iAtsTeamWorkflow).getTaskArtifacts());
   }

   @Override
   public IAtsTeamWorkflow getFirstTeam(IAtsAction action) throws OseeCoreException {
      IAtsTeamWorkflow firstTeam = null;
      Artifact artifact = workItemArtifactProvider.get(action);
      Conditions.checkNotNull(artifact, "workItem", "Can't Find Artifact matching [%s]", action.toString());
      Collection<IAtsTeamWorkflow> teamWorkflows = action.getTeamWorkflows();
      if (!teamWorkflows.isEmpty()) {
         firstTeam = teamWorkflows.iterator().next();
      }
      return firstTeam;
   }

   public IAtsWorkItemArtifactService getWorkItemArtifactProvider() {
      return workItemArtifactProvider;
   }

   @Override
   public String getCurrentStateName(IAtsWorkItem workItem) {
      return ((AbstractWorkflowArtifact) workItem).getCurrentStateName();
   }

   @Override
   public void clearImplementersCache(IAtsWorkItem workItem) {
      ((AbstractWorkflowArtifact) workItem).clearImplementersCache();
   }

   @Override
   public Collection<WidgetResult> validateWidgetTransition(IAtsWorkItem workItem, IAtsStateDefinition toStateDef) throws OseeStateException {
      return AtsXWidgetValidateManagerClient.instance.validateTransition((AbstractWorkflowArtifact) workItem,
         toStateDef);
   }

   @Override
   public Collection<IAtsTask> getTaskArtifacts(IAtsWorkItem workItem) throws OseeCoreException {
      if (workItem.isTeamWorkflow()) {
         return Collections.castAll(((TeamWorkFlowArtifact) workItem).getTaskArtifacts());
      }
      return java.util.Collections.emptyList();
   }

   @Override
   public Collection<ITransitionListener> getTransitionListeners() {
      return TransitionListeners.getListeners();
   }

   @Override
   public String getTargetedVersionStr(IAtsTeamWorkflow teamWf) throws OseeCoreException {
      return AtsClientService.get().getAtsVersionService().getTargetedVersion(teamWf).getName();
   }

}

Back to the top