Search in sources :

Example 1 with C2KLocalObject

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

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

the class TransferItem method exportItem.

public void exportItem(File dir, String path) throws Exception {
    Logger.msg("Path " + path + " in " + itemPath);
    String[] contents = Gateway.getStorage().getClusterContents(itemPath, path);
    if (contents.length > 0) {
        FileStringUtility.createNewDir(dir.getCanonicalPath());
        for (String content : contents) {
            exportItem(new File(dir, content), path + "/" + content);
        }
    } else {
        // no children, try to dump object
        try {
            C2KLocalObject obj = Gateway.getStorage().get(itemPath, path, null);
            Logger.msg("Dumping object " + path + " in " + itemPath);
            File dumpPath = new File(dir.getCanonicalPath() + ".xml");
            FileStringUtility.string2File(dumpPath, Gateway.getMarshaller().marshall(obj));
            return;
        }// not an object
         catch (ObjectNotFoundException ex) {
        }
    }
}
Also used : C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) File(java.io.File)

Example 3 with C2KLocalObject

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

the class ClusterStorageManager method clearCache.

public void clearCache(ItemPath itemPath) {
    Logger.msg(5, "ClusterStorageManager.clearCache() - removing entire cache of " + itemPath);
    if (memoryCache.containsKey(itemPath)) {
        synchronized (memoryCache) {
            if (Logger.doLog(6)) {
                Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
                int size = sysKeyMemCache.size();
                Logger.msg(6, "ClusterStorageManager.clearCache() - " + size + " objects to remove.");
            }
            memoryCache.remove(itemPath);
        }
    } else
        Logger.msg(6, "ClusterStorageManager.clearCache() - No objects cached");
}
Also used : C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 4 with C2KLocalObject

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

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

the class UserCodeProcess method getJob.

/**
 * @param jobs
 * @param transition
 * @return
 */
private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
    for (C2KLocalObject c2kLocalObject : jobs.values()) {
        Job thisJob = (Job) c2kLocalObject;
        if (thisJob.getTransition().getId() == transition) {
            Logger.msg(1, "=================================================================");
            Logger.msg(5, "UserCodeProcess.getJob() - job:" + thisJob);
            return thisJob;
        }
    }
    return null;
}
Also used : C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) Job(org.cristalise.kernel.entity.agent.Job)

Aggregations

C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)20 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)7 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 DomainPath (org.cristalise.kernel.lookup.DomainPath)4 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)4 ItemPath (org.cristalise.kernel.lookup.ItemPath)4 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 ConcurrentModificationException (java.util.ConcurrentModificationException)2 Aggregation (org.cristalise.kernel.collection.Aggregation)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 Job (org.cristalise.kernel.entity.agent.Job)2 CastorHashMap (org.cristalise.kernel.utils.CastorHashMap)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 AggregationMember (org.cristalise.kernel.collection.AggregationMember)1 Collection (org.cristalise.kernel.collection.Collection)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1