Search in sources :

Example 1 with TraceableEntity

use of org.cristalise.kernel.entity.TraceableEntity in project kernel by cristal-ise.

the class ImportItem method getTraceableEntitiy.

/**
 * @return
 * @throws ObjectNotFoundException
 * @throws CannotManageException
 * @throws ObjectAlreadyExistsException
 * @throws ObjectCannotBeUpdated
 */
private TraceableEntity getTraceableEntitiy() throws ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, ObjectCannotBeUpdated {
    TraceableEntity newItem;
    ItemPath ip = getItemPath();
    if (ip.exists()) {
        Logger.msg(1, "ImportItem.getTraceableEntitiy() - Verifying module item " + domainPath + " at " + ip);
        newItem = Gateway.getCorbaServer().getItem(getItemPath());
        isNewItem = false;
    } else {
        Logger.msg("ImportItem.getTraceableEntitiy() - Creating module item " + ip + " at " + domainPath);
        newItem = Gateway.getCorbaServer().createItem(ip);
        Gateway.getLookupManager().add(ip);
    }
    return newItem;
}
Also used : TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 2 with TraceableEntity

use of org.cristalise.kernel.entity.TraceableEntity 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 3 with TraceableEntity

use of org.cristalise.kernel.entity.TraceableEntity in project kernel by cristal-ise.

the class CreateItemFromDescription method runActivityLogic.

/**
 * Params:
 * <ol>
 * <li>Item name</li>
 * <li>Domain context</li>
 * <li>Description version to use(optional)</li>
 * <li>Initial properties to set in the new Agent (optional)</li>
 * </ol>
 * @throws ObjectNotFoundException
 * @throws InvalidDataException The input parameters were incorrect
 * @throws ObjectAlreadyExistsException The Agent already exists
 * @throws CannotManageException The Agent could not be created
 * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
 * @throws PersistencyException
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath descItemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException {
    String[] input = getDataList(requestData);
    String newName = input[0];
    String domPath = input[1];
    String descVer = input.length > 2 ? input[2] : "last";
    PropertyArrayList initProps = input.length > 3 ? unmarshallInitProperties(input[3]) : new PropertyArrayList();
    Logger.msg(1, "CreateItemFromDescription - name:" + newName);
    // check if the path is already taken
    DomainPath context = new DomainPath(new DomainPath(domPath), newName);
    if (context.exists())
        throw new ObjectAlreadyExistsException("The path " + context + " exists already.");
    // generate new item path with random uuid
    Logger.msg(6, "CreateItemFromDescription - Requesting new item path");
    ItemPath newItemPath = new ItemPath();
    // create the Item object
    Logger.msg(3, "CreateItemFromDescription - Creating Item");
    CorbaServer factory = Gateway.getCorbaServer();
    if (factory == null)
        throw new CannotManageException("This process cannot create new Items");
    TraceableEntity newItem = factory.createItem(newItemPath);
    Gateway.getLookupManager().add(newItemPath);
    initialiseItem(newItem, agent, descItemPath, initProps, newName, descVer, context, newItemPath, locker);
    return requestData;
}
Also used : TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) DomainPath(org.cristalise.kernel.lookup.DomainPath) CannotManageException(org.cristalise.kernel.common.CannotManageException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) CorbaServer(org.cristalise.kernel.entity.CorbaServer) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 4 with TraceableEntity

use of org.cristalise.kernel.entity.TraceableEntity in project kernel by cristal-ise.

the class ImportItem method create.

/**
 */
@Override
public Path create(AgentPath agentPath, boolean reset) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification, PersistencyException {
    domainPath = new DomainPath(new DomainPath(initialPath), name);
    if (domainPath.exists()) {
        ItemPath domItem = domainPath.getItemPath();
        if (!getItemPath().equals(domItem)) {
            throw new CannotManageException("Item " + domainPath + " was found with the wrong itemPath (" + domainPath.getItemPath() + " vs " + getItemPath() + ")");
        }
    } else
        isDOMPathExists = false;
    TraceableEntity newItem = getTraceableEntitiy();
    // (re)initialise the new item with properties, workflow and collections
    try {
        newItem.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(createItemProperties()), Gateway.getMarshaller().marshall(createCompositeActivity()), Gateway.getMarshaller().marshall(createCollections()));
    } catch (Exception ex) {
        Logger.error("Error initialising new item " + ns + "/" + name);
        Logger.error(ex);
        if (isNewItem)
            Gateway.getLookupManager().delete(itemPath);
        throw new CannotManageException("Problem initialising new item. See server log:" + ex.getMessage());
    }
    History hist = new History(getItemPath(), null);
    // import outcomes
    for (ImportOutcome thisOutcome : outcomes) {
        String outcomeData = thisOutcome.getData(ns);
        // load schema and state machine
        Schema schema = LocalObjectLoader.getSchema(thisOutcome.schema, thisOutcome.version);
        // parse new outcome and validate
        Outcome newOutcome = new Outcome(-1, outcomeData, schema);
        newOutcome.validateAndCheck();
        Viewpoint impView;
        try {
            impView = (Viewpoint) Gateway.getStorage().get(getItemPath(), ClusterType.VIEWPOINT + "/" + thisOutcome.schema + "/" + thisOutcome.viewname, null);
            if (newOutcome.isIdentical(impView.getOutcome())) {
                Logger.msg(5, "ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name + " identical, no update required");
                continue;
            } else {
                Logger.msg("ImportItem.create() - Difference found in view " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name);
                if (!reset && !impView.getEvent().getStepPath().equals("Import")) {
                    Logger.msg("ImportItem.create() - Last edit was not done by import, and reset not requested. Not overwriting.");
                    continue;
                }
            }
        } catch (ObjectNotFoundException ex) {
            Logger.msg("ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " not found in " + ns + "/" + name + ". Creating.");
            impView = new Viewpoint(getItemPath(), schema, thisOutcome.viewname, -1);
        }
        // write new view/outcome/event
        Event newEvent = hist.addEvent(agentPath, null, "Admin", "Import", "Import", "Import", schema, Bootstrap.getPredefSM(), PredefinedStep.DONE, thisOutcome.viewname);
        newOutcome.setID(newEvent.getID());
        impView.setEventId(newEvent.getID());
        Gateway.getStorage().put(getItemPath(), newOutcome, null);
        Gateway.getStorage().put(getItemPath(), impView, null);
    }
    // register domain path (before collections in case of recursive collections)
    if (!isDOMPathExists) {
        domainPath.setItemPath(getItemPath());
        Gateway.getLookupManager().add(domainPath);
    }
    return domainPath;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) CannotManageException(org.cristalise.kernel.common.CannotManageException) Schema(org.cristalise.kernel.persistency.outcome.Schema) History(org.cristalise.kernel.events.History) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Event(org.cristalise.kernel.events.Event) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)4 DomainPath (org.cristalise.kernel.lookup.DomainPath)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)3 CannotManageException (org.cristalise.kernel.common.CannotManageException)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)2 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)2 ArrayList (java.util.ArrayList)1 Collection (org.cristalise.kernel.collection.Collection)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)1 CorbaServer (org.cristalise.kernel.entity.CorbaServer)1 Event (org.cristalise.kernel.events.Event)1 History (org.cristalise.kernel.events.History)1 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 Schema (org.cristalise.kernel.persistency.outcome.Schema)1