Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab3ed71c38938bf1933f39daa8dd9323dadd0c14 (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
/*******************************************************************************
 * 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 org.eclipse.osee.ats.artifact.StateMachineArtifact.TransitionOption;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.ui.plugin.util.Result;

/**
 * Methods in support of programatically transitioning the Decision Review Workflow through it's states. Only to be used
 * for the DefaultReviewWorkflow of Prepare->Decision->ReWork->Complete
 * 
 * @author Donald G. Dunne
 */
public class DecisionReviewWorkflowManager {

   /**
    * Quickly transition to a state with minimal metrics and data entered. Should only be used for automated
    * transitioning for things such as developmental testing and demos.
    * 
    * @param user User to transition to OR null if should use user of current state
    * @return Result
    * @throws Exception
    */
   public static Result transitionTo(DecisionReviewArtifact reviewArt, DecisionReviewArtifact.DecisionReviewState toState, User user, boolean popup, SkynetTransaction transaction) throws OseeCoreException {
      Result result = Result.TrueResult;
      // If in Prepare state, set data and transition to Decision
      if (reviewArt.getStateMgr().getCurrentStateName().equals(
         DecisionReviewArtifact.DecisionReviewState.Prepare.name())) {
         result = setPrepareStateData(reviewArt, 100, 3, .2);

         if (result.isFalse()) {
            if (popup) {
               result.popup();
            }
            return result;
         }
         result =
            reviewArt.transition(DecisionReviewArtifact.DecisionReviewState.Decision.name(),
               (user != null ? user : reviewArt.getStateMgr().getAssignees().iterator().next()), transaction,
               TransitionOption.None);
      }
      if (result.isFalse()) {
         if (popup) {
            result.popup();
         }
         return result;
      }
      if (toState == DecisionReviewArtifact.DecisionReviewState.Decision) {
         return Result.TrueResult;
      }

      // If desired to transition to follow-up, then decision is false
      boolean decision = toState != DecisionReviewArtifact.DecisionReviewState.Followup;

      result = setDecisionStateData(reviewArt, decision, 100, .2);
      if (result.isFalse()) {
         if (popup) {
            result.popup();
         }
         return result;
      }

      result =
         reviewArt.transition(toState.name(),
            (user != null ? user : reviewArt.getStateMgr().getAssignees().iterator().next()), transaction,
            TransitionOption.None);
      if (result.isFalse()) {
         if (popup) {
            result.popup();
         }
         return result;
      }
      return Result.TrueResult;
   }

   public static Result setPrepareStateData(DecisionReviewArtifact reviewArt, int statePercentComplete, double estimateHours, double stateHoursSpent) throws OseeCoreException {
      if (!reviewArt.getStateMgr().getCurrentStateName().equals(
         DecisionReviewArtifact.DecisionReviewState.Prepare.name())) {
         return new Result("Action not in Prepare state");
      }
      reviewArt.setSoleAttributeValue(AtsAttributeTypes.EstimatedHours, estimateHours);
      reviewArt.getStateMgr().updateMetrics(stateHoursSpent, statePercentComplete, true);
      return Result.TrueResult;
   }

   public static Result setDecisionStateData(DecisionReviewArtifact reviewArt, boolean decision, int statePercentComplete, double stateHoursSpent) throws OseeCoreException {
      if (!reviewArt.getStateMgr().getCurrentStateName().equals(
         DecisionReviewArtifact.DecisionReviewState.Decision.name())) {
         return new Result("Action not in Decision state");
      }
      reviewArt.setSoleAttributeValue(AtsAttributeTypes.Decision, decision ? "Yes" : "No");
      reviewArt.getStateMgr().updateMetrics(stateHoursSpent, statePercentComplete, true);
      return Result.TrueResult;
   }

}

Back to the top