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()]);
}
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();
}
}
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;
}
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;
}
Aggregations