summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-18 10:39:05 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-18 10:39:05 +0200
commit3743d182d99dbed9d2be84dc357f6839ffe4d2ec (patch)
tree7fe88768469f34601c494f5b027bd9c3a6d622e7 /src/main/java/com/c2kernel/entity
parent1537f39761e11669335f6499474f23b11cf2cf38 (diff)
Hierarchical Roles. Fixes #199
Diffstat (limited to 'src/main/java/com/c2kernel/entity')
-rw-r--r--src/main/java/com/c2kernel/entity/agent/AgentImplementation.java4
-rw-r--r--src/main/java/com/c2kernel/entity/imports/ImportAgent.java4
-rw-r--r--src/main/java/com/c2kernel/entity/imports/ImportRole.java28
3 files changed, 30 insertions, 6 deletions
diff --git a/src/main/java/com/c2kernel/entity/agent/AgentImplementation.java b/src/main/java/com/c2kernel/entity/agent/AgentImplementation.java
index 0406387..c0f0dd0 100644
--- a/src/main/java/com/c2kernel/entity/agent/AgentImplementation.java
+++ b/src/main/java/com/c2kernel/entity/agent/AgentImplementation.java
@@ -60,7 +60,7 @@ public class AgentImplementation extends ItemImplementation implements
public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
RolePath newRole = Gateway.getLookup().getRolePath(roleName);
try {
- newRole.addAgent(mAgentPath);
+ Gateway.getLookupManager().addRole(mAgentPath, newRole);
} catch (ObjectCannotBeUpdated ex) {
throw new CannotManageException("Could not update role");
}
@@ -70,7 +70,7 @@ public class AgentImplementation extends ItemImplementation implements
public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
RolePath rolePath = Gateway.getLookup().getRolePath(roleName);
try {
- rolePath.removeAgent(mAgentPath);
+ Gateway.getLookupManager().removeRole(mAgentPath, rolePath);
} catch (ObjectCannotBeUpdated ex) {
throw new CannotManageException("Could not update role");
}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportAgent.java b/src/main/java/com/c2kernel/entity/imports/ImportAgent.java
index ac9911e..2bbd307 100644
--- a/src/main/java/com/c2kernel/entity/imports/ImportAgent.java
+++ b/src/main/java/com/c2kernel/entity/imports/ImportAgent.java
@@ -50,9 +50,9 @@ public class ImportAgent extends ModuleImport implements java.io.Serializable {
try {
thisRole = Gateway.getLookup().getRolePath(role);
} catch (ObjectNotFoundException ex) {
- throw new ObjectNotFoundException("Role "+role+" does not exist.");
+ throw new ObjectNotFoundException("Role "+role+" does not exist.", "");
}
- thisRole.addAgent(newAgent);
+ Gateway.getLookupManager().addRole(newAgent, thisRole);
}
}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportRole.java b/src/main/java/com/c2kernel/entity/imports/ImportRole.java
index dc8f351..975c18b 100644
--- a/src/main/java/com/c2kernel/entity/imports/ImportRole.java
+++ b/src/main/java/com/c2kernel/entity/imports/ImportRole.java
@@ -1,9 +1,14 @@
package com.c2kernel.entity.imports;
+import java.util.Iterator;
+
import com.c2kernel.common.CannotManageException;
import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.Path;
+import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
import com.c2kernel.process.module.ModuleImport;
@@ -15,8 +20,27 @@ public class ImportRole extends ModuleImport {
}
@Override
- public void create(AgentPath agentPath, boolean reset) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException {
- Gateway.getLookupManager().createRole(name, jobList);
+ public void create(AgentPath agentPath, boolean reset) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
+ RolePath parent = new RolePath();
+ if (name.indexOf('/') > -1) {
+ String[] roleComp = name.split("/");
+ for (int i=0; i<roleComp.length-1; i++) {
+ Iterator<Path> childIter = parent.getChildren();
+ boolean found = false;
+ while (childIter.hasNext()) {
+ RolePath childRole = (RolePath)childIter.next();
+ if (childRole.getName().equals(roleComp[i])) {
+ parent = childRole;
+ found = true;
+ break;
+ }
+ }
+ if (!found) throw new ObjectNotFoundException("Parent role "+roleComp[i]+" was not found", "");
+ }
+ name = roleComp[roleComp.length-1];
+ }
+ RolePath newRole = new RolePath(parent, name, jobList);
+ if (!newRole.exists()) Gateway.getLookupManager().createRole(newRole);
}
public boolean hasJobList() {