Search in sources :

Example 6 with Schema

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);
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Event(org.cristalise.kernel.events.Event)

Example 7 with Schema

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);
    }
}
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 Schema

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;
}
Also used : State(org.cristalise.kernel.lifecycle.instance.stateMachine.State) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Schema(org.cristalise.kernel.persistency.outcome.Schema) Transition(org.cristalise.kernel.lifecycle.instance.stateMachine.Transition) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) History(org.cristalise.kernel.events.History) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 9 with Schema

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());
    }
}
Also used : Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Aggregations

Schema (org.cristalise.kernel.persistency.outcome.Schema)9 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)8 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)4 Event (org.cristalise.kernel.events.Event)4 History (org.cristalise.kernel.events.History)4 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)1 GraphableVertex (org.cristalise.kernel.graph.model.GraphableVertex)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 State (org.cristalise.kernel.lifecycle.instance.stateMachine.State)1 Transition (org.cristalise.kernel.lifecycle.instance.stateMachine.Transition)1 AgentPath (org.cristalise.kernel.lookup.AgentPath)1