use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class AddNewSlot method runActivityLogic.
/**
* Creates a new slot in the given aggregation, that holds instances of the given item description
*
* Params:
* <ol>
* <li>Collection name</li>
* <li>Item Description key (optional)</li>
* <li>Item Description version (optional)</li>
* </ol>
*
* @throws InvalidDataException
* Then the parameters were incorrect
* @throws PersistencyException
* There was a problem loading or saving the collection from persistency
* @throws ObjectNotFoundException
* A required object, such as the collection or a PropertyDescription outcome, wasn't found
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
String collName;
ItemPath descKey = null;
String descVer = "last";
// extract parameters
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "AddNewSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
// resolve desc item path and version
try {
collName = params[0];
if (params.length > 1 && params[1].length() > 0) {
try {
descKey = new ItemPath(params[1]);
} catch (InvalidItemPathException e) {
descKey = new DomainPath(params[1]).getItemPath();
}
}
if (params.length > 2 && params[2].length() > 0)
descVer = params[2];
} catch (Exception e) {
throw new InvalidDataException("AddNewSlot: Invalid parameters " + Arrays.toString(params));
}
// load collection
C2KLocalObject collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
if (!(collObj instanceof Aggregation))
throw new InvalidDataException("AddNewSlot operates on Aggregation only.");
Aggregation agg = (Aggregation) collObj;
// get props
CastorHashMap props = new CastorHashMap();
StringBuffer classProps = new StringBuffer();
if (descKey != null) {
PropertyDescriptionList propList;
propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer, locker);
for (PropertyDescription pd : propList.list) {
props.put(pd.getName(), pd.getDefaultValue());
if (pd.getIsClassIdentifier())
classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
}
}
agg.addSlot(props, classProps.toString());
Gateway.getStorage().put(item, agg, locker);
return requestData;
}
use of org.cristalise.kernel.common.PersistencyException 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;
}
use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class RemoveSlotFromCollection method runActivityLogic.
/**
* Params: 0 - collection name 1 - slot number OR if -1: 2 - target entity key
*
* @throws ObjectNotFoundException
* @throws PersistencyException
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
String collName;
int slotNo = -1;
ItemPath currentChild = null;
Collection<? extends CollectionMember> coll;
// extract parameters
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "RemoveSlotFromCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
try {
collName = params[0];
if (params.length > 1 && params[1].length() > 0)
slotNo = Integer.parseInt(params[1]);
if (params.length > 2 && params[2].length() > 0) {
try {
currentChild = new ItemPath(params[2]);
} catch (InvalidItemPathException e) {
currentChild = new DomainPath(params[2]).getItemPath();
}
}
} catch (Exception e) {
throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters " + Arrays.toString(params));
}
if (slotNo == -1 && currentChild == null)
throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or item UUID");
// load collection
try {
coll = (Collection<? extends CollectionMember>) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
} catch (PersistencyException ex) {
Logger.error(ex);
throw new PersistencyException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': " + ex.getMessage());
}
// check the slot is there if it's given by id
CollectionMember slot = null;
if (slotNo > -1) {
slot = coll.getMember(slotNo);
}
// if both parameters are supplied, check the given item is actually in that slot
if (slot != null && currentChild != null && !slot.getItemPath().equals(currentChild)) {
throw new ObjectNotFoundException("RemoveSlotFromCollection: Item " + currentChild + " was not in slot " + slotNo);
}
if (slotNo == -1) {
// find slot from entity key
for (CollectionMember member : coll.getMembers().list) {
if (member.getItemPath().equals(currentChild)) {
slotNo = member.getID();
break;
}
}
}
if (slotNo == -1) {
throw new ObjectNotFoundException("Could not find " + currentChild + " in collection " + coll.getName());
}
// Remove the slot
coll.removeMember(slotNo);
// Store the collection
try {
Gateway.getStorage().put(item, coll, locker);
} catch (PersistencyException e) {
Logger.error(e);
throw new PersistencyException("Error storing collection");
}
return requestData;
}
use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class ModuleActivity method create.
@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException, InvalidDataException {
try {
domainPath = Bootstrap.verifyResource(ns, name, version, type.getTypeCode(), itemPath, getResourceLocation(), reset);
itemPath = domainPath.getItemPath();
} catch (Exception e) {
Logger.error(e);
throw new CannotManageException("Exception verifying module resource " + ns + "/" + name);
}
actDef = LocalObjectLoader.getActDef(name, version);
populateActivityDef();
CollectionArrayList colls;
try {
colls = actDef.makeDescCollections();
} catch (InvalidDataException e) {
Logger.error(e);
throw new CannotManageException("Could not create description collections for " + getName() + ".");
}
for (Collection<?> coll : colls.list) {
try {
Gateway.getStorage().put(itemPath, coll, null);
// create last collection
coll.setVersion(null);
Gateway.getStorage().put(itemPath, coll, null);
} catch (PersistencyException e) {
Logger.error(e);
throw new CannotManageException("Persistency exception storing description collections for " + getName() + ".");
}
}
return domainPath;
}
use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.
the class ActDefCache method loadObject.
@Override
public ActivityDef loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException {
String viewName;
if (isComposite == null) {
String prop = proxy.getProperty(COMPLEXITY);
if ("Composite".equals(prop))
viewName = COMP_ACT_DESC_RESOURCE.getSchemaName();
else if ("Elementary".equals(prop))
viewName = ELEM_ACT_DESC_RESOURCE.getSchemaName();
else
throw new InvalidDataException("Missing Item property:" + COMPLEXITY);
} else {
viewName = isComposite ? COMP_ACT_DESC_RESOURCE.getSchemaName() : ELEM_ACT_DESC_RESOURCE.getSchemaName();
}
try {
Viewpoint actView = (Viewpoint) proxy.getObject(ClusterType.VIEWPOINT + "/" + viewName + "/" + version);
String marshalledAct = actView.getOutcome().getData();
return buildObject(name, version, proxy.getPath(), marshalledAct);
} catch (PersistencyException ex) {
Logger.error(ex);
throw new ObjectNotFoundException("Problem loading Activity " + name + " v" + version + ": " + ex.getMessage());
}
}
Aggregations