use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class CreateItemFromDescription method instantiateWorkflow.
/**
* Retrieve the Workflow dependency for the given description version, instantiate the loaded CompositeActivityDef
*
* @param descItemPath
* @param descVer
* @param locker
* @return the Workflow instance
* @throws ObjectNotFoundException
* @throws InvalidDataException
* @throws PersistencyException
*/
protected CompositeActivity instantiateWorkflow(ItemPath descItemPath, String descVer, Object locker) throws ObjectNotFoundException, InvalidDataException, PersistencyException {
@SuppressWarnings("unchecked") Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>) Gateway.getStorage().get(descItemPath, ClusterType.COLLECTION + "/" + WORKFLOW + "/" + descVer, locker);
CollectionMember wfMember = thisCol.getMembers().list.get(0);
String wfDefName = wfMember.resolveItem().getName();
Object wfVerObj = wfMember.getProperties().getBuiltInProperty(VERSION);
if (wfVerObj == null || String.valueOf(wfVerObj).length() == 0) {
throw new InvalidDataException("Workflow version number not set");
}
try {
Integer wfDefVer = Integer.parseInt(wfVerObj.toString());
if (wfDefName == null)
throw new InvalidDataException("No workflow given or defined");
// load workflow def
CompositeActivityDef wfDef = (CompositeActivityDef) LocalObjectLoader.getActDef(wfDefName, wfDefVer);
return (CompositeActivity) wfDef.instantiate();
} catch (NumberFormatException ex) {
throw new InvalidDataException("Invalid workflow version number: " + wfVerObj.toString());
} catch (ClassCastException ex) {
Logger.error(ex);
throw new InvalidDataException("Activity def '" + wfDefName + "' was not Composite");
}
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class CreateItemFromDescription method initialiseItem.
/**
* @param agent
* @param descItemPath
* @param locker
* @param input
* @param newName
* @param descVer
* @param context
* @param newItemPath
* @param newItem
* @throws ObjectCannotBeUpdated
* @throws CannotManageException
* @throws InvalidDataException
* @throws ObjectAlreadyExistsException
* @throws PersistencyException
* @throws ObjectNotFoundException
*/
protected void initialiseItem(ItemOperations newItem, AgentPath agent, ItemPath descItemPath, PropertyArrayList initProps, String newName, String descVer, DomainPath context, ItemPath newItemPath, Object locker) throws ObjectCannotBeUpdated, CannotManageException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException {
// initialise it with its properties and workflow
Logger.msg(3, "CreateItemFromDescription.initialiseItem() - Initializing Item:" + newName);
try {
PropertyArrayList newProps = instantiateProperties(descItemPath, descVer, initProps, newName, agent, locker);
CollectionArrayList newColls = instantiateCollections(descItemPath, descVer, newProps, locker);
CompositeActivity newWorkflow = instantiateWorkflow(descItemPath, descVer, locker);
newItem.initialise(agent.getSystemKey(), Gateway.getMarshaller().marshall(newProps), Gateway.getMarshaller().marshall(newWorkflow), Gateway.getMarshaller().marshall(newColls));
} catch (MarshalException | ValidationException | AccessRightsException | IOException | MappingException | InvalidCollectionModification e) {
Logger.error(e);
Gateway.getLookupManager().delete(newItemPath);
throw new InvalidDataException("CreateItemFromDescription: Problem initializing new Item. See log: " + e.getMessage());
} catch (InvalidDataException | ObjectNotFoundException | PersistencyException e) {
Logger.error(e);
Gateway.getLookupManager().delete(newItemPath);
throw e;
}
// add its domain path
Logger.msg(3, "CreateItemFromDescription - Creating " + context);
context.setItemPath(newItemPath);
Gateway.getLookupManager().add(context);
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class CreateNewItem method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification {
try {
ImportItem newItem = (ImportItem) Gateway.getMarshaller().unmarshall(requestData);
newItem.create(agent, false);
return requestData;
} catch (MarshalException | ValidationException | IOException | MappingException e) {
Logger.error(e);
throw new InvalidDataException("CreateNewItem: Couldn't unmarshall new Item: " + requestData);
} catch (PersistencyException e) {
Logger.error(e);
throw new InvalidDataException("CreateNewItem: " + e.getMessage());
}
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Activity method request.
public String request(AgentPath agent, AgentPath delegate, ItemPath itemPath, int transitionID, String requestData, Object locker) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification {
// Find requested transition
Transition transition = getStateMachine().getTransition(transitionID);
// Check if the transition is possible
String usedRole = transition.getPerformingRole(this, agent);
// Verify outcome
boolean storeOutcome = false;
if (transition.hasOutcome(getProperties())) {
if (StringUtils.isNotBlank(requestData))
storeOutcome = true;
else if (transition.getOutcome().isRequired())
throw new InvalidDataException("Transition requires outcome data, but none was given");
}
// Get new state
State oldState = getStateMachine().getState(this.state);
State newState = getStateMachine().traverse(this, transition, agent);
// Run extra logic in predefined steps here
String outcome = runActivityLogic(agent, itemPath, transitionID, requestData, locker);
// set new state and reservation
setState(newState.getId());
setBuiltInProperty(AGENT_NAME, transition.getReservation(this, agent));
try {
History hist = getWf().getHistory(locker);
if (storeOutcome) {
Schema schema = transition.getSchema(getProperties());
Outcome newOutcome = new Outcome(-1, outcome, schema);
// TODO: if we were ever going to validate outcomes on storage, it would be here.
// newOutcome.validateAndCheck();
String viewpoint = resolveViewpointName(newOutcome);
int eventID = hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint).getID();
newOutcome.setID(eventID);
Gateway.getStorage().put(itemPath, newOutcome, locker);
// update specific view if defined
if (!viewpoint.equals("last")) {
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, viewpoint, eventID), locker);
}
// update the default "last" view
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, "last", eventID), locker);
updateItemProperties(itemPath, newOutcome, locker);
} else {
hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), getStateMachine(), transitionID);
}
} catch (PersistencyException ex) {
Logger.error(ex);
throw ex;
}
if (newState.isFinished() && !(getBuiltInProperty(BREAKPOINT).equals(Boolean.TRUE) && !oldState.isFinished())) {
runNext(agent, itemPath, locker);
}
DateUtility.setToNow(mStateDate);
pushJobsToAgents(itemPath);
return outcome;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Activity method pushJobsToAgents.
/**
* Collects all Role names which are associated with this Activity and the Transitions of the current State,
* and ....
*
* @param itemPath
*/
protected void pushJobsToAgents(ItemPath itemPath) {
// Shall contain a set of unique role names
Set<String> roleNames = new TreeSet<String>();
String role = getCurrentAgentRole();
if (StringUtils.isNotBlank(role)) {
for (String r : role.split(",")) roleNames.add(r);
}
try {
for (Transition trans : getStateMachine().getState(getState()).getPossibleTransitions().values()) {
role = trans.getRoleOverride(getProperties());
if (StringUtils.isNotBlank(role))
roleNames.add(role);
}
Logger.msg(7, "Activity.pushJobsToAgents() - Pushing jobs to " + roleNames.size() + " roles");
for (String roleName : roleNames) {
pushJobsToAgents(itemPath, Gateway.getLookup().getRolePath(roleName));
}
} catch (InvalidDataException ex) {
Logger.warning("Activity.pushJobsToAgents() - " + ex.getMessage());
} catch (ObjectNotFoundException e) {
Logger.warning("Activity.pushJobsToAgents() - Activity role '" + role + "' not found.");
}
}
Aggregations