Search in sources :

Example 1 with ObjectCannotBeUpdated

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

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

the class ItemImplementation method handleError.

/**
 * @param agentId
 * @param delegateId
 * @param stepPath
 * @param ex
 * @return
 * @throws PersistencyException
 * @throws ObjectNotFoundException
 * @throws AccessRightsException
 * @throws InvalidTransitionException
 * @throws InvalidDataException
 * @throws ObjectAlreadyExistsException
 * @throws InvalidCollectionModification
 */
private String handleError(SystemKey agentId, SystemKey delegateId, String stepPath, Workflow lifeCycle, Exception ex) throws PersistencyException, ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, InvalidCollectionModification {
    if (!Gateway.getProperties().getBoolean("StateMachine.enableErrorHandling", false))
        return null;
    int errorTransId = ((Activity) lifeCycle.search(stepPath)).getErrorTransitionId();
    if (errorTransId == -1)
        return null;
    try {
        AgentPath agent = new AgentPath(agentId);
        AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
        String errorOutcome = Gateway.getMarshaller().marshall(new ErrorInfo(ex));
        lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, errorTransId, errorOutcome);
        if (!(stepPath.startsWith("workflow/predefined")))
            mStorage.put(mItemPath, lifeCycle, lifeCycle);
        return errorOutcome;
    } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException | MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        return "";
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ErrorInfo(org.cristalise.kernel.scripting.ErrorInfo) Activity(org.cristalise.kernel.lifecycle.instance.Activity) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) IOException(java.io.IOException) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) MappingException(org.exolab.castor.mapping.MappingException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 3 with ObjectCannotBeUpdated

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

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

the class ClearSlot method runActivityLogic.

/**
 * Params: 0 - collection name 1 - slot number
 *
 * @throws ObjectNotFoundException
 * @throws PersistencyException
 * @throws ObjectCannotBeUpdated
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated {
    String collName;
    int slotNo;
    Aggregation agg;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "ClearSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        slotNo = Integer.parseInt(params[1]);
    } catch (Exception e) {
        throw new InvalidDataException("ClearSlot: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    try {
        agg = (Aggregation) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw new PersistencyException("ClearSlot: Error loading collection '" + collName + "': " + ex.getMessage());
    }
    // find member and clear
    boolean stored = false;
    for (AggregationMember member : agg.getMembers().list) {
        if (member.getID() == slotNo) {
            if (member.getItemPath() == null)
                throw new ObjectCannotBeUpdated("ClearSlot: Member slot " + slotNo + " already empty");
            member.clearItem();
            stored = true;
            break;
        }
    }
    if (!stored) {
        throw new ObjectNotFoundException("ClearSlot: Member slot " + slotNo + " not found.");
    }
    try {
        Gateway.getStorage().put(item, agg, locker);
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new PersistencyException("ClearSlot: Error storing collection");
    }
    return requestData;
}
Also used : Aggregation(org.cristalise.kernel.collection.Aggregation) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) AggregationMember(org.cristalise.kernel.collection.AggregationMember) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 5 with ObjectCannotBeUpdated

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

the class WriteProperty method write.

public static void write(ItemPath item, String name, String value, Object locker) throws PersistencyException, ObjectCannotBeUpdated, ObjectNotFoundException {
    Property prop = (Property) Gateway.getStorage().get(item, ClusterType.PROPERTY + "/" + name, locker);
    if (!prop.isMutable() && !value.equals(prop.getValue()))
        throw new ObjectCannotBeUpdated("WriteProperty: Property '" + name + "' is not mutable.");
    prop.setValue(value);
    Gateway.getStorage().put(item, prop, locker);
}
Also used : ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) Property(org.cristalise.kernel.property.Property)

Aggregations

ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)10 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)6 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)6 CannotManageException (org.cristalise.kernel.common.CannotManageException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)3 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)3 IOException (java.io.IOException)2 Aggregation (org.cristalise.kernel.collection.Aggregation)2 AggregationMember (org.cristalise.kernel.collection.AggregationMember)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 RolePath (org.cristalise.kernel.lookup.RolePath)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2 ValidationException (org.exolab.castor.xml.ValidationException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1