Search in sources :

Example 1 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class ItemImplementation method initialise.

@Override
public void initialise(SystemKey agentId, String propString, String initWfString, String initCollsString) throws AccessRightsException, InvalidDataException, PersistencyException {
    Logger.msg(5, "Item::initialise(" + mItemPath + ") - agent:" + agentId);
    Object locker = new Object();
    AgentPath agentPath;
    try {
        agentPath = new AgentPath(agentId);
    } catch (InvalidItemPathException e) {
        throw new AccessRightsException("Invalid Agent Id:" + agentId);
    }
    // must supply properties
    if (propString == null || propString.length() == 0 || propString.equals("<NULL/>")) {
        throw new InvalidDataException("No properties supplied");
    }
    // store properties
    try {
        PropertyArrayList props = (PropertyArrayList) Gateway.getMarshaller().unmarshall(propString);
        for (Property thisProp : props.list) mStorage.put(mItemPath, thisProp, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Properties were invalid: " + propString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Properties were invalid");
    }
    // Store an event and the initial properties
    try {
        Schema initSchema = LocalObjectLoader.getSchema("ItemInitialization", 0);
        Outcome initOutcome = new Outcome(0, propString, initSchema);
        History hist = new History(mItemPath, locker);
        Event newEvent = hist.addEvent(new AgentPath(agentId), null, "", "Initialize", "", "", initSchema, Bootstrap.getPredefSM(), PredefinedStep.DONE, "last");
        initOutcome.setID(newEvent.getID());
        Viewpoint newLastView = new Viewpoint(mItemPath, initSchema, "last", newEvent.getID());
        mStorage.put(mItemPath, initOutcome, locker);
        mStorage.put(mItemPath, newLastView, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Could not store event and outcome.");
        Logger.error(ex);
        mStorage.abort(locker);
        throw new PersistencyException("Error storing event and outcome");
    }
    // init collections
    if (initCollsString != null && initCollsString.length() > 0 && !initCollsString.equals("<NULL/>")) {
        try {
            CollectionArrayList colls = (CollectionArrayList) Gateway.getMarshaller().unmarshall(initCollsString);
            for (Collection<?> thisColl : colls.list) {
                mStorage.put(mItemPath, thisColl, locker);
            }
        } catch (Throwable ex) {
            Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Collections were invalid: " + initCollsString);
            Logger.error(ex);
            mStorage.abort(locker);
            throw new InvalidDataException("Collections were invalid");
        }
    }
    // create wf
    Workflow lc = null;
    try {
        if (initWfString == null || initWfString.length() == 0 || initWfString.equals("<NULL/>")) {
            lc = new Workflow(new CompositeActivity(), getNewPredefStepContainer());
        } else {
            lc = new Workflow((CompositeActivity) Gateway.getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
        }
        mStorage.put(mItemPath, lc, locker);
    } catch (Throwable ex) {
        Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Workflow was invalid: " + initWfString);
        Logger.error(ex);
        mStorage.abort(locker);
        throw new InvalidDataException("Workflow was invalid");
    }
    // All objects are in place, initialize the workflow to get the Item running
    lc.initialise(mItemPath, agentPath, locker);
    mStorage.put(mItemPath, lc, locker);
    mStorage.commit(locker);
    Logger.msg(3, "Initialisation of item " + mItemPath + " was successful");
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Schema(org.cristalise.kernel.persistency.outcome.Schema) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) History(org.cristalise.kernel.events.History) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Event(org.cristalise.kernel.events.Event) PersistencyException(org.cristalise.kernel.common.PersistencyException) Property(org.cristalise.kernel.property.Property)

Example 2 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class Job method getOutcome.

/**
 * Returns the Outcome if exists otherwise tries to read and duplicate the Outcome of 'last' ViewPoint.
 * If that does not exists it tries to use an OutcomeInitiator.
 *
 * @return the Outcome object or null
 * @throws InvalidDataException inconsistent data
 * @throws ObjectNotFoundException Schema was not found
 */
public Outcome getOutcome() throws InvalidDataException, ObjectNotFoundException {
    if (outcome == null && transition.hasOutcome(actProps)) {
        if (getItem().checkViewpoint(getSchema().getName(), getValidViewpointName())) {
            Outcome tempOutcome = getLastOutcome();
            outcome = new Outcome(tempOutcome.getData(), tempOutcome.getSchema());
        } else {
            OutcomeInitiator ocInit = getOutcomeInitiator();
            if (ocInit != null)
                outcome = ocInit.initOutcomeInstance(this);
        }
    } else {
        Logger.msg(8, "Job.getOutcome() - Job does not require Outcome job:" + this);
    }
    return outcome;
}
Also used : Outcome(org.cristalise.kernel.persistency.outcome.Outcome) OutcomeInitiator(org.cristalise.kernel.persistency.outcome.OutcomeInitiator)

Example 3 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class TransferItem method importItem.

public void importItem(File dir) throws Exception {
    // check if already exists
    try {
        Property name = (Property) Gateway.getStorage().get(itemPath, PROPERTY + "/" + NAME, null);
        throw new Exception("Item " + itemPath + " already in use as " + name.getValue());
    } catch (Exception ex) {
    }
    // retrieve objects
    ArrayList<String> objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true);
    ArrayList<C2KLocalObject> objects = new ArrayList<C2KLocalObject>();
    for (String element : objectFiles) {
        String xmlFile = FileStringUtility.file2String(element);
        C2KLocalObject newObj;
        String choppedPath = element.substring(dir.getCanonicalPath().length() + 1, element.length() - 4);
        Logger.msg(choppedPath);
        if (choppedPath.startsWith(OUTCOME.getName()))
            newObj = new Outcome(choppedPath, xmlFile);
        else
            newObj = (C2KLocalObject) Gateway.getMarshaller().unmarshall(xmlFile);
        objects.add(newObj);
    }
    // create item
    TraceableEntity newItem = Gateway.getCorbaServer().createItem(itemPath);
    Gateway.getLookupManager().add(itemPath);
    PropertyArrayList props = new PropertyArrayList();
    CollectionArrayList colls = new CollectionArrayList();
    Workflow wf = null;
    // put objects
    for (C2KLocalObject obj : objects) {
        if (obj instanceof Property)
            props.list.add((Property) obj);
        else if (obj instanceof Collection)
            colls.list.add((Collection<?>) obj);
        else if (obj instanceof Workflow)
            wf = (Workflow) obj;
    }
    if (wf == null)
        throw new Exception("No workflow found in import for " + itemPath);
    // init item
    newItem.initialise(importAgentId.getSystemKey(), Gateway.getMarshaller().marshall(props), Gateway.getMarshaller().marshall(wf.search("workflow/domain")), Gateway.getMarshaller().marshall(colls));
    // store objects
    importByType(ClusterType.HISTORY, objects);
    importByType(ClusterType.OUTCOME, objects);
    importByType(ClusterType.VIEWPOINT, objects);
    Gateway.getStorage().commit(this);
    // add domPaths
    for (String element : domainPaths) {
        DomainPath newPath = new DomainPath(element, itemPath);
        Gateway.getLookupManager().add(newPath);
    }
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) ArrayList(java.util.ArrayList) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Collection(org.cristalise.kernel.collection.Collection) Property(org.cristalise.kernel.property.Property)

Example 4 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class Bootstrap method verifyResource.

/**
 * @param ns
 * @param itemName
 * @param version
 * @param itemType
 * @param itemPath
 * @param outcomes
 * @param dataLocation
 * @param reset
 * @return the Path of the resource either created or initialised from existing data
 * @throws Exception
 */
private static DomainPath verifyResource(String ns, String itemName, int version, String itemType, ItemPath itemPath, Set<Outcome> outcomes, String dataLocation, boolean reset) throws Exception {
    ResourceImportHandler typeImpHandler = Gateway.getResourceImportHandler(BuiltInResources.getValue(itemType));
    Logger.msg(1, "Bootstrap.verifyResource() - Verifying " + typeImpHandler.getName() + " " + itemName + " v" + version);
    // Find or create Item for Resource
    ItemProxy thisProxy;
    DomainPath modDomPath = typeImpHandler.getPath(itemName, ns);
    if (modDomPath.exists()) {
        Logger.msg(3, "Bootstrap.verifyResource() - Found " + typeImpHandler.getName() + " " + itemName + ".");
        thisProxy = verifyPathAndModuleProperty(ns, itemType, itemName, itemPath, modDomPath, modDomPath);
    } else {
        if (itemPath == null)
            itemPath = new ItemPath();
        Logger.msg("Bootstrap.verifyResource() - " + typeImpHandler.getName() + " " + itemName + " not found. Creating new.");
        thisProxy = createResourceItem(typeImpHandler, itemName, ns, itemPath);
    }
    // Verify/Import Outcomes, creating events and views as necessary
    if (outcomes == null || outcomes.size() == 0) {
        outcomes = typeImpHandler.getResourceOutcomes(itemName, ns, dataLocation, version);
    }
    if (outcomes.size() == 0)
        Logger.warning("Bootstrap.verifyResource() - no Outcome found therefore nothing stored!");
    for (Outcome newOutcome : outcomes) {
        if (checkToStoreOutcomeVersion(thisProxy, newOutcome, version, reset)) {
            // validate it, but not for kernel objects (ns == null) because those are to validate the rest
            if (ns != null)
                newOutcome.validateAndCheck();
            storeOutcomeEventAndViews(thisProxy, newOutcome, version);
            CollectionArrayList cols = typeImpHandler.getCollections(itemName, version, newOutcome);
            for (Collection<?> col : cols.list) {
                Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
                Gateway.getStorage().clearCache(thisProxy.getPath(), ClusterType.COLLECTION + "/" + col.getName());
                col.setVersion(null);
                Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
            }
        }
    }
    Gateway.getStorage().commit(thisProxy);
    return modDomPath;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) ResourceImportHandler(org.cristalise.kernel.process.resource.ResourceImportHandler) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 5 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class ViewpointDataHelper method get.

/**
 * dataPath syntax is used for search : viewpoint:/xpath/to/field
 */
@Override
public String get(ItemPath itemPath, String actContext, String dataPath, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
    String[] paths = dataPath.split(":");
    if (paths.length != 2)
        throw new InvalidDataException("Invalid path: '" + dataPath + "' should have only one colon (:)");
    String viewpoint = paths[0];
    String xpath = paths[1];
    // Leading dot now no longer necessary - remove if present
    if (viewpoint.startsWith("./")) {
        Logger.warning("Removing leading dot on viewpoint data helper path at " + actContext + " in " + itemPath.getUUID().toString() + ". Definition should be migrated.");
        viewpoint = viewpoint.substring(2);
    }
    // load Viewpoint and Outcome
    Viewpoint view = (Viewpoint) Gateway.getStorage().get(itemPath, ClusterType.VIEWPOINT + "/" + viewpoint, 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);
    }
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) XPathExpressionException(javax.xml.xpath.XPathExpressionException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Aggregations

Outcome (org.cristalise.kernel.persistency.outcome.Outcome)19 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)6 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)6 MainTest (org.cristalise.kernel.test.process.MainTest)6 Test (org.junit.Test)6 Schema (org.cristalise.kernel.persistency.outcome.Schema)5 History (org.cristalise.kernel.events.History)4 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 Event (org.cristalise.kernel.events.Event)3 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)3 DomainPath (org.cristalise.kernel.lookup.DomainPath)3 HashMap (java.util.HashMap)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 ClusterType (org.cristalise.kernel.persistency.ClusterType)2 Property (org.cristalise.kernel.property.Property)2