Search in sources :

Example 11 with InvalidItemPathException

use of org.cristalise.kernel.lookup.InvalidItemPathException in project kernel by cristal-ise.

the class SetAgentRoles method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "SetAgentRoles: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    AgentPath targetAgent;
    try {
        targetAgent = new AgentPath(item);
    } catch (InvalidItemPathException ex) {
        throw new InvalidDataException("Could not resolve syskey " + item + " as an Agent.");
    }
    RolePath[] currentRoles = targetAgent.getRoles();
    ArrayList<RolePath> requestedRoles = new ArrayList<RolePath>();
    for (int i = 0; i < params.length; i++) {
        try {
            requestedRoles.add(Gateway.getLookup().getRolePath(params[i]));
        } catch (ObjectNotFoundException e) {
            throw new InvalidDataException("Role " + params[i] + " not found");
        }
    }
    ArrayList<RolePath> rolesToRemove = new ArrayList<RolePath>();
    for (RolePath existingRole : currentRoles) {
        // 
        if (// if we have it, and it's requested, then it will be kept
        requestedRoles.contains(existingRole))
            // so remove it from request - this will be left with roles to be added
            requestedRoles.remove(existingRole);
        else
            // else this role will be removed
            rolesToRemove.add(existingRole);
    }
    // remove roles not in new list
    for (RolePath roleToRemove : rolesToRemove) try {
        Gateway.getLookupManager().removeRole(targetAgent, roleToRemove);
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("Error removing role " + roleToRemove.getName());
    }
    // add requested roles we don't already have
    for (RolePath roleToAdd : requestedRoles) {
        try {
            Gateway.getLookupManager().addRole(targetAgent, roleToAdd);
        } catch (Exception e) {
            Logger.error(e);
            throw new InvalidDataException("Error adding role " + roleToAdd.getName());
        }
    }
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ArrayList(java.util.ArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 12 with InvalidItemPathException

use of org.cristalise.kernel.lookup.InvalidItemPathException in project kernel by cristal-ise.

the class QueryOutcomeInitiator method initOutcomeInstance.

@Override
public Outcome initOutcomeInstance(Job job) throws InvalidDataException {
    if (job.hasQuery()) {
        try {
            Outcome o = new Outcome(-1, job.getItemProxy().executeQuery(job.getQuery()), job.getSchema());
            o.validateAndCheck();
            return o;
        } catch (PersistencyException | ObjectNotFoundException | InvalidItemPathException e) {
            throw new InvalidDataException("Error executing Query:" + e.getMessage());
        }
    } else
        throw new InvalidDataException("No Query was defined for job:" + job);
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 13 with InvalidItemPathException

use of org.cristalise.kernel.lookup.InvalidItemPathException 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 14 with InvalidItemPathException

use of org.cristalise.kernel.lookup.InvalidItemPathException 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 15 with InvalidItemPathException

use of org.cristalise.kernel.lookup.InvalidItemPathException in project kernel by cristal-ise.

the class DescriptionObjectCache method findItem.

public ItemPath findItem(String name) throws ObjectNotFoundException, InvalidDataException {
    if (Gateway.getLookup() == null)
        throw new ObjectNotFoundException("Cannot find Items without a Lookup");
    // first check for a UUID name
    try {
        ItemPath resItem = new ItemPath(name);
        if (resItem.exists())
            return resItem;
    } catch (InvalidItemPathException ex) {
    }
    // then check for a direct path
    DomainPath directPath = new DomainPath(name);
    if (directPath.exists() && directPath.getItemPath() != null) {
        return directPath.getItemPath();
    }
    // else search for it in the whole tree using property description
    Property[] searchProps = new Property[classIdProps.length + 1];
    searchProps[0] = new Property(NAME, name);
    System.arraycopy(classIdProps, 0, searchProps, 1, classIdProps.length);
    Iterator<Path> e = Gateway.getLookup().search(new DomainPath(), searchProps);
    if (e.hasNext()) {
        Path defPath = e.next();
        if (e.hasNext())
            throw new ObjectNotFoundException("Too many matches for " + getTypeCode() + " " + name);
        if (defPath.getItemPath() == null)
            throw new InvalidDataException(getTypeCode() + " " + name + " was found, but was not an Item");
        return defPath.getItemPath();
    } else {
        throw new ObjectNotFoundException("No match for " + getTypeCode() + " " + name);
    }
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemPath(org.cristalise.kernel.lookup.ItemPath) Path(org.cristalise.kernel.lookup.Path) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Property(org.cristalise.kernel.property.Property) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)15 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)11 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)10 PersistencyException (org.cristalise.kernel.common.PersistencyException)8 ItemPath (org.cristalise.kernel.lookup.ItemPath)8 DomainPath (org.cristalise.kernel.lookup.DomainPath)7 AgentPath (org.cristalise.kernel.lookup.AgentPath)6 Aggregation (org.cristalise.kernel.collection.Aggregation)3 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)3 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)3 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)3 Dependency (org.cristalise.kernel.collection.Dependency)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)2 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 Property (org.cristalise.kernel.property.Property)2 CastorHashMap (org.cristalise.kernel.utils.CastorHashMap)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1