예제 #1
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.Permission#removeMask(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String)
   */
  @Override
  public void removeMask(final UnitOfWork transaction, final String maskToRemove)
      throws KException {
    ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$
    ArgCheck.isTrue(
        (transaction.getState() == State.NOT_STARTED),
        "transaction state is not NOT_STARTED"); //$NON-NLS-1$
    ArgCheck.isNotEmpty(maskToRemove, "maskToRemove"); // $NON-NLS-1$

    boolean found = false;
    final Mask[] masks = getMasks(transaction);

    if (masks.length != 0) {
      for (final Mask mask : masks) {
        if (maskToRemove.equals(mask.getName(transaction))) {
          mask.remove(transaction);
          found = true;
          break;
        }
      }
    }

    if (!found) {
      throw new KException(Messages.getString(Relational.MASK_NOT_FOUND_TO_REMOVE, maskToRemove));
    }
  }
예제 #2
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.Permission#removeCondition(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String)
   */
  @Override
  public void removeCondition(final UnitOfWork transaction, final String conditionToRemove)
      throws KException {
    ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$
    ArgCheck.isTrue(
        (transaction.getState() == State.NOT_STARTED),
        "transaction state is not NOT_STARTED"); //$NON-NLS-1$
    ArgCheck.isNotEmpty(conditionToRemove, "conditionToRemove"); // $NON-NLS-1$

    boolean found = false;
    final Condition[] conditions = getConditions(transaction);

    if (conditions.length != 0) {
      for (final Condition condition : conditions) {
        if (conditionToRemove.equals(condition.getName(transaction))) {
          condition.remove(transaction);
          found = true;
          break;
        }
      }
    }

    if (!found) {
      throw new KException(
          Messages.getString(Relational.CONDITION_NOT_FOUND_TO_REMOVE, conditionToRemove));
    }
  }
예제 #3
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.DataRole#addMappedRole(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String)
   */
  @Override
  public String[] addMappedRole(final UnitOfWork transaction, final String roleNameToAdd)
      throws KException {
    ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$
    ArgCheck.isTrue(
        (transaction.getState() == State.NOT_STARTED),
        "transaction state is not NOT_STARTED"); //$NON-NLS-1$
    ArgCheck.isNotEmpty(roleNameToAdd, "roleNameToAdd"); // $NON-NLS-1$

    String[] result = null;
    final String[] current = getMappedRoles(transaction);
    int i = 0;

    if (current.length == 0) {
      // this is first mapped role name
      result = new String[1];
    } else {
      // add to existing (make sure it doesn't already exist)
      result = new String[current.length + 1];

      for (final String mappedRoleName : current) {
        if (mappedRoleName.equals(roleNameToAdd)) {
          throw new KException(Messages.getString(Relational.DUPLICATE_ROLE_NAME, roleNameToAdd));
        }

        result[i++] = mappedRoleName;
      }
    }

    result[i] = roleNameToAdd;
    setProperty(transaction, VdbLexicon.DataRole.MAPPED_ROLE_NAMES, (Object[]) result);

    return result;
  }
예제 #4
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.DataRole#removeMappedRole(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String)
   */
  @Override
  public String[] removeMappedRole(final UnitOfWork transaction, final String roleNameToRemove)
      throws KException {
    ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$
    ArgCheck.isTrue(
        (transaction.getState() == State.NOT_STARTED),
        "transaction state is not NOT_STARTED"); //$NON-NLS-1$
    ArgCheck.isNotEmpty(roleNameToRemove, "roleNameToRemove"); // $NON-NLS-1$

    final String[] current = getMappedRoles(transaction);

    if (current.length == 0) {
      throw new KException(
          Messages.getString(Relational.MAPPED_ROLE_NOT_FOUND_TO_REMOVE, roleNameToRemove));
    }

    final String[] result = new String[current.length - 1];
    boolean found = false;
    int i = 0;

    for (final String mappedRoleName : current) {
      if (mappedRoleName.equals(roleNameToRemove)) {
        found = true;
      } else {
        result[i++] = mappedRoleName;
      }
    }

    if (!found) {
      throw new KException(
          Messages.getString(Relational.MAPPED_ROLE_NOT_FOUND_TO_REMOVE, roleNameToRemove));
    }

    final Object[] newValue = ((result.length == 0) ? null : result);
    setProperty(transaction, VdbLexicon.DataRole.MAPPED_ROLE_NAMES, newValue);

    return result;
  }
예제 #5
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.DataRole#removePermission(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String)
   */
  @Override
  public void removePermission(final UnitOfWork transaction, final String permissionToRemove)
      throws KException {
    ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$
    ArgCheck.isTrue(
        (transaction.getState() == State.NOT_STARTED),
        "transaction state is not NOT_STARTED"); //$NON-NLS-1$
    ArgCheck.isNotEmpty(permissionToRemove, "permissionToRemove"); // $NON-NLS-1$

    final Permission[] permissions = getPermissions(transaction, permissionToRemove);

    if (permissions.length == 0) {
      throw new KException(
          Messages.getString(Relational.PERMISSION_NOT_FOUND_TO_REMOVE, permissionToRemove));
    }

    // remove first occurrence
    permissions[0].remove(transaction);
  }
예제 #6
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.internal.RelationalObjectImpl#getChild(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String)
   */
  @Override
  public KomodoObject getChild(final UnitOfWork transaction, final String name) throws KException {
    ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$
    ArgCheck.isTrue(
        (transaction.getState() == State.NOT_STARTED),
        "transaction state must be NOT_STARTED"); //$NON-NLS-1$
    ArgCheck.isNotEmpty(name, "name"); // $NON-NLS-1$

    final KomodoObject[] matches = getPermissions(transaction, name);

    if (matches.length != 0) {
      return matches[0];
    }

    // child does not exist
    throw new KException(
        Messages.getString(
            org.komodo.repository.Messages.Komodo.CHILD_NOT_FOUND, name, getAbsolutePath()));
  }
예제 #7
0
        /**
         * {@inheritDoc}
         *
         * @see
         *     org.komodo.relational.internal.TypeResolver#create(org.komodo.spi.repository.Repository.UnitOfWork,
         *     org.komodo.spi.repository.Repository, org.komodo.spi.repository.KomodoObject,
         *     java.lang.String, org.komodo.relational.RelationalProperties)
         */
        @Override
        public Permission create(
            final UnitOfWork transaction,
            final Repository repository,
            final KomodoObject parent,
            final String id,
            final RelationalProperties properties)
            throws KException {
          final AdapterFactory adapter = new AdapterFactory(repository);
          final DataRole parentDataRole = adapter.adapt(transaction, parent, DataRole.class);

          if (parentDataRole == null) {
            throw new KException(
                Messages.getString(
                    Relational.INVALID_PARENT_TYPE,
                    parent.getAbsolutePath(),
                    Permission.class.getSimpleName()));
          }

          return parentDataRole.addPermission(transaction, id);
        }