use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class ImportRole method create.
@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
RolePath newRolePath = new RolePath(name.split("/"), (jobList == null) ? false : jobList);
if (Gateway.getLookup().exists(newRolePath)) {
// If jobList is null it means it was not set in the module.xml, therefore existing Role cannot be updated
if (jobList != null && newRolePath.hasJobList() != jobList) {
Logger.msg("ImportRole.create() - Updating Role:" + this.name + " joblist:" + jobList);
newRolePath.setHasJobList(jobList);
// FIXME: throws ObjectAlreadyExistsException?????
Gateway.getLookupManager().createRole(newRolePath);
}
} else {
Logger.msg("ImportRole.create() - Creating Role:" + name + " joblist:" + jobList);
// Check if parent exists and throw ObjectNotFoundException
newRolePath.getParent();
Gateway.getLookupManager().createRole(newRolePath);
}
return newRolePath;
}
use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class Bootstrap method checkAdminAgents.
public static void checkAdminAgents() throws Exception {
// check for administrative user & admin role
RolePath rootRole = new RolePath();
if (!rootRole.exists())
Gateway.getLookupManager().createRole(rootRole);
RolePath adminRole = new RolePath(rootRole, "Admin", false);
if (!adminRole.exists())
Gateway.getLookupManager().createRole(adminRole);
// check for import Agent
AgentProxy system = checkAgent("system", null, adminRole, new UUID(0, 1).toString());
ScriptConsole.setUser(system);
String ucRole = Gateway.getProperties().getString("UserCode.roleOverride", UserCodeProcess.DEFAULT_ROLE);
// check for local usercode user & role
RolePath usercodeRole = new RolePath(rootRole, ucRole, true);
if (!usercodeRole.exists())
Gateway.getLookupManager().createRole(usercodeRole);
checkAgent(Gateway.getProperties().getString(ucRole + ".agent", InetAddress.getLocalHost().getHostName()), Gateway.getProperties().getString(ucRole + ".password", "uc"), usercodeRole, UUID.randomUUID().toString());
}
use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class LookupPathClusterStorageTest method storeRolePath.
@Test
public void storeRolePath() throws Exception {
RolePath role = new RolePath("Minion", false);
inMemoryCluster.put(storingItem, role);
RolePath rolePrime = (RolePath) inMemoryCluster.get(storingItem, PATH + "/Role/" + StringUtils.join(role.getPath(), ""));
assertNotNull(rolePrime);
assertEquals(role.getStringPath(), rolePrime.getStringPath());
assertEquals(role.hasJobList(), rolePrime.hasJobList());
}
use of org.cristalise.kernel.lookup.RolePath 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);
}
}
use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class RemoveRole method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, CannotManageException, ObjectNotFoundException, ObjectCannotBeUpdated {
String[] params = getDataList(requestData);
Logger.msg(3, "RemoveRole: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length != 1)
throw new InvalidDataException("RemoveRole must have one paramater:" + Arrays.toString(params));
LookupManager lookup = Gateway.getLookupManager();
RolePath thisRole = lookup.getRolePath(params[0]);
AgentPath[] agents = Gateway.getLookup().getAgents(thisRole);
if (agents.length > 0)
throw new ObjectCannotBeUpdated("Cannot remove role as " + agents.length + " other agents still hold it.");
lookup.delete(thisRole);
return requestData;
}
Aggregations