public void setTaskState(TaskState newState, String userId) { TaskState oldState; if (getStateUpdates() == null) { this.stateUpdates = new ArrayList<StateUpdate>(); oldState = TaskState.INITIAL; } else { if (!getStateUpdates().isEmpty() && new Date().before(getStateUpdates().get(getStateUpdates().size() - 1).getUpdatedDate())) { Misc.unreachableStatement(); } //get the old task state from the previous update oldState = this.getStateUpdates().get(getStateUpdates().size() - 1).getTaskState(); } //add a state update this.getStateUpdates().add(new StateUpdateImpl(new Date(), newState, oldState, userId)); }
public void setActivityState(final ActivityState newState, final String userId) { // TODO: why not simply calling getState() to have old state ? ActivityState oldState; final Date actual = new Date(); if (getStateUpdates().isEmpty()) { oldState = ActivityState.INITIAL; } else { // get last state update final StateUpdate oldStateUpdate = getStateUpdates().get(getStateUpdates().size() - 1); final Date lastUpdate = oldStateUpdate.getUpdatedDate(); //get the old task state from the previous update oldState = oldStateUpdate.getActivityState(); // check last state update append before this state update if (actual.before(lastUpdate)) { UpdateImpl.logClockInconsistency(); } } //add a state update this.getStateUpdates().add(new StateUpdateImpl(actual, newState, oldState, userId)); } }
private Date getLastUpdateDate(final ActivityInstanceUUID activityUUID) throws ActivityNotFoundException { final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("getActivity for getLastAttachment "); stringBuilder.append(activityUUID); Misc.log(Level.FINE, stringBuilder.toString()); final ActivityInstance activity = getActivityInstance(activityUUID); Date date = null; if (!activity.getState().equals(ActivityState.READY) && !activity.getState().equals(ActivityState.SUSPENDED) && !activity.getState().equals(ActivityState.EXECUTING)) { date = activity.getLastStateUpdate().getUpdatedDate(); } else { date = new Date(); } return date; }
private static long getActivityScopeDate(final ActivityInstance activityInstance, final long defaultDate) { long maxDate = -1; if (!activityInstance.getState().equals(ActivityState.READY) && !activityInstance.getState().equals(ActivityState.SUSPENDED) && !activityInstance.getState().equals(ActivityState.EXECUTING)) { maxDate = activityInstance.getLastStateUpdate().getUpdatedDate().getTime(); } else { maxDate = defaultDate; } return maxDate; }