From 44b5685abf149f03e566e895d3cae586d164e883 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 11 Mar 2014 17:02:13 +0000
Subject: [PATCH] OPENDJ-1368 Remove AttributeValue
---
opendj3-server-dev/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java | 15 ++-
opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java | 65 +++++-------
opendj3-server-dev/src/server/org/opends/server/extensions/StaticGroup.java | 23 ++--
opendj3-server-dev/src/server/org/opends/server/controls/MatchedValuesFilter.java | 15 +-
opendj3-server-dev/src/server/org/opends/server/extensions/NumSubordinatesVirtualAttributeProvider.java | 22 ++-
opendj3-server-dev/src/server/org/opends/server/types/SortKey.java | 83 ++++++----------
opendj3-server-dev/src/server/org/opends/server/types/Entry.java | 68 -------------
7 files changed, 102 insertions(+), 189 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java b/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java
index 92e8579..f0caed3 100644
--- a/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java
+++ b/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java
@@ -33,11 +33,11 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.admin.std.server.VirtualAttributeCfg;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.SearchOperation;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.Entry;
@@ -108,10 +108,9 @@
VirtualAttributeCfg configuration,
List<LocalizableMessage> unacceptableReasons)
{
- // This default implementation does not perform any special
- // validation. It should be overridden by virtual attribute
- // provider implementations that wish to perform more detailed
- // validation.
+ // This default implementation does not perform any special validation.
+ // It should be overridden by virtual attribute provider implementations
+ // that wish to perform more detailed validation.
return true;
}
@@ -300,8 +299,7 @@
{
logger.traceException(e);
- // The substring couldn't be normalized. We have to return
- // "undefined".
+ // The substring couldn't be normalized => return "undefined".
return ConditionResult.UNDEFINED;
}
}
@@ -327,8 +325,7 @@
{
logger.traceException(e);
- // The substring couldn't be normalized. We have to return
- // "undefined".
+ // The substring couldn't be normalized => return "undefined".
return ConditionResult.UNDEFINED;
}
}
@@ -351,8 +348,7 @@
{
logger.traceException(e);
- // The substring couldn't be normalized. We have to return
- // "undefined".
+ // The substring couldn't be normalized => return "undefined".
return ConditionResult.UNDEFINED;
}
}
@@ -363,8 +359,9 @@
{
try
{
+ ByteString nv = matchingRule.normalizeAttributeValue(value.getValue());
if (matchingRule.valueMatchesSubstring(
- value.getNormalizedValue(),
+ nv,
normalizedSubInitial,
normalizedSubAny,
normalizedSubFinal))
@@ -376,8 +373,8 @@
{
logger.traceException(e);
- // The value couldn't be normalized. If we can't find a
- // definite match, then we should return "undefined".
+ // We couldn't normalize one of the attribute values.
+ // We will return "undefined" if we can't find a definite match
result = ConditionResult.UNDEFINED;
}
}
@@ -418,14 +415,13 @@
ByteString normalizedValue;
try
{
- normalizedValue = value.getNormalizedValue();
+ normalizedValue = matchingRule.normalizeAttributeValue(value.getValue());
}
catch (Exception e)
{
logger.traceException(e);
- // We couldn't normalize the provided value. We should return
- // "undefined".
+ // We couldn't normalize the provided value => return "undefined".
return ConditionResult.UNDEFINED;
}
@@ -434,10 +430,8 @@
{
try
{
- ByteString nv = v.getNormalizedValue();
- int comparisonResult =
- matchingRule.compareValues(nv, normalizedValue);
- if (comparisonResult >= 0)
+ ByteString nv = matchingRule.normalizeAttributeValue(v.getValue());
+ if (matchingRule.compareValues(nv, normalizedValue) >= 0)
{
return ConditionResult.TRUE;
}
@@ -446,9 +440,8 @@
{
logger.traceException(e);
- // We couldn't normalize one of the attribute values. If we
- // can't find a definite match, then we should return
- // "undefined".
+ // We couldn't normalize one of the attribute values.
+ // We will return "undefined" if we can't find a definite match
result = ConditionResult.UNDEFINED;
}
}
@@ -489,14 +482,13 @@
ByteString normalizedValue;
try
{
- normalizedValue = value.getNormalizedValue();
+ normalizedValue = matchingRule.normalizeAttributeValue(value.getValue());
}
catch (Exception e)
{
logger.traceException(e);
- // We couldn't normalize the provided value. We should return
- // "undefined".
+ // We couldn't normalize the provided value => return "undefined".
return ConditionResult.UNDEFINED;
}
@@ -505,10 +497,8 @@
{
try
{
- ByteString nv = v.getNormalizedValue();
- int comparisonResult =
- matchingRule.compareValues(nv, normalizedValue);
- if (comparisonResult <= 0)
+ ByteString nv = matchingRule.normalizeAttributeValue(v.getValue());
+ if (matchingRule.compareValues(nv, normalizedValue) <= 0)
{
return ConditionResult.TRUE;
}
@@ -517,9 +507,8 @@
{
logger.traceException(e);
- // We couldn't normalize one of the attribute values. If we
- // can't find a definite match, then we should return
- // "undefined".
+ // We couldn't normalize one of the attribute values.
+ // We will return "undefined" if we can't find a definite match
result = ConditionResult.UNDEFINED;
}
}
@@ -566,8 +555,7 @@
{
logger.traceException(e);
- // We couldn't normalize the provided value. We should return
- // "undefined".
+ // We couldn't normalize the provided value => return "undefined".
return ConditionResult.UNDEFINED;
}
@@ -586,9 +574,8 @@
{
logger.traceException(e);
- // We couldn't normalize one of the attribute values. If we
- // can't find a definite match, then we should return
- // "undefined".
+ // We couldn't normalize one of the attribute values.
+ // We will return "undefined" if we can't find a definite match
result = ConditionResult.UNDEFINED;
}
}
diff --git a/opendj3-server-dev/src/server/org/opends/server/controls/MatchedValuesFilter.java b/opendj3-server-dev/src/server/org/opends/server/controls/MatchedValuesFilter.java
index e04dd9d..96f4340 100644
--- a/opendj3-server-dev/src/server/org/opends/server/controls/MatchedValuesFilter.java
+++ b/opendj3-server-dev/src/server/org/opends/server/controls/MatchedValuesFilter.java
@@ -1347,8 +1347,9 @@
{
try
{
+ ByteString nv = orderingMatchingRule.normalizeAssertionValue(value.getValue());
return orderingMatchingRule.compareValues(
- assertionValue.getNormalizedValue(),
+ nv,
orderingMatchingRule.normalizeAttributeValue(
value.getValue())) >= 0;
}
@@ -1369,8 +1370,9 @@
{
try
{
+ ByteString nv = orderingMatchingRule.normalizeAssertionValue(value.getValue());
return orderingMatchingRule.compareValues(
- assertionValue.getNormalizedValue(),
+ nv,
orderingMatchingRule.normalizeAttributeValue(
value.getValue())) <= 0;
}
@@ -1395,12 +1397,9 @@
{
try
{
- ByteString nv1 = approximateMatchingRule.normalizeAttributeValue(
- assertionValue.getNormalizedValue());
- ByteString nv2 = approximateMatchingRule.normalizeAttributeValue(
- value.getValue());
-
- return approximateMatchingRule.approximatelyMatch(nv1, nv2);
+ Assertion assertion = approximateMatchingRule.getAssertion(assertionValue.getValue());
+ ByteString nv = approximateMatchingRule.normalizeAttributeValue(value.getValue());
+ return assertion.matches(nv).toBoolean();
}
catch (Exception e)
{
diff --git a/opendj3-server-dev/src/server/org/opends/server/extensions/NumSubordinatesVirtualAttributeProvider.java b/opendj3-server-dev/src/server/org/opends/server/extensions/NumSubordinatesVirtualAttributeProvider.java
index cb4d719..36e8ab6 100644
--- a/opendj3-server-dev/src/server/org/opends/server/extensions/NumSubordinatesVirtualAttributeProvider.java
+++ b/opendj3-server-dev/src/server/org/opends/server/extensions/NumSubordinatesVirtualAttributeProvider.java
@@ -34,13 +34,15 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
+import org.forgerock.opendj.ldap.DecodeException;
+import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.admin.std.server.NumSubordinatesVirtualAttributeCfg;
import org.opends.server.api.Backend;
+import org.opends.server.api.EqualityMatchingRule;
import org.opends.server.api.VirtualAttributeProvider;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SearchOperation;
import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
import static org.opends.messages.ExtensionMessages.*;
@@ -111,7 +113,6 @@
catch(DirectoryException de)
{
logger.traceException(de);
-
return false;
}
}
@@ -121,18 +122,23 @@
public boolean hasValue(Entry entry, VirtualAttributeRule rule,
AttributeValue value)
{
- Backend backend = DirectoryServer.getBackend(entry.getName());
+ Backend backend = DirectoryServer.getBackend(entry.getName());
+ EqualityMatchingRule eqRule = rule.getAttributeType().getEqualityMatchingRule();
try
{
+ String nv = eqRule.normalizeAttributeValue(value.getValue()).toString();
long count = backend.numSubordinates(entry.getName(), false);
- return count >= 0
- && Long.parseLong(value.getNormalizedValue().toString()) == count;
+ return count >= 0 && Long.parseLong(nv) == count;
}
- catch(DirectoryException de)
+ catch (DecodeException e)
{
- logger.traceException(de);
-
+ logger.traceException(e);
+ return false;
+ }
+ catch (DirectoryException e)
+ {
+ logger.traceException(e);
return false;
}
}
diff --git a/opendj3-server-dev/src/server/org/opends/server/extensions/StaticGroup.java b/opendj3-server-dev/src/server/org/opends/server/extensions/StaticGroup.java
index 7b92a80..5ca58a3 100644
--- a/opendj3-server-dev/src/server/org/opends/server/extensions/StaticGroup.java
+++ b/opendj3-server-dev/src/server/org/opends/server/extensions/StaticGroup.java
@@ -35,20 +35,25 @@
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.ldap.ByteString;
+import org.forgerock.opendj.ldap.DecodeException;
+import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
+import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.admin.std.server.GroupImplementationCfg;
import org.opends.server.admin.std.server.StaticGroupImplementationCfg;
+import org.opends.server.api.EqualityMatchingRule;
import org.opends.server.api.Group;
import org.opends.server.core.ModifyOperationBasis;
import org.opends.server.core.DirectoryServer;
-import org.forgerock.opendj.config.server.ConfigException;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.Attributes;
-import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryConfig;
import org.opends.server.types.DirectoryException;
@@ -58,11 +63,8 @@
import org.opends.server.types.MemberList;
import org.opends.server.types.MembershipException;
import org.opends.server.types.Modification;
-import org.forgerock.opendj.ldap.ModificationType;
import org.opends.server.types.ObjectClass;
-import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.SearchFilter;
-import org.forgerock.opendj.ldap.SearchScope;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
@@ -235,13 +237,15 @@
{
for (Attribute a : memberAttrList)
{
+ EqualityMatchingRule eqRule =
+ a.getAttributeType().getEqualityMatchingRule();
for (AttributeValue v : a)
{
try
{
- someMemberDNs.add(v.getNormalizedValue());
+ someMemberDNs.add(eqRule.normalizeAttributeValue(v.getValue()));
}
- catch (DirectoryException de)
+ catch (DecodeException de)
{
logger.traceException(de);
logger.error(ERR_STATICGROUP_CANNOT_DECODE_MEMBER_VALUE_AS_DN, v.getValue(),
@@ -515,8 +519,7 @@
for(DN nestedGroupDN : nestedGroups)
{
Group<? extends GroupImplementationCfg> g =
- (Group<? extends GroupImplementationCfg>)
- DirectoryServer.getGroupManager().getGroupInstance(nestedGroupDN);
+ DirectoryServer.getGroupManager().getGroupInstance(nestedGroupDN);
if((g != null) && (g.isMember(userDN, examinedGroups)))
{
return true;
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/Entry.java b/opendj3-server-dev/src/server/org/opends/server/types/Entry.java
index 4f500ac..be133e3 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/Entry.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/Entry.java
@@ -271,60 +271,6 @@
/**
- * Specifies the set of objectclasses for this entry.
- *
- * @param objectClassNames The values containing the names or OIDs
- * of the objectClasses for this entry.
- *
- * @throws DirectoryException If a problem occurs while attempting
- * to set the objectclasses for this
- * entry.
- */
- public void setObjectClasses(
- Collection<AttributeValue> objectClassNames)
- throws DirectoryException
- {
- attachment = null;
-
- // Iterate through all the provided objectclass names and make
- // sure that they are names of valid objectclasses.
- Map<ObjectClass, String> ocMap = new LinkedHashMap<ObjectClass, String>();
- for (AttributeValue v : objectClassNames)
- {
- String name = v.getValue().toString();
-
- String lowerName;
- try
- {
- lowerName = v.getNormalizedValue().toString();
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- lowerName = toLowerCase(v.getValue().toString());
- }
-
- ObjectClass oc = DirectoryServer.getObjectClass(lowerName);
- if (oc == null)
- {
- LocalizableMessage message = ERR_ENTRY_ADD_UNKNOWN_OC.get(name, dn);
- throw new DirectoryException(OBJECTCLASS_VIOLATION, message);
- }
-
- ocMap.put(oc, name);
- }
-
-
- // If we've gotten here, then everything is fine so append the new
- // set of objectclasses.
- objectClasses = ocMap;
- objectClassAttribute = null;
- }
-
-
-
- /**
* Adds the provided objectClass to this entry.
*
* @param oc The objectClass to add to this entry.
@@ -4507,20 +4453,6 @@
/**
- * Retrieves a one-line representation of this entry.
- *
- * @return A one-line representation of this entry.
- */
- public String toSingleLineString()
- {
- StringBuilder buffer = new StringBuilder();
- toSingleLineString(buffer);
- return buffer.toString();
- }
-
-
-
- /**
* Appends a single-line representation of this entry to the
* provided buffer.
*
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/SortKey.java b/opendj3-server-dev/src/server/org/opends/server/types/SortKey.java
index bc99163..9a4e887 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/SortKey.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/SortKey.java
@@ -26,11 +26,9 @@
*/
package org.opends.server.types;
-import org.opends.server.api.OrderingMatchingRule;
-
import org.forgerock.i18n.slf4j.LocalizedLogger;
-
-
+import org.forgerock.opendj.ldap.ByteString;
+import org.opends.server.api.OrderingMatchingRule;
/**
* This class defines a data structure that may be used as a sort key.
@@ -168,60 +166,40 @@
}
- // Use the ordering matching rule if one is provided. Otherwise,
- // fall back on the default ordering rule for the attribute type.
- if (orderingRule == null)
+ // Use the ordering matching rule if one is provided.
+ // Otherwise, fall back on the default ordering rule for the attribute type.
+ if (orderingRule != null)
{
- try
- {
- OrderingMatchingRule rule =
- attributeType.getOrderingMatchingRule();
- if (rule == null)
- {
- return 0;
- }
+ return compareValues(orderingRule, value1, value2);
+ }
+ final OrderingMatchingRule rule = attributeType.getOrderingMatchingRule();
+ if (rule != null)
+ {
+ return compareValues(rule, value1, value2);
+ }
+ return 0;
+ }
- if (ascending)
- {
- return rule.compareValues(value1.getNormalizedValue(),
- value2.getNormalizedValue());
- }
- else
- {
- return rule.compareValues(value2.getNormalizedValue(),
- value1.getNormalizedValue());
- }
+ private int compareValues(OrderingMatchingRule rule, AttributeValue value1,
+ AttributeValue value2)
+ {
+ try
+ {
+ final ByteString val1 = rule.normalizeAttributeValue(value1.getValue());
+ final ByteString val2 = rule.normalizeAttributeValue(value2.getValue());
+ if (ascending)
+ {
+ return rule.compareValues(val1, val2);
}
- catch (Exception e)
+ else
{
- logger.traceException(e);
-
- return 0;
+ return rule.compareValues(val2, val1);
}
}
- else
+ catch (Exception e)
{
- try
- {
- if (ascending)
- {
- return orderingRule.compareValues(
- orderingRule.normalizeAttributeValue(value1.getValue()),
- orderingRule.normalizeAttributeValue(value2.getValue()));
- }
- else
- {
- return orderingRule.compareValues(
- orderingRule.normalizeAttributeValue(value2.getValue()),
- orderingRule.normalizeAttributeValue(value1.getValue()));
- }
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- return 0;
- }
+ logger.traceException(e);
+ return 0;
}
}
@@ -232,6 +210,7 @@
*
* @return A string representation of this sort key.
*/
+ @Override
public String toString()
{
StringBuilder buffer = new StringBuilder();
@@ -275,6 +254,7 @@
*
* @return The hash code for this sort key.
*/
+ @Override
public int hashCode()
{
int hashCode = 0;
@@ -303,6 +283,7 @@
* @return <CODE>true</CODE> if the provide object is equal to this
* sort key, or <CODE>false</CODE> if it is not.
*/
+ @Override
public boolean equals(Object o)
{
if(o == null)
diff --git a/opendj3-server-dev/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java b/opendj3-server-dev/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
index ee57e20..c6b4d1e 100644
--- a/opendj3-server-dev/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
+++ b/opendj3-server-dev/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
@@ -36,6 +36,7 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.util.Reject;
import org.forgerock.util.Utils;
import org.opends.server.api.*;
@@ -45,7 +46,6 @@
import org.opends.server.schema.AuthPasswordSyntax;
import org.opends.server.schema.UserPasswordSyntax;
import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.operation.PostOperationModifyOperation;
import org.opends.server.types.operation.PostResponseModifyOperation;
import org.opends.server.types.operation.PostSynchronizationModifyOperation;
@@ -1469,7 +1469,10 @@
*/
private void validateObjectClasses(Attribute attr) throws DirectoryException
{
- Reject.ifFalse(attr.getAttributeType().isObjectClass());
+ final AttributeType attrType = attr.getAttributeType();
+ Reject.ifFalse(attrType.isObjectClass());
+ final EqualityMatchingRule eqRule = attrType.getEqualityMatchingRule();
+
for (AttributeValue v : attr)
{
String name = v.getValue().toString();
@@ -1477,13 +1480,13 @@
String lowerName;
try
{
- lowerName = v.getNormalizedValue().toString();
+ lowerName = eqRule.normalizeAttributeValue(v.getValue()).toString();
}
catch (Exception e)
{
logger.traceException(e);
- lowerName = toLowerCase(v.getValue().toString());
+ lowerName = toLowerCase(name);
}
ObjectClass oc = DirectoryServer.getObjectClass(lowerName);
@@ -1697,12 +1700,14 @@
ERR_MODIFY_INCREMENT_REQUIRES_SINGLE_VALUE.get(entryDN, attr.getName()));
}
+ EqualityMatchingRule eqRule = attr.getAttributeType().getEqualityMatchingRule();
AttributeValue v = attr.iterator().next();
long incrementValue;
try
{
- incrementValue = Long.parseLong(v.getNormalizedValue().toString());
+ String nv = eqRule.normalizeAttributeValue(v.getValue()).toString();
+ incrementValue = Long.parseLong(nv);
}
catch (Exception e)
{
--
Gitblit v1.10.0