use of org.cristalise.kernel.common.InvalidTransitionException in project kernel by cristal-ise.
the class ItemImplementation method delegatedAction.
@Override
public String delegatedAction(SystemKey agentId, SystemKey delegateId, String stepPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException, InvalidCollectionModification {
Workflow lifeCycle = null;
try {
AgentPath agent = new AgentPath(agentId);
AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
Logger.msg(1, "ItemImplementation::request(" + mItemPath + ") - Transition " + transitionID + " on " + stepPath + " by " + (delegate == null ? "" : delegate + " on behalf of ") + agent);
// TODO: check if delegate is allowed valid for agent
lifeCycle = (Workflow) mStorage.get(mItemPath, ClusterType.LIFECYCLE + "/workflow", null);
String finalOutcome = lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, transitionID, requestData);
// store the workflow if we've changed the state of the domain wf
if (!(stepPath.startsWith("workflow/predefined")))
mStorage.put(mItemPath, lifeCycle, lifeCycle);
// remove entity path if transaction was successful
if (stepPath.equals("workflow/predefined/Erase")) {
Logger.msg("Erasing item path " + mItemPath.toString());
Gateway.getLookupManager().delete(mItemPath);
}
mStorage.commit(lifeCycle);
return finalOutcome;
} catch (AccessRightsException | InvalidTransitionException | ObjectNotFoundException | PersistencyException | InvalidDataException | ObjectAlreadyExistsException | InvalidCollectionModification ex) {
if (Logger.doLog(8))
Logger.error(ex);
String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
if (StringUtils.isBlank(errorOutcome)) {
mStorage.abort(lifeCycle);
throw ex;
} else {
mStorage.commit(lifeCycle);
return errorOutcome;
}
} catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException ex) {
if (Logger.doLog(8))
Logger.error(ex);
String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
if (StringUtils.isBlank(errorOutcome)) {
mStorage.abort(lifeCycle);
throw new InvalidDataException(ex.getClass().getName() + " - " + ex.getMessage());
} else {
mStorage.commit(lifeCycle);
return errorOutcome;
}
} catch (Exception ex) {
// non-CORBA exception hasn't been caught!
Logger.error("Unknown Error: requestAction on " + mItemPath + " by " + agentId + " executing " + stepPath);
Logger.error(ex);
String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
if (StringUtils.isBlank(errorOutcome)) {
mStorage.abort(lifeCycle);
throw new InvalidDataException("Extraordinary Exception during execution:" + ex.getClass().getName() + " - " + ex.getMessage());
} else {
mStorage.commit(lifeCycle);
return errorOutcome;
}
}
}
use of org.cristalise.kernel.common.InvalidTransitionException in project kernel by cristal-ise.
the class CompositeActivity method request.
@Override
public String request(AgentPath agent, AgentPath delegator, ItemPath itemPath, int transitionID, String requestData, Object locker) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification {
Transition trans = getStateMachine().getTransition(transitionID);
if (trans.isFinishing() && hasActive()) {
if ((Boolean) getBuiltInProperty(ABORTABLE))
abort();
else
throw new InvalidTransitionException("Attempted to finish a composite activity that had active children but was not Abortable");
}
if (getStateMachine().getTransition(transitionID).reinitializes()) {
int preserveState = state;
reinit(getID());
setState(preserveState);
}
if (getChildrenGraphModel().getStartVertex() != null && (getStateMachine().getState(state).equals(getStateMachine().getInitialState()) || getStateMachine().getTransition(transitionID).reinitializes())) {
((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent, itemPath, locker);
}
return super.request(agent, delegator, itemPath, transitionID, requestData, locker);
}
use of org.cristalise.kernel.common.InvalidTransitionException in project kernel by cristal-ise.
the class UserCodeProcess method run.
@Override
public void run() {
Thread.currentThread().setName("Usercode Process");
// subscribe to job list - this will initialise the jobs using the ProxyObserver interface as callback
agent.subscribe(new MemberSubscription<Job>(this, ClusterType.JOB.getName(), true));
while (active) {
Job thisJob = getActualJob();
if (thisJob != null) {
String jobKey = thisJob.getItemPath() + ":" + thisJob.getStepPath();
int transitionId = thisJob.getTransition().getId();
try {
if (transitionId == START)
start(thisJob, jobKey);
else if (transitionId == COMPLETE)
complete(thisJob, jobKey);
} catch (InvalidTransitionException ex) {
// must have already been done by someone else - ignore
} catch (Exception ex) {
Logger.error("Error executing job:" + thisJob);
Logger.error(ex);
}
}
try {
synchronized (jobs) {
if (jobs.size() == 0) {
Logger.msg("UserCodeProcess.run() - Sleeping");
while (active && jobs.size() == 0) jobs.wait(2000);
}
}
} catch (InterruptedException ex) {
}
}
// shut down
try {
Gateway.close();
} catch (Exception ex) {
Logger.error(ex);
}
}
Aggregations