01: package org.obe.client.api.model;
02:
03: import org.obe.util.AbstractEnum;
04: import org.obe.xpdl.OBENames;
05: import org.obe.xpdl.model.activity.Activity;
06: import org.obe.xpdl.model.misc.TimeEstimation;
07: import org.obe.xpdl.model.workflow.ProcessHeader;
08:
09: import java.util.Date;
10: import java.util.HashMap;
11: import java.util.List;
12: import java.util.Map;
13:
14: /**
15: * The temporal status of a process instance, activity instance, or work item.
16: * Temporal status reflects whether the entity in question is ahead of schedule,
17: * behind schedule or overdue, according to its target and due dates. These are
18: * computed by the workflow engine from the entities Duration and Limit
19: * properties as defined in the XPDL.
20: *
21: * @author Adrian Price
22: * @see Activity #getLimit()
23: * @see ProcessHeader#getLimit()
24: * @see TimeEstimation#getDuration()
25: */
26: public final class TemporalStatus extends AbstractEnum {
27: public static final int UNDEFINED_INT = 0;
28: public static final int NORMAL_INT = 1;
29: public static final int WARNING_INT = 2;
30: public static final int OVERDUE_INT = 3;
31: public static final TemporalStatus UNDEFINED = new TemporalStatus(
32: OBENames.UNDEFINED_KIND, UNDEFINED_INT);
33: public static final TemporalStatus NORMAL = new TemporalStatus(
34: OBENames.NORMAL_KIND, NORMAL_INT);
35: public static final TemporalStatus WARNING = new TemporalStatus(
36: OBENames.WARNING_KIND, WARNING_INT);
37: public static final TemporalStatus OVERDUE = new TemporalStatus(
38: OBENames.OVERDUE_KIND, OVERDUE_INT);
39:
40: private static final TemporalStatus[] _values = { UNDEFINED,
41: NORMAL, WARNING, OVERDUE };
42: private static final Map _tagMap = new HashMap();
43: public static final List VALUES = clinit(_values, _tagMap);
44:
45: /**
46: * Computes the temporal status corresponding to the set of input values.
47: *
48: * @param completed The date at which the process or task was completed (can
49: * be null).
50: * @param target The date by which the process or task is/was expected to be
51: * complete.
52: * @param due The date by which the process or task is/was required to be
53: * complete.
54: * @return Temporal status, one of: {@link #UNDEFINED}, {@link #NORMAL},
55: * {@link #WARNING}, {@link #OVERDUE}.
56: */
57: public static TemporalStatus computeStatus(Date completed,
58: Date target, Date due) {
59:
60: long baseline = completed != null ? completed.getTime()
61: : System.currentTimeMillis();
62: TemporalStatus status;
63: if (due != null && baseline > due.getTime())
64: status = OVERDUE;
65: else if (target != null && baseline > target.getTime())
66: status = WARNING;
67: else if (due != null || target != null)
68: status = NORMAL;
69: else
70: status = UNDEFINED;
71: return status;
72: }
73:
74: private TemporalStatus(String name, int ordinal) {
75: super (name, ordinal);
76: }
77:
78: public List family() {
79: return VALUES;
80: }
81: }
|