Search in sources :

Example 6 with ObjectCannotBeUpdated

use of org.cristalise.kernel.common.ObjectCannotBeUpdated 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 7 with ObjectCannotBeUpdated

use of org.cristalise.kernel.common.ObjectCannotBeUpdated in project kernel by cristal-ise.

the class RemoveRole method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, CannotManageException, ObjectNotFoundException, ObjectCannotBeUpdated {
    String[] params = getDataList(requestData);
    Logger.msg(3, "RemoveRole: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveRole must have one paramater:" + Arrays.toString(params));
    LookupManager lookup = Gateway.getLookupManager();
    RolePath thisRole = lookup.getRolePath(params[0]);
    AgentPath[] agents = Gateway.getLookup().getAgents(thisRole);
    if (agents.length > 0)
        throw new ObjectCannotBeUpdated("Cannot remove role as " + agents.length + " other agents still hold it.");
    lookup.delete(thisRole);
    return requestData;
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 8 with ObjectCannotBeUpdated

use of org.cristalise.kernel.common.ObjectCannotBeUpdated in project kernel by cristal-ise.

the class RemoveAgent method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
    Logger.msg(1, "RemoveAgent::request() - Starting.");
    AgentPath targetAgent;
    try {
        targetAgent = new AgentPath(itemPath);
    } catch (InvalidAgentPathException ex) {
        throw new InvalidDataException("Could not resolve " + itemPath + " as an Agent.");
    }
    String agentName = targetAgent.getAgentName();
    // remove from roles
    for (RolePath role : targetAgent.getRoles()) {
        try {
            Gateway.getLookupManager().removeRole(targetAgent, role);
        } catch (ObjectCannotBeUpdated | ObjectNotFoundException | CannotManageException e) {
            Logger.error(e);
            throw new InvalidDataException("Error removing " + agentName + " from Role " + role.getName() + " exceptoin message:" + e.getMessage());
        }
    }
    return super.runActivityLogic(agent, itemPath, transitionID, requestData, locker);
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 9 with ObjectCannotBeUpdated

use of org.cristalise.kernel.common.ObjectCannotBeUpdated in project kernel by cristal-ise.

the class BulkImport method importAgentPath.

public AgentPath importAgentPath(ItemPath item, Object locker) throws PersistencyException {
    try {
        AgentPath agentPath = (AgentPath) importCluster.get(item, PATH + "/Item");
        Gateway.getLookupManager().add(agentPath);
        Gateway.getLookupManager().setAgentPassword(agentPath, "aaa");
        return agentPath;
    } catch (ObjectCannotBeUpdated | ObjectAlreadyExistsException | CannotManageException | ObjectNotFoundException | NoSuchAlgorithmException e) {
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) PersistencyException(org.cristalise.kernel.common.PersistencyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Example 10 with ObjectCannotBeUpdated

use of org.cristalise.kernel.common.ObjectCannotBeUpdated in project kernel by cristal-ise.

the class BulkImport method importItemPath.

public ItemPath importItemPath(ItemPath item, Object locker) throws PersistencyException {
    try {
        ItemPath itemPath = (ItemPath) importCluster.get(item, PATH + "/Item");
        Gateway.getLookupManager().add(itemPath);
        return itemPath;
    } catch (ObjectCannotBeUpdated | ObjectAlreadyExistsException | CannotManageException e) {
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)10 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)6 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)6 CannotManageException (org.cristalise.kernel.common.CannotManageException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)3 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)3 IOException (java.io.IOException)2 Aggregation (org.cristalise.kernel.collection.Aggregation)2 AggregationMember (org.cristalise.kernel.collection.AggregationMember)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 RolePath (org.cristalise.kernel.lookup.RolePath)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2 ValidationException (org.exolab.castor.xml.ValidationException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1