Search in sources :

Example 1 with Dependency

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

the class ImportDependency method create.

public Dependency create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
    Dependency newDep = isDescription ? new DependencyDescription(name) : new Dependency(name);
    if (version != null)
        newDep.setVersion(version);
    if (itemDescriptionPath != null && itemDescriptionPath.length() > 0) {
        ItemPath itemPath;
        try {
            itemPath = new ItemPath(itemDescriptionPath);
        } catch (InvalidItemPathException ex) {
            itemPath = new DomainPath(itemDescriptionPath).getItemPath();
        }
        String descVer = itemDescriptionVersion == null ? "last" : itemDescriptionVersion;
        PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer, null);
        StringBuffer classProps = new StringBuffer();
        for (PropertyDescription pd : propList.list) {
            props.put(pd.getName(), pd.getDefaultValue());
            if (pd.getIsClassIdentifier())
                classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
        }
        newDep.setProperties(props);
        newDep.setClassProps(classProps.toString());
    }
    for (ImportDependencyMember thisMem : dependencyMemberList) {
        ItemPath itemPath;
        try {
            itemPath = new ItemPath(thisMem.itemPath);
        } catch (InvalidItemPathException ex) {
            itemPath = new DomainPath(thisMem.itemPath).getItemPath();
        }
        org.cristalise.kernel.collection.DependencyMember newDepMem = newDep.addMember(itemPath);
        newDepMem.getProperties().putAll(thisMem.props);
    }
    return newDep;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) Dependency(org.cristalise.kernel.collection.Dependency) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) DependencyDescription(org.cristalise.kernel.collection.DependencyDescription) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 2 with Dependency

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

the class ActivityDef method configureInstance.

/**
 */
@Override
public void configureInstance(WfVertex act) throws InvalidDataException, ObjectNotFoundException {
    super.configureInstance(act);
    try {
        for (String collName : Gateway.getStorage().getClusterContents(itemPath, ClusterType.COLLECTION)) {
            Logger.msg(5, "ActivityDef.configureInstance(" + getName() + ") - Processing collection:" + collName);
            String verStr = (mVersion == null || mVersion == -1) ? "last" : String.valueOf(mVersion);
            Dependency dep = null;
            try {
                dep = (Dependency) Gateway.getStorage().get(itemPath, ClusterType.COLLECTION + "/" + collName + "/" + verStr, null);
            } catch (ObjectNotFoundException e) {
                if (Logger.doLog(8))
                    Logger.warning("Unavailable Collection path:" + itemPath + "/" + ClusterType.COLLECTION + "/" + collName + "/" + verStr);
            } catch (PersistencyException e) {
                Logger.error(e);
                throw new InvalidDataException("Collection:" + collName + " error:" + e.getMessage());
            }
            if (dep != null)
                dep.addToVertexProperties(act.getProperties());
        }
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new InvalidDataException(e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) Dependency(org.cristalise.kernel.collection.Dependency)

Example 3 with Dependency

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

the class ActivityDef method getBuiltInCollectionResource.

protected DescriptionObject[] getBuiltInCollectionResource(BuiltInCollections collection) throws ObjectNotFoundException, InvalidDataException {
    ArrayList<DescriptionObject> retArr = new ArrayList<DescriptionObject>();
    if (itemPath == null) {
        Logger.warning("ActivityDef.getBuiltInCollectionResource(actName:" + getName() + ", collection:" + collection + ") - itemPath is null! CANNOT resolve data in ClusterStorage");
        return retArr.toArray(new DescriptionObject[0]);
    // throw new InvalidDataException("actName:"+getName()+", collection:"+collection+" - itemPath is null! CANNOT resolve data in ClusterStorage");
    }
    Logger.msg(5, "ActivityDef.getBuiltInCollectionResource(actName:" + getName() + ") - Loading from collection:" + collection);
    Dependency resColl;
    try {
        String clusterPath = ClusterType.COLLECTION + "/" + collection + "/" + ((mVersion == null || mVersion == -1) ? "last" : String.valueOf(mVersion));
        String[] contents = Gateway.getStorage().getClusterContents(itemPath, clusterPath);
        if (contents != null && contents.length > 0)
            resColl = (Dependency) Gateway.getStorage().get(itemPath, clusterPath, null);
        else
            return retArr.toArray(new DescriptionObject[retArr.size()]);
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new InvalidDataException("Error loading description collection " + collection);
    }
    for (DependencyMember resMem : resColl.getMembers().list) {
        String resUUID = resMem.getChildUUID();
        Integer resVer = deriveVersionNumber(resMem.getBuiltInProperty(VERSION));
        if (resVer == null) {
            throw new InvalidDataException("Version is null for Item:" + itemPath + ", Collection:" + collection + ", DependencyMember:" + resUUID);
        }
        if (collection != ACTIVITY && retArr.size() > 0) {
            throw new InvalidDataException("actName:" + getName() + " has an invalid dependency:" + collection);
        }
        switch(collection) {
            case SCHEMA:
                retArr.add(LocalObjectLoader.getSchema(resUUID, resVer));
                break;
            case SCRIPT:
                retArr.add(LocalObjectLoader.getScript(resUUID, resVer));
                break;
            case QUERY:
                retArr.add(LocalObjectLoader.getQuery(resUUID, resVer));
                break;
            case STATE_MACHINE:
                retArr.add(LocalObjectLoader.getStateMachine(resUUID, resVer));
                break;
            case ACTIVITY:
                retArr.add(LocalObjectLoader.getActDef(resUUID, resVer));
                break;
            default:
                throw new InvalidDataException("");
        }
    }
    return retArr.toArray(new DescriptionObject[retArr.size()]);
}
Also used : DependencyMember(org.cristalise.kernel.collection.DependencyMember) DescriptionObject(org.cristalise.kernel.utils.DescriptionObject) ArrayList(java.util.ArrayList) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) Dependency(org.cristalise.kernel.collection.Dependency)

Example 4 with Dependency

use of org.cristalise.kernel.collection.Dependency 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 Dependency

use of org.cristalise.kernel.collection.Dependency 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)

Aggregations

Dependency (org.cristalise.kernel.collection.Dependency)8 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)4 PersistencyException (org.cristalise.kernel.common.PersistencyException)4 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 DependencyMember (org.cristalise.kernel.collection.DependencyMember)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 DescriptionObject (org.cristalise.kernel.utils.DescriptionObject)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CompiledScript (javax.script.CompiledScript)1 Aggregation (org.cristalise.kernel.collection.Aggregation)1 Collection (org.cristalise.kernel.collection.Collection)1 CollectionDescription (org.cristalise.kernel.collection.CollectionDescription)1 CollectionMember (org.cristalise.kernel.collection.CollectionMember)1 DependencyDescription (org.cristalise.kernel.collection.DependencyDescription)1 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)1