Skip to main content
summaryrefslogtreecommitdiffstats
blob: 68674a0f5240f8226e4090d51f42b2ca8ae6fb21 (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
package org.eclipse.osee.ats.core.util;

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.IStateToken;
import org.eclipse.osee.ats.api.workdef.StateType;
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.core.AtsCore;
import org.eclipse.osee.ats.core.workflow.state.SimpleTeamState;
import org.eclipse.osee.framework.core.exception.OseeCoreException;

/**
 * @author Donald G. Dunne
 */
public class HoursSpentUtil {

   /**
    * Return hours spent working states, reviews and tasks (not children SMAs)
    */
   public static double getHoursSpentTotal(IAtsObject atsObject) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsAction) {
         for (IAtsTeamWorkflow team : AtsCore.getWorkItemService().getTeams((IAtsAction) atsObject)) {
            if (!AtsCore.getWorkItemService().getWorkData(team).isCancelled()) {
               hours += getHoursSpentTotal(team);
            }
         }
      } else if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         hours = getHoursSpentTotal(workItem, AtsCore.getWorkItemService().getCurrentState(workItem));
      }
      return hours;
   }

   /**
    * Return hours spent working all states, reviews and tasks (not children SMAs)
    */
   public static double getHoursSpentTotal(IAtsObject atsObject, IStateToken state) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         for (String stateName : workItem.getStateMgr().getVisitedStateNames()) {
            hours += getHoursSpentStateTotal(workItem, new SimpleTeamState(stateName, StateType.Working));
         }
      }
      return hours;
   }

   /**
    * Return hours spent working SMA state, state tasks and state reviews (not children SMAs)
    */
   public static double getHoursSpentStateTotal(IAtsObject atsObject) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsAction) {
         for (IAtsTeamWorkflow team : AtsCore.getWorkItemService().getTeams((IAtsAction) atsObject)) {
            if (!AtsCore.getWorkItemService().getWorkData(team).isCancelled()) {
               hours += getHoursSpentStateTotal(team);
            }
         }
      } else if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         hours = getHoursSpentStateTotal(workItem, AtsCore.getWorkItemService().getCurrentState(workItem));
      }
      return hours;
   }

   /**
    * Return hours spent working SMA state, state tasks and state reviews (not children SMAs)
    */
   public static double getHoursSpentStateTotal(IAtsObject atsObject, IStateToken state) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         hours =
            getHoursSpentSMAState(workItem, state) + getHoursSpentFromStateTasks(workItem, state) + getHoursSpentStateReview(
               workItem, state);
      }
      return hours;
   }

   /**
    * Return hours spent working ONLY the SMA stateName (not children SMAs)
    */
   public static double getHoursSpentStateReview(IAtsObject atsObject) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsAction) {
         for (IAtsTeamWorkflow team : AtsCore.getWorkItemService().getTeams((IAtsAction) atsObject)) {
            if (!AtsCore.getWorkItemService().getWorkData(team).isCancelled()) {
               hours += getHoursSpentStateReview(team);
            }
         }
      } else if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         hours = getHoursSpentStateReview(workItem, AtsCore.getWorkItemService().getCurrentState(workItem));
      }
      return hours;
   }

   /**
    * Return hours spent working ONLY the SMA stateName (not children SMAs)
    */
   public static double getHoursSpentStateReview(IAtsObject atsObject, IStateToken state) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsTeamWorkflow) {
         for (IAtsAbstractReview review : AtsCore.getWorkItemService().getReviews((IAtsTeamWorkflow) atsObject, state)) {
            hours += review.getStateMgr().getHoursSpent(state.getName());
         }
      }
      return hours;
   }

   /**
    * Return hours spent working ONLY the SMA stateName (not children SMAs)
    */
   public static double getHoursSpentSMAState(IAtsObject atsObject) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsAction) {
         for (IAtsTeamWorkflow team : AtsCore.getWorkItemService().getTeams((IAtsAction) atsObject)) {
            if (!AtsCore.getWorkItemService().getWorkData(team).isCancelled()) {
               hours += getHoursSpentSMAState(team);
            }
         }
      } else if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         hours = getHoursSpentSMAState(workItem, AtsCore.getWorkItemService().getCurrentState(workItem));
      }
      return hours;
   }

   /**
    * Return hours spent working ONLY the SMA stateName (not children SMAs)
    */
   public static double getHoursSpentSMAState(IAtsObject atsObject, IStateToken state) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         hours = workItem.getStateMgr().getHoursSpent(state.getName());
      }
      return hours;
   }

   /**
    * Return hours spent working ONLY on tasks related to stateName
    */
   public static double getHoursSpentFromStateTasks(IAtsObject atsObject) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsAction) {
         for (IAtsTeamWorkflow team : AtsCore.getWorkItemService().getTeams((IAtsAction) atsObject)) {
            if (!AtsCore.getWorkItemService().getWorkData(team).isCancelled()) {
               hours += getHoursSpentFromStateTasks(team);
            }
         }
      } else if (atsObject instanceof IAtsWorkItem) {
         IAtsWorkItem workItem = (IAtsWorkItem) atsObject;
         hours = getHoursSpentFromStateTasks(workItem, AtsCore.getWorkItemService().getCurrentState(workItem));
      }
      return hours;
   }

   /**
    * Return Hours Spent for Tasks of "Related to State" stateName
    * 
    * @param relatedToState state name of parent workflow's state
    * @return Returns the Hours Spent
    */
   public static double getHoursSpentFromStateTasks(IAtsObject atsObject, IStateToken relatedToState) throws OseeCoreException {
      double hours = 0.0;
      if (atsObject instanceof IAtsTeamWorkflow) {
         for (IAtsTask taskArt : AtsCore.getWorkItemService().getTasks((IAtsTeamWorkflow) atsObject,
            relatedToState)) {
            hours += HoursSpentUtil.getHoursSpentTotal(taskArt);
         }
      }
      return hours;
   }

}

Back to the top