Search in sources :

Example 26 with InvalidDataException

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

the class RemoveDomainContext method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "RemoveDomainContext: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveDomainContext: Invalid parameters " + Arrays.toString(params));
    DomainPath pathToDelete = new DomainPath(params[0]);
    if (!pathToDelete.exists())
        throw new ObjectNotFoundException("Context " + pathToDelete + " does not exist");
    try {
        pathToDelete.getItemPath();
        throw new InvalidDataException("Path " + pathToDelete + " is an Entity. Use its own Erase step instead, or RemoveAgent.");
    } catch (ObjectNotFoundException ex) {
    }
    if (Gateway.getLookup().getChildren(pathToDelete).hasNext())
        throw new ObjectCannotBeUpdated("Context " + pathToDelete + " is not empty. Cannot delete.");
    Gateway.getLookupManager().delete(pathToDelete);
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated)

Example 27 with InvalidDataException

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

the class StateMachine method export.

@Override
public void export(Writer imports, File dir) throws IOException, InvalidDataException {
    String smXML;
    String typeCode = BuiltInResources.STATE_MACHINE_RESOURCE.getTypeCode();
    String fileName = getName() + (getVersion() == null ? "" : "_" + getVersion()) + ".xml";
    try {
        smXML = Gateway.getMarshaller().marshall(this);
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("Couldn't marshall state machine " + getName());
    }
    FileStringUtility.string2File(new File(new File(dir, typeCode), fileName), smXML);
    if (imports != null) {
        imports.write("<StateMachineResource " + "name=\"" + getName() + "\" " + (getItemPath() == null ? "" : "id=\"" + getItemID() + "\" ") + (getVersion() == null ? "" : "version=\"" + getVersion() + "\">") + "boot/" + typeCode + "/" + fileName + "</StateMachineResource>\n");
    }
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException) File(java.io.File) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException)

Example 28 with InvalidDataException

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

the class CompositeActivity method runNext.

@Override
public void runNext(AgentPath agent, ItemPath itemPath, Object locker) throws InvalidDataException {
    if (!getStateMachine().getState(state).isFinished()) {
        Transition trans = null;
        try {
            for (Transition possTran : getStateMachine().getPossibleTransitions(this, agent).keySet()) {
                if (trans == null || (trans.isFinishing() && !possTran.isFinishing())) {
                    trans = possTran;
                } else if (trans.isFinishing() == possTran.isFinishing()) {
                    Logger.warning("Unclear choice of transition possible from current state for Composite Activity '" + getName() + "'. Cannot automatically proceed.");
                    setActive(true);
                    return;
                }
            }
        } catch (ObjectNotFoundException e) {
            Logger.error(e);
            throw new InvalidDataException("Problem calculating possible transitions for agent " + agent.toString());
        }
        if (trans == null) {
            // current agent can't proceed
            Logger.msg(3, "Not possible for the current agent to proceed with the Composite Activity '" + getName() + "'.");
            setActive(true);
            return;
        } else {
            // automatically execute the next outcome if it doesn't require an outcome.
            if (trans.hasOutcome(getProperties()) || trans.hasScript(getProperties())) {
                Logger.msg(3, "Composite activity '" + getName() + "' has script or schema defined. Cannot proceed automatically.");
                setActive(true);
                return;
            }
            try {
                request(agent, null, itemPath, trans.getId(), null, locker);
                if (// don't run next if we didn't finish
                !trans.isFinishing())
                    return;
            } catch (Exception e) {
                Logger.error(e);
                setActive(true);
                throw new InvalidDataException("Problem completing composite activity: " + e.getMessage());
            }
        }
    }
    super.runNext(agent, itemPath, locker);
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Transition(org.cristalise.kernel.lifecycle.instance.stateMachine.Transition) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException)

Example 29 with InvalidDataException

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

the class CompositeActivity method run.

@Override
public void run(AgentPath agent, ItemPath itemPath, Object locker) throws InvalidDataException {
    Logger.msg(8, "CompositeActivity.run() path:" + getPath() + " state:" + getState());
    super.run(agent, itemPath, locker);
    Transition autoStart = getAutoStart(agent, getStateMachine().getState(state));
    if (autoStart != null) {
        try {
            request(agent, null, itemPath, autoStart.getId(), null, locker);
        } catch (RuntimeException e) {
            throw e;
        } catch (AccessRightsException e) {
            Logger.warning("Agent:" + agent + " didn't have permission to start the activity:" + getPath() + ", so leave it waiting");
            return;
        } catch (Exception e) {
            Logger.error(e);
            throw new InvalidDataException("Problem initializing composite activity: " + e.getMessage());
        }
    }
}
Also used : AccessRightsException(org.cristalise.kernel.common.AccessRightsException) Transition(org.cristalise.kernel.lifecycle.instance.stateMachine.Transition) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException)

Example 30 with InvalidDataException

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

the class ActivitySlotDef method instantiate.

@Override
public WfVertex instantiate() throws ObjectNotFoundException, InvalidDataException {
    Activity newActivity = (Activity) getTheActivityDef().instantiate();
    configureInstance(newActivity);
    if (newActivity.getProperties().getAbstract().size() > 0) {
        throw new InvalidDataException("Abstract properties not overridden: " + newActivity.getProperties().getAbstract().toString());
    }
    return newActivity;
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Activity(org.cristalise.kernel.lifecycle.instance.Activity)

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