Search in sources :

Example 21 with PersistencyException

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

the class ItemImplementation method queryLifeCycle.

/**
 */
@Override
public String queryLifeCycle(SystemKey agentId, boolean filter) throws AccessRightsException, ObjectNotFoundException, PersistencyException {
    Logger.msg(1, "ItemImplementation::queryLifeCycle(" + mItemPath + ") - agent: " + agentId);
    try {
        AgentPath agent;
        try {
            agent = new AgentPath(agentId);
        } catch (InvalidItemPathException e) {
            throw new AccessRightsException("Agent " + agentId + " doesn't exist");
        }
        Workflow wf = (Workflow) mStorage.get(mItemPath, ClusterType.LIFECYCLE + "/workflow", null);
        JobArrayList jobBag = new JobArrayList();
        CompositeActivity domainWf = (CompositeActivity) wf.search("workflow/domain");
        jobBag.list = filter ? domainWf.calculateJobs(agent, mItemPath, true) : domainWf.calculateAllJobs(agent, mItemPath, true);
        Logger.msg(1, "ItemImplementation::queryLifeCycle(" + mItemPath + ") - Returning " + jobBag.list.size() + " jobs.");
        try {
            return Gateway.getMarshaller().marshall(jobBag);
        } catch (Exception e) {
            Logger.error(e);
            throw new PersistencyException("Error marshalling job bag");
        }
    } catch (AccessRightsException | ObjectNotFoundException | PersistencyException e) {
        Logger.error(e);
        throw e;
    } catch (Throwable ex) {
        Logger.error("ItemImplementation::queryLifeCycle(" + mItemPath + ") - Unknown error");
        Logger.error(ex);
        throw new PersistencyException("Unknown error querying jobs. Please see server log.");
    }
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) AgentPath(org.cristalise.kernel.lookup.AgentPath) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) PersistencyException(org.cristalise.kernel.common.PersistencyException) JobArrayList(org.cristalise.kernel.entity.agent.JobArrayList) 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)

Example 22 with PersistencyException

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

the class ImportItem method create.

/**
 */
@Override
public Path create(AgentPath agentPath, boolean reset) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification, PersistencyException {
    domainPath = new DomainPath(new DomainPath(initialPath), name);
    if (domainPath.exists()) {
        ItemPath domItem = domainPath.getItemPath();
        if (!getItemPath().equals(domItem)) {
            throw new CannotManageException("Item " + domainPath + " was found with the wrong itemPath (" + domainPath.getItemPath() + " vs " + getItemPath() + ")");
        }
    } else
        isDOMPathExists = false;
    TraceableEntity newItem = getTraceableEntitiy();
    // (re)initialise the new item with properties, workflow and collections
    try {
        newItem.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(createItemProperties()), Gateway.getMarshaller().marshall(createCompositeActivity()), Gateway.getMarshaller().marshall(createCollections()));
    } catch (Exception ex) {
        Logger.error("Error initialising new item " + ns + "/" + name);
        Logger.error(ex);
        if (isNewItem)
            Gateway.getLookupManager().delete(itemPath);
        throw new CannotManageException("Problem initialising new item. See server log:" + ex.getMessage());
    }
    History hist = new History(getItemPath(), null);
    // import outcomes
    for (ImportOutcome thisOutcome : outcomes) {
        String outcomeData = thisOutcome.getData(ns);
        // load schema and state machine
        Schema schema = LocalObjectLoader.getSchema(thisOutcome.schema, thisOutcome.version);
        // parse new outcome and validate
        Outcome newOutcome = new Outcome(-1, outcomeData, schema);
        newOutcome.validateAndCheck();
        Viewpoint impView;
        try {
            impView = (Viewpoint) Gateway.getStorage().get(getItemPath(), ClusterType.VIEWPOINT + "/" + thisOutcome.schema + "/" + thisOutcome.viewname, null);
            if (newOutcome.isIdentical(impView.getOutcome())) {
                Logger.msg(5, "ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name + " identical, no update required");
                continue;
            } else {
                Logger.msg("ImportItem.create() - Difference found in view " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name);
                if (!reset && !impView.getEvent().getStepPath().equals("Import")) {
                    Logger.msg("ImportItem.create() - Last edit was not done by import, and reset not requested. Not overwriting.");
                    continue;
                }
            }
        } catch (ObjectNotFoundException ex) {
            Logger.msg("ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " not found in " + ns + "/" + name + ". Creating.");
            impView = new Viewpoint(getItemPath(), schema, thisOutcome.viewname, -1);
        }
        // write new view/outcome/event
        Event newEvent = hist.addEvent(agentPath, null, "Admin", "Import", "Import", "Import", schema, Bootstrap.getPredefSM(), PredefinedStep.DONE, thisOutcome.viewname);
        newOutcome.setID(newEvent.getID());
        impView.setEventId(newEvent.getID());
        Gateway.getStorage().put(getItemPath(), newOutcome, null);
        Gateway.getStorage().put(getItemPath(), impView, null);
    }
    // register domain path (before collections in case of recursive collections)
    if (!isDOMPathExists) {
        domainPath.setItemPath(getItemPath());
        Gateway.getLookupManager().add(domainPath);
    }
    return domainPath;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) CannotManageException(org.cristalise.kernel.common.CannotManageException) Schema(org.cristalise.kernel.persistency.outcome.Schema) History(org.cristalise.kernel.events.History) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Event(org.cristalise.kernel.events.Event) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 23 with PersistencyException

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

the class ItemProxy method setProperty.

/**
 * Sets the vlaue of the given Property
 *
 * @param agent the Agent who is setting the Property
 * @param name the name of the Property
 * @param value the value of the Property
 * @throws AccessRightsException Agent does not the rights to execute this operation
 * @throws PersistencyException there was a database problems during this operations
 * @throws InvalidDataException data was invalid
 */
public void setProperty(AgentProxy agent, String name, String value) throws AccessRightsException, PersistencyException, InvalidDataException {
    try {
        String[] params = { name, value };
        agent.execute(this, "WriteProperty", params);
    } catch (AccessRightsException | PersistencyException | InvalidDataException e) {
        throw (e);
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException("Could not store property:" + e.getMessage());
    }
}
Also used : AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) 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)

Example 24 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException 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 25 with PersistencyException

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

Aggregations

PersistencyException (org.cristalise.kernel.common.PersistencyException)43 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)26 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)26 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)10 IOException (java.io.IOException)9 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)8 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)6 CannotManageException (org.cristalise.kernel.common.CannotManageException)6 ItemPath (org.cristalise.kernel.lookup.ItemPath)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 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)5 History (org.cristalise.kernel.events.History)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 DomainPath (org.cristalise.kernel.lookup.DomainPath)5 ArrayList (java.util.ArrayList)4