Skip to main content
summaryrefslogtreecommitdiffstats
blob: c9e39bc80e0326592f27c6705e112e7d3994da2e (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*******************************************************************************
 * 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 java.util.List;
import java.util.logging.Level;
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.user.IAtsUser;
import org.eclipse.osee.ats.api.util.IAtsChangeSet;
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.log.ILogStorageProvider;
import org.eclipse.osee.ats.api.workflow.transition.ITransitionListener;
import org.eclipse.osee.ats.core.client.internal.Activator;
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.log.ArtifactLog;
import org.eclipse.osee.ats.core.client.workflow.transition.TransitionListeners;
import org.eclipse.osee.framework.access.AccessControlManager;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.util.Conditions;
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.logging.OseeLog;
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 boolean isReadOnly(IAtsWorkItem workItem) {
      boolean readOnly = true;
      try {
         Artifact artifact = AtsClientService.get().getArtifact(workItem);
         readOnly = artifact.isReadOnly();
      } catch (OseeCoreException ex) {
         OseeLog.log(Activator.class, Level.SEVERE, ex);
      }
      return readOnly;
   }

   @Override
   public boolean isAccessControlWrite(IAtsWorkItem workItem) {
      boolean isWrite = false;
      try {
         Artifact artifact = AtsClientService.get().getArtifact(workItem);
         isWrite = AccessControlManager.hasPermission(artifact, PermissionEnum.WRITE);
      } catch (OseeCoreException ex) {
         OseeLog.log(Activator.class, Level.SEVERE, ex);
      }
      return isWrite;
   }

   @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 void transitioned(IAtsWorkItem workItem, IAtsStateDefinition fromState, IAtsStateDefinition toState, List<? extends IAtsUser> updatedAssigees, IAtsChangeSet changes) throws OseeCoreException {
      ((AbstractWorkflowArtifact) workItem).transitioned(fromState, toState, updatedAssigees, changes);
   }

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

   @Override
   public ILogStorageProvider getLogStorageProvider(IAtsWorkItem workItem) {
      return new ArtifactLog(((AbstractWorkflowArtifact) workItem));
   }

}

Back to the top