use of org.cristalise.kernel.lookup.DomainPath in project kernel by cristal-ise.
the class ImportAggregation method create.
public org.cristalise.kernel.collection.Aggregation create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
Aggregation newAgg = isDescription ? new AggregationDescription(name) : new AggregationInstance(name);
if (version != null)
newAgg.setVersion(version);
for (ImportAggregationMember thisMem : aggregationMemberList) {
StringBuffer classProps = new StringBuffer();
ItemPath itemPath = null;
if (thisMem.itemDescriptionPath != null && thisMem.itemDescriptionPath.length() > 0) {
try {
itemPath = new ItemPath(thisMem.itemDescriptionPath);
} catch (InvalidItemPathException ex) {
itemPath = new DomainPath(thisMem.itemDescriptionPath).getItemPath();
}
String descVer = thisMem.itemDescriptionVersion == null ? "last" : thisMem.itemDescriptionVersion;
PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer, null);
for (PropertyDescription pd : propList.list) {
thisMem.props.put(pd.getName(), pd.getDefaultValue());
if (pd.getIsClassIdentifier())
classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
}
}
if (thisMem.itemPath != null && thisMem.itemPath.length() > 0) {
try {
itemPath = new ItemPath(thisMem.itemPath);
} catch (InvalidItemPathException ex) {
itemPath = new DomainPath(thisMem.itemPath).getItemPath();
}
}
newAgg.addMember(itemPath, thisMem.props, classProps.toString(), new GraphPoint(thisMem.geometry.x, thisMem.geometry.y), thisMem.geometry.width, thisMem.geometry.height);
}
return newAgg;
}
use of org.cristalise.kernel.lookup.DomainPath 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;
}
use of org.cristalise.kernel.lookup.DomainPath 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.lookup.DomainPath in project kernel by cristal-ise.
the class Bootstrap method verifyResource.
/**
* @param ns
* @param itemName
* @param version
* @param itemType
* @param itemPath
* @param outcomes
* @param dataLocation
* @param reset
* @return the Path of the resource either created or initialised from existing data
* @throws Exception
*/
private static DomainPath verifyResource(String ns, String itemName, int version, String itemType, ItemPath itemPath, Set<Outcome> outcomes, String dataLocation, boolean reset) throws Exception {
ResourceImportHandler typeImpHandler = Gateway.getResourceImportHandler(BuiltInResources.getValue(itemType));
Logger.msg(1, "Bootstrap.verifyResource() - Verifying " + typeImpHandler.getName() + " " + itemName + " v" + version);
// Find or create Item for Resource
ItemProxy thisProxy;
DomainPath modDomPath = typeImpHandler.getPath(itemName, ns);
if (modDomPath.exists()) {
Logger.msg(3, "Bootstrap.verifyResource() - Found " + typeImpHandler.getName() + " " + itemName + ".");
thisProxy = verifyPathAndModuleProperty(ns, itemType, itemName, itemPath, modDomPath, modDomPath);
} else {
if (itemPath == null)
itemPath = new ItemPath();
Logger.msg("Bootstrap.verifyResource() - " + typeImpHandler.getName() + " " + itemName + " not found. Creating new.");
thisProxy = createResourceItem(typeImpHandler, itemName, ns, itemPath);
}
// Verify/Import Outcomes, creating events and views as necessary
if (outcomes == null || outcomes.size() == 0) {
outcomes = typeImpHandler.getResourceOutcomes(itemName, ns, dataLocation, version);
}
if (outcomes.size() == 0)
Logger.warning("Bootstrap.verifyResource() - no Outcome found therefore nothing stored!");
for (Outcome newOutcome : outcomes) {
if (checkToStoreOutcomeVersion(thisProxy, newOutcome, version, reset)) {
// validate it, but not for kernel objects (ns == null) because those are to validate the rest
if (ns != null)
newOutcome.validateAndCheck();
storeOutcomeEventAndViews(thisProxy, newOutcome, version);
CollectionArrayList cols = typeImpHandler.getCollections(itemName, version, newOutcome);
for (Collection<?> col : cols.list) {
Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
Gateway.getStorage().clearCache(thisProxy.getPath(), ClusterType.COLLECTION + "/" + col.getName());
col.setVersion(null);
Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
}
}
}
Gateway.getStorage().commit(thisProxy);
return modDomPath;
}
use of org.cristalise.kernel.lookup.DomainPath in project kernel by cristal-ise.
the class Bootstrap method createResourceItem.
/**
* @param impHandler
* @param itemName
* @param ns
* @param itemPath
* @return the ItemProxy representing the newly create Item
* @throws Exception
*/
private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns, ItemPath itemPath) throws Exception {
// create props
PropertyDescriptionList pdList = impHandler.getPropDesc();
PropertyArrayList props = new PropertyArrayList();
LookupManager lookupManager = Gateway.getLookupManager();
for (int i = 0; i < pdList.list.size(); i++) {
PropertyDescription pd = pdList.list.get(i);
String propName = pd.getName();
String propVal = pd.getDefaultValue();
if (propName.equals(NAME.toString()))
propVal = itemName;
else if (propName.equals(MODULE.toString()))
propVal = (ns == null) ? "kernel" : ns;
props.list.add(new Property(propName, propVal, pd.getIsMutable()));
}
CompositeActivity ca = new CompositeActivity();
try {
ca = (CompositeActivity) ((CompositeActivityDef) LocalObjectLoader.getActDef(impHandler.getWorkflowName(), 0)).instantiate();
} catch (ObjectNotFoundException ex) {
Logger.error(ex);
Logger.error("Module resource workflow " + impHandler.getWorkflowName() + " not found. Using empty.");
}
Gateway.getCorbaServer().createItem(itemPath);
lookupManager.add(itemPath);
DomainPath newDomPath = impHandler.getPath(itemName, ns);
newDomPath.setItemPath(itemPath);
lookupManager.add(newDomPath);
ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(itemPath);
newItemProxy.initialise(systemAgents.get("system").getPath(), props, ca, null);
return newItemProxy;
}
Aggregations