From ddc834f5aa8f311192cc419cf57b0648b4971b5b Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 09 Jun 2016 13:57:09 +0000
Subject: [PATCH] Entry.getAttribute() now accepts a nameOrOid
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java | 4 +-
opendj-server-legacy/src/test/java/org/opends/server/replication/InitOnLineTest.java | 29 +++++++++-----
opendj-server-legacy/src/test/java/org/opends/server/tasks/TasksTestCase.java | 14 ++-----
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java | 12 ++---
opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java | 2
opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java | 6 +-
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java | 3 +
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java | 3 -
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/FractionalReplicationTest.java | 2
opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java | 5 ++
opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java | 16 ++-----
11 files changed, 46 insertions(+), 50 deletions(-)
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
index da8bad0..f735c95 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
@@ -536,7 +536,7 @@
return OBJECT_CLASS;
}
String attributeName = attributeType.getNameOrOID();
- return new AttributeDescription(attributeName, attributeName, attributeType, ZERO_OPTION_IMPL);
+ return new AttributeDescription(attributeName, attributeName, attributeType, ZERO_OPTION_IMPL);
}
/**
@@ -1139,6 +1139,9 @@
/**
* Returns the attribute name or the oid provided by the user associated with this attribute
* description.
+ * <p>
+ * In other words, it returns the user-provided name or oid of this attribute description,
+ * leaving out the option(s).
*
* @return The attribute name or the oid provided by the user associated with this attribute
* description.
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
index 2bf90e0..39dc729 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
@@ -601,9 +601,8 @@
}
List<Object> oldValues = oldEntry.getAttributeValues(attrName);
AttributeDescription attrDesc = AttributeDescription.valueOf(attrName);
- String attrNoOptions = attrDesc.getNameOrOID().toLowerCase();
- List<org.opends.server.types.Attribute> attrs = newEntry.getAttribute(attrNoOptions);
+ List<org.opends.server.types.Attribute> attrs = newEntry.getAttribute(attrDesc.getNameOrOID());
if (!find(attrs, attrName) && !oldValues.isEmpty())
{
modifications.add(new ModificationItem(
@@ -616,6 +615,7 @@
private static boolean find(List<org.opends.server.types.Attribute> attrs, String attrName)
{
+ // TODO JNR use Entry.hasAttribute(AttributeDescription) instead?
for (org.opends.server.types.Attribute attr : attrs)
{
if (attr.getAttributeDescription().toString().equalsIgnoreCase(attrName))
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
index 498ffde..11d0c4c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
@@ -282,8 +282,9 @@
String attrName = ava.getAttributeName();
ByteString value = ava.getAttributeValue();
boolean done = false;
- for (org.opends.server.types.Attribute attr : entry.getAttribute(attrName.toLowerCase()))
+ for (org.opends.server.types.Attribute attr : entry.getAttribute(attrName))
{
+ // TODO JNR use Entry.getAttribute(AttributeDescription) instead?
if (attr.getAttributeDescription().toString().equals(attrName))
{
List<ByteString> newValues = getValues(attr);
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java
index 043d2b3..469b44a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java
@@ -34,6 +34,7 @@
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;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.messages.Severity;
@@ -42,7 +43,6 @@
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
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.InitializationException;
@@ -311,7 +311,7 @@
private String getAttributeValue(String attributeName, boolean isRequired)
throws InitializationException
{
- List<Attribute> attrList = taskEntry.getAttribute(attributeName.toLowerCase());
+ List<Attribute> attrList = taskEntry.getAttribute(attributeName);
if (attrList.isEmpty())
{
if (isRequired)
@@ -360,7 +360,7 @@
private LinkedList<String> getAttributeValues(String attributeName) throws InitializationException
{
LinkedList<String> valueStrings = new LinkedList<>();
- List<Attribute> attrList = taskEntry.getAttribute(attributeName.toLowerCase());
+ List<Attribute> attrList = taskEntry.getAttribute(attributeName);
if (attrList.isEmpty())
{
return valueStrings;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java b/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
index 706ec2c..1e79363 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -650,18 +650,16 @@
* the version of this method that takes an
* <CODE>AttributeType</CODE> argument.
*
- * @param lowerName The name or OID of the attribute to return,
- * formatted in all lowercase characters.
- *
+ * @param nameOrOID The name or OID of the attribute to return
* @return The requested attribute element(s) for the specified
* attribute type, or an empty list if the specified
* attribute type is not present in this entry.
*/
- public List<Attribute> getAttribute(String lowerName)
+ public List<Attribute> getAttribute(String nameOrOID)
{
for (AttributeType attr : userAttributes.keySet())
{
- if (attr.hasNameOrOID(lowerName))
+ if (attr.hasNameOrOID(nameOrOID))
{
return getAttribute(attr);
}
@@ -669,13 +667,13 @@
for (AttributeType attr : operationalAttributes.keySet())
{
- if (attr.hasNameOrOID(lowerName))
+ if (attr.hasNameOrOID(nameOrOID))
{
return getAttribute(attr);
}
}
- if (lowerName.equals(OBJECTCLASS_ATTRIBUTE_TYPE_NAME)
+ if (CoreSchema.getObjectClassAttributeType().hasNameOrOID(nameOrOID)
&& !objectClasses.isEmpty())
{
return newLinkedList(getObjectClassAttribute());
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java
index ef2434b..c7222c5 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java
@@ -1480,7 +1480,7 @@
private static String getAttributeValue(Entry entry, String attrName)
{
- List<Attribute> attrs = entry.getAttribute(attrName.toLowerCase());
+ List<Attribute> attrs = entry.getAttribute(attrName);
if (attrs.isEmpty())
{
return null;
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/InitOnLineTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/InitOnLineTest.java
index 82a7388..3359378 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/InitOnLineTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/InitOnLineTest.java
@@ -16,11 +16,16 @@
*/
package org.opends.server.replication;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.UUID;
import org.assertj.core.api.Assertions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
@@ -31,12 +36,17 @@
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.replication.common.ServerStatus;
import org.opends.server.replication.plugin.LDAPReplicationDomain;
-import org.opends.server.replication.protocol.*;
+import org.opends.server.replication.protocol.DoneMsg;
+import org.opends.server.replication.protocol.EntryMsg;
+import org.opends.server.replication.protocol.ErrorMsg;
+import org.opends.server.replication.protocol.InitializeRequestMsg;
+import org.opends.server.replication.protocol.InitializeTargetMsg;
+import org.opends.server.replication.protocol.ReplicationMsg;
+import org.opends.server.replication.protocol.RoutableMsg;
import org.opends.server.replication.server.ReplServerFakeConfiguration;
import org.opends.server.replication.server.ReplicationServer;
import org.opends.server.replication.server.ReplicationServerDomain;
import org.opends.server.replication.service.ReplicationBroker;
-import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.util.Base64;
@@ -220,15 +230,13 @@
Entry resultEntry = getCompletionTime(taskEntry);
// Check that the task state is as expected.
- String stateString =
- resultEntry.parseAttribute(ATTR_TASK_STATE.toLowerCase()).asString();
+ String stateString = resultEntry.parseAttribute(ATTR_TASK_STATE).asString();
TaskState taskState = TaskState.fromString(stateString);
assertEquals(taskState, expectedState,
"The task completed in an unexpected state");
// Check that the task contains some log messages.
- Set<String> logMessages = resultEntry.parseAttribute(
- ATTR_TASK_LOG_MESSAGES.toLowerCase()).asSetOfString();
+ Set<String> logMessages = resultEntry.parseAttribute(ATTR_TASK_LOG_MESSAGES).asSetOfString();
if (taskState != TaskState.COMPLETED_SUCCESSFULLY &&
logMessages.isEmpty())
{
@@ -258,8 +266,7 @@
InternalSearchOperation searchOperation = connection.processSearch(request);
Entry resultEntry = searchOperation.getSearchEntries().getFirst();
- String completionTime = resultEntry.parseAttribute(
- ATTR_TASK_COMPLETION_TIME.toLowerCase()).asString();
+ String completionTime = resultEntry.parseAttribute(ATTR_TASK_COMPLETION_TIME).asString();
if (completionTime != null)
{
return resultEntry;
@@ -274,10 +281,10 @@
while (true);
}
- private void assertAttributeValue(Entry resultEntry, String lowerAttrName,
+ private void assertAttributeValue(Entry resultEntry, String attrName,
long expected, String message) throws DirectoryException
{
- String value = resultEntry.parseAttribute(lowerAttrName).asString();
+ String value = resultEntry.parseAttribute(attrName).asString();
assertEquals(Long.decode(value).longValue(), expected, message);
}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
index fe56e5b..1a781a3 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
@@ -621,18 +621,14 @@
InternalSearchOperation searchOperation = connection.processSearch(request);
Assertions.assertThat(searchOperation.getSearchEntries()).isNotEmpty();
Entry resultEntry = searchOperation.getSearchEntries().get(0);
- String completionTime = resultEntry.parseAttribute(
- ATTR_TASK_COMPLETION_TIME.toLowerCase()).asString();
+ String completionTime = resultEntry.parseAttribute(ATTR_TASK_COMPLETION_TIME).asString();
assertNotNull(completionTime, "The task has not completed");
return resultEntry;
}
});
// Check that the task state is as expected.
- String stateString = resultEntry.parseAttribute(
- ATTR_TASK_STATE.toLowerCase()).asString();
- TaskState taskState = TaskState.fromString(stateString);
- assertEquals(taskState, TaskState.COMPLETED_SUCCESSFULLY,
+ assertEquals(getTaskState(resultEntry), TaskState.COMPLETED_SUCCESSFULLY,
"The task completed in an unexpected state");
}
@@ -715,8 +711,7 @@
});
// Check that the task contains some log messages.
- Set<String> logMessages = resultEntry.parseAttribute(
- ATTR_TASK_LOG_MESSAGES.toLowerCase()).asSetOfString();
+ Set<String> logMessages = resultEntry.parseAttribute(ATTR_TASK_LOG_MESSAGES).asSetOfString();
TaskState taskState = getTaskState(resultEntry);
if (taskState != COMPLETED_SUCCESSFULLY && taskState != RUNNING)
@@ -748,10 +743,9 @@
}
}
- private TaskState getTaskState(Entry resultEntry)
+ private TaskState getTaskState(Entry entry)
{
- String stateString = resultEntry.parseAttribute(ATTR_TASK_STATE.toLowerCase()).asString();
- return TaskState.fromString(stateString);
+ return TaskState.fromString(entry.parseAttribute(ATTR_TASK_STATE).asString());
}
/** Add to the current DB the entries necessary to the test. */
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java
index d318fd9..b3d458b 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java
@@ -18,7 +18,6 @@
import static org.assertj.core.api.Assertions.*;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.mockito.Mockito.*;
-import static org.opends.server.util.StaticUtils.*;
import static org.testng.Assert.*;
import java.util.Iterator;
@@ -383,7 +382,7 @@
private void assertAttributeValue(Entry entry, String expectedValue)
{
- ByteString actualValue = getActualValue(entry.getAttribute(toLowerCase(ATTRIBUTE_NAME)));
+ ByteString actualValue = getActualValue(entry.getAttribute(ATTRIBUTE_NAME));
assertEquals(actualValue, expectedValue != null ? ByteString.valueOfUtf8(expectedValue) : null);
}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/FractionalReplicationTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/FractionalReplicationTest.java
index 9d84168..1e612e5 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/FractionalReplicationTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/FractionalReplicationTest.java
@@ -757,7 +757,7 @@
*/
private static void checkEntryAttributeValue(Entry entry, String attributeName, String attributeValue)
{
- List<Attribute> attrs = entry.getAttribute(attributeName.toLowerCase());
+ List<Attribute> attrs = entry.getAttribute(attributeName);
assertThat(attrs).as("Was expecting attribute " + attributeName + "=" + attributeValue).hasSize(1);
Attribute attr = attrs.get(0);
Iterator<ByteString> attrValues = attr.iterator();
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/tasks/TasksTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/tasks/TasksTestCase.java
index ad91b14..2f7e525 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/tasks/TasksTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/tasks/TasksTestCase.java
@@ -19,6 +19,7 @@
import java.util.Set;
import java.util.concurrent.Callable;
+import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.DirectoryServerTestCase;
@@ -29,8 +30,6 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
-import org.opends.server.types.AttributeParser;
-import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
import org.opends.server.util.TestTimer;
import org.testng.annotations.Test;
@@ -62,13 +61,13 @@
// Check that the task state is as expected.
Entry resultEntry = getCompletedTaskEntry(taskEntry.getName(), timeoutInSec);
- String stateString = parseAttribute(resultEntry, ATTR_TASK_STATE).asString();
+ String stateString = resultEntry.parseAttribute(ATTR_TASK_STATE).asString();
TaskState taskState = TaskState.fromString(stateString);
assertEquals(taskState, expectedState,
"The task completed in an unexpected state");
// Check that the task contains some log messages.
- Set<String> logMessages = parseAttribute(resultEntry, ATTR_TASK_LOG_MESSAGES).asSetOfString();
+ Set<String> logMessages = resultEntry.parseAttribute(ATTR_TASK_LOG_MESSAGES).asSetOfString();
assertTrue(taskState == TaskState.COMPLETED_SUCCESSFULLY || !logMessages.isEmpty(),
"No log messages were written to the task entry on a failed task.\n"
+ "taskState=" + taskState
@@ -90,7 +89,7 @@
{
InternalSearchOperation searchOperation = getRootConnection().processSearch(request);
Entry resultEntry = searchOperation.getSearchEntries().getFirst();
- String completionTime = parseAttribute(resultEntry, ATTR_TASK_COMPLETION_TIME).asString();
+ String completionTime = resultEntry.parseAttribute(ATTR_TASK_COMPLETION_TIME).asString();
assertNotNull(completionTime,
"The task had not completed after " + timeoutInSec + " seconds.\nresultEntry=[" + resultEntry + "]");
return resultEntry;
@@ -98,11 +97,6 @@
});
}
- private AttributeParser parseAttribute(Entry resultEntry, String attrName)
- {
- return resultEntry.parseAttribute(attrName.toLowerCase());
- }
-
/**
* Retrieves the specified task from the server, regardless of its current
* state.
--
Gitblit v1.10.0