use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class HierUtil method getParents.
/**
* Private utility to return the parents (direct ascendants) of a given child node.
*
* @param vertex contains node name and acts as cursor for current location.
* @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}.
* @return Set of names that are parents of given child.
*/
static Set<String> getParents(String vertex, SimpleDirectedGraph<String, Relationship> graph) {
Set<String> parents = new HashSet<>();
if (graph == null) {
// graph is null
return null;
}
LOG.debug("getParents [{}]", vertex);
Set<Relationship> edges;
try {
edges = graph.outgoingEdgesOf(vertex);
} catch (java.lang.IllegalArgumentException iae) {
// vertex is leaf.
return null;
}
for (Relationship edge : edges) {
parents.add(edge.getParent());
}
return parents;
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class HierUtil method getDescendants.
/**
* Utility function recursively traverses a given digraph to build a set of all descendants names.
*
* @param vertex contains the position of the cursor for traversal of graph.
* @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}.
* @param descendants contains the result set of names of all descendants of node.
* @return value contains the vertex of current position.
*/
private static String getDescendants(Map<String, String> vertex, SimpleDirectedGraph<String, Relationship> graph, Set<String> descendants) {
String v = vertex.get(VERTEX);
if (v == null) {
// vertex is null
return null;
} else if (graph == null) {
// graph is null
return null;
}
LOG.debug("getDescendants [{}]", v);
Set<Relationship> edges;
try {
edges = graph.incomingEdgesOf(v);
} catch (java.lang.IllegalArgumentException iae) {
// vertex is leaf.
return null;
}
for (Relationship edge : edges) {
vertex.put(VERTEX, edge.getChild());
descendants.add(edge.getChild());
v = getDescendants(vertex, graph, descendants);
}
return v;
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class RoleUtil method loadGraph.
/**
* Read this ldap record,{@code cn=Hierarchies, ou=OS-P} into this entity, {@link Hier}, before loading into this collection class,{@code org.jgrapht.graph.SimpleDirectedGraph}
* using 3rd party lib, <a href="http://www.jgrapht.org/">JGraphT</a>.
*
* @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
* @return handle to simple digraph containing role hierarchies.
*/
private synchronized SimpleDirectedGraph<String, Relationship> loadGraph(String contextId) {
Hier inHier = new Hier(Hier.Type.ROLE);
inHier.setContextId(contextId);
LOG.info("loadGraph initializing ROLE context [{}]", inHier.getContextId());
List<Graphable> descendants = null;
try {
descendants = roleP.getAllDescendants(inHier.getContextId());
} catch (SecurityException se) {
LOG.info("loadGraph caught SecurityException={}", se);
}
Hier hier = HierUtil.loadHier(contextId, descendants);
SimpleDirectedGraph<String, Relationship> graph;
graph = HierUtil.buildGraph(hier);
roleCache.put(getKey(contextId), graph);
return graph;
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class AdminMgrConsole method getParents.
/**
* @param g
*/
private static String getParents(Map vertex, SimpleDirectedGraph<String, Relationship> g, List<String> parents) {
String v;
// ReaderUtil.clearScreen();
// System.out.println("addJGraph");
// String vertex = "Max";
v = (String) vertex.get("Vertex");
if (g == null) {
System.out.println("getAscendants simple directed graph is null");
return null;
}
if (v == null) {
System.out.println("getAscendants simple directed graph is null");
return null;
}
System.out.println("getAscendants V [" + v + "]");
Set<Relationship> edges = g.outgoingEdgesOf(v);
for (Relationship edge : edges) {
if (v == null)
return null;
else {
System.out.println("Edge:" + edge);
// parents.add(edge.toString());
v = edge.toString();
// Max : Super
// getAscendants V <Super)>
int indx = v.indexOf(GlobalIds.PROP_SEP);
int indx2 = v.indexOf(')');
if (indx >= 0) {
v = v.substring(indx + 2, indx2);
}
// String parent =
vertex.put("Vertex", v);
if (!v.equalsIgnoreCase("Root"))
parents.add(v);
v = getParents(vertex, g, parents);
}
}
return v;
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class Options method getRelationship.
/**
*/
public Relationship getRelationship() {
Relationship relationship = new Relationship();
relationship.setChild(getDescendant());
relationship.setParent(getAscendant());
return relationship;
}
Aggregations