Search in sources :

Example 1 with DependencyMember

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

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

the class ActivityDef method makeDescCollection.

public Dependency makeDescCollection(BuiltInCollections collection, DescriptionObject... descs) throws InvalidDataException {
    // TODO: restrict membership based on kernel property desc
    Dependency descDep = new Dependency(collection.getName());
    if (mVersion != null && mVersion > -1) {
        descDep.setVersion(mVersion);
    }
    for (DescriptionObject thisDesc : descs) {
        if (thisDesc == null)
            continue;
        try {
            DependencyMember descMem = descDep.addMember(thisDesc.getItemPath());
            descMem.setBuiltInProperty(VERSION, thisDesc.getVersion());
        } catch (Exception e) {
            Logger.error(e);
            throw new InvalidDataException("Problem creating description collection for " + thisDesc + " in " + getName());
        }
    }
    return descDep;
}
Also used : DependencyMember(org.cristalise.kernel.collection.DependencyMember) DescriptionObject(org.cristalise.kernel.utils.DescriptionObject) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Dependency(org.cristalise.kernel.collection.Dependency) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Aggregations

Dependency (org.cristalise.kernel.collection.Dependency)2 DependencyMember (org.cristalise.kernel.collection.DependencyMember)2 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 DescriptionObject (org.cristalise.kernel.utils.DescriptionObject)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1