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
|
/*******************************************************************************
* 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.util.widgets;
import java.util.Date;
import java.util.Set;
import org.eclipse.osee.ats.artifact.ATSLog.LogType;
import org.eclipse.osee.ats.artifact.AtsAttributeTypes;
import org.eclipse.osee.ats.artifact.LogItem;
import org.eclipse.osee.ats.artifact.StateMachineArtifact;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.User;
/**
* @author Donald G. Dunne
*/
public class XCurrentStateDam extends XStateAssigneesDam {
public XCurrentStateDam(StateMachineArtifact sma) throws OseeCoreException {
super(sma, AtsAttributeTypes.CurrentState);
}
@Override
public void onAttributeTypeSet() throws OseeCoreException {
super.set(getArtifact().getSoleAttributeValue(getAttributeType(), ""));
}
public SMAState getState() throws OseeCoreException {
Set<SMAState> states = getStates();
if (states.size() != 1) {
throw new OseeArgumentException(
"Must be one current state. Found " + states.size() + " for " + getArtifact().getGuid());
}
return states.iterator().next();
}
@Override
public void setState(SMAState state) throws OseeCoreException {
StateMachineArtifact sma = getArtifact();
sma.setSoleAttributeValue(getAttributeType(), state.toXml());
}
public void updateMetrics(double additionalHours, int percentComplete, boolean logMetrics) throws OseeCoreException {
SMAState currState = getState();
currState.setHoursSpent(currState.getHoursSpent() + additionalHours);
currState.setPercentComplete(percentComplete);
setState(currState);
if (logMetrics) {
logMetrics();
}
}
public void setMetrics(double hours, int percentComplete, boolean logMetrics) throws OseeCoreException {
SMAState currState = getState();
currState.setHoursSpent(hours);
currState.setPercentComplete(percentComplete);
setState(currState);
if (logMetrics) {
logMetrics();
}
}
private void logMetrics() throws OseeCoreException {
logMetrics("");
}
public static void logMetrics(StateMachineArtifact sma, String percent, String hours, String stateName, User user, Date date) throws OseeCoreException {
LogItem logItem =
new LogItem(LogType.Metrics, date, user, stateName, String.format("Percent %s Hours %s", percent, hours),
sma.getHumanReadableId());
sma.getLog().addLogItem(logItem);
}
}
|