use of org.cristalise.kernel.collection.Aggregation 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.collection.Aggregation in project kernel by cristal-ise.
the class ClearSlot method runActivityLogic.
/**
* Params: 0 - collection name 1 - slot number
*
* @throws ObjectNotFoundException
* @throws PersistencyException
* @throws ObjectCannotBeUpdated
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated {
String collName;
int slotNo;
Aggregation agg;
// extract parameters
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "ClearSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
try {
collName = params[0];
slotNo = Integer.parseInt(params[1]);
} catch (Exception e) {
throw new InvalidDataException("ClearSlot: Invalid parameters " + Arrays.toString(params));
}
// load collection
try {
agg = (Aggregation) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
} catch (PersistencyException ex) {
Logger.error(ex);
throw new PersistencyException("ClearSlot: Error loading collection '" + collName + "': " + ex.getMessage());
}
// find member and clear
boolean stored = false;
for (AggregationMember member : agg.getMembers().list) {
if (member.getID() == slotNo) {
if (member.getItemPath() == null)
throw new ObjectCannotBeUpdated("ClearSlot: Member slot " + slotNo + " already empty");
member.clearItem();
stored = true;
break;
}
}
if (!stored) {
throw new ObjectNotFoundException("ClearSlot: Member slot " + slotNo + " not found.");
}
try {
Gateway.getStorage().put(item, agg, locker);
} catch (PersistencyException e) {
Logger.error(e);
throw new PersistencyException("ClearSlot: Error storing collection");
}
return requestData;
}
use of org.cristalise.kernel.collection.Aggregation in project kernel by cristal-ise.
the class AssignItemToSlot method runActivityLogic.
/**
* Params: 0 - collection name 1 - slot number 2 - target entity key
*
* @throws ObjectNotFoundException
* @throws PersistencyException
* @throws ObjectCannotBeUpdated
* @throws InvalidCollectionModification
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated, InvalidCollectionModification {
String collName;
int slotNo;
ItemPath childItem;
Aggregation agg;
// extract parameters
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "AssignItemToSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
try {
collName = params[0];
slotNo = Integer.parseInt(params[1]);
try {
childItem = new ItemPath(params[2]);
} catch (InvalidItemPathException e) {
childItem = new DomainPath(params[2]).getItemPath();
}
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("AssignItemToSlot: Invalid parameters " + Arrays.toString(params));
}
// load collection
C2KLocalObject collObj;
try {
collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
} catch (PersistencyException ex) {
Logger.error(ex);
throw new PersistencyException("AssignItemToSlot: Error loading collection '\"+collName+\"': " + ex.getMessage());
}
if (!(collObj instanceof Aggregation))
throw new InvalidDataException("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only.");
agg = (Aggregation) collObj;
// find member and assign entity
boolean stored = false;
for (AggregationMember member : agg.getMembers().list) {
if (member.getID() == slotNo) {
if (member.getItemPath() != null)
throw new ObjectCannotBeUpdated("AssignItemToSlot: Member slot " + slotNo + " not empty");
member.assignItem(childItem);
stored = true;
break;
}
}
if (!stored) {
throw new ObjectNotFoundException("AssignItemToSlot: Member slot " + slotNo + " not found.");
}
try {
Gateway.getStorage().put(item, agg, locker);
} catch (PersistencyException e) {
throw new PersistencyException("AssignItemToSlot: Error saving collection '" + collName + "': " + e.getMessage());
}
return requestData;
}
use of org.cristalise.kernel.collection.Aggregation in project kernel by cristal-ise.
the class ImportItem method createCollections.
/**
* @return
* @throws InvalidCollectionModification
* @throws ObjectNotFoundException
* @throws ObjectAlreadyExistsException
*/
protected CollectionArrayList createCollections() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
CollectionArrayList colls = new CollectionArrayList();
for (ImportDependency element : dependencyList) {
Dependency newDep = element.create();
colls.put(newDep);
}
for (ImportAggregation element : aggregationList) {
Aggregation newAgg = element.create();
colls.put(newAgg);
}
return colls;
}
use of org.cristalise.kernel.collection.Aggregation 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;
}
Aggregations