Search in sources :

Example 11 with ObjectNotFoundException

use of org.cristalise.kernel.common.ObjectNotFoundException 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 12 with ObjectNotFoundException

use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.

the class DescriptionObjectCache method get.

public D get(String name, int version) throws ObjectNotFoundException, InvalidDataException {
    D thisDef = null;
    synchronized (cache) {
        CacheEntry<D> thisDefEntry = cache.get(name + "_" + version);
        if (thisDefEntry == null) {
            Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " not found in cache. Checking id.");
            try {
                ItemPath defItemPath = findItem(name);
                String defId = defItemPath.getUUID().toString();
                thisDefEntry = cache.get(defId + "_" + version);
                if (thisDefEntry == null) {
                    Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " not found in cache. Loading from database.");
                    ItemProxy defItemProxy = Gateway.getProxyManager().getProxy(defItemPath);
                    if (name.equals(defId)) {
                        String itemName = defItemProxy.getName();
                        if (itemName != null)
                            name = itemName;
                    }
                    thisDef = loadObject(name, version, defItemProxy);
                    cache.put(defId + "_" + version, new CacheEntry<D>(thisDef, defItemProxy, this));
                }
            } catch (ObjectNotFoundException ex) {
                // for bootstrap and testing, try to load built-in kernel objects from resources
                if (version == 0) {
                    try {
                        return loadObjectFromBootstrap(name);
                    } catch (ObjectNotFoundException ex2) {
                    }
                }
                throw ex;
            }
        }
        if (thisDefEntry != null && thisDef == null) {
            Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " found in cache.");
            thisDef = thisDefEntry.def;
        }
    }
    return thisDef;
}
Also used : ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 13 with ObjectNotFoundException

use of org.cristalise.kernel.common.ObjectNotFoundException 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)

Example 14 with ObjectNotFoundException

use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.

the class ProxyLoader method get.

/**
 * retrieve object by path
 */
@Override
public C2KLocalObject get(ItemPath thisItem, String path) throws PersistencyException {
    try {
        Item thisEntity = getIOR(thisItem);
        ClusterType type = getClusterType(path);
        // fetch the xml from the item
        String queryData = thisEntity.queryData(path);
        if (Logger.doLog(8))
            Logger.msg("ProxyLoader.get() - " + thisItem + " : " + path + " = " + queryData);
        if (queryData != null) {
            if (type == ClusterType.OUTCOME)
                return new Outcome(path, queryData);
            else
                return (C2KLocalObject) Gateway.getMarshaller().unmarshall(queryData);
        }
    } catch (ObjectNotFoundException e) {
        return null;
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
    return null;
}
Also used : Item(org.cristalise.kernel.entity.Item) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ClusterType(org.cristalise.kernel.persistency.ClusterType) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 15 with ObjectNotFoundException

use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.

the class RemoveDomainContext method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "RemoveDomainContext: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveDomainContext: Invalid parameters " + Arrays.toString(params));
    DomainPath pathToDelete = new DomainPath(params[0]);
    if (!pathToDelete.exists())
        throw new ObjectNotFoundException("Context " + pathToDelete + " does not exist");
    try {
        pathToDelete.getItemPath();
        throw new InvalidDataException("Path " + pathToDelete + " is an Entity. Use its own Erase step instead, or RemoveAgent.");
    } catch (ObjectNotFoundException ex) {
    }
    if (Gateway.getLookup().getChildren(pathToDelete).hasNext())
        throw new ObjectCannotBeUpdated("Context " + pathToDelete + " is not empty. Cannot delete.");
    Gateway.getLookupManager().delete(pathToDelete);
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated)

Aggregations

ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)59 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)38 PersistencyException (org.cristalise.kernel.common.PersistencyException)27 DomainPath (org.cristalise.kernel.lookup.DomainPath)12 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)12 ItemPath (org.cristalise.kernel.lookup.ItemPath)12 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 AgentPath (org.cristalise.kernel.lookup.AgentPath)11 CannotManageException (org.cristalise.kernel.common.CannotManageException)9 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)8 IOException (java.io.IOException)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)7 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)6 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)6 InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)5 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)5 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)5 Property (org.cristalise.kernel.property.Property)5 MappingException (org.exolab.castor.mapping.MappingException)5 MarshalException (org.exolab.castor.xml.MarshalException)5