use of org.cristalise.kernel.scripting.ErrorInfo in project kernel by cristal-ise.
the class ItemImplementation method handleError.
/**
* @param agentId
* @param delegateId
* @param stepPath
* @param ex
* @return
* @throws PersistencyException
* @throws ObjectNotFoundException
* @throws AccessRightsException
* @throws InvalidTransitionException
* @throws InvalidDataException
* @throws ObjectAlreadyExistsException
* @throws InvalidCollectionModification
*/
private String handleError(SystemKey agentId, SystemKey delegateId, String stepPath, Workflow lifeCycle, Exception ex) throws PersistencyException, ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, InvalidCollectionModification {
if (!Gateway.getProperties().getBoolean("StateMachine.enableErrorHandling", false))
return null;
int errorTransId = ((Activity) lifeCycle.search(stepPath)).getErrorTransitionId();
if (errorTransId == -1)
return null;
try {
AgentPath agent = new AgentPath(agentId);
AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
String errorOutcome = Gateway.getMarshaller().marshall(new ErrorInfo(ex));
lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, errorTransId, errorOutcome);
if (!(stepPath.startsWith("workflow/predefined")))
mStorage.put(mItemPath, lifeCycle, lifeCycle);
return errorOutcome;
} catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException | MarshalException | ValidationException | IOException | MappingException e) {
Logger.error(e);
return "";
}
}
use of org.cristalise.kernel.scripting.ErrorInfo in project kernel by cristal-ise.
the class AgentProxy method execute.
/**
* Standard execution of jobs. Note that this method should always be the one used from clients.
* All execution parameters are taken from the job where they're probably going to be correct.
*
* @param job the Actual Job to be executed
* @return The outcome after processing. May have been altered by the step.
*
* @throws AccessRightsException The agent was not allowed to execute this step
* @throws InvalidDataException The parameters supplied were incorrect
* @throws InvalidTransitionException The step wasn't available
* @throws ObjectNotFoundException Thrown by some steps that try to locate additional objects
* @throws PersistencyException Problem writing or reading the database
* @throws ObjectAlreadyExistsException Thrown by steps that create additional object
* @throws ScriptErrorException Thrown by scripting classes
* @throws InvalidCollectionModification Thrown by steps that create/modify collections
*/
public String execute(Job job) throws AccessRightsException, InvalidDataException, InvalidTransitionException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ScriptErrorException, InvalidCollectionModification {
ItemProxy item = Gateway.getProxyManager().getProxy(job.getItemPath());
Date startTime = new Date();
Logger.msg(3, "AgentProxy.execute(job) - act:" + job.getStepPath() + " agent:" + mAgentPath.getAgentName());
if (job.hasScript()) {
Logger.msg(3, "AgentProxy.execute(job) - executing script");
try {
// pre-validate outcome for script if there is one
if (job.hasOutcome() && job.isOutcomeSet())
job.getOutcome().validateAndCheck();
// load script
ErrorInfo scriptErrors = callScript(item, job);
String errorString = scriptErrors.toString();
if (scriptErrors.getFatal()) {
Logger.error("AgentProxy.execute(job) - fatal script errors:" + scriptErrors);
throw new ScriptErrorException(scriptErrors);
}
if (errorString.length() > 0)
Logger.warning("Script errors: " + errorString);
} catch (ScriptingEngineException ex) {
Logger.error(ex);
throw new InvalidDataException(ex.getMessage());
}
} else if (job.hasQuery() && !"Query".equals(job.getActProp(BuiltInVertexProperties.OUTCOME_INIT))) {
Logger.msg(3, "AgentProxy.execute(job) - executing query (OutcomeInit != Query)");
// pre-validate outcome for query if there is one
if (job.hasOutcome() && job.isOutcomeSet())
job.getOutcome().validateAndCheck();
job.setOutcome(item.executeQuery(job.getQuery()));
}
if (job.hasOutcome() && job.isOutcomeSet())
job.getOutcome().validateAndCheck();
job.setAgentPath(mAgentPath);
Logger.msg(3, "AgentProxy.execute(job) - submitting job to item proxy");
String result = item.requestAction(job);
if (Logger.doLog(3)) {
Date timeNow = new Date();
long secsNow = (timeNow.getTime() - startTime.getTime()) / 1000;
Logger.msg(3, "AgentProxy.execute(job) - execution DONE in " + secsNow + " seconds");
}
return result;
}
use of org.cristalise.kernel.scripting.ErrorInfo in project kernel by cristal-ise.
the class Module method runScript.
public void runScript(String event, AgentProxy agent, boolean isServer) throws ScriptingEngineException {
for (ModuleEmbeddedScript script : scripts) {
if (script.shouldRun(event, isServer)) {
Logger.msg("Running " + script.event + " " + script.target + " script from " + name);
Object result = script.getScript(ns, agent).execute();
if (result instanceof ErrorInfo) {
ErrorInfo error = (ErrorInfo) result;
Logger.error(error.toString());
if (error.getFatal())
throw new ScriptingEngineException("Fatal Script Error");
} else if (result != null) {
Logger.msg(result.toString());
}
}
}
}
Aggregations