Search in sources :

Example 16 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class AddMemberToCollection method runActivityLogic.

/**
 * <pre>
 * Generates a new slot in a Dependency for the given item
 *
 * Params:
 * 0 - collection name
 * 1 - target entity key
 * 2 - slot properties
 * </pre>
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException, InvalidCollectionModification {
    String collName;
    ItemPath newChild;
    Dependency dep;
    CastorHashMap props = null;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddMemberToCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        try {
            newChild = new ItemPath(params[1]);
        } catch (InvalidItemPathException e) {
            newChild = new DomainPath(params[1]).getItemPath();
        }
        if (params.length > 2) {
            Logger.msg(5, "AddMemberToCollection: Unmarshalling Properties:" + params[2]);
            props = (CastorHashMap) Gateway.getMarshaller().unmarshall(params[2]);
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("AddMemberToCollection: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    C2KLocalObject collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    if (!(collObj instanceof Dependency))
        throw new InvalidDataException("AddMemberToCollection operates on Dependency only.");
    dep = (Dependency) collObj;
    // find member and assign entity
    if (props == null)
        dep.addMember(newChild);
    else
        dep.addMember(newChild, props, dep.getClassProps());
    Gateway.getStorage().put(item, dep, locker);
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Dependency(org.cristalise.kernel.collection.Dependency) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 17 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath 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 18 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class Erase method runActivityLogic.

// requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
    Logger.msg(1, "Erase::request() - Starting item:" + item.getUUID());
    Iterator<Path> domPaths = Gateway.getLookup().searchAliases(item);
    while (domPaths.hasNext()) {
        DomainPath path = (DomainPath) domPaths.next();
        // delete them
        if (path.getItemPath().equals(item))
            Gateway.getLookupManager().delete(path);
    }
    // clear out all storages
    Gateway.getStorage().removeCluster(item, "", locker);
    Logger.msg(1, "Erase::request() - DONE item:" + item.getUUID());
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) AgentPath(org.cristalise.kernel.lookup.AgentPath) ItemPath(org.cristalise.kernel.lookup.ItemPath) Path(org.cristalise.kernel.lookup.Path) DomainPath(org.cristalise.kernel.lookup.DomainPath)

Example 19 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class CastorXMLTest method testCastorItemPath.

@Test
public void testCastorItemPath() throws Exception {
    CastorXMLUtility marshaller = Gateway.getMarshaller();
    ItemPath item = new ItemPath(UUID.randomUUID(), ior);
    ItemPath itemPrime = (ItemPath) marshaller.unmarshall(marshaller.marshall(item));
    assertEquals(item.getUUID(), itemPrime.getUUID());
    assertEquals(item.getIORString(), itemPrime.getIORString());
    Logger.msg(marshaller.marshall(itemPrime));
}
Also used : CastorXMLUtility(org.cristalise.kernel.utils.CastorXMLUtility) ItemPath(org.cristalise.kernel.lookup.ItemPath) MainTest(org.cristalise.kernel.test.process.MainTest) Test(org.junit.Test)

Example 20 with ItemPath

use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.

the class CastorXMLTest method testCastorDomainPath_WithTarget.

@Test
public void testCastorDomainPath_WithTarget() throws Exception {
    CastorXMLUtility marshaller = Gateway.getMarshaller();
    DomainPath domain = new DomainPath("/domain/path", new ItemPath());
    DomainPath domainPrime = (DomainPath) marshaller.unmarshall(marshaller.marshall(domain));
    assertEquals(domain.getStringPath(), domainPrime.getStringPath());
    assertEquals(domain.getTargetUUID(), domainPrime.getTargetUUID());
    Logger.msg(marshaller.marshall(domainPrime));
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) CastorXMLUtility(org.cristalise.kernel.utils.CastorXMLUtility) ItemPath(org.cristalise.kernel.lookup.ItemPath) MainTest(org.cristalise.kernel.test.process.MainTest) Test(org.junit.Test)

Aggregations

ItemPath (org.cristalise.kernel.lookup.ItemPath)36 DomainPath (org.cristalise.kernel.lookup.DomainPath)16 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)14 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)10 PersistencyException (org.cristalise.kernel.common.PersistencyException)10 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)10 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)6 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)5 CannotManageException (org.cristalise.kernel.common.CannotManageException)4 AgentPath (org.cristalise.kernel.lookup.AgentPath)4 Test (org.junit.Test)4 Aggregation (org.cristalise.kernel.collection.Aggregation)3 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)3 Path (org.cristalise.kernel.lookup.Path)3 Property (org.cristalise.kernel.property.Property)3 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)3 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)3 ConcurrentModificationException (java.util.ConcurrentModificationException)2 StringTokenizer (java.util.StringTokenizer)2 Dependency (org.cristalise.kernel.collection.Dependency)2