Search in sources :

Example 1 with Aggregation

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;
}
Also used : Aggregation(org.cristalise.kernel.collection.Aggregation) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) AggregationDescription(org.cristalise.kernel.collection.AggregationDescription) GraphPoint(org.cristalise.kernel.graph.model.GraphPoint) AggregationInstance(org.cristalise.kernel.collection.AggregationInstance) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 2 with Aggregation

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;
}
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 3 with Aggregation

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;
}
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 4 with Aggregation

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;
}
Also used : Aggregation(org.cristalise.kernel.collection.Aggregation) Dependency(org.cristalise.kernel.collection.Dependency) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList)

Example 5 with Aggregation

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;
}
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) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

Aggregation (org.cristalise.kernel.collection.Aggregation)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 PersistencyException (org.cristalise.kernel.common.PersistencyException)3 DomainPath (org.cristalise.kernel.lookup.DomainPath)3 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)3 AggregationMember (org.cristalise.kernel.collection.AggregationMember)2 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)2 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)2 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)2 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)2 AggregationDescription (org.cristalise.kernel.collection.AggregationDescription)1 AggregationInstance (org.cristalise.kernel.collection.AggregationInstance)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 Dependency (org.cristalise.kernel.collection.Dependency)1 GraphPoint (org.cristalise.kernel.graph.model.GraphPoint)1 CastorHashMap (org.cristalise.kernel.utils.CastorHashMap)1