summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/c2kernel/entity')
-rw-r--r--src/main/java/com/c2kernel/entity/agent/Job.java66
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/AgentProxy.java31
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/ItemProxy.java2
3 files changed, 66 insertions, 33 deletions
diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java
index b5274ec..216a88d 100644
--- a/src/main/java/com/c2kernel/entity/agent/Job.java
+++ b/src/main/java/com/c2kernel/entity/agent/Job.java
@@ -11,6 +11,7 @@ import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
+import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.KeyValuePair;
import com.c2kernel.utils.Logger;
@@ -46,12 +47,16 @@ public class Job implements C2KLocalObject
private CastorHashMap mActProps = new CastorHashMap();
private String mOutcome;
+
+ private ErrorInfo mError;
private String mStepType;
private ItemProxy item = null;
private AgentProxy agent = null;
+
+ private boolean outcomeSet;
/***************************************************************************
* Empty constructor for Castor
@@ -105,29 +110,43 @@ public class Job implements C2KLocalObject
public String getSchemaType()
{
- return (String) mActProps.get("SchemaType");
+ if (isError()) return "Errors";
+ if (requiresOutcome()) return (String)mActProps.get("SchemaType");
+ else return null;
}
public int getSchemaVersion()
{
- try
- {
- return Integer.parseInt((String) mActProps.get("SchemaVersion"));
- } catch (NumberFormatException ex)
- {
- return -1;
- }
+ if (isError()) return 0;
+ if (requiresOutcome())
+ try {
+ return Integer.parseInt((String) mActProps.get("SchemaVersion"));
+ } catch (NumberFormatException ex) {
+ return -1;
+ }
+ return -1;
}
public void setOutcome(String outcome)
{
- mOutcome = outcome;
+ mOutcome = outcome;
+ outcomeSet = !(mOutcome == null);
+ }
+
+ public void setError(ErrorInfo errors)
+ {
+ mError = errors;
+ try {
+ mOutcome = Gateway.getMarshaller().marshall(errors);
+ } catch (Exception e) {
+ Logger.error("Error marshalling ErrorInfo in job");
+ Logger.error(e);
+ }
}
public String getOutcomeString()
{
- Logger.debug(8, "getOutcomeString() " + (mOutcome == null && isOutcomeUsed()));
- if (mOutcome == null && isOutcomeUsed())
+ if (mOutcome == null && requiresOutcome())
{
String viewName = (String) getActProp("Viewpoint");
mOutcome = null;
@@ -136,16 +155,19 @@ public class Job implements C2KLocalObject
{
Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaType() + "/" + viewName, null);
mOutcome = view.getOutcome().getData();
+ outcomeSet = true;
} catch (Exception ex)
- { // not found, return null
+ {
+ mOutcome = null;
+ outcomeSet = false;
}
+
}
return mOutcome;
}
public Outcome getOutcome()
{
- Logger.msg(1, "Get outcome");
return new Outcome(-1, getOutcomeString(), getSchemaType(), getSchemaVersion());
}
@@ -186,10 +208,22 @@ public class Job implements C2KLocalObject
mAgentRole = role;
}
- public boolean isOutcomeUsed()
+ public boolean requiresOutcome()
{
- String schemaType = getSchemaType();
- return (Boolean.TRUE.equals(getActProp("AlwaysUseOutcome")) || mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals(""));
+ String schemaType = (String) mActProps.get("SchemaVersion");
+ return (mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals(""));
+ }
+
+ public boolean isError() {
+ return (mPossibleTransition == Transitions.SUSPEND);
+ }
+
+ public boolean hasOutcome() {
+ return requiresOutcome() || isError();
+ }
+
+ public boolean isOutcomeSet() {
+ return outcomeSet;
}
public int getID()
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()));
diff --git a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java
index dcaef55..55e1fe9 100644
--- a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java
+++ b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java
@@ -105,7 +105,7 @@ public class ItemProxy extends EntityProxy
String outcome = thisJob.getOutcomeString();
// check fields that should have been filled in
if (outcome==null)
- if (thisJob.isOutcomeUsed())
+ if (thisJob.requiresOutcome())
throw new InvalidDataException("Outcome is required.", "");
else
outcome="";