Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7b39cebfc25c5ff7ea6fd24cc81bd4bf4d8f3da9 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.artifact;

import java.util.Date;
import org.eclipse.osee.ats.actions.wizard.ITeamWorkflowProvider;
import org.eclipse.osee.ats.util.TeamState;
import org.eclipse.osee.ats.util.TransitionOption;
import org.eclipse.osee.ats.workflow.TransitionManager;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.ui.plugin.util.Result;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.IWorkPage;

/**
 * Methods in support of programatically transitioning the DefaultWorkFlow through it's states. Only to be used for the
 * DefaultTeamWorkflow of Endorse->Analyze->Auth->Implement->Complete
 * 
 * @author Donald G. Dunne
 */
public class TeamWorkflowManager {

   private final TeamWorkFlowArtifact teamArt;

   public TeamWorkflowManager(TeamWorkFlowArtifact teamArt) {
      this.teamArt = teamArt;
   }

   /**
    * Quickly transition to a state with minimal metrics and data entered. Should only be used for automated transition
    * for things such as developmental testing and demos.
    * 
    * @param user User to transition to OR null if should use user of current state
    */
   public Result transitionTo(TeamState toState, User user, boolean popup, SkynetTransaction transaction) throws OseeCoreException {
      Date date = new Date();
      if (teamArt.isInState(TeamState.Endorse)) {
         Result result = processEndorseState(popup, teamArt, user, date, transaction);
         if (result.isFalse()) {
            return result;
         }
      }
      if (toState == TeamState.Analyze) {
         return Result.TrueResult;
      }

      Result result = processAnalyzeState(popup, teamArt, user, date, transaction);
      if (result.isFalse()) {
         return result;
      }

      if (toState == TeamState.Authorize) {
         return Result.TrueResult;
      }

      result = processAuthorizeState(popup, teamArt, user, date, transaction);
      if (result.isFalse()) {
         return result;
      }

      if (toState == TeamState.Implement) {
         return Result.TrueResult;
      }

      result = transitionToState(popup, teamArt, TeamState.Completed, user, transaction);
      if (result.isFalse()) {
         return result;
      }
      return Result.TrueResult;

   }

   private User getUserOrDefault(User user) throws OseeCoreException {
      if (user == null) {
         return UserManager.getUser();
      }
      return user;
   }

   private Result processAuthorizeState(boolean popup, TeamWorkFlowArtifact teamArt, User user, Date date, SkynetTransaction transaction) throws OseeCoreException {
      Result result = setAuthorizeData(popup, 100, .2, getUserOrDefault(user), date);
      if (result.isFalse()) {
         return result;
      }
      result = transitionToState(popup, teamArt, TeamState.Implement, user, transaction);
      if (result.isFalse()) {
         return result;
      }
      return Result.TrueResult;
   }

   private Result processAnalyzeState(boolean popup, TeamWorkFlowArtifact teamArt, User user, Date date, SkynetTransaction transaction) throws OseeCoreException {
      Result result = setAnalyzeData(popup, null, null, 1, 100, .2, getUserOrDefault(user), date);
      if (result.isFalse()) {
         return result;
      }
      result = transitionToState(popup, teamArt, TeamState.Authorize, user, transaction);
      if (result.isFalse()) {
         return result;
      }
      return Result.TrueResult;
   }

   private Result processEndorseState(boolean popup, TeamWorkFlowArtifact teamArt, User user, Date date, SkynetTransaction transaction) throws OseeCoreException {
      Result result = setEndorseData(popup, null, 100, .2, getUserOrDefault(user), date);
      if (result.isFalse()) {
         return result;
      }
      result = transitionToState(popup, teamArt, TeamState.Analyze, user, transaction);
      if (result.isFalse()) {
         return result;
      }
      return Result.TrueResult;
   }

   private Result transitionToState(boolean popup, TeamWorkFlowArtifact teamArt, IWorkPage toState, User user, SkynetTransaction transaction) throws OseeCoreException {
      TransitionManager transitionMgr = new TransitionManager(teamArt);
      Result result =
         transitionMgr.transition(toState,
            (user == null ? teamArt.getStateMgr().getAssignees().iterator().next() : user), transaction,
            TransitionOption.None);
      if (result.isFalse() && popup) {
         result.popup();
      }
      return result;
   }

   public Result setEndorseData(boolean popup, String propRes, int statePercentComplete, double stateHoursSpent, User user, Date date) throws OseeCoreException {
      if (!teamArt.isInState(TeamState.Endorse)) {
         Result result = new Result("Action not in Endorse state");
         if (result.isFalse() && popup) {
            result.popup();
            return result;
         }
      }
      teamArt.getStateMgr().setMetrics(TeamState.Endorse, stateHoursSpent, statePercentComplete, true, user, date);
      return Result.TrueResult;
   }

   public Result setAnalyzeData(boolean popup, String problem, String propRes, double hourEstimate, int statePercentComplete, double stateHoursSpent, User user, Date date) throws OseeCoreException {
      if (!teamArt.isInState(TeamState.Analyze)) {
         Result result = new Result("Action not in Analyze state");
         if (result.isFalse() && popup) {
            result.popup();
            return result;
         }
      }
      teamArt.setSoleAttributeValue(AtsAttributeTypes.EstimatedHours, hourEstimate);
      teamArt.getStateMgr().setMetrics(TeamState.Analyze, stateHoursSpent, statePercentComplete, true, user, date);
      return Result.TrueResult;
   }

   public Result setAuthorizeData(boolean popup, int statePercentComplete, double stateHoursSpent, User user, Date date) throws OseeCoreException {
      if (!teamArt.isInState(TeamState.Authorize)) {
         Result result = new Result("Action not in Authorize state");
         if (result.isFalse() && popup) {
            result.popup();
            return result;
         }
      }
      teamArt.getStateMgr().setMetrics(TeamState.Authorize, stateHoursSpent, statePercentComplete, true, user, date);
      return Result.TrueResult;
   }

   public Result setImplementData(boolean popup, String resolution, int statePercentComplete, double stateHoursSpent, User user, Date date) throws OseeCoreException {
      if (!teamArt.isInState(TeamState.Implement)) {
         Result result = new Result("Action not in Implement state");
         if (result.isFalse() && popup) {
            result.popup();
            return result;
         }
      }
      teamArt.getStateMgr().setMetrics(TeamState.Implement, stateHoursSpent, statePercentComplete, true, user, date);
      return Result.TrueResult;
   }

   /**
    * Assigned or computed Id that will show at the top of the editor
    */
   public static String getPcrId(AbstractWorkflowArtifact awa) throws OseeCoreException {
      TeamWorkFlowArtifact teamArt = awa.getParentTeamWorkflow();
      for (ITeamWorkflowProvider atsTeamWorkflow : TeamWorkflowProviders.getAtsTeamWorkflowExtensions()) {
         String pcrId = atsTeamWorkflow.getPcrId(teamArt);
         if (Strings.isValid(pcrId)) {
            return pcrId;
         }
      }
      if (teamArt != null) {
         return teamArt.getTeamName() + " " + awa.getHumanReadableId();
      }
      return "";
   }

   public static String getArtifactTypeShortName(TeamWorkFlowArtifact teamArt) {
      for (ITeamWorkflowProvider atsTeamWorkflow : TeamWorkflowProviders.getAtsTeamWorkflowExtensions()) {
         String typeName = atsTeamWorkflow.getArtifactTypeShortName(teamArt);
         if (Strings.isValid(typeName)) {
            return typeName;
         }
      }
      return null;
   }

}

Back to the top