/** * {@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)); } }
/** * {@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)); } }
/** * {@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; }
/** * {@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; }
/** * 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); } }
/** * {@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); } }
/** * {@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); } }
/** * {@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); } }
/** * {@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; }
/** * {@inheritDoc} * * @see * org.komodo.relational.internal.RelationalObjectImpl#getChild(org.komodo.spi.repository.Repository.UnitOfWork, * java.lang.String, java.lang.String) */ @Override public KomodoObject getChild( 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)) { final KomodoObject[] permissions = getPermissions(transaction, name); if (permissions.length != 0) { return permissions[0]; } } // child does not exist throw new KException( Messages.getString( org.komodo.repository.Messages.Komodo.CHILD_NOT_FOUND, name, getAbsolutePath())); }
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); } }
/** * {@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); }
/** * {@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; }
/** * {@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); }
/** * {@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); }
private RuleImpl createRule( final UnitOfWork uow, final String name, final String nodeType, final Rule.ValidationType validationType, final Rule.RuleType ruleType, final String ruleNodeType, final List<LocalizedMessage> descriptions, final List<LocalizedMessage> messages) throws Exception { assert (uow != null); assert (validationType != null); assert (ruleType != null); ArgCheck.isNotEmpty(name, "name"); // $NON-NLS-1$ ArgCheck.isNotEmpty(nodeType, "nodeType"); // $NON-NLS-1$ ArgCheck.isNotEmpty(ruleNodeType, "ruleNodeType"); // $NON-NLS-1$ ArgCheck.isNotEmpty(descriptions, "descriptions"); // $NON-NLS-1$ final KomodoObject parent = getValidationAreaNode(uow); final KomodoObject rule = parent.addChild(uow, name, nodeType); rule.setProperty(uow, KomodoLexicon.Rule.NODE_TYPE, ruleNodeType); rule.setProperty(uow, KomodoLexicon.Rule.VALIDATION_TYPE, validationType.name()); // add description and optional messages final KomodoObject messagesNode = rule.addChild( uow, KomodoLexicon.Rule.MESSAGES, KomodoLexicon.Rule.LOCALIZED_MESSAGE_GROUPING); { // add descriptions final KomodoObject description = messagesNode.addChild( uow, MessageKey.DESCRIPTION.name(), KomodoLexicon.Rule.LOCALIZED_MESSAGE); for (final LocalizedMessage localizedDescription : descriptions) { final KomodoObject node = description.addChild( uow, localizedDescription.getLocaleCode(), KomodoLexicon.Rule.LOCALIZED_TEXT_TYPE); node.setProperty(uow, KomodoLexicon.Rule.LOCALIZED_TEXT, localizedDescription.getMessage()); } } { // add messages if ((messages != null) && !messages.isEmpty()) { for (final LocalizedMessage localizedMessage : messages) { final String id = localizedMessage.getId(); KomodoObject message = null; if (messagesNode.hasChild(uow, id, KomodoLexicon.Rule.LOCALIZED_MESSAGE)) { message = messagesNode.getChild(uow, id, KomodoLexicon.Rule.LOCALIZED_MESSAGE); } else { message = messagesNode.addChild(uow, id, KomodoLexicon.Rule.LOCALIZED_MESSAGE); } final KomodoObject node = message.addChild( uow, localizedMessage.getLocaleCode(), KomodoLexicon.Rule.LOCALIZED_TEXT_TYPE); node.setProperty(uow, KomodoLexicon.Rule.LOCALIZED_TEXT, localizedMessage.getMessage()); } } } return new RuleImpl(uow, this.repo, rule.getAbsolutePath()); }