Search in sources :

Example 6 with CollectionArrayList

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

the class ImportItem method createCollections.

/**
 * @return
 * @throws InvalidCollectionModification
 * @throws ObjectNotFoundException
 * @throws ObjectAlreadyExistsException
 */
protected CollectionArrayList createCollections() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
    CollectionArrayList colls = new CollectionArrayList();
    for (ImportDependency element : dependencyList) {
        Dependency newDep = element.create();
        colls.put(newDep);
    }
    for (ImportAggregation element : aggregationList) {
        Aggregation newAgg = element.create();
        colls.put(newAgg);
    }
    return colls;
}
Also used : Aggregation(org.cristalise.kernel.collection.Aggregation) Dependency(org.cristalise.kernel.collection.Dependency) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList)

Example 7 with CollectionArrayList

use of org.cristalise.kernel.collection.CollectionArrayList 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 8 with CollectionArrayList

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

the class CreateItemFromDescription method initialiseItem.

/**
 * @param agent
 * @param descItemPath
 * @param locker
 * @param input
 * @param newName
 * @param descVer
 * @param context
 * @param newItemPath
 * @param newItem
 * @throws ObjectCannotBeUpdated
 * @throws CannotManageException
 * @throws InvalidDataException
 * @throws ObjectAlreadyExistsException
 * @throws PersistencyException
 * @throws ObjectNotFoundException
 */
protected void initialiseItem(ItemOperations newItem, AgentPath agent, ItemPath descItemPath, PropertyArrayList initProps, String newName, String descVer, DomainPath context, ItemPath newItemPath, Object locker) throws ObjectCannotBeUpdated, CannotManageException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException {
    // initialise it with its properties and workflow
    Logger.msg(3, "CreateItemFromDescription.initialiseItem() - Initializing Item:" + newName);
    try {
        PropertyArrayList newProps = instantiateProperties(descItemPath, descVer, initProps, newName, agent, locker);
        CollectionArrayList newColls = instantiateCollections(descItemPath, descVer, newProps, locker);
        CompositeActivity newWorkflow = instantiateWorkflow(descItemPath, descVer, locker);
        newItem.initialise(agent.getSystemKey(), Gateway.getMarshaller().marshall(newProps), Gateway.getMarshaller().marshall(newWorkflow), Gateway.getMarshaller().marshall(newColls));
    } catch (MarshalException | ValidationException | AccessRightsException | IOException | MappingException | InvalidCollectionModification e) {
        Logger.error(e);
        Gateway.getLookupManager().delete(newItemPath);
        throw new InvalidDataException("CreateItemFromDescription: Problem initializing new Item. See log: " + e.getMessage());
    } catch (InvalidDataException | ObjectNotFoundException | PersistencyException e) {
        Logger.error(e);
        Gateway.getLookupManager().delete(newItemPath);
        throw e;
    }
    // add its domain path
    Logger.msg(3, "CreateItemFromDescription - Creating " + context);
    context.setItemPath(newItemPath);
    Gateway.getLookupManager().add(context);
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) ValidationException(org.exolab.castor.xml.ValidationException) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) IOException(java.io.IOException) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) MappingException(org.exolab.castor.mapping.MappingException) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 9 with CollectionArrayList

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

the class ModuleActivity method create.

@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException, InvalidDataException {
    try {
        domainPath = Bootstrap.verifyResource(ns, name, version, type.getTypeCode(), itemPath, getResourceLocation(), reset);
        itemPath = domainPath.getItemPath();
    } catch (Exception e) {
        Logger.error(e);
        throw new CannotManageException("Exception verifying module resource " + ns + "/" + name);
    }
    actDef = LocalObjectLoader.getActDef(name, version);
    populateActivityDef();
    CollectionArrayList colls;
    try {
        colls = actDef.makeDescCollections();
    } catch (InvalidDataException e) {
        Logger.error(e);
        throw new CannotManageException("Could not create description collections for " + getName() + ".");
    }
    for (Collection<?> coll : colls.list) {
        try {
            Gateway.getStorage().put(itemPath, coll, null);
            // create last collection
            coll.setVersion(null);
            Gateway.getStorage().put(itemPath, coll, null);
        } catch (PersistencyException e) {
            Logger.error(e);
            throw new CannotManageException("Persistency exception storing description collections for " + getName() + ".");
        }
    }
    return domainPath;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException)

Example 10 with CollectionArrayList

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

the class Script method makeDescCollections.

/**
 */
@Override
public CollectionArrayList makeDescCollections() throws InvalidDataException, ObjectNotFoundException {
    CollectionArrayList retArr = new CollectionArrayList();
    Dependency includeColl = new Dependency(INCLUDE);
    for (Script script : mIncludes) {
        try {
            includeColl.addMember(script.getItemPath());
        } catch (InvalidCollectionModification e) {
            throw new InvalidDataException("Could not add " + script.getName() + " to description collection. " + e.getMessage());
        } catch (ObjectAlreadyExistsException e) {
            throw new InvalidDataException("Script " + script.getName() + " included more than once.");
        }
    // 
    }
    retArr.put(includeColl);
    return retArr;
}
Also used : CompiledScript(javax.script.CompiledScript) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) Dependency(org.cristalise.kernel.collection.Dependency) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Aggregations

CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)10 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 Dependency (org.cristalise.kernel.collection.Dependency)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 PersistencyException (org.cristalise.kernel.common.PersistencyException)3 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)3 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)3 Collection (org.cristalise.kernel.collection.Collection)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)2 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 Property (org.cristalise.kernel.property.Property)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CompiledScript (javax.script.CompiledScript)1 Aggregation (org.cristalise.kernel.collection.Aggregation)1