Search in sources :

Example 1 with ScriptErrorException

use of org.cristalise.kernel.scripting.ScriptErrorException 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;
}
Also used : ScriptErrorException(org.cristalise.kernel.scripting.ScriptErrorException) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) ErrorInfo(org.cristalise.kernel.scripting.ErrorInfo) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)1 ErrorInfo (org.cristalise.kernel.scripting.ErrorInfo)1 ScriptErrorException (org.cristalise.kernel.scripting.ScriptErrorException)1 ScriptingEngineException (org.cristalise.kernel.scripting.ScriptingEngineException)1