Search in sources :

Example 1 with DescriptionObject

use of org.cristalise.kernel.utils.DescriptionObject 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 DescriptionObject

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

the class DefaultResourceImportHandler method getCollections.

private CollectionArrayList getCollections(String name, Integer version, String xml) throws Exception {
    if (type == SCHEMA_RESOURCE) {
        return new Schema(name, version, null, xml).makeDescCollections();
    } else if (type == SCRIPT_RESOURCE) {
        return new Script(name, version, null, xml).makeDescCollections();
    } else if (type == QUERY_RESOURCE) {
        return new Query(name, version, null, xml).makeDescCollections();
    } else {
        DescriptionObject descObject = (DescriptionObject) Gateway.getMarshaller().unmarshall(xml);
        descObject.setVersion(version);
        return descObject.makeDescCollections();
    }
}
Also used : Script(org.cristalise.kernel.scripting.Script) Query(org.cristalise.kernel.querying.Query) Schema(org.cristalise.kernel.persistency.outcome.Schema) DescriptionObject(org.cristalise.kernel.utils.DescriptionObject)

Example 3 with DescriptionObject

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

the class ActivitySlotDef method getTheActivityDef.

public ActivityDef getTheActivityDef() throws ObjectNotFoundException, InvalidDataException {
    if (theActivityDef == null) {
        try {
            Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - try to load from item desc collection of ActSlotDef:" + getName());
            DescriptionObject[] parentActDefs = ((CompositeActivityDef) getParent()).getBuiltInCollectionResource(ACTIVITY);
            for (DescriptionObject thisActDef : parentActDefs) {
                String childUUID = thisActDef.getItemID();
                Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - Collection childUUID:" + childUUID + " of ActSlotDef:" + getName());
                if (childUUID.equals(getActivityDef()) || thisActDef.getName().equals(getActivityDef())) {
                    ActivityDef currentActDef = (ActivityDef) thisActDef;
                    Integer requiredVersion = deriveVersionNumber(getBuiltInProperty(VERSION));
                    if (// collection indicated a different version - get the right one
                    currentActDef.getVersion() != requiredVersion)
                        setTheActivityDef(LocalObjectLoader.getActDef(childUUID, requiredVersion));
                    else
                        // use the existing one
                        setTheActivityDef(currentActDef);
                    break;
                }
            }
        }// old def with no collection
         catch (ObjectNotFoundException ex) {
        }
        if (theActivityDef == null) {
            // try to load from property
            Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - try to load from property of ActSlotDef:" + getName());
            Integer version = deriveVersionNumber(getBuiltInProperty(VERSION));
            if (version == null)
                throw new InvalidDataException("No version defined in ActivityDefSlot " + getName());
            setTheActivityDef(LocalObjectLoader.getActDef(getActivityDef(), version));
        }
    }
    return theActivityDef;
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) DescriptionObject(org.cristalise.kernel.utils.DescriptionObject) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 4 with DescriptionObject

use of org.cristalise.kernel.utils.DescriptionObject 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

DescriptionObject (org.cristalise.kernel.utils.DescriptionObject)4 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)3 Dependency (org.cristalise.kernel.collection.Dependency)2 DependencyMember (org.cristalise.kernel.collection.DependencyMember)2 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 Schema (org.cristalise.kernel.persistency.outcome.Schema)1 Query (org.cristalise.kernel.querying.Query)1 Script (org.cristalise.kernel.scripting.Script)1