Search in sources :

Example 1 with Viewpoint

use of org.cristalise.kernel.persistency.outcome.Viewpoint 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 Viewpoint

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

the class Bootstrap method storeOutcomeEventAndViews.

/**
 * @param item
 * @param newOutcome
 * @param version
 * @throws PersistencyException
 * @throws ObjectNotFoundException
 * @throws InvalidDataException
 */
private static void storeOutcomeEventAndViews(ItemProxy item, Outcome newOutcome, int version) throws PersistencyException, ObjectNotFoundException, InvalidDataException {
    Logger.msg("Bootstrap.storeOutcomeEventAndViews() - Writing new " + newOutcome.getSchema().getName() + " v" + version + " to " + item.getName());
    History hist = new History(item.getPath(), item);
    String viewName = String.valueOf(version);
    int eventID = hist.addEvent(systemAgents.get("system").getPath(), null, "Admin", "Bootstrap", "Bootstrap", "Bootstrap", newOutcome.getSchema(), getPredefSM(), PredefinedStep.DONE, viewName).getID();
    newOutcome.setID(eventID);
    Viewpoint newLastView = new Viewpoint(item.getPath(), newOutcome.getSchema(), "last", eventID);
    Viewpoint newNumberView = new Viewpoint(item.getPath(), newOutcome.getSchema(), viewName, eventID);
    Gateway.getStorage().put(item.getPath(), newOutcome, item);
    Gateway.getStorage().put(item.getPath(), newLastView, item);
    Gateway.getStorage().put(item.getPath(), newNumberView, item);
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) History(org.cristalise.kernel.events.History) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 3 with Viewpoint

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

the class ClusterStorageManager method get.

/**
 * Internal get method. Retrieves clusters from ClusterStorages & maintains the memory cache.
 * <br>
 * There is a special case for Viewpoint. When path ends with /data it returns referenced Outcome instead of Viewpoint.
 *
 * @param itemPath current Iten
 * @param path the cluster path
 * @return the C2KObject located by path
 */
public C2KLocalObject get(ItemPath itemPath, String path) throws PersistencyException, ObjectNotFoundException {
    // check cache first
    Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
    if (sysKeyMemCache != null) {
        synchronized (sysKeyMemCache) {
            C2KLocalObject obj = sysKeyMemCache.get(path);
            if (obj != null) {
                Logger.msg(7, "ClusterStorageManager.get() - found " + itemPath + "/" + path + " in memcache");
                return obj;
            }
        }
    }
    // special case for Viewpoint- When path ends with /data it returns referenced Outcome instead of Viewpoint
    if (path.startsWith(VIEWPOINT.getName()) && path.endsWith("/data")) {
        StringTokenizer tok = new StringTokenizer(path, "/");
        if (tok.countTokens() == 4) {
            // to not catch viewpoints called 'data'
            Viewpoint view = (Viewpoint) get(itemPath, path.substring(0, path.lastIndexOf("/")));
            if (view != null)
                return view.getOutcome();
            else
                return null;
        }
    }
    C2KLocalObject result = null;
    // deal out top level remote maps
    if (path.indexOf('/') == -1) {
        if (path.equals(HISTORY.getName())) {
            result = new History(itemPath, null);
        } else if (path.equals(JOB.getName())) {
            if (itemPath instanceof AgentPath)
                result = new JobList((AgentPath) itemPath, null);
            else
                throw new ObjectNotFoundException("Items do not have job lists");
        }
    }
    if (result == null) {
        // else try each reader in turn until we find it
        ArrayList<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
        for (ClusterStorage thisReader : readers) {
            try {
                result = thisReader.get(itemPath, path);
                Logger.msg(7, "ClusterStorageManager.get() - reading " + path + " from " + thisReader.getName() + " for item " + itemPath);
                // got it!
                if (result != null)
                    break;
            } catch (PersistencyException e) {
                Logger.msg(7, "ClusterStorageManager.get() - reader " + thisReader.getName() + " could not retrieve " + itemPath + "/" + path + ": " + e.getMessage());
            }
        }
    }
    // No result was found after reading the list of ClusterStorages
    if (result == null) {
        throw new ObjectNotFoundException("ClusterStorageManager.get() - Path " + path + " not found in " + itemPath);
    }
    putInMemoryCache(itemPath, path, result);
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) JobList(org.cristalise.kernel.entity.agent.JobList) History(org.cristalise.kernel.events.History)

Example 4 with Viewpoint

use of org.cristalise.kernel.persistency.outcome.Viewpoint 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)

Example 5 with Viewpoint

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

the class DescriptionObjectCache method loadObject.

public D loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException {
    Viewpoint smView = (Viewpoint) proxy.getObject(ClusterType.VIEWPOINT + "/" + getSchemaName() + "/" + version);
    String rawRes;
    try {
        rawRes = smView.getOutcome().getData();
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw new ObjectNotFoundException("Problem loading " + getSchemaName() + " " + name + " v" + version + ": " + ex.getMessage());
    }
    return buildObject(name, version, proxy.getPath(), rawRes);
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Aggregations

Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)11 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)8 PersistencyException (org.cristalise.kernel.common.PersistencyException)7 History (org.cristalise.kernel.events.History)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 Schema (org.cristalise.kernel.persistency.outcome.Schema)6 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)4 Event (org.cristalise.kernel.events.Event)4 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 AgentPath (org.cristalise.kernel.lookup.AgentPath)2 StringTokenizer (java.util.StringTokenizer)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 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)1 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)1 JobList (org.cristalise.kernel.entity.agent.JobList)1 GraphableVertex (org.cristalise.kernel.graph.model.GraphableVertex)1