summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lookup/RolePath.java
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/lookup/RolePath.java
parent1537f39761e11669335f6499474f23b11cf2cf38 (diff)
Hierarchical Roles. Fixes #199
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/RolePath.java')
-rw-r--r--src/main/java/com/c2kernel/lookup/RolePath.java56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/main/java/com/c2kernel/lookup/RolePath.java b/src/main/java/com/c2kernel/lookup/RolePath.java
index 9f9c597..e82c7ad 100644
--- a/src/main/java/com/c2kernel/lookup/RolePath.java
+++ b/src/main/java/com/c2kernel/lookup/RolePath.java
@@ -10,14 +10,12 @@
package com.c2kernel.lookup;
-import java.util.ArrayList;
import java.util.Iterator;
import com.c2kernel.common.CannotManageException;
import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.process.Gateway;
-import com.c2kernel.utils.Logger;
@@ -32,13 +30,31 @@ public class RolePath extends DomainPath
*/
private boolean hasJobList = false;
+
+ public RolePath() {
+ super("agent");
+ }
- public RolePath(String roleName) {
- super(new DomainPath("agent"), roleName);
+ @Override
+ public RolePath getParent() {
+ try {
+ if (mPath.length > 2)
+ return Gateway.getLookup().getRolePath(mPath[mPath.length-2]);
+ } catch (ObjectNotFoundException ex) { }
+ return null;
+ }
+
+ public RolePath(RolePath parent, String roleName) {
+ super(parent, roleName);
+ }
+
+ public RolePath(String[] path, boolean jobList) {
+ super(path);
+ hasJobList = jobList;
}
- public RolePath(String roleName, boolean jobList) {
- this(roleName);
+ public RolePath(RolePath parent, String roleName, boolean jobList) {
+ this(parent, roleName);
hasJobList = jobList;
}
@@ -56,7 +72,6 @@ public class RolePath extends DomainPath
*/
public void setHasJobList(boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
this.hasJobList = hasJobList;
- Gateway.getLookupManager().setHasJobList(this, hasJobList);
}
@@ -64,30 +79,9 @@ public class RolePath extends DomainPath
protected void checkType() {
mType = CONTEXT;
}
-
- public Iterator<Path> getChildren() {
- AgentPath[] agents = getAgentsWithRole();
- ArrayList<Path> children = new ArrayList<Path>(agents.length);
- for (int i = 0; i < agents.length; i++)
- children.add(i, agents[i]);
- return children.iterator();
- }
-
- public AgentPath[] getAgentsWithRole() {
- try {
- return Gateway.getLookup().getAgents(this);
- } catch (ObjectNotFoundException ex) {
- Logger.error("Cannot retrieve agent list. Role "+getName()+" does not exist in LDAP");
- return new AgentPath[0];
- }
- }
-
- public void addAgent(AgentPath agent) throws ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
- Gateway.getLookupManager().addRole(agent, this);
- }
-
- public void removeAgent(AgentPath agent) throws ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
- Gateway.getLookupManager().removeRole(agent, this);
+
+ public Iterator<Path> getChildren() {
+ return Gateway.getLookup().getChildren(this);
}
@Override