public boolean getRelation( XRI3Segment[] contributorXris, XRI3Segment relativeContextNodeXri, XRI3Segment arcXri, XRI3Segment targetContextNodeXri, XRI3Segment contextNodeXri, GetOperation operation, MessageResult messageResult, ExecutionContext executionContext) throws Xdi2MessagingException { MessageResult tempMessageResult = new MessageResult(); this.getContext( contributorXris, relativeContextNodeXri, contextNodeXri, operation, tempMessageResult, executionContext); ContextNode tempContextNode = tempMessageResult.getGraph().findContextNode(contextNodeXri, false); if (tempContextNode == null) return false; if (Variables.isVariableSingle(targetContextNodeXri)) { Iterator<Relation> relations; if (Variables.isVariableSingle(arcXri)) { relations = tempContextNode.getRelations(); } else { relations = tempContextNode.getRelations(arcXri); } while (relations.hasNext()) CopyUtil.copyRelation(relations.next(), messageResult.getGraph(), null); } else { Relation relation = tempContextNode.getRelation(arcXri, targetContextNodeXri); if (relation == null) return false; CopyUtil.copyRelation(relation, messageResult.getGraph(), null); } return false; }
/** * Gets all assignees of this Link Contract node * * @return an iterator over the list of assignees */ public Iterator<ContextNode> getAssignees() { List<ContextNode> assignees = new ArrayList<ContextNode>(); Iterator<Relation> allRelations = contextNode.getRelations(); for (; allRelations.hasNext(); ) { Relation r = allRelations.next(); if (r.getArcXri().equals(XDILinkContractConstants.XRI_S_IS_DO)) { ContextNode assignee = r.follow(); assignees.add(assignee); } } if (assignees.isEmpty()) { return new EmptyIterator<ContextNode>(); } else { return new SelectingIterator<ContextNode>(assignees.iterator()) { @Override public boolean select(ContextNode contextNode) { return true; } }; } }
/** * Removes an assignment relationship of a LinkContract from an assignee node * * @param assignee The context node who will not longer have access to this LinkContract * @return NONE */ public boolean removeAssignee(ContextNode assignee) { boolean status = false; if (assignee == null) { // TBD // write error in debug log return status; } Iterator<Relation> allRelations = contextNode.getRelations(); Relation r = null; for (; allRelations.hasNext(); ) { r = allRelations.next(); ContextNode target = r.follow(); if (target.equals(assignee)) { // write debug log with information about the relation XRI that // is removed // TBD status = true; break; } } if (status) { contextNode.deleteRelation(XDILinkContractConstants.XRI_S_IS_DO, r.getTargetContextNodeXri()); } return status; }
public Iterator<ContextNode> getNodesWithPermission(XDILinkContractPermission permission) { List<ContextNode> nodesWithPermission = new ArrayList<ContextNode>(); XRI3Segment perm = null; switch (permission) { case LC_OP_GET: perm = XDILinkContractConstants.XRI_S_GET; break; case LC_OP_ADD: perm = XDILinkContractConstants.XRI_S_ADD; break; case LC_OP_MOD: perm = XDILinkContractConstants.XRI_S_MOD; break; case LC_OP_DEL: perm = XDILinkContractConstants.XRI_S_DEL; break; case LC_OP_ALL: perm = XDILinkContractConstants.XRI_S_ALL; break; default: // TBD // debug log break; } if (null == perm) { return new EmptyIterator<ContextNode>(); } Iterator<Relation> allRelations = contextNode.getRelations(); for (; allRelations.hasNext(); ) { Relation r = allRelations.next(); if (r.getArcXri().equals(perm)) { ContextNode nodeWithPermission = r.follow(); nodesWithPermission.add(nodeWithPermission); } } return new SelectingIterator<ContextNode>(nodesWithPermission.iterator()) { @Override public boolean select(ContextNode contextNode) { return true; } }; }
private static void addContextNodeToBuffer(StringBuffer buffer, ContextNode contextNode) { buffer.append("{\n"); buffer.append("type: \"context\",\n"); buffer.append("name: \"" + contextNode.getXDIAddress() + "\",\n"); buffer.append( "arc: \"" + (contextNode.isRootContextNode() ? "" : contextNode.getXDIArc()) + "\",\n"); buffer.append("root: " + XdiAbstractRoot.isValid(contextNode) + ",\n"); buffer.append("contents: [\n"); for (Iterator<ContextNode> innerContextNodes = contextNode.getContextNodes(); innerContextNodes.hasNext(); ) { ContextNode innerContextNode = innerContextNodes.next(); addContextNodeToBuffer(buffer, innerContextNode); if (innerContextNodes.hasNext() || contextNode.containsLiteralNode()) buffer.append(","); buffer.append("\n"); } if (contextNode.containsLiteralNode()) { buffer.append("{\n"); buffer.append("type: \"literal\",\n"); buffer.append("name: \"\\\"" + contextNode.getLiteralNode().getLiteralData() + "\\\"\",\n"); buffer.append("arc: \"&\"\n"); buffer.append("}\n"); } buffer.append("],\n"); buffer.append("rel: ["); for (Iterator<Relation> relations = contextNode.getRelations(); relations.hasNext(); ) { Relation relation = relations.next(); buffer.append("{\n"); buffer.append("type: \"relation\",\n"); buffer.append("arc: \"" + relation.getXDIAddress() + "\",\n"); buffer.append("target: \"" + relation.getTargetXDIAddress() + "\"\n"); buffer.append("}"); if (relations.hasNext()) buffer.append(","); buffer.append("\n"); } buffer.append("]"); buffer.append("}\n"); }
public boolean removePermission(XDILinkContractPermission permission, ContextNode targetNode) { boolean status = false; XRI3Segment perm = null; switch (permission) { case LC_OP_GET: perm = XDILinkContractConstants.XRI_S_GET; break; case LC_OP_ADD: perm = XDILinkContractConstants.XRI_S_ADD; break; case LC_OP_MOD: perm = XDILinkContractConstants.XRI_S_MOD; break; case LC_OP_DEL: perm = XDILinkContractConstants.XRI_S_DEL; break; case LC_OP_ALL: perm = XDILinkContractConstants.XRI_S_ALL; break; default: // TBD // debug log break; } if (null == perm) { return status; } Iterator<Relation> allRelations = contextNode.getRelations(); Relation r = null; for (; allRelations.hasNext(); ) { r = allRelations.next(); if (r.getArcXri().equals(perm)) { ContextNode nodeWithPermission = r.follow(); if (nodeWithPermission.equals(targetNode)) { status = true; break; } } } if (status) { contextNode.deleteRelation(r.getArcXri(), r.getTargetContextNodeXri()); } return status; }