private static boolean containsOnlyLiteralNode(ContextNode contextNode) { if (contextNode.containsContextNodes()) return false; if (contextNode.containsRelations()) return false; if (! contextNode.containsLiteralNode()) return false; return true; }
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; Object subjectLiteralData = subject.getLiteralNode().getLiteralData(); Object objectLiteralData = object.getLiteralNode().getLiteralData(); if (subjectLiteralData == null || objectLiteralData == null) return false; return AbstractLiteralNode.LITERALDATACOMPARATOR.compare(subjectLiteralData, objectLiteralData) > 0; } return false; } }
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; Object subjectLiteralData = subject.getLiteralNode().getLiteralData(); Object objectLiteralData = object.getLiteralNode().getLiteralData(); if (subjectLiteralData == null || objectLiteralData == null) return false; return AbstractLiteralNode.LITERALDATACOMPARATOR.compare(subjectLiteralData, objectLiteralData) < 0; } return false; } }
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; String subjectLiteralData = subject.getLiteralNode().getLiteralDataString(); String objectLiteralData = object.getLiteralNode().getLiteralDataString(); if (subjectLiteralData == null || objectLiteralData == null) return false; return Pattern.matches(objectLiteralData, subjectLiteralData); } return false; } }
if (innerContextNode.getXDIArc().equals(XDIConstants.CS_LITERAL.toString()) && innerContextNode.containsLiteralNode()) {
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; Object subjectLiteralData = subject.getLiteralNode().getLiteralData(); Object objectLiteralData = object.getLiteralNode().getLiteralData(); if (subjectLiteralData == null || objectLiteralData == null) return false; return AbstractLiteralNode.isLiteralDataEqual(subjectLiteralData, objectLiteralData); } return false; } }
private void putAttributeIntoEntityJsonObject(ContextNode attributeContextNode, JsonObject entityJsonObject, XDIAddress parentXDIAddress) throws IOException { XDIAddress XDIaddress = attributeContextNode.getXDIAddress(); XDIAddress localXDIAddress = XDIAddressUtil.localXDIAddress(XDIaddress, - parentXDIAddress.getNumXDIArcs()); // set up attribute JsonObject attributeJsonObject = new JsonObject(); entityJsonObject.add(localXDIAddress.toString(), attributeJsonObject); // context nodes for (ContextNode contextNode : attributeContextNode.getContextNodes()) { if (XdiAbstractAttribute.isValid(contextNode) || XdiAttributeCollection.isValid(contextNode)) { this.putAttributeIntoEntityJsonObject(contextNode, entityJsonObject, parentXDIAddress); continue; } throw new Xdi2RuntimeException("Unexpected context node: " + contextNode + " on attribute context node: " + attributeContextNode); } // relations for (Relation relation : attributeContextNode.getRelations()) { this.putRelationIntoJsonObject(relation, attributeJsonObject); } // literal node if (attributeContextNode.containsLiteralNode()) { LiteralNode literalNode = attributeContextNode.getLiteralNode(); this.putLiteralNodeIntoAttributeJsonObject(literalNode, attributeJsonObject, XDIaddress); } // finish attribute if (attributeJsonObject.entrySet().isEmpty() && ! attributeContextNode.isEmpty()) { if (! this.isWriteImplied()) entityJsonObject.remove(localXDIAddress.toString()); } }
if (entityContextNode.containsLiteralNode()) {
if (rootContextNode.containsLiteralNode()) {
private static ContextNode collapseContextNode(ContextNode contextNode) { if (contextNode.getContextNodeCount() != 1) return contextNode; if (contextNode.containsRelations()) return contextNode; if (contextNode.containsLiteralNode()) return contextNode; ContextNode childContextNode = contextNode.getContextNodes().next(); if (! (XdiAbstractEntity.isValid(contextNode) || XdiEntityCollection.isValid(contextNode)) && (XdiAbstractEntity.isValid(childContextNode) || XdiEntityCollection.isValid(childContextNode))) return contextNode; if (! (XdiAbstractAttribute.isValid(contextNode) || XdiAttributeCollection.isValid(contextNode)) && (XdiAbstractAttribute.isValid(childContextNode) || XdiAttributeCollection.isValid(childContextNode))) return contextNode; return collapseContextNode(childContextNode); }
if (attributeContextNode.containsLiteralNode()) {
if (contextNode.containsLiteralNode()) {
if (entityContextNode.containsLiteralNode()) {
if (rootContextNode.containsLiteralNode()) {
assertNull(c.getLiteralNode().getLiteralDataNumber()); assertNull(c.getLiteralNode().getLiteralDataBoolean()); assertTrue(c.containsLiteralNode(s)); assertTrue(c.containsLiteralString(s)); assertEquals(c.getLiteralNode().getLiteralDataNumber(), d); assertNull(c.getLiteralNode().getLiteralDataBoolean()); assertTrue(c.containsLiteralNode(d)); assertTrue(c.containsLiteralNumber(d)); assertNull(c.getLiteralNode().getLiteralDataNumber()); assertEquals(c.getLiteralNode().getLiteralDataBoolean(), b); assertTrue(c.containsLiteralNode(b)); assertTrue(c.containsLiteralBoolean(b)); assertNull(c.getLiteralNode().getLiteralDataNumber()); assertNull(c.getLiteralNode().getLiteralDataBoolean()); assertTrue(c.containsLiteralNode(a)); assertNull(c.getLiteralNode().getLiteralDataNumber()); assertNull(c.getLiteralNode().getLiteralDataBoolean()); assertTrue(c.containsLiteralNode(o)); assertNull(c.getLiteralNode().getLiteralDataNumber()); assertNull(c.getLiteralNode().getLiteralDataBoolean()); assertTrue(c.containsLiteralNode(n));
public void testSimple() throws Exception { Graph graph0 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-0"); ContextNode markus = graph0.getRootContextNode().setContextNode(XDIArc.create("=markus")); ContextNode email = markus.setContextNode(XDIArc.create("<#email>")); email.setLiteralNode("abc@gmail.com"); markus.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=drummond")); markus = graph0.getRootContextNode().getContextNode(XDIArc.create("=markus")); assertNotNull(markus); assertFalse(markus.isRootContextNode()); assertFalse(markus.isEmpty()); assertFalse(markus.isLeafContextNode()); assertTrue(markus.containsRelations()); assertFalse(markus.containsLiteralNode()); assertTrue(email.isLeafContextNode()); assertTrue(email.containsLiteralNode()); ContextNode drummond = graph0.getRootContextNode().getContextNode(XDIArc.create("=drummond")); assertNotNull(drummond); assertTrue(drummond.isEmpty()); assertTrue(drummond.isLeafContextNode()); email.setLiteralNode("xyz@gmail.com"); assertEquals(graph0.getDeepLiteralNode(XDIAddress.create("=markus<#email>&")).getLiteralData(), "xyz@gmail.com"); assertEquals(graph0.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode().getLiteralData(), "xyz@gmail.com"); graph0.close(); }
markus.setRelation(XDIAddress.create("$is#"), XDIAddress.create("#person")); assertFalse(attribute.containsLiteralNode()); assertFalse(markus.containsRelations(XDIAddress.create("#friend"))); assertTrue(markus.containsRelation(XDIAddress.create("$is#"), XDIAddress.create("#person"))); assertTrue(attribute.containsLiteralNode()); assertTrue(markus.containsRelations(XDIAddress.create("#friend"))); assertFalse(markus.containsRelation(XDIAddress.create("$is#"), XDIAddress.create("#person"))); } else { assertFalse(attribute.containsLiteralNode()); assertFalse(markus.containsRelations(XDIAddress.create("#friend"))); assertTrue(markus.containsRelation(XDIAddress.create("$is#"), XDIAddress.create("#person")));
public void testDelete() throws Exception { Graph graph26 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-26"); ContextNode root = graph26.getRootContextNode(); root.setContextNode(XDIArc.create("+a")); assertTrue(root.containsContextNode(XDIArc.create("+a"))); assertNotNull(root.getContextNode(XDIArc.create("+a"))); root.delContextNode(XDIArc.create("+a")); assertFalse(graph26.getRootContextNode().containsContextNode(XDIArc.create("+a"))); assertFalse(root.containsContextNode(XDIArc.create("+a"))); assertNull(graph26.getRootContextNode().getContextNode(XDIArc.create("+a"))); assertNull(root.getContextNode(XDIArc.create("+a"))); root.setRelation(XDIAddress.create("+a"), XDIAddress.create("#b")); assertTrue(root.containsRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); assertNotNull(root.getRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); root.delRelation(XDIAddress.create("+a"), XDIAddress.create("#b")); assertFalse(root.containsRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); assertNull(root.getRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); root.setDeepContextNode(XDIAddress.create("<#a>")).setLiteralNode("a"); assertTrue(root.getDeepContextNode(XDIAddress.create("<#a>")).containsLiteralNode("a")); assertNotNull(root.getDeepContextNode(XDIAddress.create("<#a>")).getLiteralNode("a")); assertNotNull(root.getDeepLiteralNode(XDIAddress.create("<#a>&"))); root.getDeepContextNode(XDIAddress.create("<#a>")).delLiteralNode(); assertFalse(root.getDeepContextNode(XDIAddress.create("<#a>")).containsLiteralNode("a")); assertNull(root.getDeepContextNode(XDIAddress.create("<#a>")).getLiteralNode("a")); assertNull(root.getDeepLiteralNode(XDIAddress.create("<#a>&"))); root.getContextNode(XDIArc.create("#b")).delete(); root.getDeepContextNode(XDIAddress.create("<#a>")).delete(); assertTrue(root.isEmpty()); graph26.close(); }
assertFalse(root.containsContextNodes()); assertFalse(root.containsRelations()); assertFalse(root.containsLiteralNode()); assertFalse(root.getContextNodes().hasNext()); assertFalse(root.getRelations().hasNext()); assertTrue(root.containsContextNodes()); assertTrue(root.containsRelations()); assertFalse(root.containsLiteralNode()); assertTrue(root.getContextNodes().hasNext()); assertTrue(root.getRelations().hasNext()); assertTrue(root.containsContextNodes()); assertTrue(root.containsRelations()); assertFalse(root.containsLiteralNode()); assertTrue(root.getContextNodes().hasNext()); assertTrue(root.getRelations().hasNext()); assertFalse(root.containsContextNodes()); assertFalse(root.containsRelations()); assertFalse(root.containsLiteralNode()); assertFalse(root.getContextNodes().hasNext()); assertFalse(root.getRelations().hasNext());
assertTrue(abcPassport1ContextNode.getDeepContextNode(XDIAddress.create("<#number>")).containsLiteralNode()); assertTrue(abcPassport1ContextNode.getDeepContextNode(XDIAddress.create("<#country>")).containsLiteralNode()); assertTrue(abcPassport1ContextNode.getDeepContextNode(XDIAddress.create("<$t>")).containsLiteralNode()); assertTrue(abcPassportC1ContextNode.containsContextNode(XDIArc.create("<$t>"))); assertFalse(abcPassportC2ContextNode.containsContextNode(XDIArc.create("<$t>"))); // MANIPULATED assertTrue(abcPassportC1ContextNode.getDeepContextNode(XDIAddress.create("<$t>")).containsLiteralNode()); assertEquals(contextNodesArray[i].containsLiteralNode(), literalsArray[i].booleanValue());