Search in sources :

Example 1 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException 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;
        }
    }
}
Also used : InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) MarshalException(org.exolab.castor.xml.MarshalException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 2 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class ItemImplementation method initialise.

@Override
public void initialise(SystemKey agentId, String propString, String initWfString, String initCollsString) throws AccessRightsException, InvalidDataException, PersistencyException {
    Logger.msg(5, "Item::initialise(" + mItemPath + ") - agent:" + agentId);
    Object locker = new Object();
    AgentPath agentPath;
    try {
        agentPath = new AgentPath(agentId);
    } catch (InvalidItemPathException e) {
        throw new AccessRightsException("Invalid Agent Id:" + agentId);
    }
    // must supply properties
    if (propString == null || propString.length() == 0 || propString.equals("<NULL/>")) {
        throw new InvalidDataException("No properties supplied");
    }
    // store properties
    try {
        PropertyArrayList props = (PropertyArrayList) Gateway.getMarshaller().unmarshall(propString);
        for (Property thisProp : props.list) mStorage.put(mItemPath, thisProp, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Properties were invalid: " + propString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Properties were invalid");
    }
    // Store an event and the initial properties
    try {
        Schema initSchema = LocalObjectLoader.getSchema("ItemInitialization", 0);
        Outcome initOutcome = new Outcome(0, propString, initSchema);
        History hist = new History(mItemPath, locker);
        Event newEvent = hist.addEvent(new AgentPath(agentId), null, "", "Initialize", "", "", initSchema, Bootstrap.getPredefSM(), PredefinedStep.DONE, "last");
        initOutcome.setID(newEvent.getID());
        Viewpoint newLastView = new Viewpoint(mItemPath, initSchema, "last", newEvent.getID());
        mStorage.put(mItemPath, initOutcome, locker);
        mStorage.put(mItemPath, newLastView, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Could not store event and outcome.");
        Logger.error(ex);
        mStorage.abort(locker);
        throw new PersistencyException("Error storing event and outcome");
    }
    // init collections
    if (initCollsString != null && initCollsString.length() > 0 && !initCollsString.equals("<NULL/>")) {
        try {
            CollectionArrayList colls = (CollectionArrayList) Gateway.getMarshaller().unmarshall(initCollsString);
            for (Collection<?> thisColl : colls.list) {
                mStorage.put(mItemPath, thisColl, locker);
            }
        } catch (Throwable ex) {
            Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Collections were invalid: " + initCollsString);
            Logger.error(ex);
            mStorage.abort(locker);
            throw new InvalidDataException("Collections were invalid");
        }
    }
    // create wf
    Workflow lc = null;
    try {
        if (initWfString == null || initWfString.length() == 0 || initWfString.equals("<NULL/>")) {
            lc = new Workflow(new CompositeActivity(), getNewPredefStepContainer());
        } else {
            lc = new Workflow((CompositeActivity) Gateway.getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
        }
        mStorage.put(mItemPath, lc, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Workflow was invalid: " + initWfString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Workflow was invalid");
    }
    // All objects are in place, initialize the workflow to get the Item running
    lc.initialise(mItemPath, agentPath, locker);
    mStorage.put(mItemPath, lc, locker);
    mStorage.commit(locker);
    Logger.msg(3, "Initialisation of item " + mItemPath + " was successful");
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Schema(org.cristalise.kernel.persistency.outcome.Schema) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) History(org.cristalise.kernel.events.History) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Event(org.cristalise.kernel.events.Event) PersistencyException(org.cristalise.kernel.common.PersistencyException) Property(org.cristalise.kernel.property.Property)

Example 3 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Job method getOutcomeInitiator.

/**
 * Retrieve the OutcomeInitiator associated with this Job.
 *
 * @see BuiltInVertexProperties#OUTCOME_INIT
 *
 * @return the configured OutcomeInitiator
 * @throws InvalidDataException OutcomeInitiator could not be created
 */
public OutcomeInitiator getOutcomeInitiator() throws InvalidDataException {
    String ocInitName = getActPropString(OUTCOME_INIT);
    if (StringUtils.isNotBlank(ocInitName)) {
        String ocConfigPropName = OUTCOME_INIT.getName() + "." + ocInitName;
        OutcomeInitiator ocInit;
        synchronized (ocInitCache) {
            Logger.msg(5, "Job.getOutcomeInitiator() - ocConfigPropName:" + ocConfigPropName);
            ocInit = ocInitCache.get(ocConfigPropName);
            if (ocInit == null) {
                if (!Gateway.getProperties().containsKey(ocConfigPropName)) {
                    throw new InvalidDataException("Property OutcomeInstantiator " + ocConfigPropName + " isn't defined. Check module.xml");
                }
                try {
                    ocInit = (OutcomeInitiator) Gateway.getProperties().getInstance(ocConfigPropName);
                    ocInitCache.put(ocConfigPropName, ocInit);
                } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                    Logger.error(e);
                    throw new InvalidDataException("OutcomeInstantiator " + ocConfigPropName + " couldn't be instantiated:" + e.getMessage());
                }
            }
        }
        return ocInit;
    } else
        return null;
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException) OutcomeInitiator(org.cristalise.kernel.persistency.outcome.OutcomeInitiator)

Example 4 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Job method setActPropsAndEvaluateValues.

/**
 * @param act
 * @throws InvalidDataException
 */
private void setActPropsAndEvaluateValues(Activity act) throws InvalidDataException {
    setActProps(act.getProperties());
    List<String> errors = new ArrayList<String>();
    for (Map.Entry<String, Object> entry : act.getProperties().entrySet()) {
        try {
            Object newVal = act.evaluatePropertyValue(null, entry.getValue(), null);
            if (newVal != null)
                actProps.put(entry.getKey(), newVal);
        } catch (InvalidDataException | PersistencyException | ObjectNotFoundException e) {
            Logger.error(e);
            errors.add(e.getMessage());
        }
    }
    if (errors.size() != 0) {
        StringBuffer buffer = new StringBuffer();
        for (String msg : errors) buffer.append(msg);
        throw new InvalidDataException(buffer.toString());
    }
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ArrayList(java.util.ArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) HashMap(java.util.HashMap) Map(java.util.Map) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap)

Example 5 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException 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

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)91 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)40 PersistencyException (org.cristalise.kernel.common.PersistencyException)33 IOException (java.io.IOException)14 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)11 DomainPath (org.cristalise.kernel.lookup.DomainPath)10 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 CannotManageException (org.cristalise.kernel.common.CannotManageException)8 AgentPath (org.cristalise.kernel.lookup.AgentPath)8 Schema (org.cristalise.kernel.persistency.outcome.Schema)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)7 ItemPath (org.cristalise.kernel.lookup.ItemPath)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ArrayList (java.util.ArrayList)5 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5