use of org.cristalise.kernel.lookup.InvalidItemPathException in project kernel by cristal-ise.
the class ItemImplementation method initialise.
@Override
public void initialise(SystemKey agentId, String propString, String initWfString, String initCollsString) throws AccessRightsException, InvalidDataException, PersistencyException {
Logger.msg(5, "Item::initialise(" + mItemPath + ") - agent:" + agentId);
Object locker = new Object();
AgentPath agentPath;
try {
agentPath = new AgentPath(agentId);
} catch (InvalidItemPathException e) {
throw new AccessRightsException("Invalid Agent Id:" + agentId);
}
// must supply properties
if (propString == null || propString.length() == 0 || propString.equals("<NULL/>")) {
throw new InvalidDataException("No properties supplied");
}
// store properties
try {
PropertyArrayList props = (PropertyArrayList) Gateway.getMarshaller().unmarshall(propString);
for (Property thisProp : props.list) mStorage.put(mItemPath, thisProp, locker);
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Properties were invalid: " + propString);
Logger.error(ex);
mStorage.abort(locker);
throw new InvalidDataException("Properties were invalid");
}
// Store an event and the initial properties
try {
Schema initSchema = LocalObjectLoader.getSchema("ItemInitialization", 0);
Outcome initOutcome = new Outcome(0, propString, initSchema);
History hist = new History(mItemPath, locker);
Event newEvent = hist.addEvent(new AgentPath(agentId), null, "", "Initialize", "", "", initSchema, Bootstrap.getPredefSM(), PredefinedStep.DONE, "last");
initOutcome.setID(newEvent.getID());
Viewpoint newLastView = new Viewpoint(mItemPath, initSchema, "last", newEvent.getID());
mStorage.put(mItemPath, initOutcome, locker);
mStorage.put(mItemPath, newLastView, locker);
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Could not store event and outcome.");
Logger.error(ex);
mStorage.abort(locker);
throw new PersistencyException("Error storing event and outcome");
}
// init collections
if (initCollsString != null && initCollsString.length() > 0 && !initCollsString.equals("<NULL/>")) {
try {
CollectionArrayList colls = (CollectionArrayList) Gateway.getMarshaller().unmarshall(initCollsString);
for (Collection<?> thisColl : colls.list) {
mStorage.put(mItemPath, thisColl, locker);
}
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Collections were invalid: " + initCollsString);
Logger.error(ex);
mStorage.abort(locker);
throw new InvalidDataException("Collections were invalid");
}
}
// create wf
Workflow lc = null;
try {
if (initWfString == null || initWfString.length() == 0 || initWfString.equals("<NULL/>")) {
lc = new Workflow(new CompositeActivity(), getNewPredefStepContainer());
} else {
lc = new Workflow((CompositeActivity) Gateway.getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
}
mStorage.put(mItemPath, lc, locker);
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Workflow was invalid: " + initWfString);
Logger.error(ex);
mStorage.abort(locker);
throw new InvalidDataException("Workflow was invalid");
}
// All objects are in place, initialize the workflow to get the Item running
lc.initialise(mItemPath, agentPath, locker);
mStorage.put(mItemPath, lc, locker);
mStorage.commit(locker);
Logger.msg(3, "Initialisation of item " + mItemPath + " was successful");
}
use of org.cristalise.kernel.lookup.InvalidItemPathException 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.InvalidItemPathException 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.InvalidItemPathException in project kernel by cristal-ise.
the class Bootstrap method verifyBootDataItems.
/**
* @param bootList
* @param ns
* @param reset
* @throws InvalidItemPathException
*/
private static void verifyBootDataItems(String bootList, String ns, boolean reset) throws InvalidItemPathException {
StringTokenizer str = new StringTokenizer(bootList, "\n\r");
while (str.hasMoreTokens() && !shutdown) {
String thisItem = str.nextToken();
String[] idFilename = thisItem.split(",");
String id = idFilename[0], filename = idFilename[1];
ItemPath itemPath = new ItemPath(id);
String[] fileParts = filename.split("/");
String itemType = fileParts[0], itemName = fileParts[1];
try {
String location = "boot/" + filename + (itemType.equals("OD") ? ".xsd" : ".xml");
verifyResource(ns, itemName, 0, itemType, itemPath, location, reset);
} catch (Exception e) {
Logger.error(e);
Logger.die("Error importing bootstrap items. Unsafe to continue.");
}
}
}
use of org.cristalise.kernel.lookup.InvalidItemPathException in project kernel by cristal-ise.
the class SetAgentPassword method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
String[] params = getDataList(requestData);
Logger.msg(3, "SetAgentPassword: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length != 1)
throw new InvalidDataException("SetAgentPassword: Invalid parameters " + Arrays.toString(params));
try {
AgentPath targetAgent = new AgentPath(item);
if (!targetAgent.equals(agent) && !agent.hasRole("Admin")) {
throw new InvalidDataException("Agent passwords may only be set by those Agents or by an Administrator");
}
Gateway.getLookupManager().setAgentPassword(targetAgent, params[0]);
// censor password from outcome
params[0] = "REDACTED";
return bundleData(params);
} catch (InvalidItemPathException ex) {
Logger.error(ex);
throw new InvalidDataException("Can only set password on an Agent. " + item + " is an Item.");
} catch (NoSuchAlgorithmException e) {
Logger.error(e);
throw new InvalidDataException("Cryptographic libraries for password hashing not found.");
}
}
Aggregations