Search in sources :

Example 1 with CastorHashMap

use of org.cristalise.kernel.utils.CastorHashMap 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 2 with CastorHashMap

use of org.cristalise.kernel.utils.CastorHashMap in project kernel by cristal-ise.

the class Dependency method convertToVertextPropsByScript.

/**
 * Executes Script if it was defined in the Member properties
 *
 * @param props the current list of VertexProperties
 * @param member the current DependencyMember
 * @return true when Script was executed
 * @throws InvalidDataException
 * @throws ObjectNotFoundException
 */
private boolean convertToVertextPropsByScript(CastorHashMap props, DependencyMember member) throws InvalidDataException, ObjectNotFoundException {
    Logger.msg(5, "Dependency.convertToVertextPropsByScript() - Dependency:" + getName() + " memberUUID:" + member.getChildUUID());
    String scriptName = (String) member.getBuiltInProperty(SCRIPT_NAME);
    if (scriptName != null && scriptName.length() > 0) {
        CastorHashMap newProps = (CastorHashMap) member.evaluateScript();
        props.merge(newProps);
        return true;
    }
    return false;
}
Also used : CastorHashMap(org.cristalise.kernel.utils.CastorHashMap)

Example 3 with CastorHashMap

use of org.cristalise.kernel.utils.CastorHashMap in project kernel by cristal-ise.

the class CompositeActivityDef method propagateCollectionProperties.

/**
 * Reading collections during configureInstance() the properties of CAInstance can be updated to
 * contain CastorHashMaps, which contain properties to be propagated to the Vertices of CAInstance.
 *
 * @param caInstance the CompAct instance beeing instantiated
 * @throws InvalidDataException
 */
private void propagateCollectionProperties(CompositeActivity caInstance) throws InvalidDataException {
    // Propagate now properties to Vertices
    CastorHashMap caProps = caInstance.getProperties();
    List<String> keysToDelete = new ArrayList<String>();
    for (Entry<String, Object> aCAProp : caProps.entrySet()) {
        if (aCAProp.getValue() instanceof CastorHashMap) {
            for (Vertex vertex : caInstance.getChildrenGraphModel().getVertices()) {
                CastorHashMap propsToPropagate = (CastorHashMap) aCAProp.getValue();
                propsToPropagate.dump(8);
                BuiltInVertexProperties builtInProp = BuiltInVertexProperties.getValue(aCAProp.getKey());
                if (builtInProp == null) {
                    ((GraphableVertex) vertex).updatePropertiesFromCollection(Integer.parseInt(aCAProp.getKey()), propsToPropagate);
                } else {
                    ((GraphableVertex) vertex).updatePropertiesFromCollection(builtInProp, propsToPropagate);
                }
            }
            keysToDelete.add(aCAProp.getKey());
        }
    }
    for (String key : keysToDelete) caProps.remove(key);
}
Also used : Vertex(org.cristalise.kernel.graph.model.Vertex) WfVertex(org.cristalise.kernel.lifecycle.instance.WfVertex) GraphableVertex(org.cristalise.kernel.graph.model.GraphableVertex) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) ArrayList(java.util.ArrayList) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) GraphableVertex(org.cristalise.kernel.graph.model.GraphableVertex) BuiltInVertexProperties(org.cristalise.kernel.graph.model.BuiltInVertexProperties)

Example 4 with CastorHashMap

use of org.cristalise.kernel.utils.CastorHashMap in project kernel by cristal-ise.

the class AddMemberToCollection method runActivityLogic.

/**
 * <pre>
 * Generates a new slot in a Dependency for the given item
 *
 * Params:
 * 0 - collection name
 * 1 - target entity key
 * 2 - slot properties
 * </pre>
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException, InvalidCollectionModification {
    String collName;
    ItemPath newChild;
    Dependency dep;
    CastorHashMap props = null;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddMemberToCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        try {
            newChild = new ItemPath(params[1]);
        } catch (InvalidItemPathException e) {
            newChild = new DomainPath(params[1]).getItemPath();
        }
        if (params.length > 2) {
            Logger.msg(5, "AddMemberToCollection: Unmarshalling Properties:" + params[2]);
            props = (CastorHashMap) Gateway.getMarshaller().unmarshall(params[2]);
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("AddMemberToCollection: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    C2KLocalObject collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    if (!(collObj instanceof Dependency))
        throw new InvalidDataException("AddMemberToCollection operates on Dependency only.");
    dep = (Dependency) collObj;
    // find member and assign entity
    if (props == null)
        dep.addMember(newChild);
    else
        dep.addMember(newChild, props, dep.getClassProps());
    Gateway.getStorage().put(item, dep, locker);
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Dependency(org.cristalise.kernel.collection.Dependency) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 5 with CastorHashMap

use of org.cristalise.kernel.utils.CastorHashMap in project kernel by cristal-ise.

the class Dependency method addToVertexProperties.

/**
 * Add Dependency specific values to VertexProperties (CastorHashMap). First checks if there is a Script
 * to be executed, if no Script defined it will use the default conversion implemented for BuiltInCollections
 *
 * @param props the current list of VertexProperties
 * @throws InvalidDataException inconsistent data was provided
 * @throws ObjectNotFoundException objects were not found while reading the properties
 */
public void addToVertexProperties(CastorHashMap props) throws InvalidDataException, ObjectNotFoundException {
    Logger.msg(2, "Dependency.addToVertexProperties(" + getName() + ") - Starting ...");
    BuiltInCollections builtInColl = BuiltInCollections.getValue(getName());
    for (DependencyMember member : getMembers().list) {
        String memberUUID = member.getChildUUID();
        Integer memberVer = LocalObjectLoader.deriveVersionNumber(member.getBuiltInProperty(VERSION));
        if (memberVer == null) {
            throw new InvalidDataException("Version is null for Collection:" + getName() + ", DependencyMember:" + memberUUID);
        }
        // - or this is not a BuiltInCollection
        if (convertToVertextPropsByScript(props, member) || builtInColl == null)
            continue;
        Logger.msg(5, "Dependency.addToVertexProperties() - Dependency:" + getName() + " memberUUID:" + memberUUID);
        // LocalObjectLoader checks if data is valid and loads object to cache
        switch(builtInColl) {
            // ***************************************************************************************************
            case SCHEMA:
                try {
                    LocalObjectLoader.getSchema(memberUUID, memberVer);
                    props.setBuiltInProperty(SCHEMA_NAME, memberUUID);
                    props.setBuiltInProperty(SCHEMA_VERSION, memberVer);
                } catch (ObjectNotFoundException e) {
                    // Schema dependency could be defined in Properties
                    if (props.containsKey(SCHEMA_NAME)) {
                        Logger.msg(8, "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
                        String uuid = LocalObjectLoader.getSchema(props).getItemPath().getUUID().toString();
                        props.setBuiltInProperty(SCHEMA_NAME, uuid);
                    }
                }
                break;
            // ***************************************************************************************************
            case SCRIPT:
                try {
                    LocalObjectLoader.getScript(memberUUID, memberVer);
                    props.setBuiltInProperty(SCRIPT_NAME, memberUUID);
                    props.setBuiltInProperty(SCRIPT_VERSION, memberVer);
                } catch (ObjectNotFoundException e) {
                    // Backward compability: Script dependency could be defined in Properties
                    if (props.containsKey(SCRIPT_NAME)) {
                        Logger.msg(8, "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
                        String uuid = LocalObjectLoader.getScript(props).getItemPath().getUUID().toString();
                        props.setBuiltInProperty(SCRIPT_NAME, uuid);
                    }
                }
                break;
            // ***************************************************************************************************
            case QUERY:
                try {
                    LocalObjectLoader.getQuery(memberUUID, memberVer);
                    props.setBuiltInProperty(QUERY_NAME, memberUUID);
                    props.setBuiltInProperty(QUERY_VERSION, memberVer);
                } catch (ObjectNotFoundException e) {
                    // Backward compability: Query dependency could be defined in Properties
                    if (props.containsKey(QUERY_NAME)) {
                        Logger.msg(8, "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
                        String uuid = LocalObjectLoader.getQuery(props).getItemPath().getUUID().toString();
                        props.setBuiltInProperty(QUERY_NAME, uuid);
                    }
                }
                break;
            // ***************************************************************************************************
            case STATE_MACHINE:
                try {
                    LocalObjectLoader.getStateMachine(memberUUID, memberVer);
                    props.setBuiltInProperty(STATE_MACHINE_NAME, memberUUID);
                    props.setBuiltInProperty(STATE_MACHINE_VERSION, memberVer);
                } catch (ObjectNotFoundException e) {
                    if (props.containsKey(STATE_MACHINE_NAME)) {
                        Logger.msg(8, "Dependency.addToVertexProperties() -  BACKWARD COMPABILITY: Dependency '" + getName() + "' is defined in Properties");
                        String uuid = LocalObjectLoader.getStateMachine(props).getItemPath().getUUID().toString();
                        props.setBuiltInProperty(STATE_MACHINE_NAME, uuid);
                    }
                }
                break;
            // ***************************************************************************************************
            case ACTIVITY:
                ActivityDef actDef = LocalObjectLoader.getActDef(memberUUID, memberVer);
                CastorHashMap chm = null;
                if (props.containsKey(ACTIVITY_DEF_URN)) {
                    chm = (CastorHashMap) props.getBuiltInProperty(ACTIVITY_DEF_URN);
                } else {
                    chm = new CastorHashMap();
                    props.setBuiltInProperty(ACTIVITY_DEF_URN, chm);
                }
                Logger.msg(8, "Dependency.addToVertexProperties(" + getName() + ") - actDef:" + actDef.getActName());
                chm.put(actDef.getActName(), memberUUID + "~" + memberVer);
                break;
            // ***************************************************************************************************
            default:
                Logger.msg(8, "Dependency.addToVertexProperties() - Cannot handle BuiltIn Dependency:" + getName());
                break;
        }
    }
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ActivityDef(org.cristalise.kernel.lifecycle.ActivityDef)

Aggregations

CastorHashMap (org.cristalise.kernel.utils.CastorHashMap)6 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 ArrayList (java.util.ArrayList)1 Aggregation (org.cristalise.kernel.collection.Aggregation)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 Dependency (org.cristalise.kernel.collection.Dependency)1 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)1 BuiltInVertexProperties (org.cristalise.kernel.graph.model.BuiltInVertexProperties)1 GraphableVertex (org.cristalise.kernel.graph.model.GraphableVertex)1 Vertex (org.cristalise.kernel.graph.model.Vertex)1 ActivityDef (org.cristalise.kernel.lifecycle.ActivityDef)1 WfVertex (org.cristalise.kernel.lifecycle.instance.WfVertex)1 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)1