Search in sources :

Example 36 with InvalidDataException

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

the class OrSplit method runNext.

@Override
public void runNext(AgentPath agent, ItemPath itemPath, Object locker) throws InvalidDataException {
    String[] nextsTab = calculateNexts(itemPath, locker);
    int active = 0;
    DirectedEdge[] outEdges = getOutEdges();
    for (String thisNext : nextsTab) {
        Logger.msg(7, "OrSplit.runNext() - Finding next " + thisNext);
        for (DirectedEdge outEdge : outEdges) {
            Next nextEdge = (Next) outEdge;
            if (thisNext != null && thisNext.equals(nextEdge.getBuiltInProperty(ALIAS))) {
                WfVertex term = nextEdge.getTerminusVertex();
                try {
                    term.run(agent, itemPath, locker);
                } catch (InvalidDataException e) {
                    Logger.error(e);
                    throw new InvalidDataException("Error enabling next " + thisNext);
                }
                Logger.msg(7, "OrSplit.runNext() - Running " + nextEdge.getBuiltInProperty(ALIAS));
                active++;
            }
        }
    }
    // if no active nexts throw exception
    if (active == 0)
        throw new InvalidDataException("No nexts were activated!");
}
Also used : DirectedEdge(org.cristalise.kernel.graph.model.DirectedEdge) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 37 with InvalidDataException

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

the class XOrSplit method runNext.

@Override
public void runNext(AgentPath agent, ItemPath itemPath, Object locker) throws InvalidDataException {
    String[] nextsTab = calculateNexts(itemPath, locker);
    ArrayList<DirectedEdge> nextsToFollow = new ArrayList<DirectedEdge>();
    DirectedEdge[] outEdges = getOutEdges();
    for (DirectedEdge outEdge : outEdges) {
        if (isInTable((String) ((Next) outEdge).getBuiltInProperty(ALIAS), nextsTab))
            nextsToFollow.add(outEdge);
    }
    if (nextsToFollow.size() != 1)
        throw new InvalidDataException("not good number of active next");
    followNext((Next) nextsToFollow.get(0), agent, itemPath, locker);
}
Also used : DirectedEdge(org.cristalise.kernel.graph.model.DirectedEdge) ArrayList(java.util.ArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 38 with InvalidDataException

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

the class AssignItemToSlot method runActivityLogic.

/**
 * Params: 0 - collection name 1 - slot number 2 - target entity key
 *
 * @throws ObjectNotFoundException
 * @throws PersistencyException
 * @throws ObjectCannotBeUpdated
 * @throws InvalidCollectionModification
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated, InvalidCollectionModification {
    String collName;
    int slotNo;
    ItemPath childItem;
    Aggregation agg;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AssignItemToSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        slotNo = Integer.parseInt(params[1]);
        try {
            childItem = new ItemPath(params[2]);
        } catch (InvalidItemPathException e) {
            childItem = new DomainPath(params[2]).getItemPath();
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("AssignItemToSlot: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    C2KLocalObject collObj;
    try {
        collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw new PersistencyException("AssignItemToSlot: Error loading collection '\"+collName+\"': " + ex.getMessage());
    }
    if (!(collObj instanceof Aggregation))
        throw new InvalidDataException("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only.");
    agg = (Aggregation) collObj;
    // find member and assign entity
    boolean stored = false;
    for (AggregationMember member : agg.getMembers().list) {
        if (member.getID() == slotNo) {
            if (member.getItemPath() != null)
                throw new ObjectCannotBeUpdated("AssignItemToSlot: Member slot " + slotNo + " not empty");
            member.assignItem(childItem);
            stored = true;
            break;
        }
    }
    if (!stored) {
        throw new ObjectNotFoundException("AssignItemToSlot: Member slot " + slotNo + " not found.");
    }
    try {
        Gateway.getStorage().put(item, agg, locker);
    } catch (PersistencyException e) {
        throw new PersistencyException("AssignItemToSlot: Error saving collection '" + collName + "': " + e.getMessage());
    }
    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) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) AggregationMember(org.cristalise.kernel.collection.AggregationMember) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 39 with InvalidDataException

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

the class CreateNewAgent method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
    try {
        ImportAgent newAgent = (ImportAgent) Gateway.getMarshaller().unmarshall(requestData);
        newAgent.create(agent, true);
        newAgent.setPassword("REDACTED");
        return Gateway.getMarshaller().marshall(newAgent);
    } catch (MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: " + requestData);
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) ImportAgent(org.cristalise.kernel.entity.imports.ImportAgent) MappingException(org.exolab.castor.mapping.MappingException)

Example 40 with InvalidDataException

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

the class CreateNewRole method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
    try {
        ImportRole newRole = (ImportRole) Gateway.getMarshaller().unmarshall(requestData);
        if (Gateway.getLookup().exists(new RolePath(newRole.getName(), newRole.jobList)))
            throw new ObjectAlreadyExistsException("CreateNewRole: Role '" + newRole.getName() + "' already exists.");
        newRole.create(agent, true);
        return requestData;
    } catch (MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        throw new InvalidDataException("CreateNewRole: Couldn't unmarshall new Role: " + requestData);
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) ImportRole(org.cristalise.kernel.entity.imports.ImportRole) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) RolePath(org.cristalise.kernel.lookup.RolePath) MappingException(org.exolab.castor.mapping.MappingException)

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