コード例 #1
0
ファイル: RestVdbMask.java プロジェクト: vhalbert/komodo
  /**
   * Constructor for use when serializing.
   *
   * @param baseUri the base uri of the REST request
   * @param mask the mask
   * @param uow the transaction
   * @throws KException if error occurs
   */
  public RestVdbMask(URI baseUri, Mask mask, UnitOfWork uow) throws KException {
    super(baseUri, mask, uow);

    setName(mask.getName(uow));
    setOrder(mask.getOrder(uow));

    Permission permission = ancestor(mask, Permission.class, uow);
    ArgCheck.isNotNull(permission);
    String permName = permission.getName(uow);

    DataRole dataRole = ancestor(permission, DataRole.class, uow);
    ArgCheck.isNotNull(dataRole);
    String dataRoleName = dataRole.getName(uow);

    Vdb vdb = ancestor(dataRole, Vdb.class, uow);
    ArgCheck.isNotNull(vdb);
    String vdbName = vdb.getName(uow);

    Properties settings = getUriBuilder().createSettings(SettingNames.VDB_NAME, vdbName);
    getUriBuilder().addSetting(settings, SettingNames.DATA_ROLE_ID, dataRoleName);
    getUriBuilder().addSetting(settings, SettingNames.PERMISSION_ID, permName);
    getUriBuilder()
        .addSetting(settings, SettingNames.PERMISSION_CHILD_TYPE, LinkType.MASKS.uriName());
    getUriBuilder().addSetting(settings, SettingNames.PERMISSION_CHILD_ID, getId());

    addLink(
        new RestLink(
            LinkType.SELF, getUriBuilder().buildVdbPermissionChildUri(LinkType.SELF, settings)));
    addLink(
        new RestLink(
            LinkType.PARENT,
            getUriBuilder().buildVdbPermissionChildUri(LinkType.PARENT, settings)));
  }
コード例 #2
0
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String mappedRoleName =
          requiredArgument(0, I18n.bind(DataRoleCommandsI18n.missingMappedRoleName));

      final DataRole dataRole = getDataRole();
      dataRole.addMappedRole(getTransaction(), mappedRoleName);

      result =
          new CommandResultImpl(I18n.bind(DataRoleCommandsI18n.mappedRoleAdded, mappedRoleName));
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
コード例 #3
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);
        }
コード例 #4
0
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String name =
          requiredArgument(0, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));
      final String value =
          requiredArgument(1, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));

      final DataRole dataRole = getDataRole();
      final UnitOfWork transaction = getTransaction();
      String errorMsg = null;

      switch (name) {
        case ALLOWED_CREATE_TEMPORARY_TABLES:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            dataRole.setAllowCreateTempTables(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg =
                I18n.bind(
                    WorkspaceCommandsI18n.invalidBooleanPropertyValue,
                    ALLOWED_CREATE_TEMPORARY_TABLES);
          }

          break;
        case ANY_AUTHENTICATED:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            dataRole.setAnyAuthenticated(transaction, Boolean.parseBoolean(value));
          } else {
            I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, ANY_AUTHENTICATED);
          }

          break;
        case DESCRIPTION:
          dataRole.setDescription(transaction, value);
          break;
        case GRANT_ALL:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            dataRole.setGrantAll(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, GRANT_ALL);
          }

          break;
        default:
          errorMsg =
              I18n.bind(
                  WorkspaceCommandsI18n.invalidPropertyName, name, DataRole.class.getSimpleName());
          break;
      }

      if (StringUtils.isBlank(errorMsg)) {
        result = new CommandResultImpl(I18n.bind(WorkspaceCommandsI18n.setPropertySuccess, name));
      } else {
        result = new CommandResultImpl(false, errorMsg, null);
      }
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }