Search in sources :

Example 31 with ObjectNotFoundException

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

the class CorbaServer method getAgent.

/**
 * Returns a CORBA servant for a pre-existing entity
 *
 * @param agentPath the AgentPath representing the Agent
 * @return the servant
 * @throws InvalidAgentPathException agentPath was not Agent
 * @throws ObjectNotFoundException agentPath was not found
 */
public ActiveEntity getAgent(AgentPath agentPath) throws InvalidAgentPathException, ObjectNotFoundException {
    Servant agent = null;
    if (!agentPath.exists())
        throw new ObjectNotFoundException(agentPath + " does not exist");
    synchronized (mItemCache) {
        agent = mItemCache.get(agentPath);
        if (agent == null) {
            Logger.msg(7, "Creating new servant for " + agentPath);
            agent = new ActiveEntity(agentPath, mAgentPOA);
            mItemCache.put(agentPath, agent);
        } else if (!(agent instanceof ActiveEntity))
            throw new InvalidAgentPathException("Item " + agentPath + " was not an agent");
    }
    return (ActiveEntity) agent;
}
Also used : ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Servant(org.omg.PortableServer.Servant) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity)

Example 32 with ObjectNotFoundException

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

the class CreateAgentFromDescription method createAgentAddRoles.

/**
 * @param newAgentPath
 * @param roles
 * @return
 * @throws CannotManageException
 * @throws ObjectCannotBeUpdated
 * @throws ObjectAlreadyExistsException
 */
protected ActiveEntity createAgentAddRoles(AgentPath newAgentPath, String[] roles, String pwd) throws CannotManageException, ObjectCannotBeUpdated, ObjectAlreadyExistsException {
    // create the Agent object
    Logger.msg(3, "CreateAgentFromDescription.createAgentAddRoles() - Creating Agent");
    CorbaServer factory = Gateway.getCorbaServer();
    if (factory == null)
        throw new CannotManageException("This process cannot create new Items");
    ActiveEntity newAgent = factory.createAgent(newAgentPath);
    Gateway.getLookupManager().add(newAgentPath);
    try {
        if (StringUtils.isNotBlank(pwd))
            Gateway.getLookupManager().setAgentPassword(newAgentPath, pwd);
        for (String roleName : roles) {
            RolePath role = Gateway.getLookupManager().getRolePath(roleName);
            Gateway.getLookupManager().addRole(newAgentPath, role);
        }
    } catch (ObjectNotFoundException | NoSuchAlgorithmException e) {
        Logger.error(e);
        Gateway.getLookupManager().delete(newAgentPath);
    }
    return newAgent;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CorbaServer(org.cristalise.kernel.entity.CorbaServer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 33 with ObjectNotFoundException

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

the class RemoveDomainPath method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "RemoveDomainPath: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveDomainPath: Invalid parameters " + Arrays.toString(params));
    DomainPath domainPath = new DomainPath(params[0]);
    if (!domainPath.exists()) {
        throw new ObjectNotFoundException("RemoveDomainPath: Domain path " + domainPath + " does not exist.");
    }
    if (!domainPath.getItemPath().equals(item)) {
        throw new InvalidDataException("RemoveDomainPath: Domain path " + domainPath + " is not an alias of the current Item " + item);
    }
    Gateway.getLookupManager().delete(domainPath);
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 34 with ObjectNotFoundException

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

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

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