Removed Attribute.getOptions()
| | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.LDIFExportConfig; |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.util.LDIFException; |
| | | |
| | | /** |
| | |
| | | continue; |
| | | } |
| | | |
| | | StringBuilder attrName = attrNameWithOptions(a); |
| | | String attrName = a.getNameWithOptions(); |
| | | if (typesOnly) |
| | | { |
| | | attrName.append(":"); |
| | | StringBuilder attrLine = new StringBuilder(attrName); |
| | | attrLine.append(":"); |
| | | |
| | | writeLDIFLine(attrName, writer, wrapLines, wrapColumn); |
| | | writeLDIFLine(attrLine, writer, wrapLines, wrapColumn); |
| | | } |
| | | else |
| | | { |
| | |
| | | continue; |
| | | } |
| | | |
| | | StringBuilder attrName = attrNameWithOptions(a); |
| | | String attrName = a.getNameWithOptions(); |
| | | if (typesOnly) |
| | | { |
| | | attrName.append(":"); |
| | | StringBuilder attrLine = new StringBuilder(attrName); |
| | | attrLine.append(":"); |
| | | |
| | | writeLDIFLine(attrName, writer, wrapLines, wrapColumn); |
| | | writeLDIFLine(attrLine, writer, wrapLines, wrapColumn); |
| | | } |
| | | else |
| | | { |
| | |
| | | return true; |
| | | } |
| | | |
| | | private StringBuilder attrNameWithOptions(Attribute a) |
| | | { |
| | | StringBuilder attrName = new StringBuilder(a.getName()); |
| | | for (String o : a.getOptions()) |
| | | { |
| | | attrName.append(";"); |
| | | attrName.append(o); |
| | | } |
| | | return attrName; |
| | | } |
| | | |
| | | private boolean contains(List<Attribute> urlAttrList, ByteString v) |
| | | { |
| | | if (urlAttrList != null) |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | |
| | | |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append(getName()); |
| | | for (String option : getOptions()) |
| | | for (String option : getAttributeDescription().getOptions()) |
| | | { |
| | | buffer.append(';'); |
| | | buffer.append(option); |
| | |
| | | return hashCode; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation calls {@link #getOptions()} to |
| | | * retrieve this attribute's set of options and then compares them |
| | | * one at a time against the provided option. All comparisons are |
| | | * case insensitive. |
| | | */ |
| | | @Override |
| | | public boolean hasOption(String option) |
| | | { |
| | | // FIXME use AttributeDescription instead |
| | | return containsOption(getOptions(), option); |
| | | } |
| | | |
| | | private static boolean containsOption(Set<String> options, String optionToFind) |
| | | { |
| | | String normToFind = toLowerCase(optionToFind); |
| | | |
| | | // Cannot use Set.contains() because the options are not normalized. |
| | | for (String o : options) |
| | | { |
| | | String norm = toLowerCase(o); |
| | | if (norm.equals(normToFind)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | return getAttributeDescription().hasOption(option); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public boolean hasOptions() |
| | | { |
| | | return !getOptions().isEmpty(); |
| | | return getAttributeDescription().hasOptions(); |
| | | } |
| | | |
| | | /** |
| | |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | String getNameWithOptions(); |
| | | |
| | | /** |
| | | * Retrieves the unmodifiable set of attribute options for this attribute. The returned set of |
| | | * options are not normalized. |
| | | * |
| | | * @return The unmodifiable set of attribute options for this attribute. |
| | | * @Deprecated use {@link #getAttributeDescription()} |
| | | */ |
| | | Set<String> getOptions(); |
| | | |
| | | /** |
| | | * Indicates whether this attribute has any value(s) that are |
| | | * greater than or equal to the provided value. |
| | | * |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() |
| | | { |
| | | return Collections.unmodifiableSet(toSet(attributeDescription.getOptions())); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOption(String option) |
| | | { |
| | | return attributeDescription.hasOption(option); |
| | |
| | | { |
| | | return getName(); |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() |
| | | { |
| | | return Collections.emptySet(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | this(attribute.getAttributeType(), attribute.getName()); |
| | | |
| | | for (String option : attribute.getOptions()) |
| | | { |
| | | setOption(option); |
| | | } |
| | | |
| | | setOptions(attribute.getAttributeDescription().getOptions()); |
| | | if (!omitValues) |
| | | { |
| | | addAll(attribute); |
| | |
| | | return isModified; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this attribute builder has exactly the |
| | | * specified set of options. |
| | | * Indicates whether this attribute builder has exactly the specified set of options. |
| | | * |
| | | * This implementation returns |
| | | * {@link java.util.AbstractCollection#isEmpty()} |
| | | * if the provided set of options is <code>null</code>. |
| | | * Otherwise it checks that the size of the provided |
| | | * set of options is equal to the size of this attribute |
| | | * builder options, returns <code>false</code> if the |
| | | * sizes differ. If the sizes are the same then each |
| | | * option in the provided set is checked and if all the |
| | | * provided options are present <code>true</code> is |
| | | * returned. |
| | | * |
| | | * @param options |
| | | * The set of options for which to make the |
| | | * determination (may be <code>null</code>). |
| | | * @return <code>true</code> if this attribute |
| | | * builder has exactly the specified |
| | | * set of options. |
| | | * @param attributeDescription |
| | | * The attribute description containing the set of options for which to make the |
| | | * determination |
| | | * @return <code>true</code> if this attribute builder has exactly the specified set of options. |
| | | */ |
| | | public boolean optionsEqual(Set<String> options) |
| | | public boolean optionsEqual(AttributeDescription attributeDescription) |
| | | { |
| | | if (options == null) |
| | | { |
| | | return this.options.isEmpty(); |
| | | } |
| | | |
| | | if (this.options.size() != options.size()) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | for (String option : options) |
| | | { |
| | | if (!this.options.contains(option)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | return toAttribute0().getAttributeDescription().equals(attributeDescription); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns the number of attribute values in this attribute builder. |
| | | * |
| | |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.server.types; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | this.attribute = attribute; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConditionResult approximatelyEqualTo(ByteString assertionValue) { |
| | | return attribute.approximatelyEqualTo(assertionValue); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean contains(ByteString value) { |
| | | return attribute.contains(value); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() { |
| | | return attribute.getOptions(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConditionResult greaterThanOrEqualTo(ByteString assertionValue) { |
| | | return attribute.greaterThanOrEqualTo(assertionValue); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVirtual() { |
| | | return true; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Iterator<ByteString> iterator() { |
| | | return attribute.iterator(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConditionResult lessThanOrEqualTo(ByteString assertionValue) { |
| | | return attribute.lessThanOrEqualTo(assertionValue); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConditionResult matchesSubstring(ByteString subInitial, |
| | | List<ByteString> subAny, ByteString subFinal) { |
| | | return attribute.matchesSubstring(subInitial, subAny, subFinal); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int size() { |
| | | return attribute.size(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int hashCode() |
| | | { |
| | | return attribute.hashCode(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void toString(StringBuilder buffer) { |
| | | attribute.toString(buffer); |
| | |
| | | { |
| | | for (Attribute a : attrList) |
| | | { |
| | | StringBuilder attrName = new StringBuilder(a.getName()); |
| | | for (String o : a.getOptions()) |
| | | { |
| | | attrName.append(";"); |
| | | attrName.append(o); |
| | | } |
| | | |
| | | String attrName = a.getNameWithOptions(); |
| | | for (ByteString v : a) |
| | | { |
| | | StringBuilder attrLine = new StringBuilder(attrName); |
| | |
| | | BufferedWriter writer, boolean wrapLines, int wrapColumn) |
| | | throws IOException |
| | | { |
| | | StringBuilder attrName = new StringBuilder(attribute.getName()); |
| | | for (String o : attribute.getOptions()) |
| | | { |
| | | attrName.append(";"); |
| | | attrName.append(o); |
| | | } |
| | | |
| | | String attrName = attribute.getNameWithOptions(); |
| | | if (typesOnly) |
| | | { |
| | | attrName.append(":"); |
| | | StringBuilder attrLine = new StringBuilder(attrName); |
| | | attrLine.append(":"); |
| | | |
| | | LDIFWriter.writeLDIFLine(attrName, writer, wrapLines, wrapColumn); |
| | | LDIFWriter.writeLDIFLine(attrLine, writer, wrapLines, wrapColumn); |
| | | } |
| | | else |
| | | { |
| | |
| | | buffer.append(","); |
| | | } |
| | | |
| | | buffer.append(a.getName()); |
| | | |
| | | if (a.hasOptions()) |
| | | { |
| | | for (String optionString : a.getOptions()) |
| | | { |
| | | buffer.append(";"); |
| | | buffer.append(optionString); |
| | | } |
| | | } |
| | | buffer.append(a.getNameWithOptions()); |
| | | |
| | | buffer.append("={"); |
| | | Iterator<ByteString> valueIterator = a.iterator(); |
| | |
| | | |
| | | // Now add in remaining options from original attribute |
| | | // (this will not overwrite options already present). |
| | | builder.setOptions(attribute.getOptions()); |
| | | builder.setOptions(attribute.getAttributeDescription().getOptions()); |
| | | |
| | | if (!omitValues) |
| | | { |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.core.DirectoryServer; |
| | | |
| | | import static org.opends.messages.SchemaMessages.*; |
| | |
| | | { |
| | | AttributeBuilder builder = new AttributeBuilder(subAttr.getAttributeType()); |
| | | builder.addAll(subAttr); |
| | | Set<String> options = new LinkedHashSet<>(subAttr.getOptions()); |
| | | options.remove(ATTR_OPTION_COLLECTIVE); |
| | | builder.setOptions(options); |
| | | for (String option : subAttr.getAttributeDescription().getOptions()) |
| | | { |
| | | if (!option.equals(ATTR_OPTION_COLLECTIVE)) |
| | | { |
| | | builder.setOption(option); |
| | | } |
| | | } |
| | | Attribute attr = builder.toAttribute(); |
| | | CollectiveVirtualAttribute collectiveAttr = new CollectiveVirtualAttribute(attr); |
| | | this.collectiveAttributes.add(collectiveAttr); |
| | |
| | | package org.opends.server.types; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | return attributeDescription; |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() |
| | | { |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the virtual attribute rule that governs the behavior of |
| | | * this virtual attribute. |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.api.plugin.PluginResult; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.PluginConfigManager; |
| | |
| | | import org.opends.server.types.AcceptRejectWarn; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | |
| | | int colonPos = parseColonPosition(lines, line); |
| | | String attrDescr = line.substring(0, colonPos); |
| | | final Attribute attribute = parseAttrDescription(attrDescr); |
| | | final String attrName = attribute.getName(); |
| | | final AttributeDescription attrDesc = attribute.getAttributeDescription(); |
| | | final AttributeType attrType = attrDesc.getAttributeType(); |
| | | final String attrName = attrType.getNameOrOID(); |
| | | |
| | | // Now parse the attribute value. |
| | | ByteString value = parseSingleValue(lines, line, entryDN, colonPos, attrName); |
| | |
| | | } |
| | | else |
| | | { |
| | | AttributeType attrType = DirectoryServer.getAttributeType(attrName); |
| | | if (! importConfig.includeAttribute(attrType)) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | |
| | | // options. If so, then try to add a value to that attribute. |
| | | for (AttributeBuilder a : attrList) |
| | | { |
| | | if (a.optionsEqual(attribute.getOptions())) |
| | | if (a.optionsEqual(attrDesc)) |
| | | { |
| | | if (!a.add(attributeValue) && checkSchema) |
| | | { |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.tools.makeldif.TemplateEntry; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.tools.makeldif.TemplateEntry; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.LDIFExportConfig; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.types.RawModification; |
| | | |
| | | import static org.forgerock.util.Reject.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | |
| | | { |
| | | for (Attribute a : entry.getUserAttribute(attrType)) |
| | | { |
| | | StringBuilder attrName = new StringBuilder(a.getName()); |
| | | for (String o : a.getOptions()) |
| | | { |
| | | attrName.append(";"); |
| | | attrName.append(o); |
| | | } |
| | | |
| | | StringBuilder attrName = new StringBuilder(a.getNameWithOptions()); |
| | | for (ByteString v : a) |
| | | { |
| | | writeAttribute(attrName, v, writer, wrapLines, wrapColumn); |
| | |
| | | { |
| | | StringBuilder attrName = new StringBuilder(); |
| | | attrName.append("# "); |
| | | attrName.append(a.getName()); |
| | | for (String o : a.getOptions()) |
| | | { |
| | | attrName.append(";"); |
| | | attrName.append(o); |
| | | } |
| | | attrName.append(a.getNameWithOptions()); |
| | | |
| | | for (ByteString v : a) |
| | | { |
| | |
| | | Modification m = iterator.next(); |
| | | Attribute a = m.getAttribute(); |
| | | |
| | | StringBuilder nameBuffer = new StringBuilder(a.getName()); |
| | | for (String o : a.getOptions()) |
| | | { |
| | | nameBuffer.append(";"); |
| | | nameBuffer.append(o); |
| | | } |
| | | String name = nameBuffer.toString(); |
| | | String name = a.getNameWithOptions(); |
| | | |
| | | StringBuilder modTypeLine = new StringBuilder(); |
| | | modTypeLine.append(m.getModificationType()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2015 ForgeRock AS |
| | | * Portions Copyright 2012-2016 ForgeRock AS |
| | | */ |
| | | package org.opends.server.protocols.ldap; |
| | | |
| | |
| | | List<Attribute> attrs = e.getAttribute("usercertificate"); |
| | | Attribute a = attrs.get(0); |
| | | assertNotNull(a); |
| | | assertTrue(a.getOptions().contains("binary")); |
| | | assertThat(a.getAttributeDescription().getOptions()).contains("binary"); |
| | | } |
| | | |
| | | /** |
| | |
| | | builder.setOptions(Arrays.asList(threeOptions)); |
| | | Attribute a = builder.toAttribute(); |
| | | |
| | | Assert.assertTrue(a.getOptions().containsAll(Arrays.asList(threeOptions))); |
| | | Assert.assertEquals(a.getOptions().size(), threeOptions.length); |
| | | assertThat(a.getAttributeDescription().getOptions()).containsOnly(threeOptions); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Tests {@link Attribute#getOptions()}. |
| | | * Tests {@link AttributeDescription#getOptions()}. |
| | | * |
| | | * @param testCase |
| | | * Test case index (useful for debugging). |
| | |
| | | AttributeType type, String name, String[] options, String[] values) |
| | | throws Exception |
| | | { |
| | | // Check getOptions(). |
| | | Set<String> s = a.getOptions(); |
| | | |
| | | Assert.assertEquals(s.size(), options.length); |
| | | Assert.assertTrue(s.containsAll(Arrays.asList(options))); |
| | | |
| | | try |
| | | { |
| | | // The option set must be unmodifiable. |
| | | s.add("xxxx"); |
| | | Assert.fail("getOptions() returned a modifiable option set"); |
| | | } |
| | | catch (UnsupportedOperationException e) |
| | | { |
| | | // Expected exception. |
| | | } |
| | | assertThat(a.getAttributeDescription().getOptions()).containsOnly(options); |
| | | } |
| | | |
| | | |