Search in sources :

Example 6 with DomainPath

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

the class LookupPathClusterStorageTest method storeDomainPath.

@Test
public void storeDomainPath() throws Exception {
    DomainPath domain = new DomainPath("/my/path.2", new ItemPath());
    inMemoryCluster.put(storingItem, domain);
    String name = StringUtils.remove(StringUtils.join(domain.getPath(), ""), ".");
    DomainPath domainPrime = (DomainPath) inMemoryCluster.get(storingItem, PATH + "/Domain/" + name);
    assertNotNull(domainPrime);
    assertEquals(domain.getStringPath(), domainPrime.getStringPath());
    assertEquals(domain.getTargetUUID(), domainPrime.getTargetUUID());
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemPath(org.cristalise.kernel.lookup.ItemPath) Test(org.junit.Test)

Example 7 with DomainPath

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

the class CreateItemFromDescription method runActivityLogic.

/**
 * Params:
 * <ol>
 * <li>Item name</li>
 * <li>Domain context</li>
 * <li>Description version to use(optional)</li>
 * <li>Initial properties to set in the new Agent (optional)</li>
 * </ol>
 * @throws ObjectNotFoundException
 * @throws InvalidDataException The input parameters were incorrect
 * @throws ObjectAlreadyExistsException The Agent already exists
 * @throws CannotManageException The Agent could not be created
 * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
 * @throws PersistencyException
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath descItemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException {
    String[] input = getDataList(requestData);
    String newName = input[0];
    String domPath = input[1];
    String descVer = input.length > 2 ? input[2] : "last";
    PropertyArrayList initProps = input.length > 3 ? unmarshallInitProperties(input[3]) : new PropertyArrayList();
    Logger.msg(1, "CreateItemFromDescription - name:" + newName);
    // check if the path is already taken
    DomainPath context = new DomainPath(new DomainPath(domPath), newName);
    if (context.exists())
        throw new ObjectAlreadyExistsException("The path " + context + " exists already.");
    // generate new item path with random uuid
    Logger.msg(6, "CreateItemFromDescription - Requesting new item path");
    ItemPath newItemPath = new ItemPath();
    // create the Item object
    Logger.msg(3, "CreateItemFromDescription - Creating Item");
    CorbaServer factory = Gateway.getCorbaServer();
    if (factory == null)
        throw new CannotManageException("This process cannot create new Items");
    TraceableEntity newItem = factory.createItem(newItemPath);
    Gateway.getLookupManager().add(newItemPath);
    initialiseItem(newItem, agent, descItemPath, initProps, newName, descVer, context, newItemPath, locker);
    return requestData;
}
Also used : TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) DomainPath(org.cristalise.kernel.lookup.DomainPath) CannotManageException(org.cristalise.kernel.common.CannotManageException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) CorbaServer(org.cristalise.kernel.entity.CorbaServer) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 8 with DomainPath

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

the class RemoveDomainContext method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "RemoveDomainContext: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveDomainContext: Invalid parameters " + Arrays.toString(params));
    DomainPath pathToDelete = new DomainPath(params[0]);
    if (!pathToDelete.exists())
        throw new ObjectNotFoundException("Context " + pathToDelete + " does not exist");
    try {
        pathToDelete.getItemPath();
        throw new InvalidDataException("Path " + pathToDelete + " is an Entity. Use its own Erase step instead, or RemoveAgent.");
    } catch (ObjectNotFoundException ex) {
    }
    if (Gateway.getLookup().getChildren(pathToDelete).hasNext())
        throw new ObjectCannotBeUpdated("Context " + pathToDelete + " is not empty. Cannot delete.");
    Gateway.getLookupManager().delete(pathToDelete);
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated)

Example 9 with DomainPath

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

use of org.cristalise.kernel.lookup.DomainPath 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)

Aggregations

DomainPath (org.cristalise.kernel.lookup.DomainPath)26 ItemPath (org.cristalise.kernel.lookup.ItemPath)15 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)12 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)5 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)4 Property (org.cristalise.kernel.property.Property)4 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)4 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)4 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)4 Aggregation (org.cristalise.kernel.collection.Aggregation)3 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)3 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 Path (org.cristalise.kernel.lookup.Path)3 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)3 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 Test (org.junit.Test)3