use of org.cristalise.kernel.lifecycle.instance.stateMachine.State in project kernel by cristal-ise.
the class Activity method request.
public String request(AgentPath agent, AgentPath delegate, ItemPath itemPath, int transitionID, String requestData, Object locker) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification {
// Find requested transition
Transition transition = getStateMachine().getTransition(transitionID);
// Check if the transition is possible
String usedRole = transition.getPerformingRole(this, agent);
// Verify outcome
boolean storeOutcome = false;
if (transition.hasOutcome(getProperties())) {
if (StringUtils.isNotBlank(requestData))
storeOutcome = true;
else if (transition.getOutcome().isRequired())
throw new InvalidDataException("Transition requires outcome data, but none was given");
}
// Get new state
State oldState = getStateMachine().getState(this.state);
State newState = getStateMachine().traverse(this, transition, agent);
// Run extra logic in predefined steps here
String outcome = runActivityLogic(agent, itemPath, transitionID, requestData, locker);
// set new state and reservation
setState(newState.getId());
setBuiltInProperty(AGENT_NAME, transition.getReservation(this, agent));
try {
History hist = getWf().getHistory(locker);
if (storeOutcome) {
Schema schema = transition.getSchema(getProperties());
Outcome newOutcome = new Outcome(-1, outcome, schema);
// TODO: if we were ever going to validate outcomes on storage, it would be here.
// newOutcome.validateAndCheck();
String viewpoint = resolveViewpointName(newOutcome);
int eventID = hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint).getID();
newOutcome.setID(eventID);
Gateway.getStorage().put(itemPath, newOutcome, locker);
// update specific view if defined
if (!viewpoint.equals("last")) {
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, viewpoint, eventID), locker);
}
// update the default "last" view
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, "last", eventID), locker);
updateItemProperties(itemPath, newOutcome, locker);
} else {
hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), getStateMachine(), transitionID);
}
} catch (PersistencyException ex) {
Logger.error(ex);
throw ex;
}
if (newState.isFinished() && !(getBuiltInProperty(BREAKPOINT).equals(Boolean.TRUE) && !oldState.isFinished())) {
runNext(agent, itemPath, locker);
}
DateUtility.setToNow(mStateDate);
pushJobsToAgents(itemPath);
return outcome;
}
Aggregations