From 20c81748688547c1b13686f15c65fbb1d60d81a0 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 12 Jul 2012 14:52:36 +0200 Subject: Suspend transition now can carry an optional 'Errors' outcome where client processes can record the reason for the suspension. Errors XML is marshalled ErrorInfo. UserCodeProcess automatically sends fatal ErrorInfos through suspend jobs. Job API added to to support all this. fixes #23 --- .../java/com/c2kernel/entity/proxy/AgentProxy.java | 31 +++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/proxy/AgentProxy.java') diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java index 5c6a37e..286be88 100644 --- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java @@ -36,6 +36,7 @@ import com.c2kernel.persistency.outcome.Schema; import com.c2kernel.process.Gateway; import com.c2kernel.scripting.ErrorInfo; import com.c2kernel.scripting.Script; +import com.c2kernel.scripting.ScriptErrorException; import com.c2kernel.scripting.ScriptingEngineException; import com.c2kernel.utils.LocalObjectLoader; import com.c2kernel.utils.Logger; @@ -98,6 +99,7 @@ public class AgentProxy extends EntityProxy * * @param item - item holding this job * @param job - the job to execute + * @throws ScriptErrorException */ public void execute(ItemProxy item, Job job) throws AccessRightsException, @@ -105,24 +107,19 @@ public class AgentProxy extends EntityProxy ObjectNotFoundException, InvalidDataException, PersistencyException, - ObjectAlreadyExistsException + ObjectAlreadyExistsException, + ScriptErrorException { OutcomeValidator validator = null; String scriptName = job.getActPropString("ScriptName"); Date startTime = new Date(); Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+path.getAgentName()); // get the outcome validator if present - if (job.isOutcomeUsed()) + if (job.isOutcomeSet()) { + String schemaName = job.getSchemaType(); + int schemaVersion = job.getSchemaVersion(); - // get schema info from act props - String schemaName = job.getActPropString("SchemaType"); - int schemaVersion; - try { - schemaVersion = Integer.parseInt(job.getActPropString("SchemaVersion")); - } catch (Exception e) { - throw new InvalidDataException(e.getClass().getName()+" extracing schema version", ""); - } Logger.msg(5, "AgentProxy - fetching schema "+schemaName+"_"+schemaVersion+" for validation"); // retrieve schema Schema schema = LocalObjectLoader.getSchema(schemaName, schemaVersion); @@ -155,20 +152,20 @@ public class AgentProxy extends EntityProxy // load script ErrorInfo scriptErrors = (ErrorInfo)callScript(item, job); + String errorString = scriptErrors.toString(); if (scriptErrors.getFatal()) { Logger.msg(3, "AgentProxy - fatal script error"); - Logger.error(scriptErrors.getErrors()); - throw new InvalidDataException("Fatal Script Error: \n"+scriptErrors.getErrors(), ""); + throw new ScriptErrorException(scriptErrors); } - if (scriptErrors.getErrors().length() > 0) - Logger.warning("Script errors: "+scriptErrors.getErrors()); + if (errorString.length() > 0) + Logger.warning("Script errors: "+errorString); } catch (ScriptingEngineException ex) { Logger.error(ex); throw new InvalidDataException(ex.getMessage(), ""); } } - if (job.isOutcomeUsed()) { + if (job.isOutcomeSet()) { Logger.msg(3, "AgentProxy - validating outcome"); String error = validator.validate(job.getOutcomeString()); if (error.length() > 0) @@ -201,6 +198,7 @@ public class AgentProxy extends EntityProxy * @throws ObjectNotFoundException * @throws PersistencyException * @throws ObjectAlreadyExistsException + * @throws ScriptErrorException */ public void execute(Job job) throws AccessRightsException, @@ -208,7 +206,8 @@ public class AgentProxy extends EntityProxy InvalidTransitionException, ObjectNotFoundException, PersistencyException, - ObjectAlreadyExistsException + ObjectAlreadyExistsException, + ScriptErrorException { try { ItemProxy targetItem = (ItemProxy)Gateway.getProxyManager().getProxy(new EntityPath(job.getItemSysKey())); -- cgit v1.2.3