use of org.cristalise.kernel.common.ObjectCannotBeUpdated in project kernel by cristal-ise.
the class ItemImplementation method delegatedAction.
@Override
public String delegatedAction(SystemKey agentId, SystemKey delegateId, String stepPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException, InvalidCollectionModification {
Workflow lifeCycle = null;
try {
AgentPath agent = new AgentPath(agentId);
AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
Logger.msg(1, "ItemImplementation::request(" + mItemPath + ") - Transition " + transitionID + " on " + stepPath + " by " + (delegate == null ? "" : delegate + " on behalf of ") + agent);
// TODO: check if delegate is allowed valid for agent
lifeCycle = (Workflow) mStorage.get(mItemPath, ClusterType.LIFECYCLE + "/workflow", null);
String finalOutcome = lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, transitionID, requestData);
// store the workflow if we've changed the state of the domain wf
if (!(stepPath.startsWith("workflow/predefined")))
mStorage.put(mItemPath, lifeCycle, lifeCycle);
// remove entity path if transaction was successful
if (stepPath.equals("workflow/predefined/Erase")) {
Logger.msg("Erasing item path " + mItemPath.toString());
Gateway.getLookupManager().delete(mItemPath);
}
mStorage.commit(lifeCycle);
return finalOutcome;
} catch (AccessRightsException | InvalidTransitionException | ObjectNotFoundException | PersistencyException | InvalidDataException | ObjectAlreadyExistsException | InvalidCollectionModification ex) {
if (Logger.doLog(8))
Logger.error(ex);
String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
if (StringUtils.isBlank(errorOutcome)) {
mStorage.abort(lifeCycle);
throw ex;
} else {
mStorage.commit(lifeCycle);
return errorOutcome;
}
} catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException ex) {
if (Logger.doLog(8))
Logger.error(ex);
String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
if (StringUtils.isBlank(errorOutcome)) {
mStorage.abort(lifeCycle);
throw new InvalidDataException(ex.getClass().getName() + " - " + ex.getMessage());
} else {
mStorage.commit(lifeCycle);
return errorOutcome;
}
} catch (Exception ex) {
// non-CORBA exception hasn't been caught!
Logger.error("Unknown Error: requestAction on " + mItemPath + " by " + agentId + " executing " + stepPath);
Logger.error(ex);
String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
if (StringUtils.isBlank(errorOutcome)) {
mStorage.abort(lifeCycle);
throw new InvalidDataException("Extraordinary Exception during execution:" + ex.getClass().getName() + " - " + ex.getMessage());
} else {
mStorage.commit(lifeCycle);
return errorOutcome;
}
}
}
use of org.cristalise.kernel.common.ObjectCannotBeUpdated in project kernel by cristal-ise.
the class ItemImplementation method handleError.
/**
* @param agentId
* @param delegateId
* @param stepPath
* @param ex
* @return
* @throws PersistencyException
* @throws ObjectNotFoundException
* @throws AccessRightsException
* @throws InvalidTransitionException
* @throws InvalidDataException
* @throws ObjectAlreadyExistsException
* @throws InvalidCollectionModification
*/
private String handleError(SystemKey agentId, SystemKey delegateId, String stepPath, Workflow lifeCycle, Exception ex) throws PersistencyException, ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, InvalidCollectionModification {
if (!Gateway.getProperties().getBoolean("StateMachine.enableErrorHandling", false))
return null;
int errorTransId = ((Activity) lifeCycle.search(stepPath)).getErrorTransitionId();
if (errorTransId == -1)
return null;
try {
AgentPath agent = new AgentPath(agentId);
AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
String errorOutcome = Gateway.getMarshaller().marshall(new ErrorInfo(ex));
lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, errorTransId, errorOutcome);
if (!(stepPath.startsWith("workflow/predefined")))
mStorage.put(mItemPath, lifeCycle, lifeCycle);
return errorOutcome;
} catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException | MarshalException | ValidationException | IOException | MappingException e) {
Logger.error(e);
return "";
}
}
use of org.cristalise.kernel.common.ObjectCannotBeUpdated 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;
}
use of org.cristalise.kernel.common.ObjectCannotBeUpdated 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;
}
use of org.cristalise.kernel.common.ObjectCannotBeUpdated in project kernel by cristal-ise.
the class WriteProperty method write.
public static void write(ItemPath item, String name, String value, Object locker) throws PersistencyException, ObjectCannotBeUpdated, ObjectNotFoundException {
Property prop = (Property) Gateway.getStorage().get(item, ClusterType.PROPERTY + "/" + name, locker);
if (!prop.isMutable() && !value.equals(prop.getValue()))
throw new ObjectCannotBeUpdated("WriteProperty: Property '" + name + "' is not mutable.");
prop.setValue(value);
Gateway.getStorage().put(item, prop, locker);
}
Aggregations