use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class OrSplit method runNext.
@Override
public void runNext(AgentPath agent, ItemPath itemPath, Object locker) throws InvalidDataException {
String[] nextsTab = calculateNexts(itemPath, locker);
int active = 0;
DirectedEdge[] outEdges = getOutEdges();
for (String thisNext : nextsTab) {
Logger.msg(7, "OrSplit.runNext() - Finding next " + thisNext);
for (DirectedEdge outEdge : outEdges) {
Next nextEdge = (Next) outEdge;
if (thisNext != null && thisNext.equals(nextEdge.getBuiltInProperty(ALIAS))) {
WfVertex term = nextEdge.getTerminusVertex();
try {
term.run(agent, itemPath, locker);
} catch (InvalidDataException e) {
Logger.error(e);
throw new InvalidDataException("Error enabling next " + thisNext);
}
Logger.msg(7, "OrSplit.runNext() - Running " + nextEdge.getBuiltInProperty(ALIAS));
active++;
}
}
}
// if no active nexts throw exception
if (active == 0)
throw new InvalidDataException("No nexts were activated!");
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class XOrSplit method runNext.
@Override
public void runNext(AgentPath agent, ItemPath itemPath, Object locker) throws InvalidDataException {
String[] nextsTab = calculateNexts(itemPath, locker);
ArrayList<DirectedEdge> nextsToFollow = new ArrayList<DirectedEdge>();
DirectedEdge[] outEdges = getOutEdges();
for (DirectedEdge outEdge : outEdges) {
if (isInTable((String) ((Next) outEdge).getBuiltInProperty(ALIAS), nextsTab))
nextsToFollow.add(outEdge);
}
if (nextsToFollow.size() != 1)
throw new InvalidDataException("not good number of active next");
followNext((Next) nextsToFollow.get(0), agent, itemPath, locker);
}
use of org.cristalise.kernel.common.InvalidDataException 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.InvalidDataException in project kernel by cristal-ise.
the class CreateNewAgent method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
try {
ImportAgent newAgent = (ImportAgent) Gateway.getMarshaller().unmarshall(requestData);
newAgent.create(agent, true);
newAgent.setPassword("REDACTED");
return Gateway.getMarshaller().marshall(newAgent);
} catch (MarshalException | ValidationException | IOException | MappingException e) {
Logger.error(e);
throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: " + requestData);
}
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class CreateNewRole method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
try {
ImportRole newRole = (ImportRole) Gateway.getMarshaller().unmarshall(requestData);
if (Gateway.getLookup().exists(new RolePath(newRole.getName(), newRole.jobList)))
throw new ObjectAlreadyExistsException("CreateNewRole: Role '" + newRole.getName() + "' already exists.");
newRole.create(agent, true);
return requestData;
} catch (MarshalException | ValidationException | IOException | MappingException e) {
Logger.error(e);
throw new InvalidDataException("CreateNewRole: Couldn't unmarshall new Role: " + requestData);
}
}
Aggregations