Search in sources :

Example 51 with ObjectNotFoundException

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

the class Module method importAgents.

/**
 * @param systemAgent
 * @param reset
 * @throws Exception
 */
private void importAgents(AgentProxy systemAgent, boolean reset) throws Exception {
    for (ImportAgent thisAgent : imports.getAgents()) {
        if (Bootstrap.shutdown)
            return;
        try {
            Gateway.getLookup().getAgentPath(thisAgent.name);
            Logger.msg(3, "Module.importAgents() - Agent '" + thisAgent.name + "' found.");
            continue;
        } catch (ObjectNotFoundException ex) {
        }
        Logger.msg("Module.importAgents() - Agent '" + thisAgent.name + "' not found. Creating.");
        addItemToContents(thisAgent.create(systemAgent.getPath(), reset));
    }
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ImportAgent(org.cristalise.kernel.entity.imports.ImportAgent)

Example 52 with ObjectNotFoundException

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

the class Module method addImports.

/**
 * Adds the members of this Collection recursively to the imports of this Module. It checks if the Item
 * referenced by the member has a Collections or not, and adds all of members of those Collection as well.
 *
 * @param contents the Collection to be added as a list of imports
 * @throws ObjectNotFoundException the data was not found
 * @throws InvalidDataException the data was invalid
 */
public void addImports(Collection<?> contents) throws ObjectNotFoundException, InvalidDataException {
    for (CollectionMember mem : contents.getMembers().list) {
        if (mem.getItemPath() != null) {
            ItemProxy child = mem.resolveItem();
            String name = child.getName();
            Integer version = Integer.valueOf(mem.getProperties().get(VERSION.getName()).toString());
            String type = child.getProperty(TYPE);
            ModuleImport newImport;
            switch(type) {
                case "ActivityDesc":
                    String complex = child.getProperty(COMPLEXITY);
                    if (complex.equals("Elementary"))
                        newImport = new ModuleActivity(child, version);
                    else
                        newImport = new ModuleWorkflow(child, version);
                    break;
                case "Script":
                case "Query":
                case "StateMachine":
                case "Schema":
                    newImport = new ModuleResource();
                    break;
                default:
                    throw new InvalidDataException("Resource type '" + type + "' unknown for module export");
            }
            newImport.setName(name);
            newImport.setItemPath(mem.getItemPath());
            newImport.setNamespace(getNamespace());
            if (!imports.list.contains(newImport)) {
                try {
                    // check if child already assigned to a different module
                    String childModule = child.getProperty(MODULE);
                    if (StringUtils.isNotBlank(childModule) && !childModule.equals(getNamespace()))
                        return;
                }// no module property, ok to include
                 catch (ObjectNotFoundException ex) {
                }
                imports.list.add(newImport);
                for (String collName : child.getContents(ClusterType.COLLECTION)) {
                    Collection<?> childColl = child.getCollection(collName, version);
                    addImports(childColl);
                }
            }
        }
    }
}
Also used : ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) CollectionMember(org.cristalise.kernel.collection.CollectionMember) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 53 with ObjectNotFoundException

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

the class AddNewSlot method runActivityLogic.

/**
 * Creates a new slot in the given aggregation, that holds instances of the given item description
 *
 * Params:
 * <ol>
 * <li>Collection name</li>
 * <li>Item Description key (optional)</li>
 * <li>Item Description version (optional)</li>
 * </ol>
 *
 * @throws InvalidDataException
 *             Then the parameters were incorrect
 * @throws PersistencyException
 *             There was a problem loading or saving the collection from persistency
 * @throws ObjectNotFoundException
 *             A required object, such as the collection or a PropertyDescription outcome, wasn't found
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
    String collName;
    ItemPath descKey = null;
    String descVer = "last";
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddNewSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    // resolve desc item path and version
    try {
        collName = params[0];
        if (params.length > 1 && params[1].length() > 0) {
            try {
                descKey = new ItemPath(params[1]);
            } catch (InvalidItemPathException e) {
                descKey = new DomainPath(params[1]).getItemPath();
            }
        }
        if (params.length > 2 && params[2].length() > 0)
            descVer = params[2];
    } catch (Exception e) {
        throw new InvalidDataException("AddNewSlot: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    C2KLocalObject collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    if (!(collObj instanceof Aggregation))
        throw new InvalidDataException("AddNewSlot operates on Aggregation only.");
    Aggregation agg = (Aggregation) collObj;
    // get props
    CastorHashMap props = new CastorHashMap();
    StringBuffer classProps = new StringBuffer();
    if (descKey != null) {
        PropertyDescriptionList propList;
        propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer, locker);
        for (PropertyDescription pd : propList.list) {
            props.put(pd.getName(), pd.getDefaultValue());
            if (pd.getIsClassIdentifier())
                classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
        }
    }
    agg.addSlot(props, classProps.toString());
    Gateway.getStorage().put(item, agg, locker);
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Aggregation(org.cristalise.kernel.collection.Aggregation) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 54 with ObjectNotFoundException

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

the class RemoveSlotFromCollection method runActivityLogic.

/**
 * Params: 0 - collection name 1 - slot number OR if -1: 2 - target entity key
 *
 * @throws ObjectNotFoundException
 * @throws PersistencyException
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
    String collName;
    int slotNo = -1;
    ItemPath currentChild = null;
    Collection<? extends CollectionMember> coll;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "RemoveSlotFromCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        if (params.length > 1 && params[1].length() > 0)
            slotNo = Integer.parseInt(params[1]);
        if (params.length > 2 && params[2].length() > 0) {
            try {
                currentChild = new ItemPath(params[2]);
            } catch (InvalidItemPathException e) {
                currentChild = new DomainPath(params[2]).getItemPath();
            }
        }
    } catch (Exception e) {
        throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters " + Arrays.toString(params));
    }
    if (slotNo == -1 && currentChild == null)
        throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or item UUID");
    // load collection
    try {
        coll = (Collection<? extends CollectionMember>) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw new PersistencyException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': " + ex.getMessage());
    }
    // check the slot is there if it's given by id
    CollectionMember slot = null;
    if (slotNo > -1) {
        slot = coll.getMember(slotNo);
    }
    // if both parameters are supplied, check the given item is actually in that slot
    if (slot != null && currentChild != null && !slot.getItemPath().equals(currentChild)) {
        throw new ObjectNotFoundException("RemoveSlotFromCollection: Item " + currentChild + " was not in slot " + slotNo);
    }
    if (slotNo == -1) {
        // find slot from entity key
        for (CollectionMember member : coll.getMembers().list) {
            if (member.getItemPath().equals(currentChild)) {
                slotNo = member.getID();
                break;
            }
        }
    }
    if (slotNo == -1) {
        throw new ObjectNotFoundException("Could not find " + currentChild + " in collection " + coll.getName());
    }
    // Remove the slot
    coll.removeMember(slotNo);
    // Store the collection
    try {
        Gateway.getStorage().put(item, coll, locker);
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new PersistencyException("Error storing collection");
    }
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) CollectionMember(org.cristalise.kernel.collection.CollectionMember) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 55 with ObjectNotFoundException

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

the class ModuleActivity method create.

@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException, InvalidDataException {
    try {
        domainPath = Bootstrap.verifyResource(ns, name, version, type.getTypeCode(), itemPath, getResourceLocation(), reset);
        itemPath = domainPath.getItemPath();
    } catch (Exception e) {
        Logger.error(e);
        throw new CannotManageException("Exception verifying module resource " + ns + "/" + name);
    }
    actDef = LocalObjectLoader.getActDef(name, version);
    populateActivityDef();
    CollectionArrayList colls;
    try {
        colls = actDef.makeDescCollections();
    } catch (InvalidDataException e) {
        Logger.error(e);
        throw new CannotManageException("Could not create description collections for " + getName() + ".");
    }
    for (Collection<?> coll : colls.list) {
        try {
            Gateway.getStorage().put(itemPath, coll, null);
            // create last collection
            coll.setVersion(null);
            Gateway.getStorage().put(itemPath, coll, null);
        } catch (PersistencyException e) {
            Logger.error(e);
            throw new CannotManageException("Persistency exception storing description collections for " + getName() + ".");
        }
    }
    return domainPath;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) 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)

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