use of org.cristalise.kernel.persistency.outcome.Schema in project kernel by cristal-ise.
the class WriteViewpoint method write.
public static void write(ItemPath item, String schemaName, String viewName, int eventId, Object locker) throws PersistencyException, ObjectNotFoundException, InvalidDataException {
Event event = (Event) Gateway.getStorage().get(item, ClusterType.HISTORY + "/" + eventId, locker);
if (StringUtils.isBlank(event.getSchemaName())) {
throw new InvalidDataException("Event " + eventId + " does not reference an Outcome, so cannot be assigned to a Viewpoint.");
}
// checks Schema name/version
Schema thisSchema = LocalObjectLoader.getSchema(schemaName, event.getSchemaVersion());
if (!event.getSchemaName().equals(thisSchema.getItemID())) {
throw new InvalidDataException("Event outcome schema is " + event.getSchemaName() + ", and cannot be used for a " + schemaName + " Viewpoint");
}
Gateway.getStorage().put(item, new Viewpoint(item, thisSchema, viewName, eventId), locker);
}
use of org.cristalise.kernel.persistency.outcome.Schema in project kernel by cristal-ise.
the class ActivityDataHelper method get.
/**
* Retrieves the Workflow of the given Item, searches the Activity using the activity path and
* retrieves a single value based on XPath
*/
@Override
public String get(ItemPath itemPath, String actContext, String dataPath, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
Logger.msg(5, "ActivityDataHelper.get() - item:" + itemPath + ", actContext:" + actContext + ", dataPath:" + dataPath);
String[] paths = dataPath.split(":");
if (paths.length != 2)
throw new InvalidDataException("Invalid path '" + dataPath + "' it must have one and only one colon (:)");
String actPath = paths[0];
String xpath = paths[1];
if (actPath.startsWith(".")) {
actPath = actContext + (actContext.endsWith("/") ? "" : "/") + actPath.substring(2);
}
// Find the referenced activity, so get the workflow and search
Workflow workflow = (Workflow) Gateway.getStorage().get(itemPath, ClusterType.LIFECYCLE + "/workflow", locker);
GraphableVertex act = workflow.search(actPath);
if (act == null) {
throw new InvalidDataException("Workflow search failed for actPath:" + actPath + " - item:" + itemPath + ", actContext:" + actContext + ", dataPath:" + dataPath);
}
// Get the schema and viewpoint names
String schemaName = act.getBuiltInProperty(SCHEMA_NAME).toString();
Integer schemaVersion = Integer.valueOf(act.getBuiltInProperty(SCHEMA_VERSION).toString());
String viewName = act.getBuiltInProperty(VIEW_POINT).toString();
if (StringUtils.isBlank(viewName))
viewName = "last";
// checks if schema/version was correct
Schema schema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
// get the viewpoint and outcome
Viewpoint view = (Viewpoint) Gateway.getStorage().get(itemPath, ClusterType.VIEWPOINT + "/" + schema.getName() + "/" + viewName, locker);
Outcome outcome = (Outcome) view.getOutcome(locker);
// apply the XPath to its outcome
try {
return outcome.getFieldByXPath(xpath);
} catch (XPathExpressionException e) {
throw new InvalidDataException("Invalid xpath:" + xpath + " - item:" + itemPath + ", actContext:" + actContext + ", dataPath:" + dataPath);
}
}
use of org.cristalise.kernel.persistency.outcome.Schema 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.persistency.outcome.Schema in project kernel by cristal-ise.
the class SchemaCache method buildObject.
@Override
public Schema buildObject(String name, int version, ItemPath path, String data) throws InvalidDataException {
try {
Schema thisSchema = new Schema(name, version, path, data);
thisSchema.validate();
return thisSchema;
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidDataException("Could not parse Schema '" + name + "' v" + version + ": " + ex.getMessage());
}
}
Aggregations