use of org.cristalise.kernel.lifecycle.instance.Workflow in project kernel by cristal-ise.
the class ReplaceDomainWorkflow method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException {
Workflow lifeCycle = getWf();
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "ReplaceDomainWorkflow: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length != 1)
throw new InvalidDataException("ReplaceDomainWorkflow: Invalid parameters " + Arrays.toString(params));
lifeCycle.getChildrenGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
CompositeActivity domain;
try {
domain = (CompositeActivity) Gateway.getMarshaller().unmarshall(params[0]);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("ReplaceDomainWorkflow: Could not unmarshall new workflow: " + e.getMessage());
}
domain.setName("domain");
lifeCycle.initChild(domain, true, new GraphPoint(150, 100));
// if new workflow, activate it, otherwise refresh the jobs
if (!domain.active)
lifeCycle.run(agent, item, locker);
else
lifeCycle.refreshJobs(item);
// store new wf
try {
Gateway.getStorage().put(item, lifeCycle, locker);
} catch (PersistencyException e) {
throw new PersistencyException("ReplaceDomainWorkflow: Could not write new workflow to storage: " + e.getMessage());
}
return requestData;
}
use of org.cristalise.kernel.lifecycle.instance.Workflow 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.lifecycle.instance.Workflow in project kernel by cristal-ise.
the class Bootstrap method initServerItemWf.
public static void initServerItemWf() throws Exception {
CompositeActivityDef serverWfCa = (CompositeActivityDef) LocalObjectLoader.getActDef("ServerItemWorkflow", 0);
Workflow wf = new Workflow((CompositeActivity) serverWfCa.instantiate(), new ServerPredefinedStepContainer());
wf.initialise(thisServerPath.getItemPath(), systemAgents.get("system").getPath(), null);
Gateway.getStorage().put(thisServerPath.getItemPath(), wf, null);
}
Aggregations