Search in sources :

Example 6 with Workflow

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;
}
Also used : GraphPoint(org.cristalise.kernel.graph.model.GraphPoint) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 7 with Workflow

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);
    }
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) GraphableVertex(org.cristalise.kernel.graph.model.GraphableVertex) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow)

Example 8 with Workflow

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);
}
Also used : Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef) ServerPredefinedStepContainer(org.cristalise.kernel.lifecycle.instance.predefined.server.ServerPredefinedStepContainer)

Aggregations

Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)8 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)4 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)4 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)3 IOException (java.io.IOException)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)2 CannotManageException (org.cristalise.kernel.common.CannotManageException)2 InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)2 Schema (org.cristalise.kernel.persistency.outcome.Schema)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 Property (org.cristalise.kernel.property.Property)2 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)2 MappingException (org.exolab.castor.mapping.MappingException)2