Skip to main content
summaryrefslogtreecommitdiffstats
blob: e6198b8bcad59aabd2badcca64bd4dedfd806c52 (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
/*******************************************************************************
 * 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.workflow.item;

import java.util.Arrays;
import java.util.Collection;
import java.util.logging.Level;
import org.eclipse.osee.ats.artifact.ATSLog.LogType;
import org.eclipse.osee.ats.artifact.DecisionReviewArtifact;
import org.eclipse.osee.ats.artifact.ReviewSMArtifact.ReviewBlockType;
import org.eclipse.osee.ats.artifact.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.internal.AtsPlugin;
import org.eclipse.osee.ats.util.widgets.ReviewManager;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
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.skynet.core.utility.Artifacts;
import org.eclipse.osee.framework.skynet.core.utility.UsersByIds;
import org.eclipse.osee.framework.ui.skynet.widgets.workflow.WorkRuleDefinition;

/**
 * @author Donald G. Dunne
 */
public class AtsAddDecisionReviewRule extends WorkRuleDefinition {

   public static String ID = "atsAddDecisionReview";
   public static enum DecisionParameter {
      title,
      forState,
      forEvent,
      reviewBlockingType,
      assignees,
      options,
      description
   };

   public static enum DecisionRuleOption {
      None,
      TransitionToDecision
   }

   public AtsAddDecisionReviewRule() {
      this(ID, ID);
   }

   public AtsAddDecisionReviewRule(String name, String id) {
      super(name, id);
      setDescription("Work Page and Team Definition Option: Decision Review will be auto-created based on WorkData attribute values.");
      setDecisionParameterValue(this, DecisionParameter.title, "Enter Title Here");
      setDecisionParameterValue(this, DecisionParameter.reviewBlockingType, "Transition");
      setDecisionParameterValue(this, DecisionParameter.forState, "Implement");
      setDecisionParameterValue(this, DecisionParameter.forEvent, StateEventType.TransitionTo.name());
      try {
         setDecisionParameterValue(this, DecisionParameter.assignees, "<99999997>");
         setDecisionParameterValue(this, DecisionParameter.options, "Completed;Completed;");
      } catch (Exception ex) {
         OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
      }
   }

   public static void setDecisionParameterValue(WorkRuleDefinition workRuleDefinition, DecisionParameter decisionParameter, String value) {
      workRuleDefinition.addWorkDataKeyValue(decisionParameter.name(), value);
   }

   public static String getDecisionParameterValue(WorkRuleDefinition workRuleDefinition, DecisionParameter decisionParameter) {
      return workRuleDefinition.getWorkDataValue(decisionParameter.name());
   }

   /**
    * Creates decision review if one of same name doesn't already exist
    * 
    * @param atsAddDecisionReviewRule
    * @param sma
    * @return DecisionReviewArtifact
    * @throws OseeCoreException
    */
   public static DecisionReviewArtifact createNewDecisionReview(WorkRuleDefinition atsAddDecisionReviewRule, SkynetTransaction transaction, TeamWorkFlowArtifact teamArt, DecisionRuleOption... decisionRuleOption) throws OseeCoreException {
      if (!atsAddDecisionReviewRule.getId().startsWith(AtsAddDecisionReviewRule.ID)) {
         throw new OseeArgumentException("WorkRuleDefinition must be AtsAddDecisionReviewRule.ID");
      }
      String title = getValueOrDefault(teamArt, atsAddDecisionReviewRule, DecisionParameter.title);
      if (Artifacts.artNames(ReviewManager.getReviews(teamArt)).contains(title)) {
         // Already created this review
         return null;
      }
      DecisionReviewArtifact decArt = null;
      if (Collections.getAggregate(decisionRuleOption).contains(DecisionRuleOption.TransitionToDecision)) {
         decArt =
            ReviewManager.createNewDecisionReviewAndTransitionToDecision(teamArt, title,
               getValueOrDefault(teamArt, atsAddDecisionReviewRule, DecisionParameter.description),
               getValueOrDefault(teamArt, atsAddDecisionReviewRule, DecisionParameter.forState),
               getReviewBlockTypeOrDefault(teamArt, atsAddDecisionReviewRule),
               getValueOrDefault(teamArt, atsAddDecisionReviewRule, DecisionParameter.options),
               getAssigneesOrDefault(teamArt, atsAddDecisionReviewRule), transaction);
      } else {
         decArt =
            ReviewManager.createNewDecisionReview(teamArt, title,
               getValueOrDefault(teamArt, atsAddDecisionReviewRule, DecisionParameter.description),
               getValueOrDefault(teamArt, atsAddDecisionReviewRule, DecisionParameter.forState),
               getReviewBlockTypeOrDefault(teamArt, atsAddDecisionReviewRule),
               getValueOrDefault(teamArt, atsAddDecisionReviewRule, DecisionParameter.options),
               getAssigneesOrDefault(teamArt, atsAddDecisionReviewRule), transaction);
      }

      decArt.getLog().addLog(LogType.Note, null, "Review auto-generated off rule " + atsAddDecisionReviewRule.getId());
      return decArt;
   }

   public static ReviewBlockType getReviewBlockTypeOrDefault(TeamWorkFlowArtifact teamArt, WorkRuleDefinition workRuleDefinition) {
      String value = getDecisionParameterValue(workRuleDefinition, DecisionParameter.reviewBlockingType);
      if (!Strings.isValid(value)) {
         return null;
      }
      return ReviewBlockType.valueOf(value);
   }

   public static StateEventType getStateEventType(TeamWorkFlowArtifact teamArt, WorkRuleDefinition workRuleDefinition) {
      String value = getDecisionParameterValue(workRuleDefinition, DecisionParameter.forEvent);
      if (!Strings.isValid(value)) {
         return null;
      }
      return StateEventType.valueOf(value);
   }

   private static String getValueOrDefault(TeamWorkFlowArtifact teamArt, WorkRuleDefinition workRuleDefinition, DecisionParameter decisionParameter) throws OseeCoreException {
      String value = getDecisionParameterValue(workRuleDefinition, decisionParameter);
      if (!Strings.isValid(value)) {
         if (decisionParameter == DecisionParameter.title) {
            return "Decide on \"" + teamArt.getName() + "\"";
         } else if (decisionParameter == DecisionParameter.options) {
            return "Yes;Followup;<" + UserManager.getUser().getUserId() + ">\n" + "No;Completed;";
         } else if (decisionParameter == DecisionParameter.description) {
            return null;
         } else if (decisionParameter == DecisionParameter.forState) {
            return teamArt.getStateMgr().getCurrentStateName();
         }
      }
      return value;
   }

   public static Collection<User> getAssigneesOrDefault(TeamWorkFlowArtifact teamArt, WorkRuleDefinition workRuleDefinition) throws OseeCoreException {
      String value = getDecisionParameterValue(workRuleDefinition, DecisionParameter.assignees);
      if (!Strings.isValid(value)) {
         return Arrays.asList(new User[] {UserManager.getUser()});
      }
      Collection<User> users = UsersByIds.getUsers(value);
      if (users.isEmpty()) {
         users.add(UserManager.getUser());
      }
      return users;
   }
}

Back to the top