Search in sources :

Example 1 with RolePath

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;
}
Also used : RolePath(org.cristalise.kernel.lookup.RolePath)

Example 2 with RolePath

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());
}
Also used : AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) UUID(java.util.UUID) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 3 with RolePath

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());
}
Also used : RolePath(org.cristalise.kernel.lookup.RolePath) Test(org.junit.Test)

Example 4 with RolePath

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);
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) ImportRole(org.cristalise.kernel.entity.imports.ImportRole) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) RolePath(org.cristalise.kernel.lookup.RolePath) MappingException(org.exolab.castor.mapping.MappingException)

Example 5 with RolePath

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;
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) RolePath(org.cristalise.kernel.lookup.RolePath)

Aggregations

RolePath (org.cristalise.kernel.lookup.RolePath)13 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)4 CannotManageException (org.cristalise.kernel.common.CannotManageException)3 ArrayList (java.util.ArrayList)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)2 ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UUID (java.util.UUID)1 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1 CorbaServer (org.cristalise.kernel.entity.CorbaServer)1 ImportRole (org.cristalise.kernel.entity.imports.ImportRole)1 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)1 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1