From 00e59615c33ec795efd9ac0758d56c54a42dbbdc Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 08 Aug 2016 07:31:26 +0000
Subject: [PATCH] Partial OPENDJ-3106 Migrate Entry
---
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java | 7 ++-
opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java | 4 +-
opendj-server-legacy/src/main/java/org/opends/server/util/CollectionUtils.java | 12 ++++++
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java | 20 +++++-----
opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java | 21 +++++-----
opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java | 20 +++++-----
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java | 8 ++--
7 files changed, 53 insertions(+), 39 deletions(-)
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 821de92..099261e 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
@@ -16,6 +16,15 @@
*/
package org.opends.server.types;
+import static org.forgerock.opendj.ldap.ResultCode.*;
+import static org.opends.messages.CoreMessages.*;
+import static org.opends.messages.UtilityMessages.*;
+import static org.opends.server.core.DirectoryServer.*;
+import static org.opends.server.util.CollectionUtils.*;
+import static org.opends.server.util.LDIFWriter.*;
+import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.util.StaticUtils.*;
+
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
@@ -65,15 +74,6 @@
import org.opends.server.util.LDIFException;
import org.opends.server.util.LDIFWriter;
-import static org.forgerock.opendj.ldap.ResultCode.*;
-import static org.opends.messages.CoreMessages.*;
-import static org.opends.messages.UtilityMessages.*;
-import static org.opends.server.core.DirectoryServer.*;
-import static org.opends.server.util.CollectionUtils.*;
-import static org.opends.server.util.LDIFWriter.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.util.StaticUtils.*;
-
/**
* This class defines a data structure for a Directory Server entry.
* It includes a DN and a set of attributes.
@@ -773,7 +773,7 @@
* attribute type is not present in this entry with the
* provided set of options.
*/
- public List<Attribute> getAllAttributes(AttributeDescription attributeDescription)
+ public Iterable<Attribute> getAllAttributes(AttributeDescription attributeDescription)
{
AttributeType attributeType = attributeDescription.getAttributeType();
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java b/opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java
index b628042..ea2f85e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java
@@ -18,6 +18,7 @@
package org.opends.server.types;
import static org.opends.messages.CoreMessages.*;
+import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -2569,8 +2570,8 @@
}
// See if the entry has an attribute with the requested type.
- List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
- if (attrs.isEmpty())
+ Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
+ if (isEmpty(attrs))
{
if (logger.isTraceEnabled())
{
@@ -2673,8 +2674,8 @@
}
// See if the entry has an attribute with the requested type.
- List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
- if (attrs.isEmpty())
+ Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
+ if (isEmpty(attrs))
{
if (logger.isTraceEnabled())
{
@@ -2774,8 +2775,8 @@
}
// See if the entry has an attribute with the requested type.
- List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
- if (attrs.isEmpty())
+ Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
+ if (isEmpty(attrs))
{
if (logger.isTraceEnabled())
{
@@ -2872,8 +2873,8 @@
}
// See if the entry has an attribute with the requested type.
- List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
- if (attrs.isEmpty())
+ Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
+ if (isEmpty(attrs))
{
if (logger.isTraceEnabled())
{
@@ -3015,8 +3016,8 @@
}
// See if the entry has an attribute with the requested type.
- List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
- if (attrs.isEmpty())
+ Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
+ if (isEmpty(attrs))
{
if (logger.isTraceEnabled())
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/CollectionUtils.java b/opendj-server-legacy/src/main/java/org/opends/server/util/CollectionUtils.java
index 6aea607..dc11501 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/CollectionUtils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/CollectionUtils.java
@@ -125,4 +125,16 @@
}
return outputCollection;
}
+
+ /**
+ * Returns whether the provided iterable is empty, i.e. whether it has not elements.
+ *
+ * @param iterable
+ * the iterable for which to omake the determination
+ * @return {@code true} if the iterable is empty, {@code false} otherwise.
+ */
+ public static boolean isEmpty(Iterable<?> iterable)
+ {
+ return !iterable.iterator().hasNext();
+ }
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java b/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
index 2db4083..041908b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
@@ -16,7 +16,13 @@
*/
package org.opends.server.workflowelement.localbackend;
-import java.util.List;
+import static org.opends.messages.CoreMessages.*;
+import static org.opends.server.core.DirectoryServer.*;
+import static org.opends.server.types.AbstractOperation.*;
+import static org.opends.server.util.CollectionUtils.*;
+import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.workflowelement.localbackend.LocalBackendWorkflowElement.*;
+
import java.util.concurrent.atomic.AtomicBoolean;
import org.forgerock.i18n.LocalizableMessage;
@@ -46,12 +52,6 @@
import org.opends.server.types.operation.PostResponseCompareOperation;
import org.opends.server.types.operation.PreOperationCompareOperation;
-import static org.opends.messages.CoreMessages.*;
-import static org.opends.server.core.DirectoryServer.*;
-import static org.opends.server.types.AbstractOperation.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.workflowelement.localbackend.LocalBackendWorkflowElement.*;
-
/**
* This class defines an operation that may be used to determine whether a
* specified entry in the Directory Server contains a given attribute-value pair.
@@ -233,8 +233,8 @@
// Actually perform the compare operation.
AttributeDescription attrDesc = getAttributeDescription();
- List<Attribute> attrList = entry.getAllAttributes(attrDesc);
- if (attrList.isEmpty())
+ Iterable<Attribute> attrList = entry.getAllAttributes(attrDesc);
+ if (isEmpty(attrList))
{
setResultCode(ResultCode.NO_SUCH_ATTRIBUTE);
Arg2<Object, Object> errorMsg = attrDesc.hasOptions()
@@ -255,7 +255,7 @@
}
}
- private ResultCode matchExists(List<Attribute> attrList, ByteString value)
+ private ResultCode matchExists(Iterable<Attribute> attrList, ByteString value)
{
for (Attribute a : attrList)
{
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java
index 74bd263..dba2744 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java
@@ -357,8 +357,8 @@
retrieveCompletedOperationElements(addOperation);
Entry e = DirectoryServer.getEntry(DN.valueOf("ou=People,o=test"));
- List<Attribute> attrList = e.getAllAttributes(a.getAttributeDescription());
- assertFalse(attrList.isEmpty());
+ Iterable<Attribute> attrList = e.getAllAttributes(a.getAttributeDescription());
+ assertThat(attrList).isNotEmpty();
boolean foundFoo = false;
boolean foundBar = false;
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java
index bd92761..ddd3b48 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java
@@ -429,12 +429,13 @@
return getValues(entry.getAllAttributes(mod.getAttribute().getAttributeDescription()));
}
- private List<ByteString> getValues(List<Attribute> attributes)
+ private List<ByteString> getValues(Iterable<Attribute> attributes)
{
- if (!attributes.isEmpty())
+ Iterator<Attribute> it = attributes.iterator();
+ if (it.hasNext())
{
assertThat(attributes).hasSize(1);
- return getValues(attributes.get(0));
+ return getValues(it.next());
}
return Collections.emptyList();
}
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 f57244e..625a9d7 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
@@ -21,7 +21,6 @@
import static org.testng.Assert.*;
import java.util.Iterator;
-import java.util.List;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.opendj.ldap.ByteString;
@@ -356,12 +355,13 @@
return getActualValue(entry.getAllAttributes(mod.getAttribute().getAttributeDescription()));
}
- private ByteString getActualValue(List<Attribute> attributes)
+ private ByteString getActualValue(Iterable<Attribute> attributes)
{
- if (!attributes.isEmpty())
+ Iterator<Attribute> it = attributes.iterator();
+ if (it.hasNext())
{
assertThat(attributes).hasSize(1);
- Attribute attribute = attributes.get(0);
+ Attribute attribute = it.next();
assertThat(attribute).hasSize(1);
return attribute.iterator().next();
}
--
Gitblit v1.10.0