Skip to content

Commit

Permalink
#1 demo -- variable definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jnorthrup committed Jan 31, 2015
1 parent add601c commit e743846
Showing 1 changed file with 77 additions and 35 deletions.
112 changes: 77 additions & 35 deletions policyviz/src/main/java/pviz/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -95,10 +94,10 @@ public static void visitPolicySet(JAXBElement<PolicySetType> e, ClusterOrGraph g
ClusterOrGraph c = graph;
visitTarget(graph, policySet, top.getTarget());
final AdviceExpressionsType adviceExpressions = top.getAdviceExpressions();
final Node node = visitAdviceExpressions(c, adviceExpressions);
addChildToFirstOf(node,c);
List<JAXBElement<?>> policySetOrPolicyOrPolicySetIdReference =
top.getPolicySetOrPolicyOrPolicySetIdReference();
addChildToFirstOf(visitAdviceExpressions(c, adviceExpressions),c);
addChildToFirstOf(visitObligationExpressions(c, top.getObligationExpressions()),c);
List<JAXBElement<?>> policySetOrPolicyOrPolicySetIdReference =top.getPolicySetOrPolicyOrPolicySetIdReference();

for (JAXBElement<?> jaxbElement : policySetOrPolicyOrPolicySetIdReference)
switch (jaxbElement.getValue().getClass().getSimpleName()) {
case "PolicySetType":
Expand All @@ -115,6 +114,51 @@ public static void visitPolicySet(JAXBElement<PolicySetType> e, ClusterOrGraph g
}
}

public static void visitPolicy(JAXBElement<PolicyType> e, ClusterOrGraph graph,
Object... createEdgeToHere) {
PolicyType top = e.getValue();
String PolicyId = top.getPolicyId();
Node policyNode =
new Node().withId(id()).withLabel("Policy:" + urnTip(PolicyId));
addChildToFirstOf(policyNode, graph);
linkChildToFirstOf(graph, policyNode, createEdgeToHere);
System.err.println("Policy: " + (top).toString());

ClusterOrGraph c = graph;
// Cluster c = new Cluster().withStyle(Style.INVIS);
// addChildToFirstOf(c, graph);

Node fnNode = visitTarget(c, policyNode, top.getTarget());
final AdviceExpressionsType adviceExpressions = top.getAdviceExpressions();
linkChildToFirstOf(graph, visitAdviceExpressions(c, adviceExpressions), policyNode);

linkChildToFirstOf(graph, visitObligationExpressions(c, top.getObligationExpressions()), policyNode);

// top.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().stream().filter(o -> o instanceof RuleType).map(o -> (RuleType) o).forEach(ruleType -> {
// visitRule(policyNode, c, fnNode, ruleType);
// });
top.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().forEach(o -> {
final String simpleName = o.getClass().getSimpleName();
switch (simpleName){
case "RuleType":{
visitRule(policyNode, c, fnNode, (RuleType) o);
break;
}
case "VariableDefinitionType":{
VariableDefinitionType v= (VariableDefinitionType) o;
final Node aaaa00 = new Node().withLabel(urnTip(v.getVariableId())).withId(id()).withColor("#EEEE00").withStyle(Style.FILLED);
addChildToFirstOf(aaaa00,c);
linkChildToFirstOf(c, aaaa00,policyNode);
linkChildToFirstOf(c,visitExpression(c, v.getExpression()),aaaa00);


}

}

});

}
private static Node visitAdviceExpressions(ClusterOrGraph outer, AdviceExpressionsType adviceExpressions) {
final Node[] adviceNode = new Node[1];

Expand All @@ -126,41 +170,39 @@ private static Node visitAdviceExpressions(ClusterOrGraph outer, AdviceExpressio
adviceNode[0] = new Node().withId(id()).withColor(appliesTo !=EffectType.DENY? LTGREEN : LTRED).withShape(Shape.INVTRAPEZIUM).withStyle(Style.FILLED).withLabel(adviceExpressionType.getAdviceId());
addChildToFirstOf(adviceNode[0],advCluster);
adviceExpressionType.getAttributeAssignmentExpression().forEach(aa -> {

final Cluster ac= new Cluster().withId(id()).withColor(LTGREY).withLabel(aa.getAttributeId());

addChildToFirstOf(ac,advCluster);
addChildToFirstOf(visitExpression(aa.getExpression(), ac),ac);
addChildToFirstOf(visitExpression(ac, aa.getExpression()),ac);
});
});

return adviceNode[0];
}

public static void visitPolicy(JAXBElement<PolicyType> e, ClusterOrGraph graph,
Object... createEdgeToHere) {
PolicyType top = e.getValue();
String PolicyId = top.getPolicyId();
Node policyNode =
new Node().withId(id()).withLabel("Policy:" + urnTip(PolicyId));
addChildToFirstOf(policyNode, graph);
linkChildToFirstOf(graph, policyNode, createEdgeToHere);
System.err.println("Policy: " + (top).toString());
private static Node visitObligationExpressions(ClusterOrGraph outer, ObligationExpressionsType ObligationExpressions) {
final Node[] ObligationNode = new Node[1];

ClusterOrGraph c = graph;
// Cluster c = new Cluster().withStyle(Style.INVIS);
// addChildToFirstOf(c, graph);
if(null!=ObligationExpressions)
ObligationExpressions.getObligationExpression().forEach(ObligationExpressionType -> {
final Cluster advCluster = new Cluster().withId(id());
addChildToFirstOf(advCluster,outer);
final EffectType appliesTo = ObligationExpressionType.getFulfillOn();
ObligationNode[0] = new Node().withId(id()).withColor(appliesTo !=EffectType.DENY? LTGREEN : LTRED).withShape(Shape.INVHOUSE).withStyle(Style.FILLED).withLabel(ObligationExpressionType.getObligationId());
addChildToFirstOf(ObligationNode[0],advCluster);
ObligationExpressionType.getAttributeAssignmentExpression().forEach(aa -> {

Node fnNode = visitTarget(c, policyNode, top.getTarget());
final AdviceExpressionsType adviceExpressions = top.getAdviceExpressions();
linkChildToFirstOf(graph, visitAdviceExpressions(c, adviceExpressions), policyNode);

top.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().stream().filter(o -> o instanceof RuleType).map(o -> (RuleType) o).forEach(ruleType -> {
visitRule(policyNode, c, fnNode, ruleType);
final Cluster ac= new Cluster().withId(id()).withColor(LTGREY).withLabel(aa.getAttributeId());
addChildToFirstOf(ac, advCluster);
addChildToFirstOf(visitExpression(ac, aa.getExpression()),ac);
});
});


return ObligationNode[0];
}

private static void visitRule(Node topLink, ClusterOrGraph c, Node prevLink, RuleType ruleType) {
private static Node visitRule(Node topLink, ClusterOrGraph c, Node prevLink, RuleType ruleType) {
boolean permit = ruleType.getEffect() == EffectType.PERMIT;
Node rule = new Node().withId(id()).withColor(permit ? GREEN : RED).withLabel("Rule:" + urnTip(ruleType.getRuleId())).withShape(permit ? Shape.HOUSE : Shape.OCTAGON).withStyle(Style.FILLED);
Cluster ruleCluster = new Cluster().withId(id()).withStyle(Style.INVIS);
Expand All @@ -174,13 +216,14 @@ private static void visitRule(Node topLink, ClusterOrGraph c, Node prevLink, Rul

if (!expression.isNil()) {
Cluster outer = new Cluster().withId(id()).withStyle(Style.INVIS);
Node node = visitExpression(expression, outer);
Node node = visitExpression(outer, expression);
addChildToFirstOf(outer, c);
linkChildToFirstOf(outer, node, prev);

}
} linkChildToFirstOf(ruleCluster, visitAdviceExpressions(ruleCluster, ruleType.getAdviceExpressions()),prev,prevLink);

}
linkChildToFirstOf(ruleCluster, visitAdviceExpressions(ruleCluster, ruleType.getAdviceExpressions()),prev,prevLink);
linkChildToFirstOf(ruleCluster, visitObligationExpressions(ruleCluster, ruleType.getObligationExpressions()),prev,prevLink);
return rule;
}

public static Node visitTarget(ClusterOrGraph graph, Node parent, TargetType targetType) {
Expand Down Expand Up @@ -277,13 +320,12 @@ private static void writeGraph(Graph graph, String out) throws JAXBException, IO

String fileName = out + ".dot";
TransformerFactory.newInstance().newTransformer(xslt).transform(ourGraph, new StreamResult(new FileWriter(fileName)));
// "-Gperipheries=0","-Gpack","-Gvisit","-Gconcentrate",
Process start = new ProcessBuilder().command("dot", "-Gclusterrank", "-Gsplines=polyline", fileName, "-Tsvg", "-o" + out + ".svg", "-Tpng", "-o" + out + ".png").start();
// "-Gperipheries=0","-Gpack","-Gvisit","-Gconcentrate","-Gsplines=ortho","-Gsplines=curved","-Gsplines=polyline","-Gclusterrank","-Gsplines=ortho","-Goverlap=false"
Process start = new ProcessBuilder().command("dot", fileName,"-Goverlap=false", "-Tsvg", "-o" + out + ".svg", "-Tpng", "-o" + out + ".png").start();
// Process gxl = new ProcessBuilder().command("dot2gxl", "/tmp/x.dot","-o/tmp/x.gxl" ).start();
start.waitFor();
// gxl.waitFor();
System.err.println("see " + aaa.toURL().toExternalForm());

}

} catch (TransformerException e1) {
Expand Down Expand Up @@ -343,7 +385,7 @@ static void addChildToFirstOf(Object child, Object... parent) {
}
}

static Node visitExpression(JAXBElement<?> expression, Cluster outer) {
static Node visitExpression(ClusterOrGraph outer, JAXBElement<?> expression) {
/*possible object is
AttributeValueType
AttributeDesignatorType
Expand All @@ -365,7 +407,7 @@ static Node visitExpression(JAXBElement<?> expression, Cluster outer) {
//visitExpression
addChildToFirstOf(applyCluster, outer);
addChildToFirstOf(applyNode, applyCluster);
applyType.getExpression().forEach(jaxbElement -> linkChildToFirstOf(applyCluster, visitExpression(jaxbElement, applyCluster), applyNode));
applyType.getExpression().forEach(jaxbElement -> linkChildToFirstOf(applyCluster, visitExpression(applyCluster, jaxbElement), applyNode));
return applyNode;
}
case "AttributeValueType": {
Expand Down

0 comments on commit e743846

Please sign in to comment.