From 3743d182d99dbed9d2be84dc357f6839ffe4d2ec Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 18 Sep 2014 10:39:05 +0200 Subject: Hierarchical Roles. Fixes #199 --- src/main/java/com/c2kernel/lookup/RolePath.java | 56 +++++++++++-------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/RolePath.java') 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 getChildren() { - AgentPath[] agents = getAgentsWithRole(); - ArrayList children = new ArrayList(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 getChildren() { + return Gateway.getLookup().getChildren(this); } @Override -- cgit v1.2.3