use of org.cristalise.kernel.entity.agent.ActiveEntity in project kernel by cristal-ise.
the class CorbaServer method createAgent.
public ActiveEntity createAgent(AgentPath agentPath) throws CannotManageException, ObjectAlreadyExistsException {
if (agentPath.exists())
throw new ObjectAlreadyExistsException();
agentPath.setIOR(getAgentIOR(agentPath));
ActiveEntity agent = new ActiveEntity(agentPath, mAgentPOA);
synchronized (mItemCache) {
mItemCache.put(agentPath, agent);
}
return agent;
}
use of org.cristalise.kernel.entity.agent.ActiveEntity in project kernel by cristal-ise.
the class ImportAgent method create.
@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
if (roles.isEmpty())
throw new ObjectNotFoundException("Agent '" + name + "' must declare at least one Role ");
AgentPath newAgent = new AgentPath(getItemPath(), name);
ActiveEntity newAgentEnt = Gateway.getCorbaServer().createAgent(newAgent);
Gateway.getLookupManager().add(newAgent);
// assemble properties
properties.add(new Property(NAME, name, true));
properties.add(new Property(TYPE, "Agent", false));
try {
if (StringUtils.isNotBlank(password))
Gateway.getLookupManager().setAgentPassword(newAgent, password);
newAgentEnt.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), null, null);
} catch (Exception ex) {
Logger.error(ex);
throw new CannotManageException("Error initialising new agent name:" + name);
}
for (ImportRole role : roles) {
RolePath thisRole = (RolePath) role.create(agentPath, reset);
Gateway.getLookupManager().addRole(newAgent, thisRole);
}
return newAgent;
}
use of org.cristalise.kernel.entity.agent.ActiveEntity 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.entity.agent.ActiveEntity 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.entity.agent.ActiveEntity in project kernel by cristal-ise.
the class CreateAgentFromDescription method runActivityLogic.
/**
* Params:
* <ol>
* <li>Agent name</li>
* <li>Domain context</li>
* <li>Comma-delimited Role names to assign to the Agent</li>
* <li>Password (optional)</li>
* <li>Initial properties to set in the new Agent (optional)</li>
* <li>Description version to use(optional)</li>
* </ol>
* @throws ObjectNotFoundException
* @throws InvalidDataException The input parameters were incorrect
* @throws ObjectAlreadyExistsException The Agent already exists
* @throws CannotManageException The Agent could not be created
* @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
* @throws PersistencyException
* @see org.cristalise.kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(AgentPath, ItemPath, int, String, Object)
*/
@Override
protected String runActivityLogic(AgentPath agentPath, ItemPath descItemPath, int transitionID, String requestData, Object locker) throws ObjectNotFoundException, InvalidDataException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException {
String[] input = getDataList(requestData);
String newName = input[0];
String contextS = input[1];
String[] roles = input[2].split(",");
String pwd = input.length > 3 ? input[3] : "";
String descVer = input.length > 4 ? input[4] : "last";
PropertyArrayList initProps = input.length > 5 ? unmarshallInitProperties(input[5]) : new PropertyArrayList();
// generate new agent path with new UUID
Logger.msg(1, "CreateAgentFromDescription - Requesting new agent path name:" + newName);
AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
// check if the agent's name is already taken
if (Gateway.getLookup().exists(newAgentPath))
throw new ObjectAlreadyExistsException("The agent name " + newName + " exists already.");
DomainPath context = new DomainPath(new DomainPath(contextS), newName);
if (context.exists())
throw new ObjectAlreadyExistsException("The path " + context + " exists already.");
ActiveEntity newAgent = createAgentAddRoles(newAgentPath, roles, pwd);
initialiseItem(newAgent, agentPath, descItemPath, initProps, newName, descVer, context, newAgentPath, locker);
// censor password from outcome
if (input.length > 3)
input[3] = "REDACTED";
return bundleData(input);
}
Aggregations