Ejemplo n.º 1
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.Permission#getMasks(org.komodo.spi.repository.Repository.UnitOfWork)
   */
  @Override
  public Mask[] getMasks(final UnitOfWork transaction) 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$

    Mask[] result = null;

    if (hasChild(
        transaction, VdbLexicon.DataRole.Permission.MASKS, VdbLexicon.DataRole.Permission.MASKS)) {
      final KomodoObject grouping =
          getChild(
              transaction,
              VdbLexicon.DataRole.Permission.MASKS,
              VdbLexicon.DataRole.Permission.MASKS);
      final List<Mask> temp = new ArrayList<>();

      for (final KomodoObject kobject :
          grouping.getChildrenOfType(transaction, VdbLexicon.DataRole.Permission.Mask.MASK)) {
        final Mask mask = new MaskImpl(transaction, getRepository(), kobject.getAbsolutePath());
        temp.add(mask);
      }

      result = temp.toArray(new Mask[temp.size()]);
    } else {
      result = Mask.NO_MASKS;
    }

    return result;
  }
Ejemplo n.º 2
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.Permission#getConditions(org.komodo.spi.repository.Repository.UnitOfWork)
   */
  @Override
  public Condition[] getConditions(final UnitOfWork transaction) 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$

    Condition[] result = null;

    if (hasChild(
        transaction,
        VdbLexicon.DataRole.Permission.CONDITIONS,
        VdbLexicon.DataRole.Permission.CONDITIONS)) {
      final KomodoObject grouping =
          getChild(
              transaction,
              VdbLexicon.DataRole.Permission.CONDITIONS,
              VdbLexicon.DataRole.Permission.CONDITIONS);
      final List<Condition> temp = new ArrayList<>();

      for (final KomodoObject kobject :
          grouping.getChildrenOfType(
              transaction, VdbLexicon.DataRole.Permission.Condition.CONDITION)) {
        final Condition condition =
            new ConditionImpl(transaction, getRepository(), kobject.getAbsolutePath());
        temp.add(condition);
      }

      result = temp.toArray(new Condition[temp.size()]);
    } else {
      result = Condition.NO_CONDITIONS;
    }

    return result;
  }
Ejemplo n.º 3
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));
    }
  }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
0
  /**
   * Constructor for use when serializing.
   *
   * @param baseUri the base uri of the REST request
   * @param source the source
   * @param uow the transaction
   * @throws KException if error occurs
   */
  public RestVdbModelSource(URI baseUri, ModelSource source, UnitOfWork uow) throws KException {
    super(baseUri, source, uow);

    setJndiName(source.getJndiName(uow));
    String translatorName = source.getTranslatorName(uow);
    setTranslator(translatorName);

    Model model = ancestor(source, Model.class, uow);
    ArgCheck.isNotNull(model);
    String modelName = model.getName(uow);

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

    Properties settings = getUriBuilder().createSettings(SettingNames.VDB_NAME, vdbName);
    getUriBuilder().addSetting(settings, SettingNames.MODEL_NAME, modelName);
    getUriBuilder().addSetting(settings, SettingNames.SOURCE_NAME, getId());

    addLink(
        new RestLink(
            LinkType.SELF, getUriBuilder().buildVdbModelSourceUri(LinkType.SELF, settings)));
    addLink(
        new RestLink(
            LinkType.PARENT, getUriBuilder().buildVdbModelSourceUri(LinkType.PARENT, settings)));

    Translator[] translators = vdb.getTranslators(uow, translatorName);
    if (translators != null && translators.length == 1) {
      getUriBuilder().addSetting(settings, SettingNames.TRANSLATOR_NAME, translatorName);
      addLink(
          new RestLink(
              LinkType.REFERENCE,
              getUriBuilder().buildVdbModelSourceUri(LinkType.REFERENCE, settings)));
    }
  }
Ejemplo n.º 6
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));
    }
  }
Ejemplo n.º 7
0
  /**
   * 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)));
  }
Ejemplo n.º 8
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.DataRole#getMappedRoles(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String[])
   */
  @Override
  public String[] getMappedRoles(final UnitOfWork transaction, final String... namePatterns)
      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$

    final Property property = getProperty(transaction, VdbLexicon.DataRole.MAPPED_ROLE_NAMES);

    if (property == null) {
      return StringConstants.EMPTY_ARRAY;
    }

    final boolean matchPattern = ((namePatterns != null) && (namePatterns.length != 0));
    final List<String> roleNames = new ArrayList<>();

    for (final String value : property.getStringValues(transaction)) {
      if (matchPattern) {
        for (final String pattern : namePatterns) {
          // convert pattern to a regex
          final String regex = pattern.replace("*", ".*"); // $NON-NLS-1$ //$NON-NLS-2$

          if (value.matches(regex)) {
            roleNames.add(value);
          }
        }
      } else {
        roleNames.add(value);
      }
    }

    return roleNames.toArray(new String[roleNames.size()]);
  }
Ejemplo n.º 9
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.spi.repository.ValidationManager#addChildRelationshipValidationRule(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String, java.lang.String, java.lang.String, java.util.List, java.util.List,
   *     java.util.List, java.util.List, java.util.List, java.util.List)
   */
  @Override
  public Rule addChildRelationshipValidationRule(
      final UnitOfWork transaction,
      final String name,
      final String nodeType,
      final String childType,
      final List<String> propsThatMustExist,
      final List<String> propsThatMustNotExist,
      final List<String> childTypesThatMustExist,
      final List<String> childTypesThatMustNotExist,
      final List<LocalizedMessage> descriptions,
      final List<LocalizedMessage> messages)
      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(childType, "childType"); // $NON-NLS-1$
    ArgCheck.isTrue(
        ((propsThatMustExist != null) && !propsThatMustExist.isEmpty())
            || ((propsThatMustNotExist != null) && !propsThatMustNotExist.isEmpty())
            || ((childTypesThatMustExist != null) && !childTypesThatMustExist.isEmpty())
            || ((childTypesThatMustNotExist != null) && !childTypesThatMustNotExist.isEmpty()),
        "at least one relationship collection must not be empty"); //$NON-NLS-1$

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "addChildRelationshipValidationRule: transaction = {0}, name = {1}",
          transaction.getName(), name); // $NON-NLS-1$
    }

    try {
      final RuleImpl rule =
          createRule(
              transaction,
              name,
              KomodoLexicon.Rule.RELATIONSHIP_RULE,
              Rule.ValidationType.CHILD,
              Rule.RuleType.RELATIONSHIP,
              nodeType,
              descriptions,
              messages);

      processMultiValuedProperty(
          transaction, rule, KomodoLexicon.Rule.PROP_EXISTS, propsThatMustExist);
      processMultiValuedProperty(
          transaction, rule, KomodoLexicon.Rule.PROP_ABSENT, propsThatMustNotExist);
      processMultiValuedProperty(
          transaction, rule, KomodoLexicon.Rule.CHILD_EXISTS, childTypesThatMustExist);
      processMultiValuedProperty(
          transaction, rule, KomodoLexicon.Rule.CHILD_ABSENT, childTypesThatMustNotExist);

      return rule;
    } catch (final Exception e) {
      throw ObjectImpl.handleError(e);
    }
  }
Ejemplo n.º 10
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.spi.repository.ValidationManager#addPropertyValueNumberValidationRule(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String, java.lang.String, java.lang.String, java.lang.Number, boolean,
   *     java.lang.Number, boolean, java.util.List, java.util.List)
   */
  @Override
  public Rule addPropertyValueNumberValidationRule(
      final UnitOfWork transaction,
      final String name,
      final String nodeType,
      final String propertyName,
      final Number minValue,
      final boolean minInclusive,
      final Number maxValue,
      final boolean maxInclusive,
      final List<LocalizedMessage> descriptions,
      final List<LocalizedMessage> messages)
      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(propertyName, "propertyName"); // $NON-NLS-1$
    ArgCheck.isTrue(
        (minValue != null) || (maxValue != null),
        "minValue or maxValue must not be null"); //$NON-NLS-1$

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "addPropertyValueNumberValidationRule: transaction = {0}, name = {1}",
          transaction.getName(), name); // $NON-NLS-1$
    }

    try {
      final RuleImpl rule =
          createRule(
              transaction,
              name,
              KomodoLexicon.Rule.NUMBER_RULE,
              Rule.ValidationType.PROPERTY,
              Rule.RuleType.NUMBER,
              nodeType,
              descriptions,
              messages);
      rule.setProperty(transaction, KomodoLexicon.Rule.JCR_NAME, propertyName);

      if (minValue != null) {
        rule.setProperty(transaction, KomodoLexicon.Rule.MIN_VALUE, minValue.toString());
        rule.setProperty(transaction, KomodoLexicon.Rule.MIN_VALUE_INCLUSIVE, minInclusive);
      }

      if (maxValue != null) {
        rule.setProperty(transaction, KomodoLexicon.Rule.MAX_VALUE, maxValue.toString());
        rule.setProperty(transaction, KomodoLexicon.Rule.MAX_VALUE_INCLUSIVE, maxInclusive);
      }

      return rule;
    } catch (final Exception e) {
      throw ObjectImpl.handleError(e);
    }
  }
Ejemplo n.º 11
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.internal.RelationalObjectImpl#getParent(org.komodo.spi.repository.Repository.UnitOfWork)
   */
  @Override
  public Vdb getParent(final UnitOfWork transaction) 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$

    final KomodoObject grouping = super.getParent(transaction);
    final Vdb result = Vdb.RESOLVER.resolve(transaction, grouping.getParent(transaction));
    return result;
  }
Ejemplo n.º 12
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.internal.RelationalObjectImpl#getChildren(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String[])
   */
  @Override
  public KomodoObject[] getChildren(final UnitOfWork transaction, final String... namePatterns)
      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$

    final KomodoObject[] result = getPermissions(transaction, namePatterns);
    return result;
  }
Ejemplo n.º 13
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.repository.ObjectImpl#getChildren(org.komodo.spi.repository.Repository.UnitOfWork)
   */
  @Override
  public KomodoObject[] getChildren(final UnitOfWork transaction) 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$

    final Condition[] conditions = getConditions(transaction);
    final Mask[] masks = getMasks(transaction);

    final KomodoObject[] result = new KomodoObject[conditions.length + masks.length];
    System.arraycopy(conditions, 0, result, 0, conditions.length);
    System.arraycopy(masks, 0, result, conditions.length, masks.length);

    return result;
  }
Ejemplo n.º 14
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.internal.RelationalObjectImpl#hasChild(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String, java.lang.String)
   */
  @Override
  public boolean hasChild(final UnitOfWork transaction, final String name, final String typeName)
      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$
    ArgCheck.isNotEmpty(typeName, "typeName"); // $NON-NLS-1$

    if (VdbLexicon.DataRole.Permission.PERMISSION.equals(typeName)) {
      return (getPermissions(transaction, name).length != 0);
    }

    return false;
  }
Ejemplo n.º 15
0
  /**
   * Constructs a filter.
   *
   * @param namesToExclude a collection of names being excluded (cannot be <code>null</code> or
   *     empty)
   */
  public ExcludeQNamesFilter(final String... namesToExclude) {
    ArgCheck.isNotEmpty(namesToExclude, "qnames"); // $NON-NLS-1$
    this.qnames = new ArrayList<>(namesToExclude.length);

    for (final String name : namesToExclude) {
      this.qnames.add(name);
    }
  }
Ejemplo n.º 16
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);
  }
Ejemplo n.º 17
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()));
  }
Ejemplo n.º 18
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.internal.RelationalObjectImpl#getChildrenOfType(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String, java.lang.String[])
   */
  @Override
  public KomodoObject[] getChildrenOfType(
      final UnitOfWork transaction, final String type, final String... namePatterns)
      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$

    KomodoObject[] result = null;

    if (VdbLexicon.DataRole.Permission.PERMISSION.equals(type)) {
      result = getPermissions(transaction, namePatterns);
    } else {
      result = KomodoObject.EMPTY_ARRAY;
    }

    return result;
  }
Ejemplo n.º 19
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.spi.repository.ValidationManager#addPropertyPatternRule(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.List,
   *     java.util.List)
   */
  @Override
  public Rule addPropertyPatternRule(
      final UnitOfWork transaction,
      final String name,
      final String nodeType,
      final String propertyName,
      final String pattern,
      final List<LocalizedMessage> descriptions,
      final List<LocalizedMessage> messages)
      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(propertyName, "propertyName"); // $NON-NLS-1$
    ArgCheck.isNotEmpty(pattern, "pattern"); // $NON-NLS-1$

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "addPropertyPatternRule: transaction = {0}, name = {1}",
          transaction.getName(), name); // $NON-NLS-1$
    }

    try {
      final RuleImpl rule =
          createRule(
              transaction,
              name,
              KomodoLexicon.Rule.PATTERN_RULE,
              Rule.ValidationType.PROPERTY,
              Rule.RuleType.PATTERN,
              nodeType,
              descriptions,
              messages);
      rule.setProperty(transaction, KomodoLexicon.Rule.JCR_NAME, propertyName);
      rule.setProperty(transaction, KomodoLexicon.Rule.PATTERN, pattern);
      return rule;
    } catch (final Exception e) {
      throw ObjectImpl.handleError(e);
    }
  }
Ejemplo n.º 20
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.spi.repository.Repository#createTransaction(java.lang.String, boolean,
  *     org.komodo.spi.repository.Repository.UnitOfWorkListener)
  */
 @Override
 public UnitOfWork createTransaction(
     final String name, final boolean rollbackOnly, final UnitOfWorkListener callback)
     throws KException {
   ArgCheck.isNotEmpty(name, "name"); // $NON-NLS-1$
   LOGGER.debug(
       "creating transaction {0} with rollbackOnly = {1}", name, rollbackOnly); // $NON-NLS-1$
   final Session session = createSession();
   final UnitOfWork uow = new LocalRepositoryTransaction(name, session, rollbackOnly, callback);
   this.sessions.put(session, uow);
   return uow;
 }
Ejemplo n.º 21
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;
  }
Ejemplo n.º 22
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.spi.repository.ValidationManager#addSameNameSiblingValidationRule(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String, java.lang.String, boolean, java.util.List, java.util.List)
   */
  @Override
  public Rule addSameNameSiblingValidationRule(
      final UnitOfWork transaction,
      final String name,
      final String nodeType,
      final boolean matchType,
      final List<LocalizedMessage> descriptions,
      final List<LocalizedMessage> messages)
      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$

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "addSameNameSiblingValidationRule: transaction = {0}, name = {1}",
          transaction.getName(), name); // $NON-NLS-1$
    }

    try {
      final RuleImpl rule =
          createRule(
              transaction,
              name,
              KomodoLexicon.Rule.SNS_RULE,
              Rule.ValidationType.CHILD,
              Rule.RuleType.SAME_NAME_SIBLING,
              nodeType,
              descriptions,
              messages);
      rule.setProperty(transaction, KomodoLexicon.Rule.MATCH_TYPE, matchType);
      return rule;
    } catch (final Exception e) {
      throw ObjectImpl.handleError(e);
    }
  }
  /**
   * Converts the specified text (usually from the System Clipboard) representing a single table row
   * into a list. Data elements are separated by tabs. Any empty column is filled with a zero length
   * string.
   *
   * @param theRowData the text being converted
   * @return the row data as a list
   * @throws IllegalArgumentException if the input is <code>null</code>
   */
  public static List<String> convertColumnData(String theRowData) {
    ArgCheck.isNotNull(theRowData);

    String sThisToken = ""; // $NON-NLS-1$
    String sLastToken = ""; // $NON-NLS-1$
    final String EMPTY_STRING = ""; // $NON-NLS-1$
    ArrayList<String> arylResult = new ArrayList<String>();

    StringTokenizer stInner = new StringTokenizer(theRowData, COLUMN_DELIMITER, true);

    if (stInner.hasMoreTokens()) {
      boolean firstToken = true;

      while (stInner.hasMoreTokens()) {
        sThisToken = stInner.nextToken();

        if (sThisToken.equals(COLUMN_DELIMITER)) {
          if (firstToken) {
            // first value was delimiter so set first value to empty string
            arylResult.add(EMPTY_STRING);
          } else if (sLastToken.equals(COLUMN_DELIMITER)) {
            // if both this and last were delims,
            //  we must supply the missing data between them
            arylResult.add(EMPTY_STRING);
          } else {
            // if this is a delim, but the last was not a delim,
            //  take no action.
          }
        } else {
          // if this token is NOT a delim, just add it to the array
          arylResult.add(sThisToken);
        }
        sLastToken = sThisToken;

        if (firstToken) {
          firstToken = false;
        }
      }

      if (sLastToken.equals(COLUMN_DELIMITER)) {
        arylResult.add(EMPTY_STRING);
      }
    } else {
      // no delimeters found so only one value
      arylResult.add(theRowData);
    }

    return arylResult;
  }
Ejemplo n.º 24
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.komodo.relational.vdb.DataRole#getPermissions(org.komodo.spi.repository.Repository.UnitOfWork,
   *     java.lang.String[])
   */
  @Override
  public Permission[] getPermissions(final UnitOfWork transaction, final String... namePatterns)
      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$

    final KomodoObject grouping = getPermissionsGroupingNode(transaction);

    if (grouping != null) {
      final List<Permission> temp = new ArrayList<>();

      for (final KomodoObject kobject : grouping.getChildren(transaction, namePatterns)) {
        final Permission permission =
            new PermissionImpl(transaction, getRepository(), kobject.getAbsolutePath());
        temp.add(permission);
      }

      return temp.toArray(new Permission[temp.size()]);
    }

    return Permission.NO_PERMISSIONS;
  }
  /**
   * Converts the specified text (usually from the System Clipboard) representing a table into a
   * list of lists where the outer lists are the rows and the internal lists are the columns. Lines
   * are terminated by CRLF and columns are separated by tabs.
   *
   * @param theTableData the text being converted
   * @return a list of lists where the outer list represents rows and the inner list represents
   *     columns
   * @throws IllegalArgumentException if the input is <code>null</code>
   */
  public static List<List<String>> convertTableData(String theTableData) {
    ArgCheck.isNotNull(theTableData);

    ArrayList<List<String>> arylResult = new ArrayList<List<String>>();
    final String DELIMITER = "\r\n"; // $NON-NLS-1$
    boolean firstToken = true;

    StringTokenizer stOuter = new StringTokenizer(theTableData, DELIMITER, true);
    boolean prevTokenWasDelimiter = false;

    while (stOuter.hasMoreTokens()) {
      String token = stOuter.nextToken();

      // code should handle if "\r\n" or just "\n" is found
      if (token.equals("\r")) { // $NON-NLS-1$
        token = stOuter.nextToken();
      }

      if (token.equals("\n")) { // $NON-NLS-1$
        if (firstToken) {
          // first value was delimiter so set first value to empty string
          token = ""; // $NON-NLS-1$
          prevTokenWasDelimiter = true;
        } else if (prevTokenWasDelimiter) {
          // replace delimiter with empty string to signify blank input found for row
          token = ""; // $NON-NLS-1$
        } else {
          // don't process this since it just signifies end of row data
          prevTokenWasDelimiter = true;
          continue;
        }
      } else {
        prevTokenWasDelimiter = false;
      }

      if (firstToken) {
        firstToken = false;
      }

      List<String> lstLineArry = convertColumnData(token);
      arylResult.add(lstLineArry);
    }

    return arylResult;
  }
Ejemplo n.º 26
0
  private void processMultiValuedProperty(
      final UnitOfWork uow,
      final KomodoObject rule,
      final String propName,
      final List<String> values)
      throws Exception {
    if ((values != null) && !values.isEmpty()) {
      final String[] result = new String[values.size()];
      int i = 0;

      for (final String value : values) {
        ArgCheck.isNotEmpty(value, "value"); // $NON-NLS-1$
        result[i++] = value;
      }

      rule.setProperty(uow, propName, (Object[]) result);
    }
  }
Ejemplo n.º 27
0
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.spi.repository.ValidationManager#validateRules(java.io.File)
   */
  @Override
  public List<String> validateRules(final File rulesXmlFile) throws KException {
    ArgCheck.isNotNull(rulesXmlFile, "rulesXmlFile"); // $NON-NLS-1$

    try {
      if (_parser == null) {
        setupValidationParser();
      }

      ValidationHandler handler = new ValidationHandler();
      _parser.parse(rulesXmlFile, handler);

      // return any errors
      List<String> result = new ArrayList<>();
      result.addAll(handler.getFatalErrors());
      result.addAll(handler.getErrors());
      return result;
    } catch (final Exception e) {
      throw new KException(e);
    }
  }
Ejemplo n.º 28
0
 /** @param name the name of this search */
 public KomodoSavedSearcher(String name) {
   ArgCheck.isNotNull(name);
   this.name = name;
 }
Ejemplo n.º 29
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.relational.RelationalObject.Filter#rejectProperty(java.lang.String)
  */
 @Override
 public boolean rejectProperty(final String propName) {
   ArgCheck.isNotEmpty(propName, "propName"); // $NON-NLS-1$
   return this.qnames.contains(propName);
 }
Ejemplo n.º 30
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.relational.RelationalObject.Filter#rejectDescriptor(java.lang.String)
  */
 @Override
 public boolean rejectDescriptor(final String descriptorName) {
   ArgCheck.isNotEmpty(descriptorName, "descriptorName"); // $NON-NLS-1$
   return this.qnames.contains(descriptorName);
 }