コード例 #1
0
ファイル: LinkContract.java プロジェクト: prashaantt/xdi2
  /**
   * 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;
  }
コード例 #2
0
ファイル: LinkContract.java プロジェクト: prashaantt/xdi2
  /**
   * 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;
  }
コード例 #3
0
ファイル: LinkContract.java プロジェクト: prashaantt/xdi2
  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;
  }
コード例 #4
0
ファイル: LinkContract.java プロジェクト: prashaantt/xdi2
  /**
   * 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;
  }