Prep work for OPENDJ-2803 Migrate Attribute
Attribute.java:
Inlined getName(), replaced with getAttributeDescription().getNameOrOID().
| | |
| | | { |
| | | final org.opends.server.types.Attribute attribute = |
| | | LDIFReader.parseAttrDescription(wholeName); |
| | | final String attrName = attribute.getName(); |
| | | final String attrName = attribute.getAttributeDescription().getNameOrOID(); |
| | | |
| | | // See if this is an objectclass or an attribute. Then get the |
| | | // corresponding definition and add the value to the appropriate hash. |
| | |
| | | for (String wholeName : csr.getAttributeNames()) |
| | | { |
| | | final Attribute attribute = parseAttrDescription(wholeName); |
| | | final String attrName = attribute.getName(); |
| | | final String attrName = attribute.getAttributeDescription().getNameOrOID(); |
| | | |
| | | // See if this is an objectclass or an attribute. Then get the |
| | | // corresponding definition and add the value to the appropriate hash. |
| | |
| | | else |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_SCHEMA_MODIFY_UNSUPPORTED_ATTRIBUTE_TYPE.get(a.getName()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | message); |
| | | ERR_SCHEMA_MODIFY_UNSUPPORTED_ATTRIBUTE_TYPE.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | |
| | | break; |
| | |
| | | if (a.isEmpty()) |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_SCHEMA_MODIFY_DELETE_NO_VALUES.get(a.getName()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | message); |
| | | ERR_SCHEMA_MODIFY_DELETE_NO_VALUES.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | |
| | | if (at.equals(attributeTypesType)) |
| | |
| | | else |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_SCHEMA_MODIFY_UNSUPPORTED_ATTRIBUTE_TYPE.get(a.getName()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | message); |
| | | ERR_SCHEMA_MODIFY_UNSUPPORTED_ATTRIBUTE_TYPE.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | |
| | | break; |
| | |
| | | |
| | | LocalizableMessage message = |
| | | ERR_SCHEMA_MODIFY_CANNOT_WRITE_NEW_SCHEMA.get(getExceptionMessage(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message, e); |
| | | } |
| | | finally |
| | | { |
| | |
| | | if (pendingValueSet) |
| | | { |
| | | // We cannot have multiple pending values. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc.getNameOrOID())); |
| | | } |
| | | if (a.isEmpty()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | // Get the value and parse it as a Boolean. |
| | |
| | | if (iterator.hasNext()) |
| | | { |
| | | // This is illegal -- it must be single-valued. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // This is illegal -- only the pending option is allowed for |
| | | // configuration attributes. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | else |
| | |
| | | if (activeValueSet) |
| | | { |
| | | // We cannot have multiple active values. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc.getNameOrOID())); |
| | | } |
| | | if (a.isEmpty()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | // Get the value and parse it as a Boolean. |
| | |
| | | if (iterator.hasNext()) |
| | | { |
| | | // This is illegal -- it must be single-valued. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | // We cannot have multiple pending value sets. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()); |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | // This is fine. The pending value set can be empty. |
| | | pendingValues = new ArrayList<>(0); |
| | |
| | | if (numValues > 1 && !isMultiValued()) |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | pendingValues = new ArrayList<>(numValues); |
| | |
| | | // This is illegal -- only the pending option is allowed for |
| | | // configuration attributes. |
| | | throw new ConfigException( |
| | | ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName())); |
| | | ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | else |
| | |
| | | { |
| | | // We cannot have multiple active value sets. |
| | | throw new ConfigException( |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName())); |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | // This is fine. The active value set can be empty. |
| | | activeValues = new ArrayList<>(0); |
| | |
| | | if (numValues > 1 && !isMultiValued()) |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | activeValues = new ArrayList<>(numValues); |
| | |
| | | { |
| | | // We cannot have multiple pending value sets. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()); |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()); |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get( |
| | | v, a.getName(), e); |
| | | v, a.getAttributeDescription().getNameOrOID(), e); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | |
| | |
| | | if (hasLowerBound && longValue < lowerBound) |
| | | { |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get( |
| | | a.getName(), longValue, lowerBound); |
| | | a.getAttributeDescription().getNameOrOID(), longValue, lowerBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (hasUpperBound && longValue > upperBound) |
| | | { |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get( |
| | | a.getName(), longValue, upperBound); |
| | | a.getAttributeDescription().getNameOrOID(), longValue, upperBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | // configuration attributes. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get( |
| | | a.getName()); |
| | | a.getAttributeDescription().getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | |
| | | { |
| | | // We cannot have multiple active value sets. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName()); |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()); |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get( |
| | | v, a.getName(), e); |
| | | v, a.getAttributeDescription().getNameOrOID(), e); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | |
| | |
| | | if (hasLowerBound && longValue < lowerBound) |
| | | { |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get( |
| | | a.getName(), longValue, lowerBound); |
| | | a.getAttributeDescription().getNameOrOID(), longValue, lowerBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (hasUpperBound && longValue > upperBound) |
| | | { |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get( |
| | | a.getName(), longValue, upperBound); |
| | | a.getAttributeDescription().getNameOrOID(), longValue, upperBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (!attrDesc.hasOption(OPTION_PENDING_VALUES)) |
| | | { |
| | | // This is illegal -- only the pending option is allowed for configuration attributes. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | if (pendingUnit != null) |
| | | { |
| | | // We cannot have multiple pending value sets. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | String valueString = getValue(a); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get(valueString, a.getName(), e)); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get( |
| | | valueString, attrDesc.getNameOrOID(), e)); |
| | | } |
| | | |
| | | pendingCalculatedValue = calculateValue(pendingIntValue, activeUnit, pendingUnit, a); |
| | |
| | | if (activeUnit != null) |
| | | { |
| | | // We cannot have multiple active value sets. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | String valueString = getValue(a); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get(valueString, a.getName(), e)); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get( |
| | | valueString, attrDesc.getNameOrOID(), e)); |
| | | } |
| | | |
| | | activeCalculatedValue = calculateValue(activeIntValue, activeUnit, activeUnit, a); |
| | |
| | | |
| | | private String getValue(Attribute a) throws ConfigException |
| | | { |
| | | AttributeDescription attrDesc = a.getAttributeDescription(); |
| | | if (a.isEmpty()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | Iterator<ByteString> iterator = a.iterator(); |
| | |
| | | if (iterator.hasNext()) |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | return valueString; |
| | | } |
| | |
| | | private long calculateValue(long intValue, String activeUnit, String pendingUnit, Attribute a) throws ConfigException |
| | | { |
| | | // Get the unit and use it to determine the corresponding multiplier. |
| | | AttributeDescription attrDesc = a.getAttributeDescription(); |
| | | if (!units.containsKey(pendingUnit)) |
| | | { |
| | | throw new ConfigException(ERR_CONFIG_ATTR_INVALID_UNIT.get(pendingUnit, a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_INVALID_UNIT.get(pendingUnit, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | double multiplier = units.get(activeUnit); |
| | |
| | | // Check the bounds set for this attribute. |
| | | if (hasLowerBound && result < lowerBound) |
| | | { |
| | | throw new ConfigException(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(a.getName(), result, lowerBound)); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(attrDesc.getNameOrOID(), result, lowerBound)); |
| | | } |
| | | if (hasUpperBound && result > upperBound) |
| | | { |
| | | throw new ConfigException(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(a.getName(), result, upperBound)); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(attrDesc.getNameOrOID(), result, upperBound)); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | { |
| | | for (org.opends.server.types.Attribute a : monitor.getMonitorData()) |
| | | { |
| | | attrs.add(new MBeanAttributeInfo(a.getName(), String.class.getName(), |
| | | attrs.add(new MBeanAttributeInfo(a.getAttributeDescription().getNameOrOID(), String.class.getName(), |
| | | null, true, false, false)); |
| | | } |
| | | } |
| | |
| | | { |
| | | // We cannot have multiple pending value sets. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()); |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | // This is fine. The pending value set can be empty. |
| | | pendingValues = new ArrayList<>(0); |
| | |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (! allowedValues.contains(lowerValue)) |
| | | { |
| | | // This is illegal -- the value is not allowed. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(v, a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(v, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | pendingValues.add(v.toString()); |
| | |
| | | // This is illegal -- only the pending option is allowed for |
| | | // configuration attributes. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName()); |
| | | ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | |
| | | { |
| | | // We cannot have multiple active value sets. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName()); |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()); |
| | | LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | // This is fine. The active value set can be empty. |
| | |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | if (! allowedValues.contains(lowerValue)) |
| | | { |
| | | // This is illegal -- the value is not allowed. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(v, a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(v, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | activeValues.add(v.toString()); |
| | |
| | | if (pendingValues != null) |
| | | { |
| | | // We cannot have multiple pending value sets. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | // This is fine. The pending value set can be empty. |
| | | pendingValues = new ArrayList<>(0); |
| | |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | { |
| | | // This is illegal -- only the pending option is allowed for |
| | | // configuration attributes. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | else |
| | |
| | | if (activeValues!= null) |
| | | { |
| | | // We cannot have multiple active value sets. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName())); |
| | | throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc.getNameOrOID())); |
| | | } |
| | | // This is fine. The active value set can be empty. |
| | | activeValues = new ArrayList<>(0); |
| | |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | LocalizableMessage message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc.getNameOrOID()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | |
| | | && !isSynchronizationOperation()) |
| | | { |
| | | throw new LDAPException(LDAPResultCode.UNWILLING_TO_PERFORM, |
| | | ERR_ADD_ATTR_IS_NO_USER_MOD.get(entryDN, attr.getName())); |
| | | ERR_ADD_ATTR_IS_NO_USER_MOD.get(entryDN, attr.getAttributeDescription().getNameOrOID())); |
| | | } |
| | | |
| | | boolean hasBinaryOption = attr.getAttributeDescription().hasOption("binary"); |
| | |
| | | { |
| | | // binary option is not honored for non-BER-encodable attributes. |
| | | throw new LDAPException(LDAPResultCode.UNDEFINED_ATTRIBUTE_TYPE, |
| | | ERR_ADD_ATTR_IS_INVALID_OPTION.get(entryDN, attr.getName())); |
| | | ERR_ADD_ATTR_IS_INVALID_OPTION.get(entryDN, attr.getAttributeDescription().getNameOrOID())); |
| | | } |
| | | |
| | | if (attrType.isObjectClass()) |
| | |
| | | { |
| | | // binary option is not honored for non-BER-encodable attributes. |
| | | throw new LDAPException(LDAPResultCode.UNDEFINED_ATTRIBUTE_TYPE, |
| | | ERR_ADD_ATTR_IS_INVALID_OPTION.get(entryDN, attr.getName())); |
| | | ERR_ADD_ATTR_IS_INVALID_OPTION.get(entryDN, attr.getAttributeDescription().getNameOrOID())); |
| | | } |
| | | |
| | | modifications.add(mod); |
| | |
| | | { |
| | | if (!isSchemaAttribute(attribute)) |
| | | { |
| | | schema.addExtraAttribute(attribute.getName(), attribute); |
| | | schema.addExtraAttribute(attribute.getAttributeDescription().getNameOrOID(), attribute); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | Attribute a = mod.getAttribute(); |
| | | buffer.append(a.getName()); |
| | | buffer.append(a.getAttributeDescription().getNameOrOID()); |
| | | buffer.append(EOL); |
| | | |
| | | append(buffer, a); |
| | |
| | | { |
| | | for (ByteString v : a) |
| | | { |
| | | buffer.append(a.getName()); |
| | | buffer.append(a.getAttributeDescription().getNameOrOID()); |
| | | buffer.append(":"); |
| | | encodeValue(v, buffer); |
| | | buffer.append(EOL); |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.server.ConfigChangeResult; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.IndexType; |
| | |
| | | { |
| | | try |
| | | { |
| | | AttributeDescription attrDesc = attr.getAttributeDescription(); |
| | | for (ByteString attrVal : attr) |
| | | { |
| | | DN valueEntryDN = DN.valueOf(attrVal); |
| | |
| | | && valueEntryDN.isInScopeOf(entryBaseDN, SearchScope.SUBORDINATES)) |
| | | { |
| | | return PluginResult.PreOperation.stopProcessing(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_PLUGIN_REFERENT_NAMINGCONTEXT_MISMATCH.get(valueEntryDN, attr.getName(), entryDN)); |
| | | ERR_PLUGIN_REFERENT_NAMINGCONTEXT_MISMATCH.get(valueEntryDN, attrDesc.getNameOrOID(), entryDN)); |
| | | } |
| | | valueEntry = DirectoryServer.getEntry(valueEntryDN); |
| | | |
| | |
| | | if (valueEntry == null) |
| | | { |
| | | return PluginResult.PreOperation.stopProcessing(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_PLUGIN_REFERENT_ENTRY_MISSING.get(valueEntryDN, attr.getName(), entryDN)); |
| | | ERR_PLUGIN_REFERENT_ENTRY_MISSING.get(valueEntryDN, attrDesc.getNameOrOID(), entryDN)); |
| | | } |
| | | |
| | | // Verify that the value entry conforms to the filter. |
| | | SearchFilter filter = attrFiltMap.get(attr.getAttributeDescription().getAttributeType()); |
| | | SearchFilter filter = attrFiltMap.get(attrDesc.getAttributeType()); |
| | | if (filter != null && !filter.matchesEntry(valueEntry)) |
| | | { |
| | | return PluginResult.PreOperation.stopProcessing(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_PLUGIN_REFERENT_FILTER_MISMATCH.get(valueEntry.getName(), attr.getName(), entryDN, filter)); |
| | | ERR_PLUGIN_REFERENT_FILTER_MISMATCH.get(valueEntry.getName(), attrDesc.getNameOrOID(), entryDN, filter)); |
| | | } |
| | | } |
| | | } |
| | |
| | | ListIterator<Modification> modIter = modifications.listIterator(); |
| | | while (modIter.hasNext()) |
| | | { |
| | | String name = modIter.next().getAttribute().getName().toLowerCase(); |
| | | String name = modIter.next().getAttribute().getAttributeDescription().getNameOrOID().toLowerCase(); |
| | | if (ignoreAttrs.contains(name)) |
| | | { |
| | | modIter.remove(); |
| | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation returns the primary name associated with this |
| | | * attribute's attribute type or, if there is no primary name, the |
| | | * attribute type's OID. |
| | | */ |
| | | @Override |
| | | public String getName() |
| | | { |
| | | return getAttributeDescription().getNameOrOID(); |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() |
| | | { |
| | |
| | | AttributeDescription getAttributeDescription(); |
| | | |
| | | /** |
| | | * Retrieves the user-provided name for this attribute. |
| | | * |
| | | * @return The user-provided name for this attribute. |
| | | */ |
| | | String getName(); |
| | | |
| | | /** |
| | | * Indicates whether this attribute has any value(s) that are |
| | | * greater than or equal to the provided value. |
| | | * |
| | |
| | | if (a == null) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_INCREMENT_NO_SUCH_ATTRIBUTE.get( |
| | | attribute.getName()); |
| | | attribute.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.NO_SUCH_ATTRIBUTE, message); |
| | | } |
| | | |
| | |
| | | if (!i.hasNext()) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_INCREMENT_INVALID_VALUE_COUNT.get( |
| | | attribute.getName()); |
| | | attribute.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message); |
| | | } |
| | | |
| | |
| | | catch (NumberFormatException e) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_INCREMENT_CANNOT_PARSE_AS_INT.get( |
| | | attribute.getName()); |
| | | attribute.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message); |
| | | } |
| | | |
| | | if (i.hasNext()) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_INCREMENT_INVALID_VALUE_COUNT.get( |
| | | attribute.getName()); |
| | | attribute.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message); |
| | | } |
| | | |
| | |
| | | catch (NumberFormatException e) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_INCREMENT_CANNOT_PARSE_AS_INT.get( |
| | | attribute.getName()); |
| | | attribute.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException( |
| | | ResultCode.CONSTRAINT_VIOLATION, message); |
| | | } |
| | |
| | | { |
| | | if (!relaxConstraints) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_DUPLICATE_VALUES.get(a.getName()); |
| | | LocalizableMessage message = ERR_ENTRY_DUPLICATE_VALUES.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ATTRIBUTE_OR_VALUE_EXISTS, message); |
| | | } |
| | | } |
| | |
| | | { |
| | | if (objectClasses.remove(oc) == null && !relaxConstraints) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_NO_SUCH_VALUE.get(a.getName()); |
| | | LocalizableMessage message = ERR_ENTRY_NO_SUCH_VALUE.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(NO_SUCH_ATTRIBUTE, message); |
| | | } |
| | | } |
| | |
| | | addAttribute(a, duplicateValues); |
| | | if (!duplicateValues.isEmpty() && !relaxConstraints) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_DUPLICATE_VALUES.get(a.getName()); |
| | | LocalizableMessage message = ERR_ENTRY_DUPLICATE_VALUES.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(ATTRIBUTE_OR_VALUE_EXISTS, message); |
| | | } |
| | | break; |
| | |
| | | removeAttribute(a, missingValues); |
| | | if (!missingValues.isEmpty() && !relaxConstraints) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_NO_SUCH_VALUE.get(a.getName()); |
| | | LocalizableMessage message = ERR_ENTRY_NO_SUCH_VALUE.get(a.getAttributeDescription().getNameOrOID()); |
| | | throw new DirectoryException(NO_SUCH_ATTRIBUTE, message); |
| | | } |
| | | break; |
| | |
| | | Attribute ocAttr = getObjectClassAttribute(); |
| | | if (ocAttr != null) |
| | | { |
| | | if (!attrName.equals(ocAttr.getName())) |
| | | if (!attrName.equals(ocAttr.getAttributeDescription().getNameOrOID())) |
| | | { |
| | | // User requested non-default object class type name. |
| | | AttributeBuilder builder = new AttributeBuilder(ocAttr); |
| | |
| | | AttributeDescription subAttrDesc = attribute.getAttributeDescription(); |
| | | AttributeType subAttrType = subAttrDesc.getAttributeType(); |
| | | |
| | | if ((attrName != null && !attrName.equals(attribute.getName())) |
| | | if ((attrName != null && !attrName.equals(attribute.getAttributeDescription().getNameOrOID())) |
| | | || attrDesc.hasOptions()) |
| | | { |
| | | AttributeBuilder builder = new AttributeBuilder(); |
| | |
| | | // want to rename "name" to "cn". |
| | | if (attrName == null || !subAttrType.equals(attrDesc.getAttributeType())) |
| | | { |
| | | builder.setAttributeType(subAttrType, attribute.getName()); |
| | | builder.setAttributeType(subAttrType, attribute.getAttributeDescription().getNameOrOID()); |
| | | } |
| | | else |
| | | { |
| | |
| | | Iterator<Attribute> iterator = attributes.iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | | buffer.append(iterator.next().getName()); |
| | | buffer.append(iterator.next().getAttributeDescription().getNameOrOID()); |
| | | if (iterator.hasNext()) |
| | | { |
| | | buffer.append(", "); |
| | |
| | | int colonPos = parseColonPosition(lines, line); |
| | | String attrDescr = line.substring(0, colonPos); |
| | | Attribute attribute = parseAttrDescription(attrDescr); |
| | | String attrName = attribute.getName(); |
| | | String attrName = attribute.getAttributeDescription().getNameOrOID(); |
| | | |
| | | if (attributeName != null) |
| | | { |
| | |
| | | { |
| | | StringBuilder line = lines.remove(); |
| | | Attribute attr = readSingleValueAttribute(lines, line, entryDN, null); |
| | | String name = attr.getName(); |
| | | String name = attr.getAttributeDescription().getNameOrOID(); |
| | | |
| | | // Get the attribute description |
| | | String attrDescr = attr.iterator().next().toString(); |
| | |
| | | { |
| | | // Value is not human-readable |
| | | message = WARN_ADD_OP_INVALID_SYNTAX_NO_VALUE. |
| | | get(entryDN, a.getName(), invalidReason); |
| | | get(entryDN, a.getAttributeDescription().getNameOrOID(), invalidReason); |
| | | } |
| | | else |
| | | { |
| | | message = WARN_ADD_OP_INVALID_SYNTAX. |
| | | get(entryDN, v, a.getName(), invalidReason); |
| | | get(entryDN, v, a.getAttributeDescription().getNameOrOID(), invalidReason); |
| | | } |
| | | |
| | | switch (DirectoryServer.getSyntaxEnforcementPolicy()) |
| | |
| | | && !isSynchronizationOperation()) |
| | | { |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_MODDN_OLD_RDN_ATTR_IS_NO_USER_MOD.get(entryDN, a.getName())); |
| | | ERR_MODDN_OLD_RDN_ATTR_IS_NO_USER_MOD.get(entryDN, a.getAttributeDescription().getNameOrOID())); |
| | | } |
| | | |
| | | List<ByteString> missingValues = new LinkedList<>(); |
| | |
| | | if (!isInternalOperation() && !isSynchronizationOperation()) |
| | | { |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_MODDN_NEW_RDN_ATTR_IS_NO_USER_MOD.get(entryDN, a.getName())); |
| | | ERR_MODDN_NEW_RDN_ATTR_IS_NO_USER_MOD.get(entryDN, a.getAttributeDescription().getNameOrOID())); |
| | | } |
| | | } |
| | | else |
| | |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg3; |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg4; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | |
| | | for (Modification m : modifications) |
| | | { |
| | | Attribute a = m.getAttribute(); |
| | | AttributeType t = a.getAttributeDescription().getAttributeType(); |
| | | AttributeDescription attrDesc = a.getAttributeDescription(); |
| | | AttributeType t = attrDesc.getAttributeType(); |
| | | |
| | | |
| | | // If the attribute type is marked "NO-USER-MODIFICATION" then fail unless |
| | |
| | | { |
| | | throw newDirectoryException(currentEntry, |
| | | ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_MODIFY_ATTR_IS_NO_USER_MOD.get(entryDN, a.getName())); |
| | | ERR_MODIFY_ATTR_IS_NO_USER_MOD.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | // If the attribute type is marked "OBSOLETE" and the modification is |
| | |
| | | { |
| | | throw newDirectoryException(currentEntry, |
| | | ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_MODIFY_ATTR_IS_OBSOLETE.get(entryDN, a.getName())); |
| | | ERR_MODIFY_ATTR_IS_OBSOLETE.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // case INCREMENT does not make any sense for passwords |
| | | default: |
| | | Attribute a = m.getAttribute(); |
| | | AttributeDescription attrDesc = m.getAttribute().getAttributeDescription(); |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_MODIFY_INVALID_MOD_TYPE_FOR_PASSWORD.get(m.getModificationType(), a.getName())); |
| | | ERR_MODIFY_INVALID_MOD_TYPE_FOR_PASSWORD.get(m.getModificationType(), attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | |
| | |
| | | private void processAddModification(Attribute attr) throws DirectoryException |
| | | { |
| | | // Make sure that one or more values have been provided for the attribute. |
| | | AttributeDescription attrDesc = attr.getAttributeDescription(); |
| | | if (attr.isEmpty()) |
| | | { |
| | | throw newDirectoryException(currentEntry, ResultCode.PROTOCOL_ERROR, |
| | | ERR_MODIFY_ADD_NO_VALUES.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_ADD_NO_VALUES.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | if (mustCheckSchema()) |
| | |
| | | |
| | | // If the attribute to be added is the object class attribute |
| | | // then make sure that all the object classes are known and not obsoleted. |
| | | if (attr.getAttributeDescription().getAttributeType().isObjectClass()) |
| | | if (attrDesc.getAttributeType().isObjectClass()) |
| | | { |
| | | validateObjectClasses(attr); |
| | | } |
| | |
| | | |
| | | throw newDirectoryException(currentEntry, |
| | | ResultCode.ATTRIBUTE_OR_VALUE_EXISTS, |
| | | ERR_MODIFY_ADD_DUPLICATE_VALUE.get(entryDN, attr.getName(), duplicateValuesStr)); |
| | | ERR_MODIFY_ADD_DUPLICATE_VALUE.get(entryDN, attrDesc.getNameOrOID(), duplicateValuesStr)); |
| | | } |
| | | } |
| | | |
| | |
| | | Arg3<Object, Object, Object> invalidSyntaxNoValueErrorMsg) throws DirectoryException |
| | | { |
| | | AcceptRejectWarn syntaxPolicy = DirectoryServer.getSyntaxEnforcementPolicy(); |
| | | Syntax syntax = attr.getAttributeDescription().getAttributeType().getSyntax(); |
| | | AttributeDescription attrDesc = attr.getAttributeDescription(); |
| | | Syntax syntax = attrDesc.getAttributeType().getSyntax(); |
| | | |
| | | LocalizableMessageBuilder invalidReason = new LocalizableMessageBuilder(); |
| | | for (ByteString v : attr) |
| | |
| | | if (!syntax.valueIsAcceptable(v, invalidReason)) |
| | | { |
| | | LocalizableMessage msg = isHumanReadable(syntax) |
| | | ? invalidSyntaxErrorMsg.get(entryDN, attr.getName(), v, invalidReason) |
| | | : invalidSyntaxNoValueErrorMsg.get(entryDN, attr.getName(), invalidReason); |
| | | ? invalidSyntaxErrorMsg.get(entryDN, attrDesc.getNameOrOID(), v, invalidReason) |
| | | : invalidSyntaxNoValueErrorMsg.get(entryDN, attrDesc.getNameOrOID(), invalidReason); |
| | | |
| | | switch (syntaxPolicy) |
| | | { |
| | |
| | | List<ByteString> missingValues = new LinkedList<>(); |
| | | boolean attrExists = modifiedEntry.removeAttribute(attr, missingValues); |
| | | |
| | | AttributeDescription attrDesc = attr.getAttributeDescription(); |
| | | if (attrExists) |
| | | { |
| | | if (missingValues.isEmpty()) |
| | | { |
| | | AttributeType t = attr.getAttributeDescription().getAttributeType(); |
| | | AttributeType t = attrDesc.getAttributeType(); |
| | | |
| | | RDN rdn = modifiedEntry.getName().rdn(); |
| | | if (rdn != null |
| | | && rdn.hasAttributeType(t) |
| | | && !modifiedEntry.hasValue(attr.getAttributeDescription(), rdn.getAttributeValue(t))) |
| | | && !modifiedEntry.hasValue(attrDesc, rdn.getAttributeValue(t))) |
| | | { |
| | | throw newDirectoryException(currentEntry, |
| | | ResultCode.NOT_ALLOWED_ON_RDN, |
| | | ERR_MODIFY_DELETE_RDN_ATTR.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_DELETE_RDN_ATTR.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | else if (!permissiveModify) |
| | |
| | | String missingValuesStr = Utils.joinAsString(", ", missingValues); |
| | | |
| | | throw newDirectoryException(currentEntry, ResultCode.NO_SUCH_ATTRIBUTE, |
| | | ERR_MODIFY_DELETE_MISSING_VALUES.get(entryDN, attr.getName(), missingValuesStr)); |
| | | ERR_MODIFY_DELETE_MISSING_VALUES.get(entryDN, attrDesc.getNameOrOID(), missingValuesStr)); |
| | | } |
| | | } |
| | | else if (!permissiveModify) |
| | | { |
| | | throw newDirectoryException(currentEntry, ResultCode.NO_SUCH_ATTRIBUTE, |
| | | ERR_MODIFY_DELETE_NO_SUCH_ATTR.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_DELETE_NO_SUCH_ATTR.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | } |
| | | |
| | |
| | | && !modifiedEntry.hasValue(attr.getAttributeDescription(), rdn.getAttributeValue(t))) |
| | | { |
| | | throw newDirectoryException(modifiedEntry, ResultCode.NOT_ALLOWED_ON_RDN, |
| | | ERR_MODIFY_DELETE_RDN_ATTR.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_DELETE_RDN_ATTR.get(entryDN, attr.getAttributeDescription().getNameOrOID())); |
| | | } |
| | | } |
| | | |
| | |
| | | private void processIncrementModification(Attribute attr) throws DirectoryException |
| | | { |
| | | // The specified attribute type must not be an RDN attribute. |
| | | AttributeType t = attr.getAttributeDescription().getAttributeType(); |
| | | AttributeDescription attrDesc = attr.getAttributeDescription(); |
| | | AttributeType t = attrDesc.getAttributeType(); |
| | | RDN rdn = modifiedEntry.getName().rdn(); |
| | | if (rdn != null && rdn.hasAttributeType(t)) |
| | | { |
| | | throw newDirectoryException(modifiedEntry, ResultCode.NOT_ALLOWED_ON_RDN, |
| | | ERR_MODIFY_INCREMENT_RDN.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_INCREMENT_RDN.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | // The provided attribute must have a single value, and it must be an integer |
| | | if (attr.isEmpty()) |
| | | { |
| | | throw newDirectoryException(modifiedEntry, ResultCode.PROTOCOL_ERROR, |
| | | ERR_MODIFY_INCREMENT_REQUIRES_VALUE.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_INCREMENT_REQUIRES_VALUE.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | else if (attr.size() > 1) |
| | | { |
| | | throw newDirectoryException(modifiedEntry, ResultCode.PROTOCOL_ERROR, |
| | | ERR_MODIFY_INCREMENT_REQUIRES_SINGLE_VALUE.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_INCREMENT_REQUIRES_SINGLE_VALUE.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | MatchingRule eqRule = attr.getAttributeDescription().getAttributeType().getEqualityMatchingRule(); |
| | | MatchingRule eqRule = t.getEqualityMatchingRule(); |
| | | ByteString v = attr.iterator().next(); |
| | | |
| | | long incrementValue; |
| | |
| | | logger.traceException(e); |
| | | |
| | | throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, |
| | | ERR_MODIFY_INCREMENT_PROVIDED_VALUE_NOT_INTEGER.get(entryDN, attr.getName(), v), e); |
| | | ERR_MODIFY_INCREMENT_PROVIDED_VALUE_NOT_INTEGER.get(entryDN, attrDesc.getNameOrOID(), v), e); |
| | | } |
| | | |
| | | // Get the attribute that is to be incremented. |
| | | Attribute a = modifiedEntry.getExactAttribute(attr.getAttributeDescription()); |
| | | if (a == null) |
| | | Attribute modifiedAttr = modifiedEntry.getExactAttribute(attrDesc); |
| | | if (modifiedAttr == null) |
| | | { |
| | | throw newDirectoryException(modifiedEntry, |
| | | ResultCode.CONSTRAINT_VIOLATION, |
| | | ERR_MODIFY_INCREMENT_REQUIRES_EXISTING_VALUE.get(entryDN, attr.getName())); |
| | | ERR_MODIFY_INCREMENT_REQUIRES_EXISTING_VALUE.get(entryDN, attrDesc.getNameOrOID())); |
| | | } |
| | | |
| | | // Increment each attribute value by the specified amount. |
| | | AttributeBuilder builder = new AttributeBuilder(a.getAttributeDescription()); |
| | | for (ByteString existingValue : a) |
| | | AttributeDescription modifiedAttrDesc = modifiedAttr.getAttributeDescription(); |
| | | AttributeBuilder builder = new AttributeBuilder(modifiedAttrDesc); |
| | | for (ByteString existingValue : modifiedAttr) |
| | | { |
| | | long currentValue; |
| | | try |
| | |
| | | |
| | | throw new DirectoryException( |
| | | ResultCode.INVALID_ATTRIBUTE_SYNTAX, |
| | | ERR_MODIFY_INCREMENT_REQUIRES_INTEGER_VALUE.get(entryDN, a.getName(), existingValue), |
| | | ERR_MODIFY_INCREMENT_REQUIRES_INTEGER_VALUE.get(entryDN, modifiedAttrDesc.getNameOrOID(), existingValue), |
| | | e); |
| | | } |
| | | |
| | |
| | | // We now have the parent entry - so construct the new entry. |
| | | Attributes attributes = new BasicAttributes(); |
| | | for (org.opends.server.types.Attribute attribute : entry.getAttributes()) { |
| | | BasicAttribute ba = new BasicAttribute(attribute.getName()); |
| | | BasicAttribute ba = new BasicAttribute(attribute.getAttributeDescription().getNameOrOID()); |
| | | for (ByteString value : attribute) { |
| | | ba.add(value.toString()); |
| | | } |
| | |
| | | final Attribute expectedAttr = expectedAttrs.get(i); |
| | | final Attribute actualAttr = actualAttrs.get(i).toAttribute(); |
| | | |
| | | assertTrue(expectedAttr.getName().equalsIgnoreCase(actualAttr.getName())); |
| | | assertTrue(expectedAttr.getAttributeDescription().getNameOrOID().equalsIgnoreCase(actualAttr.getAttributeDescription().getNameOrOID())); |
| | | assertTrue(expectedAttr.toString().equalsIgnoreCase(actualAttr.toString()), |
| | | "Comparing: " + expectedAttr + " and " + actualAttr); |
| | | } |
| | |
| | | final Attribute expectedAttr = expectedAttrs.get(i); |
| | | final Attribute actualAttr = actualAttrs.get(i).toAttribute(); |
| | | |
| | | assertTrue(expectedAttr.getName().equalsIgnoreCase(actualAttr.getName())); |
| | | assertTrue(expectedAttr.getAttributeDescription().getNameOrOID().equalsIgnoreCase(actualAttr.getAttributeDescription().getNameOrOID())); |
| | | assertTrue(expectedAttr.toString().equalsIgnoreCase(actualAttr.toString()), |
| | | "Comparing: " + expectedAttr + " and " + actualAttr); |
| | | } |
| | |
| | | |
| | | Attribute a = builder.toAttribute(); |
| | | Assert.assertEquals(a.getAttributeDescription().getAttributeType(), cnType); |
| | | Assert.assertEquals(a.getName(), "cn"); |
| | | Assert.assertEquals(a.getAttributeDescription().getNameOrOID(), "cn"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | Attribute a = builder.toAttribute(); |
| | | Assert.assertEquals(a.getAttributeDescription().getAttributeType(), cnType); |
| | | Assert.assertEquals(a.getName(), "cn"); |
| | | Assert.assertEquals(a.getAttributeDescription().getNameOrOID(), "cn"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | Attribute a = builder.toAttribute(); |
| | | Assert.assertEquals(a.getAttributeDescription().getAttributeType(), cnType); |
| | | Assert.assertEquals(a.getName(), "CN"); |
| | | Assert.assertEquals(a.getAttributeDescription().getNameOrOID(), "CN"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | Attribute a = builder.toAttribute(); |
| | | Assert.assertEquals(a.getAttributeDescription().getAttributeType(), cnType); |
| | | Assert.assertEquals(a.getName(), "CN"); |
| | | Assert.assertEquals(a.getAttributeDescription().getNameOrOID(), "CN"); |
| | | } |
| | | |
| | | |
| | |
| | | AttributeType type, String name, String[] options, String[] values) |
| | | throws Exception |
| | | { |
| | | Assert.assertEquals(a.getName(), name); |
| | | Assert.assertEquals(a.getAttributeDescription().getNameOrOID(), name); |
| | | } |
| | | |
| | | |