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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations