Search in sources :

Example 1 with InvalidCollectionModification

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

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

the class Dependency method addMember.

/**
 */
@Override
public DependencyMember addMember(ItemPath itemPath, CastorHashMap props, String classProps) throws InvalidCollectionModification, ObjectAlreadyExistsException {
    if (itemPath == null)
        throw new InvalidCollectionModification("Cannot add empty slot to Dependency collection");
    if (contains(itemPath))
        throw new ObjectAlreadyExistsException("Item " + itemPath + " already exists in Dependency " + getName());
    if (classProps != null && !classProps.equals(mClassProps))
        throw new InvalidCollectionModification("Cannot change classProps in dependency member");
    DependencyMember depMember = new DependencyMember();
    depMember.setID(getCounter());
    // merge props
    CastorHashMap newProps = new CastorHashMap();
    for (Object name : props.keySet()) {
        String key = (String) name;
        newProps.put(key, props.get(key));
    }
    // class props override local
    for (Object name : mProperties.keySet()) {
        String key = (String) name;
        newProps.put(key, mProperties.get(key));
    }
    depMember.setProperties(newProps);
    depMember.setClassProps(mClassProps);
    // assign entity
    depMember.assignItem(itemPath);
    mMembers.list.add(depMember);
    Logger.msg(8, "Dependency.addMember(" + itemPath + ") added to children.");
    return depMember;
}
Also used : CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Example 3 with InvalidCollectionModification

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

the class DependencyMember method assignItem.

@Override
public void assignItem(ItemPath itemPath) throws InvalidCollectionModification {
    if (itemPath != null) {
        if (mClassProps == null || getProperties() == null)
            throw new InvalidCollectionModification("ClassProps not yet set. Cannot check membership validity.");
        // for each mandatory prop check if its in the member property and has the matching value
        StringTokenizer sub = new StringTokenizer(mClassProps, ",");
        while (sub.hasMoreTokens()) {
            String aClassProp = sub.nextToken();
            try {
                String memberValue = (String) getProperties().get(aClassProp);
                Property ItemProperty = (Property) Gateway.getStorage().get(itemPath, ClusterType.PROPERTY + "/" + aClassProp, null);
                if (ItemProperty == null)
                    throw new InvalidCollectionModification("Property " + aClassProp + " does not exist for item " + itemPath);
                if (!ItemProperty.getValue().equalsIgnoreCase(memberValue))
                    throw new InvalidCollectionModification("DependencyMember::checkProperty() Values of mandatory prop " + aClassProp + " do not match " + ItemProperty.getValue() + "!=" + memberValue);
            } catch (Exception ex) {
                Logger.error(ex);
                throw new InvalidCollectionModification("Error checking properties");
            }
        }
    }
    mItemPath = itemPath;
    mItem = null;
}
Also used : StringTokenizer(java.util.StringTokenizer) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) Property(org.cristalise.kernel.property.Property) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException)

Example 4 with InvalidCollectionModification

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

the class AggregationMember method assignItem.

@Override
public void assignItem(ItemPath itemPath) throws InvalidCollectionModification {
    if (itemPath != null) {
        if (mClassProps == null || getProperties() == null)
            throw new InvalidCollectionModification("ClassProps not yet set. Cannot check membership validity.");
        // for each mandatory prop check if its in the member property and has the matching value
        StringTokenizer sub = new StringTokenizer(mClassProps, ",");
        while (sub.hasMoreTokens()) {
            String aClassProp = sub.nextToken();
            try {
                String memberValue = (String) getProperties().get(aClassProp);
                Property ItemProperty = (Property) Gateway.getStorage().get(itemPath, ClusterType.PROPERTY + "/" + aClassProp, null);
                if (ItemProperty == null)
                    throw new InvalidCollectionModification("Property " + aClassProp + " does not exist for item " + itemPath);
                if (ItemProperty.getValue() == null || !ItemProperty.getValue().equalsIgnoreCase(memberValue))
                    throw new InvalidCollectionModification("Value of mandatory prop " + aClassProp + " does not match: " + ItemProperty.getValue() + "!=" + memberValue);
            } catch (InvalidCollectionModification ex) {
                throw ex;
            } catch (Exception ex) {
                Logger.error(ex);
                throw new InvalidCollectionModification("Error checking properties");
            }
        }
    }
    mItemPath = itemPath;
    mItem = null;
    mItemName = null;
}
Also used : StringTokenizer(java.util.StringTokenizer) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) Property(org.cristalise.kernel.property.Property) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 5 with InvalidCollectionModification

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

the class Dependency method addMember.

/**
 * Add a member to the Dependency
 *
 * @param itemPath the Item to be added as a Member
 * @return DependencyMember the newly created DependencyMember
 * @throws InvalidCollectionModification if Item is null or the Properties of the Item (e.g. Type) does not match the Collection's
 * @throws ObjectAlreadyExistsException Item is already a member
 */
public DependencyMember addMember(ItemPath itemPath) throws InvalidCollectionModification, ObjectAlreadyExistsException {
    if (itemPath == null)
        throw new InvalidCollectionModification("Cannot add empty slot to Dependency collection");
    if (contains(itemPath))
        throw new ObjectAlreadyExistsException("Item " + itemPath + " already exists in Dependency " + getName());
    // create member object
    DependencyMember depMember = new DependencyMember();
    depMember.setID(getCounter());
    depMember.setProperties((CastorHashMap) mProperties.clone());
    depMember.setClassProps(mClassProps);
    // assign entity
    depMember.assignItem(itemPath);
    mMembers.list.add(depMember);
    Logger.msg(8, "Dependency.addMember(" + itemPath + ") added to children.");
    return depMember;
}
Also used : InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Aggregations

InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)8 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)4 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 Property (org.cristalise.kernel.property.Property)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2 ValidationException (org.exolab.castor.xml.ValidationException)2 CompiledScript (javax.script.CompiledScript)1 Dependency (org.cristalise.kernel.collection.Dependency)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)1 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)1 Vertex (org.cristalise.kernel.graph.model.Vertex)1