use of org.cristalise.kernel.collection.Collection in project kernel by cristal-ise.
the class TransferItem method importItem.
public void importItem(File dir) throws Exception {
// check if already exists
try {
Property name = (Property) Gateway.getStorage().get(itemPath, PROPERTY + "/" + NAME, null);
throw new Exception("Item " + itemPath + " already in use as " + name.getValue());
} catch (Exception ex) {
}
// retrieve objects
ArrayList<String> objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true);
ArrayList<C2KLocalObject> objects = new ArrayList<C2KLocalObject>();
for (String element : objectFiles) {
String xmlFile = FileStringUtility.file2String(element);
C2KLocalObject newObj;
String choppedPath = element.substring(dir.getCanonicalPath().length() + 1, element.length() - 4);
Logger.msg(choppedPath);
if (choppedPath.startsWith(OUTCOME.getName()))
newObj = new Outcome(choppedPath, xmlFile);
else
newObj = (C2KLocalObject) Gateway.getMarshaller().unmarshall(xmlFile);
objects.add(newObj);
}
// create item
TraceableEntity newItem = Gateway.getCorbaServer().createItem(itemPath);
Gateway.getLookupManager().add(itemPath);
PropertyArrayList props = new PropertyArrayList();
CollectionArrayList colls = new CollectionArrayList();
Workflow wf = null;
// put objects
for (C2KLocalObject obj : objects) {
if (obj instanceof Property)
props.list.add((Property) obj);
else if (obj instanceof Collection)
colls.list.add((Collection<?>) obj);
else if (obj instanceof Workflow)
wf = (Workflow) obj;
}
if (wf == null)
throw new Exception("No workflow found in import for " + itemPath);
// init item
newItem.initialise(importAgentId.getSystemKey(), Gateway.getMarshaller().marshall(props), Gateway.getMarshaller().marshall(wf.search("workflow/domain")), Gateway.getMarshaller().marshall(colls));
// store objects
importByType(ClusterType.HISTORY, objects);
importByType(ClusterType.OUTCOME, objects);
importByType(ClusterType.VIEWPOINT, objects);
Gateway.getStorage().commit(this);
// add domPaths
for (String element : domainPaths) {
DomainPath newPath = new DomainPath(element, itemPath);
Gateway.getLookupManager().add(newPath);
}
}
use of org.cristalise.kernel.collection.Collection 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;
}
use of org.cristalise.kernel.collection.Collection in project kernel by cristal-ise.
the class CreateItemFromDescription method instantiateWorkflow.
/**
* Retrieve the Workflow dependency for the given description version, instantiate the loaded CompositeActivityDef
*
* @param descItemPath
* @param descVer
* @param locker
* @return the Workflow instance
* @throws ObjectNotFoundException
* @throws InvalidDataException
* @throws PersistencyException
*/
protected CompositeActivity instantiateWorkflow(ItemPath descItemPath, String descVer, Object locker) throws ObjectNotFoundException, InvalidDataException, PersistencyException {
@SuppressWarnings("unchecked") Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>) Gateway.getStorage().get(descItemPath, ClusterType.COLLECTION + "/" + WORKFLOW + "/" + descVer, locker);
CollectionMember wfMember = thisCol.getMembers().list.get(0);
String wfDefName = wfMember.resolveItem().getName();
Object wfVerObj = wfMember.getProperties().getBuiltInProperty(VERSION);
if (wfVerObj == null || String.valueOf(wfVerObj).length() == 0) {
throw new InvalidDataException("Workflow version number not set");
}
try {
Integer wfDefVer = Integer.parseInt(wfVerObj.toString());
if (wfDefName == null)
throw new InvalidDataException("No workflow given or defined");
// load workflow def
CompositeActivityDef wfDef = (CompositeActivityDef) LocalObjectLoader.getActDef(wfDefName, wfDefVer);
return (CompositeActivity) wfDef.instantiate();
} catch (NumberFormatException ex) {
throw new InvalidDataException("Invalid workflow version number: " + wfVerObj.toString());
} catch (ClassCastException ex) {
Logger.error(ex);
throw new InvalidDataException("Activity def '" + wfDefName + "' was not Composite");
}
}
use of org.cristalise.kernel.collection.Collection in project kernel by cristal-ise.
the class CreateNewCollectionVersion method runActivityLogic.
/**
* Generates a new snapshot of a collection from its current state.
* The new version is given the next available number, starting at 0.
* <pre>
* Params:
* 0 - Collection name
* 1 - Version (optional)
* </pre>
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
// extract parameters
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "CreateNewCollectionVersion: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length == 0 || params.length > 2) {
throw new InvalidDataException("CreateNewCollectionVersion: Invalid parameters " + Arrays.toString(params));
}
String collName = params[0];
Collection<?> coll = (Collection<?>) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
int newVersion;
if (params.length > 1) {
newVersion = Integer.valueOf(params[1]);
} else {
// find last numbered version
String[] versions = Gateway.getStorage().getClusterContents(item, ClusterType.COLLECTION + "/" + collName);
int lastVer = -1;
for (String thisVerStr : versions) {
try {
int thisVer = Integer.parseInt(thisVerStr);
if (thisVer > lastVer)
lastVer = thisVer;
}// ignore non-integer versions
catch (NumberFormatException ex) {
}
}
newVersion = lastVer + 1;
}
// Remove it from the cache before we change it
Gateway.getStorage().clearCache(item, ClusterType.COLLECTION + "/" + collName + "/last");
// Set the version & store it
try {
coll.setVersion(newVersion);
Gateway.getStorage().put(item, coll, locker);
} catch (PersistencyException e) {
throw new PersistencyException("CreateNewCollectionVersion: Error saving new collection '" + collName + "': " + e.getMessage());
}
return requestData;
}
Aggregations