Search in sources :

Example 1 with CollectionArrayList

use of org.cristalise.kernel.collection.CollectionArrayList 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 CollectionArrayList

use of org.cristalise.kernel.collection.CollectionArrayList in project kernel by cristal-ise.

the class ActivityDef method makeDescCollections.

@Override
public CollectionArrayList makeDescCollections() throws InvalidDataException, ObjectNotFoundException {
    CollectionArrayList retArr = new CollectionArrayList();
    retArr.put(makeDescCollection(SCHEMA, getSchema()));
    retArr.put(makeDescCollection(SCRIPT, getScript()));
    retArr.put(makeDescCollection(QUERY, getQuery()));
    retArr.put(makeDescCollection(STATE_MACHINE, getStateMachine()));
    return retArr;
}
Also used : CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList)

Example 3 with CollectionArrayList

use of org.cristalise.kernel.collection.CollectionArrayList 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 CollectionArrayList

use of org.cristalise.kernel.collection.CollectionArrayList 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 CollectionArrayList

use of org.cristalise.kernel.collection.CollectionArrayList in project kernel by cristal-ise.

the class CompositeActivityDef method makeDescCollections.

@Override
public CollectionArrayList makeDescCollections() throws InvalidDataException, ObjectNotFoundException {
    CollectionArrayList retArr = super.makeDescCollections();
    retArr.put(makeActDefCollection());
    return retArr;
}
Also used : CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList)

Aggregations

CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)10 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 Dependency (org.cristalise.kernel.collection.Dependency)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 PersistencyException (org.cristalise.kernel.common.PersistencyException)3 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)3 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)3 Collection (org.cristalise.kernel.collection.Collection)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)2 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 Property (org.cristalise.kernel.property.Property)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CompiledScript (javax.script.CompiledScript)1 Aggregation (org.cristalise.kernel.collection.Aggregation)1