use of org.cristalise.kernel.collection.AggregationMember 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.AggregationMember 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.AggregationMember in project kernel by cristal-ise.
the class AggregationMemberRenderer method draw.
@Override
public void draw(Graphics2D g2d, Vertex vertex) {
GraphPoint centre = vertex.getCentrePoint();
GraphPoint[] outline = vertex.getOutlinePoints();
FontMetrics metrics = g2d.getFontMetrics();
AggregationMember memberPair = mAggregation.getMemberPair(vertex.getID());
try {
String name = memberPair.getItemName();
g2d.drawString(name, centre.x - metrics.stringWidth(name) / 2, vertex.getID() % 2 == 0 ? topYOfOutline(outline) : bottomYOfOutline(outline) + metrics.getHeight());
g2d.drawImage(getImage(memberPair), centre.x - 8, centre.y - 8, null);
// Draw the outline of the vertex
if (outline.length > 1) {
for (int i = 0; i < outline.length - 1; i++) {
g2d.drawLine(outline[i].x, outline[i].y, outline[i + 1].x, outline[i + 1].y);
}
g2d.drawLine(outline[outline.length - 1].x, outline[outline.length - 1].y, outline[0].x, outline[0].y);
}
} catch (Exception ex) {
Logger.error("AggregationMemberRenderer::draw() " + ex);
}
}
Aggregations