Search in sources :

Example 1 with CollectionMember

use of org.cristalise.kernel.collection.CollectionMember in project kernel by cristal-ise.

the class ModuleActivity method getDescRef.

public ModuleDescRef getDescRef(ItemProxy child, BuiltInCollections collection) throws ObjectNotFoundException, InvalidDataException {
    Collection<?> coll = child.getCollection(collection.getName(), version);
    if (coll.size() == 1)
        throw new InvalidDataException("Too many members in " + collection + " collection in " + name);
    CollectionMember collMem = coll.getMembers().list.get(0);
    return new ModuleDescRef(null, collMem.getChildUUID(), Integer.valueOf(collMem.getProperties().get("Version").toString()));
}
Also used : CollectionMember(org.cristalise.kernel.collection.CollectionMember) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 2 with CollectionMember

use of org.cristalise.kernel.collection.CollectionMember in project kernel by cristal-ise.

the class CreateItemFromDescription method instantiateCollections.

/**
 * Copies the CollectionDescriptions of the Item requesting this predefined step.
 *
 * @param descItemPath
 * @param descVer
 * @param locker
 * @return the new collection
 * @throws ObjectNotFoundException
 * @throws PersistencyException
 * @throws InvalidDataException
 */
protected CollectionArrayList instantiateCollections(ItemPath descItemPath, String descVer, PropertyArrayList newProps, Object locker) throws ObjectNotFoundException, PersistencyException, InvalidDataException {
    // loop through collections, collecting instantiated descriptions and finding the default workflow def
    CollectionArrayList colls = new CollectionArrayList();
    String[] collNames = Gateway.getStorage().getClusterContents(descItemPath, ClusterType.COLLECTION);
    for (String collName : collNames) {
        @SuppressWarnings("unchecked") Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>) Gateway.getStorage().get(descItemPath, ClusterType.COLLECTION + "/" + collName + "/" + descVer, locker);
        if (thisCol instanceof CollectionDescription) {
            Logger.msg(5, "CreateItemFromDescription - Instantiating CollectionDescription:" + collName);
            CollectionDescription<?> thisDesc = (CollectionDescription<?>) thisCol;
            colls.put(thisDesc.newInstance());
        } else if (thisCol instanceof Dependency) {
            Logger.msg(5, "CreateItemFromDescription - Instantiating Dependency:" + collName);
            ((Dependency) thisCol).addToItemProperties(newProps);
        } else {
            Logger.warning("CreateItemFromDescription - CANNOT instantiate collection:" + collName + " class:" + thisCol.getClass().getName());
        }
    }
    return colls;
}
Also used : CollectionMember(org.cristalise.kernel.collection.CollectionMember) CollectionDescription(org.cristalise.kernel.collection.CollectionDescription) Collection(org.cristalise.kernel.collection.Collection) Dependency(org.cristalise.kernel.collection.Dependency) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList)

Example 3 with CollectionMember

use of org.cristalise.kernel.collection.CollectionMember in project kernel by cristal-ise.

the class CreateItemFromDescription method instantiateWorkflow.

/**
 * Retrieve the Workflow dependency for the given description version, instantiate the loaded CompositeActivityDef
 *
 * @param descItemPath
 * @param descVer
 * @param locker
 * @return the Workflow instance
 * @throws ObjectNotFoundException
 * @throws InvalidDataException
 * @throws PersistencyException
 */
protected CompositeActivity instantiateWorkflow(ItemPath descItemPath, String descVer, Object locker) throws ObjectNotFoundException, InvalidDataException, PersistencyException {
    @SuppressWarnings("unchecked") Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>) Gateway.getStorage().get(descItemPath, ClusterType.COLLECTION + "/" + WORKFLOW + "/" + descVer, locker);
    CollectionMember wfMember = thisCol.getMembers().list.get(0);
    String wfDefName = wfMember.resolveItem().getName();
    Object wfVerObj = wfMember.getProperties().getBuiltInProperty(VERSION);
    if (wfVerObj == null || String.valueOf(wfVerObj).length() == 0) {
        throw new InvalidDataException("Workflow version number not set");
    }
    try {
        Integer wfDefVer = Integer.parseInt(wfVerObj.toString());
        if (wfDefName == null)
            throw new InvalidDataException("No workflow given or defined");
        // load workflow def
        CompositeActivityDef wfDef = (CompositeActivityDef) LocalObjectLoader.getActDef(wfDefName, wfDefVer);
        return (CompositeActivity) wfDef.instantiate();
    } catch (NumberFormatException ex) {
        throw new InvalidDataException("Invalid workflow version number: " + wfVerObj.toString());
    } catch (ClassCastException ex) {
        Logger.error(ex);
        throw new InvalidDataException("Activity def '" + wfDefName + "' was not Composite");
    }
}
Also used : CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) CollectionMember(org.cristalise.kernel.collection.CollectionMember) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Collection(org.cristalise.kernel.collection.Collection) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef)

Example 4 with CollectionMember

use of org.cristalise.kernel.collection.CollectionMember in project kernel by cristal-ise.

the class Module method addImports.

/**
 * Adds the members of this Collection recursively to the imports of this Module. It checks if the Item
 * referenced by the member has a Collections or not, and adds all of members of those Collection as well.
 *
 * @param contents the Collection to be added as a list of imports
 * @throws ObjectNotFoundException the data was not found
 * @throws InvalidDataException the data was invalid
 */
public void addImports(Collection<?> contents) throws ObjectNotFoundException, InvalidDataException {
    for (CollectionMember mem : contents.getMembers().list) {
        if (mem.getItemPath() != null) {
            ItemProxy child = mem.resolveItem();
            String name = child.getName();
            Integer version = Integer.valueOf(mem.getProperties().get(VERSION.getName()).toString());
            String type = child.getProperty(TYPE);
            ModuleImport newImport;
            switch(type) {
                case "ActivityDesc":
                    String complex = child.getProperty(COMPLEXITY);
                    if (complex.equals("Elementary"))
                        newImport = new ModuleActivity(child, version);
                    else
                        newImport = new ModuleWorkflow(child, version);
                    break;
                case "Script":
                case "Query":
                case "StateMachine":
                case "Schema":
                    newImport = new ModuleResource();
                    break;
                default:
                    throw new InvalidDataException("Resource type '" + type + "' unknown for module export");
            }
            newImport.setName(name);
            newImport.setItemPath(mem.getItemPath());
            newImport.setNamespace(getNamespace());
            if (!imports.list.contains(newImport)) {
                try {
                    // check if child already assigned to a different module
                    String childModule = child.getProperty(MODULE);
                    if (StringUtils.isNotBlank(childModule) && !childModule.equals(getNamespace()))
                        return;
                }// no module property, ok to include
                 catch (ObjectNotFoundException ex) {
                }
                imports.list.add(newImport);
                for (String collName : child.getContents(ClusterType.COLLECTION)) {
                    Collection<?> childColl = child.getCollection(collName, version);
                    addImports(childColl);
                }
            }
        }
    }
}
Also used : ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) CollectionMember(org.cristalise.kernel.collection.CollectionMember) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 5 with CollectionMember

use of org.cristalise.kernel.collection.CollectionMember in project kernel by cristal-ise.

the class RemoveSlotFromCollection method runActivityLogic.

/**
 * Params: 0 - collection name 1 - slot number OR if -1: 2 - target entity key
 *
 * @throws ObjectNotFoundException
 * @throws PersistencyException
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
    String collName;
    int slotNo = -1;
    ItemPath currentChild = null;
    Collection<? extends CollectionMember> coll;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "RemoveSlotFromCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        if (params.length > 1 && params[1].length() > 0)
            slotNo = Integer.parseInt(params[1]);
        if (params.length > 2 && params[2].length() > 0) {
            try {
                currentChild = new ItemPath(params[2]);
            } catch (InvalidItemPathException e) {
                currentChild = new DomainPath(params[2]).getItemPath();
            }
        }
    } catch (Exception e) {
        throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters " + Arrays.toString(params));
    }
    if (slotNo == -1 && currentChild == null)
        throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or item UUID");
    // load collection
    try {
        coll = (Collection<? extends CollectionMember>) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw new PersistencyException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': " + ex.getMessage());
    }
    // check the slot is there if it's given by id
    CollectionMember slot = null;
    if (slotNo > -1) {
        slot = coll.getMember(slotNo);
    }
    // if both parameters are supplied, check the given item is actually in that slot
    if (slot != null && currentChild != null && !slot.getItemPath().equals(currentChild)) {
        throw new ObjectNotFoundException("RemoveSlotFromCollection: Item " + currentChild + " was not in slot " + slotNo);
    }
    if (slotNo == -1) {
        // find slot from entity key
        for (CollectionMember member : coll.getMembers().list) {
            if (member.getItemPath().equals(currentChild)) {
                slotNo = member.getID();
                break;
            }
        }
    }
    if (slotNo == -1) {
        throw new ObjectNotFoundException("Could not find " + currentChild + " in collection " + coll.getName());
    }
    // Remove the slot
    coll.removeMember(slotNo);
    // Store the collection
    try {
        Gateway.getStorage().put(item, coll, locker);
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new PersistencyException("Error storing collection");
    }
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) CollectionMember(org.cristalise.kernel.collection.CollectionMember) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) 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)

Aggregations

CollectionMember (org.cristalise.kernel.collection.CollectionMember)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 Collection (org.cristalise.kernel.collection.Collection)2 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 CollectionDescription (org.cristalise.kernel.collection.CollectionDescription)1 Dependency (org.cristalise.kernel.collection.Dependency)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)1 CompositeActivityDef (org.cristalise.kernel.lifecycle.CompositeActivityDef)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 DomainPath (org.cristalise.kernel.lookup.DomainPath)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 ItemPath (org.cristalise.kernel.lookup.ItemPath)1