Search in sources :

Example 51 with InvalidDataException

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

the class Import method runActivityLogic.

/**
 * Params: Schemaname_version:Viewpoint (optional), Outcome, Timestamp (optional)
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "Import: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    int split1 = params[0].indexOf('_');
    int split2 = params[0].indexOf(':');
    if (split1 == -1)
        throw new InvalidDataException("Import: Invalid parameters " + Arrays.toString(params));
    requestData = params[1];
    Schema schema;
    String viewpoint = null;
    String schemaName = params[0].substring(0, split1);
    int schemaVersion;
    if (split2 > -1) {
        schemaVersion = Integer.parseInt(params[0].substring(split1 + 1, split2));
        viewpoint = params[0].substring(split2 + 1);
    } else
        schemaVersion = Integer.parseInt(params[0].substring(split1 + 1));
    schema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
    String timestamp;
    if (params.length == 3)
        timestamp = params[2];
    else
        timestamp = DateUtility.timeToString(DateUtility.getNow());
    // write event, outcome and viewpoints to storage
    TransactionManager storage = Gateway.getStorage();
    History hist = getWf().getHistory();
    Event event = hist.addEvent(agent, null, getCurrentAgentRole(), getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint, timestamp);
    try {
        storage.put(item, new Outcome(event.getID(), requestData, schema), locker);
        storage.put(item, new Viewpoint(item, schema, viewpoint, event.getID()), locker);
        if (!"last".equals(viewpoint))
            storage.put(item, new Viewpoint(item, schema, "last", event.getID()), locker);
    } catch (PersistencyException e) {
        storage.abort(locker);
        throw e;
    }
    storage.commit(locker);
    return requestData;
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Event(org.cristalise.kernel.events.Event) PersistencyException(org.cristalise.kernel.common.PersistencyException) History(org.cristalise.kernel.events.History) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 52 with InvalidDataException

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

the class RemoveDomainPath 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);
    if (Logger.doLog(3))
        Logger.msg(3, "RemoveDomainPath: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveDomainPath: Invalid parameters " + Arrays.toString(params));
    DomainPath domainPath = new DomainPath(params[0]);
    if (!domainPath.exists()) {
        throw new ObjectNotFoundException("RemoveDomainPath: Domain path " + domainPath + " does not exist.");
    }
    if (!domainPath.getItemPath().equals(item)) {
        throw new InvalidDataException("RemoveDomainPath: Domain path " + domainPath + " is not an alias of the current Item " + item);
    }
    Gateway.getLookupManager().delete(domainPath);
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 53 with InvalidDataException

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

the class ReplaceDomainWorkflow method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException {
    Workflow lifeCycle = getWf();
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "ReplaceDomainWorkflow: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("ReplaceDomainWorkflow: Invalid parameters " + Arrays.toString(params));
    lifeCycle.getChildrenGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
    CompositeActivity domain;
    try {
        domain = (CompositeActivity) Gateway.getMarshaller().unmarshall(params[0]);
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("ReplaceDomainWorkflow: Could not unmarshall new workflow: " + e.getMessage());
    }
    domain.setName("domain");
    lifeCycle.initChild(domain, true, new GraphPoint(150, 100));
    // if new workflow, activate it, otherwise refresh the jobs
    if (!domain.active)
        lifeCycle.run(agent, item, locker);
    else
        lifeCycle.refreshJobs(item);
    // store new wf
    try {
        Gateway.getStorage().put(item, lifeCycle, locker);
    } catch (PersistencyException e) {
        throw new PersistencyException("ReplaceDomainWorkflow: Could not write new workflow to storage: " + e.getMessage());
    }
    return requestData;
}
Also used : GraphPoint(org.cristalise.kernel.graph.model.GraphPoint) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 54 with InvalidDataException

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

the class WriteViewpoint method write.

public static void write(ItemPath item, String schemaName, String viewName, int eventId, Object locker) throws PersistencyException, ObjectNotFoundException, InvalidDataException {
    Event event = (Event) Gateway.getStorage().get(item, ClusterType.HISTORY + "/" + eventId, locker);
    if (StringUtils.isBlank(event.getSchemaName())) {
        throw new InvalidDataException("Event " + eventId + " does not reference an Outcome, so cannot be assigned to a Viewpoint.");
    }
    // checks Schema name/version
    Schema thisSchema = LocalObjectLoader.getSchema(schemaName, event.getSchemaVersion());
    if (!event.getSchemaName().equals(thisSchema.getItemID())) {
        throw new InvalidDataException("Event outcome schema is " + event.getSchemaName() + ", and cannot be used for a " + schemaName + " Viewpoint");
    }
    Gateway.getStorage().put(item, new Viewpoint(item, thisSchema, viewName, eventId), locker);
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Event(org.cristalise.kernel.events.Event)

Example 55 with InvalidDataException

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

the class WriteViewpoint method runActivityLogic.

/**
 * SchemaName, name and event Id. Event and Outcome should be checked so schema version should be discovered.
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "WriteViewpoint: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 3) {
        throw new InvalidDataException("WriteViewpoint: Invalid parameters " + Arrays.toString(params));
    }
    String schemaName = params[0];
    String viewName = params[1];
    int eventId;
    try {
        eventId = Integer.parseInt(params[2]);
    } catch (NumberFormatException ex) {
        throw new InvalidDataException("WriteViewpoint: Parameter 3 (EventId) must be an integer");
    }
    write(item, schemaName, viewName, eventId, locker);
    return requestData;
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

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