/** * Adds a assignment relationship of a LinkContract to a target assignee node * * @param assignee The context node to whom this LinkContract is being assigned to * @return NONE */ public boolean addAssignee(ContextNode assignee) { boolean status = false; if (assignee == null) { // TBD // write error in debug log return status; } // one cannot add this Link Contract node as assignee to itself if (assignee.equals(contextNode)) { return false; } try { if (contextNode.createRelation(XDILinkContractConstants.XRI_S_IS_DO, assignee) != null) { status = true; } else { // TBD // write error in debug log } } catch (Xdi2GraphException relationExists) { } return status; }
/** * Adds a permission (one of GET, ADD, MOD, DEL, COPY , MOVE , ALL) from this Link Contract node * to a target node * * @param permission The enum value of permission * @param targetNode The target node where the permission relation arc will terminate * @return NONE */ public boolean addPermission(XDILinkContractPermission permission, ContextNode targetNode) { boolean status = false; XRI3Segment perm = null; // one cannot add an authorization permission to the Link Contract Node // itself if (targetNode.equals(contextNode)) { return false; } // if the same permission arc exists for the same target node, then a // new arc should not be added for (Iterator<ContextNode> iter = this.getNodesWithPermission(permission); iter.hasNext(); ) { ContextNode t = iter.next(); if (t.equals(targetNode)) { return true; } } // if an arc to the given target node exists with $all, then no other // permission arc should be allowed for (Iterator<ContextNode> iter = this.getNodesWithPermission(XDILinkContractPermission.LC_OP_ALL); iter.hasNext(); ) { ContextNode t = iter.next(); if (t.equals(targetNode)) { return true; } } // if a $all permission is added to the target node then all other // permission arcs should be deleted if (permission == XDILinkContractPermission.LC_OP_ALL) { this.removePermission(XDILinkContractPermission.LC_OP_GET, targetNode); this.removePermission(XDILinkContractPermission.LC_OP_ADD, targetNode); this.removePermission(XDILinkContractPermission.LC_OP_MOD, targetNode); this.removePermission(XDILinkContractPermission.LC_OP_DEL, targetNode); } 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) { try { if (null != contextNode.createRelation(perm, targetNode)) { status = true; } } catch (Xdi2GraphException relationExists) { } } return status; }