Search in sources :

Example 31 with PersistencyException

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

the class Activity method request.

public String request(AgentPath agent, AgentPath delegate, ItemPath itemPath, int transitionID, String requestData, Object locker) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification {
    // Find requested transition
    Transition transition = getStateMachine().getTransition(transitionID);
    // Check if the transition is possible
    String usedRole = transition.getPerformingRole(this, agent);
    // Verify outcome
    boolean storeOutcome = false;
    if (transition.hasOutcome(getProperties())) {
        if (StringUtils.isNotBlank(requestData))
            storeOutcome = true;
        else if (transition.getOutcome().isRequired())
            throw new InvalidDataException("Transition requires outcome data, but none was given");
    }
    // Get new state
    State oldState = getStateMachine().getState(this.state);
    State newState = getStateMachine().traverse(this, transition, agent);
    // Run extra logic in predefined steps here
    String outcome = runActivityLogic(agent, itemPath, transitionID, requestData, locker);
    // set new state and reservation
    setState(newState.getId());
    setBuiltInProperty(AGENT_NAME, transition.getReservation(this, agent));
    try {
        History hist = getWf().getHistory(locker);
        if (storeOutcome) {
            Schema schema = transition.getSchema(getProperties());
            Outcome newOutcome = new Outcome(-1, outcome, schema);
            // TODO: if we were ever going to validate outcomes on storage, it would be here.
            // newOutcome.validateAndCheck();
            String viewpoint = resolveViewpointName(newOutcome);
            int eventID = hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint).getID();
            newOutcome.setID(eventID);
            Gateway.getStorage().put(itemPath, newOutcome, locker);
            // update specific view if defined
            if (!viewpoint.equals("last")) {
                Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, viewpoint, eventID), locker);
            }
            // update the default "last" view
            Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, "last", eventID), locker);
            updateItemProperties(itemPath, newOutcome, locker);
        } else {
            hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), getStateMachine(), transitionID);
        }
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw ex;
    }
    if (newState.isFinished() && !(getBuiltInProperty(BREAKPOINT).equals(Boolean.TRUE) && !oldState.isFinished())) {
        runNext(agent, itemPath, locker);
    }
    DateUtility.setToNow(mStateDate);
    pushJobsToAgents(itemPath);
    return outcome;
}
Also used : State(org.cristalise.kernel.lifecycle.instance.stateMachine.State) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Schema(org.cristalise.kernel.persistency.outcome.Schema) Transition(org.cristalise.kernel.lifecycle.instance.stateMachine.Transition) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) History(org.cristalise.kernel.events.History) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 32 with PersistencyException

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

the class ClusterStorageManager method instantiateStores.

public ArrayList<ClusterStorage> instantiateStores(String allClusters) throws PersistencyException {
    ArrayList<ClusterStorage> rootStores = new ArrayList<ClusterStorage>();
    StringTokenizer tok = new StringTokenizer(allClusters, ",");
    clusterPriority = new String[tok.countTokens()];
    while (tok.hasMoreTokens()) {
        ClusterStorage newStorage = null;
        String newStorageClass = tok.nextToken();
        try {
            if (!newStorageClass.contains("."))
                newStorageClass = "org.cristalise.storage." + newStorageClass;
            newStorage = (ClusterStorage) (Class.forName(newStorageClass).newInstance());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
            throw new PersistencyException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + " could not be found.");
        }
        rootStores.add(newStorage);
    }
    return rootStores;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 33 with PersistencyException

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

the class RemoteMap method loadKeys.

protected void loadKeys() {
    if (keyLock != null)
        return;
    clear();
    keyLock = new Object();
    synchronized (this) {
        String[] keys;
        try {
            keys = storage.getClusterContents(mItemPath, mPath + mName);
            for (String key : keys) super.put(key, null);
        } catch (PersistencyException e) {
            Logger.error(e);
        }
    }
}
Also used : PersistencyException(org.cristalise.kernel.common.PersistencyException) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject)

Example 34 with PersistencyException

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

the class Outcome method setMetaDataFromPath.

/**
 * Retrieves the SchemaName, Version, EevetnId triplet from the path. Check getClusterPath() implementation
 *
 * @param path the ClusterPath to work with
 * @throws PersistencyException path was incorrect
 * @throws InvalidDataException Schema was not found or the Path has incorrect data
 */
protected void setMetaDataFromPath(String path) throws PersistencyException, InvalidDataException {
    StringTokenizer tok = new StringTokenizer(path, "/");
    if (tok.countTokens() != 3 && !(tok.nextToken().equals(OUTCOME.getName())))
        throw new PersistencyException("Outcome() - Outcome path must have three components:" + path);
    String schemaName = tok.nextToken();
    String verString = tok.nextToken();
    String objId = tok.nextToken();
    try {
        Integer schemaVersion = Integer.valueOf(verString);
        mSchema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
        mID = Integer.valueOf(objId);
    } catch (NumberFormatException ex) {
        throw new InvalidDataException("Outcome() - Version or EventID was an invalid number version:" + verString + " eventID:" + objId);
    } catch (ObjectNotFoundException e) {
        Logger.error(e);
        throw new InvalidDataException("Outcome() - problem loading schema:" + schemaName + " version:" + verString);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 35 with PersistencyException

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

the class QueryOutcomeInitiator method initOutcomeInstance.

@Override
public Outcome initOutcomeInstance(Job job) throws InvalidDataException {
    if (job.hasQuery()) {
        try {
            Outcome o = new Outcome(-1, job.getItemProxy().executeQuery(job.getQuery()), job.getSchema());
            o.validateAndCheck();
            return o;
        } catch (PersistencyException | ObjectNotFoundException | InvalidItemPathException e) {
            throw new InvalidDataException("Error executing Query:" + e.getMessage());
        }
    } else
        throw new InvalidDataException("No Query was defined for job:" + job);
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) 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