Search in sources :

Example 81 with InvalidDataException

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

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

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

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

the class CreateNewCollectionVersion method runActivityLogic.

/**
 * Generates a new snapshot of a collection from its current state.
 * The new version is given the next available number, starting at 0.
 * <pre>
 * Params:
 * 0 - Collection name
 * 1 - Version (optional)
 * </pre>
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "CreateNewCollectionVersion: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length == 0 || params.length > 2) {
        throw new InvalidDataException("CreateNewCollectionVersion: Invalid parameters " + Arrays.toString(params));
    }
    String collName = params[0];
    Collection<?> coll = (Collection<?>) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    int newVersion;
    if (params.length > 1) {
        newVersion = Integer.valueOf(params[1]);
    } else {
        // find last numbered version
        String[] versions = Gateway.getStorage().getClusterContents(item, ClusterType.COLLECTION + "/" + collName);
        int lastVer = -1;
        for (String thisVerStr : versions) {
            try {
                int thisVer = Integer.parseInt(thisVerStr);
                if (thisVer > lastVer)
                    lastVer = thisVer;
            }// ignore non-integer versions
             catch (NumberFormatException ex) {
            }
        }
        newVersion = lastVer + 1;
    }
    // Remove it from the cache before we change it
    Gateway.getStorage().clearCache(item, ClusterType.COLLECTION + "/" + collName + "/last");
    // Set the version & store it
    try {
        coll.setVersion(newVersion);
        Gateway.getStorage().put(item, coll, locker);
    } catch (PersistencyException e) {
        throw new PersistencyException("CreateNewCollectionVersion: Error saving new collection '" + collName + "': " + e.getMessage());
    }
    return requestData;
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Collection(org.cristalise.kernel.collection.Collection) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 85 with InvalidDataException

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

Aggregations

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)91 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)40 PersistencyException (org.cristalise.kernel.common.PersistencyException)33 IOException (java.io.IOException)14 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)11 DomainPath (org.cristalise.kernel.lookup.DomainPath)10 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 CannotManageException (org.cristalise.kernel.common.CannotManageException)8 AgentPath (org.cristalise.kernel.lookup.AgentPath)8 Schema (org.cristalise.kernel.persistency.outcome.Schema)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)7 ItemPath (org.cristalise.kernel.lookup.ItemPath)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ArrayList (java.util.ArrayList)5 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5