Search in sources :

Example 1 with AggregationMember

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;
}
Also used : Aggregation(org.cristalise.kernel.collection.Aggregation) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) AggregationMember(org.cristalise.kernel.collection.AggregationMember) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 2 with AggregationMember

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;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Aggregation(org.cristalise.kernel.collection.Aggregation) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) AggregationMember(org.cristalise.kernel.collection.AggregationMember) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 3 with AggregationMember

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);
    }
}
Also used : GraphPoint(org.cristalise.kernel.graph.model.GraphPoint) FontMetrics(java.awt.FontMetrics) AggregationMember(org.cristalise.kernel.collection.AggregationMember) GraphPoint(org.cristalise.kernel.graph.model.GraphPoint)

Aggregations

AggregationMember (org.cristalise.kernel.collection.AggregationMember)3 Aggregation (org.cristalise.kernel.collection.Aggregation)2 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)2 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)2 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 FontMetrics (java.awt.FontMetrics)1 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)1 GraphPoint (org.cristalise.kernel.graph.model.GraphPoint)1 DomainPath (org.cristalise.kernel.lookup.DomainPath)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 ItemPath (org.cristalise.kernel.lookup.ItemPath)1