Search in sources :

Example 56 with InvalidDataException

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

the class RemoveAgent method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
    Logger.msg(1, "RemoveAgent::request() - Starting.");
    AgentPath targetAgent;
    try {
        targetAgent = new AgentPath(itemPath);
    } catch (InvalidAgentPathException ex) {
        throw new InvalidDataException("Could not resolve " + itemPath + " as an Agent.");
    }
    String agentName = targetAgent.getAgentName();
    // remove from roles
    for (RolePath role : targetAgent.getRoles()) {
        try {
            Gateway.getLookupManager().removeRole(targetAgent, role);
        } catch (ObjectCannotBeUpdated | ObjectNotFoundException | CannotManageException e) {
            Logger.error(e);
            throw new InvalidDataException("Error removing " + agentName + " from Role " + role.getName() + " exceptoin message:" + e.getMessage());
        }
    }
    return super.runActivityLogic(agent, itemPath, transitionID, requestData, locker);
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 57 with InvalidDataException

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

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

the class AddDomainContext method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectCannotBeUpdated, ObjectAlreadyExistsException, CannotManageException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "AddDomainContext: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("AddDomainContext: Invalid parameters " + Arrays.toString(params));
    DomainPath pathToAdd = new DomainPath(params[0]);
    if (pathToAdd.exists())
        throw new ObjectAlreadyExistsException("Context " + pathToAdd + " already exists");
    // collect parent paths if they don't exist
    Stack<DomainPath> pathsToAdd = new Stack<DomainPath>();
    while (pathToAdd != null && !pathToAdd.exists()) {
        pathsToAdd.push(pathToAdd);
        pathToAdd = pathToAdd.getParent();
    }
    while (!pathsToAdd.empty()) {
        pathToAdd = pathsToAdd.pop();
        Gateway.getLookupManager().add(pathToAdd);
    }
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) Stack(java.util.Stack)

Example 59 with InvalidDataException

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

the class ActivitySlotDef method getTheActivityDef.

public ActivityDef getTheActivityDef() throws ObjectNotFoundException, InvalidDataException {
    if (theActivityDef == null) {
        try {
            Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - try to load from item desc collection of ActSlotDef:" + getName());
            DescriptionObject[] parentActDefs = ((CompositeActivityDef) getParent()).getBuiltInCollectionResource(ACTIVITY);
            for (DescriptionObject thisActDef : parentActDefs) {
                String childUUID = thisActDef.getItemID();
                Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - Collection childUUID:" + childUUID + " of ActSlotDef:" + getName());
                if (childUUID.equals(getActivityDef()) || thisActDef.getName().equals(getActivityDef())) {
                    ActivityDef currentActDef = (ActivityDef) thisActDef;
                    Integer requiredVersion = deriveVersionNumber(getBuiltInProperty(VERSION));
                    if (// collection indicated a different version - get the right one
                    currentActDef.getVersion() != requiredVersion)
                        setTheActivityDef(LocalObjectLoader.getActDef(childUUID, requiredVersion));
                    else
                        // use the existing one
                        setTheActivityDef(currentActDef);
                    break;
                }
            }
        }// old def with no collection
         catch (ObjectNotFoundException ex) {
        }
        if (theActivityDef == null) {
            // try to load from property
            Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - try to load from property of ActSlotDef:" + getName());
            Integer version = deriveVersionNumber(getBuiltInProperty(VERSION));
            if (version == null)
                throw new InvalidDataException("No version defined in ActivityDefSlot " + getName());
            setTheActivityDef(LocalObjectLoader.getActDef(getActivityDef(), version));
        }
    }
    return theActivityDef;
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) DescriptionObject(org.cristalise.kernel.utils.DescriptionObject) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 60 with InvalidDataException

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

the class CompositeActivityDef method export.

@Override
public void export(Writer imports, File dir) throws InvalidDataException, ObjectNotFoundException, IOException {
    // rebuild the child refs in case any slots have been removed
    setRefChildActDef(findRefActDefs(getChildrenGraphModel()));
    // export child activitz defs, routing scripts and schemas
    for (GraphableVertex vert : getChildren()) {
        if (vert instanceof AndSplitDef) {
            try {
                ((AndSplitDef) vert).getRoutingScript().export(imports, dir);
            } catch (ObjectNotFoundException ex) {
            }
        } else if (vert instanceof ActivitySlotDef) {
            ActivityDef refAct = ((ActivitySlotDef) vert).getTheActivityDef();
            refAct.export(imports, dir);
        }
    }
    String tc = COMP_ACT_DESC_RESOURCE.getTypeCode();
    try {
        // export marshalled compAct
        String compactXML = Gateway.getMarshaller().marshall(this);
        FileStringUtility.string2File(new File(new File(dir, tc), getActName() + (getVersion() == null ? "" : "_" + getVersion()) + ".xml"), compactXML);
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("Couldn't marshall composite activity def " + getActName());
    }
    if (imports != null) {
        imports.write("<Workflow " + getExportAttributes(tc) + ">" + getExportCollections());
        for (ActivityDef childActDef : refChildActDef) {
            imports.write("<Activity name=\"" + childActDef.getActName() + "\" id=\"" + childActDef.getItemID() + "\" version=\"" + childActDef.getVersion() + "\"/>");
        }
        imports.write("</Workflow>\n");
    }
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) GraphableVertex(org.cristalise.kernel.graph.model.GraphableVertex) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) File(java.io.File) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) IOException(java.io.IOException)

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