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;
}
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;
}
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);
}
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());
}
}
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());
}
}
Aggregations