From 04751fedb241ac1f383bab06ba60fbc9e58a7082 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 05 Aug 2016 10:14:44 +0000
Subject: [PATCH] AddOperationBasis: Change constructor to accept an Entry rather than its fields
---
opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java | 80 +------------------
opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java | 8 -
opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java | 3
opendj-server-legacy/src/main/java/org/opends/server/core/AddOperationBasis.java | 39 ++++-----
opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxConnectTest.java | 36 ++------
opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java | 11 --
opendj-server-legacy/src/test/java/org/opends/server/replication/protocol/SynchronizationMsgTest.java | 9 +-
7 files changed, 45 insertions(+), 141 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/AddOperationBasis.java b/opendj-server-legacy/src/main/java/org/opends/server/core/AddOperationBasis.java
index 8ef1ab0..1bff6ad 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/AddOperationBasis.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/AddOperationBasis.java
@@ -28,6 +28,7 @@
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.schema.AttributeType;
+import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.opends.server.api.ClientConnection;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.protocols.ldap.LDAPResultCode;
@@ -39,7 +40,6 @@
import org.opends.server.types.Control;
import org.opends.server.types.Entry;
import org.opends.server.types.LDAPException;
-import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.opends.server.types.Operation;
import org.opends.server.types.OperationType;
import org.opends.server.types.RawAttribute;
@@ -121,36 +121,29 @@
objectClasses = null;
}
-
-
/**
* Creates a new add operation with the provided information.
*
- * @param clientConnection The client connection with which this
- * operation is associated.
- * @param operationID The operation ID for this operation.
- * @param messageID The message ID of the request with which
- * this operation is associated.
- * @param requestControls The set of controls included in the request.
- * @param entryDN The DN for the entry.
- * @param objectClasses The set of objectclasses for the entry.
- * @param userAttributes The set of user attributes for the entry.
- * @param operationalAttributes The set of operational attributes for the
- * entry.
+ * @param clientConnection
+ * The client connection with which this operation is associated.
+ * @param operationID
+ * The operation ID for this operation.
+ * @param messageID
+ * The message ID of the request with which this operation is associated.
+ * @param requestControls
+ * The set of controls included in the request.
+ * @param entry
+ * The entry to add.
*/
public AddOperationBasis(ClientConnection clientConnection, long operationID,
- int messageID, List<Control> requestControls,
- DN entryDN, Map<ObjectClass,String> objectClasses,
- Map<AttributeType,List<Attribute>> userAttributes,
- Map<AttributeType,List<Attribute>> operationalAttributes)
+ int messageID, List<Control> requestControls, Entry entry)
{
super(clientConnection, operationID, messageID, requestControls);
-
- this.entryDN = entryDN;
- this.objectClasses = objectClasses;
- this.userAttributes = userAttributes;
- this.operationalAttributes = operationalAttributes;
+ this.entryDN = entry.getName();
+ this.objectClasses = entry.getObjectClasses();
+ this.userAttributes = entry.getUserAttributes();
+ this.operationalAttributes = entry.getOperationalAttributes();
rawEntryDN = ByteString.valueOfUtf8(entryDN.toString());
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java
index 626bb08..953cdf2 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java
@@ -758,74 +758,6 @@
* Processes an internal add operation with the provided
* information.
*
- * @param entryDN The entry DN for the add
- * operation.
- * @param objectClasses The set of object classes for the
- * add operation.
- * @param userAttributes The set of user attributes for the
- * add operation.
- * @param operationalAttributes The set of operational attributes
- * for the add operation.
- *
- * @return A reference to the add operation that was processed and
- * contains information about the result of the processing.
- */
- public AddOperation processAdd(DN entryDN,
- Map<ObjectClass,String> objectClasses,
- Map<AttributeType,List<Attribute>>
- userAttributes,
- Map<AttributeType,List<Attribute>>
- operationalAttributes)
- {
- return processAdd(entryDN, objectClasses, userAttributes,
- operationalAttributes, null);
- }
-
-
-
- /**
- * Processes an internal add operation with the provided
- * information.
- *
- * @param entryDN The entry DN for the add
- * operation.
- * @param objectClasses The set of object classes for the
- * add operation.
- * @param userAttributes The set of user attributes for the
- * add operation.
- * @param operationalAttributes The set of operational attributes
- * for the add operation.
- * @param controls The set of controls to include in
- * the request.
- *
- * @return A reference to the add operation that was processed and
- * contains information about the result of the processing.
- */
- public AddOperation processAdd(DN entryDN,
- Map<ObjectClass,String> objectClasses,
- Map<AttributeType,List<Attribute>>
- userAttributes,
- Map<AttributeType,List<Attribute>>
- operationalAttributes,
- List<Control> controls)
- {
- AddOperationBasis addOperation =
- new AddOperationBasis(this, nextOperationID(),
- nextMessageID(), controls, entryDN,
- objectClasses, userAttributes,
- operationalAttributes);
- addOperation.setInternalOperation(true);
-
- addOperation.run();
- return addOperation;
- }
-
-
-
- /**
- * Processes an internal add operation with the provided
- * information.
- *
* @param entry The entry to be added.
*
* @return A reference to the add operation that was processed and
@@ -850,10 +782,10 @@
*/
public AddOperation processAdd(Entry entry, List<Control> controls)
{
- return processAdd(entry.getName(), entry.getObjectClasses(),
- entry.getUserAttributes(),
- entry.getOperationalAttributes(),
- controls);
+ AddOperationBasis addOperation = new AddOperationBasis(this, nextOperationID(), nextMessageID(), controls, entry);
+ addOperation.setInternalOperation(true);
+ addOperation.run();
+ return addOperation;
}
@@ -892,7 +824,9 @@
}
}
- return processAdd(addRecord.getDN(), objectClasses, userAttrs, opAttrs);
+ // TODO JNR can we directly pass e instead of addEntry()?
+ Entry addEntry = new Entry(addRecord.getDN(), objectClasses, userAttrs, opAttrs);
+ return processAdd(addEntry, null);
}
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 3ef4619..6f47f22 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
@@ -114,8 +114,7 @@
private AddOperationBasis newAddOperationBasis(Entry e, List<Control> controls)
{
- return new AddOperationBasis(getRootConnection(), nextOperationID(), nextMessageID(), controls,
- e.getName(), e.getObjectClasses(), e.getUserAttributes(), e.getOperationalAttributes());
+ return new AddOperationBasis(getRootConnection(), nextOperationID(), nextMessageID(), controls, e);
}
@Override
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxConnectTest.java b/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxConnectTest.java
index 6d43ba6..5a71764 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxConnectTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxConnectTest.java
@@ -16,6 +16,7 @@
*/
package org.opends.server.protocols.jmx;
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.testng.Assert.*;
import java.io.File;
@@ -36,20 +37,19 @@
import javax.net.ssl.TrustManagerFactory;
import org.forgerock.i18n.LocalizableMessage;
-import org.opends.server.TestCaseUtils;
+import org.forgerock.opendj.config.server.ConfigChangeResult;
+import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.server.config.meta.JMXConnectionHandlerCfgDefn;
import org.forgerock.opendj.server.config.server.JMXConnectionHandlerCfg;
+import org.opends.server.TestCaseUtils;
import org.opends.server.config.JMXMBean;
import org.opends.server.core.AddOperationBasis;
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.DeleteOperationBasis;
import org.opends.server.core.DirectoryServer;
import org.opends.server.extensions.InitializationUtils;
-import org.opends.server.protocols.internal.InternalClientConnection;
-import org.forgerock.opendj.config.server.ConfigChangeResult;
-import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
-import org.forgerock.opendj.ldap.ResultCode;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
@@ -136,15 +136,10 @@
@AfterClass
public void afterClass() throws Exception
{
- InternalClientConnection conn = InternalClientConnection
- .getRootConnection();
-
- DeleteOperation deleteOperation = conn.processDelete(DN
- .valueOf("cn=Privileged User,o=test"));
+ DeleteOperation deleteOperation = getRootConnection().processDelete(DN.valueOf("cn=Privileged User,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
- deleteOperation = conn.processDelete(DN
- .valueOf("cn=Unprivileged JMX User,o=test"));
+ deleteOperation = getRootConnection().processDelete(DN.valueOf("cn=Unprivileged JMX User,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
@@ -292,15 +287,8 @@
"ds-cfg-enabled: true",
"ds-cfg-use-ssl: false", "ds-cfg-listen-port: "
+ serverJmxPort, "cn: JMX Connection Handler");
- InternalClientConnection connection =
- InternalClientConnection.getRootConnection();
- AddOperationBasis addOp = new AddOperationBasis(connection,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null,
- newJmxConnectionJmx.getName(), newJmxConnectionJmx
- .getObjectClasses(), newJmxConnectionJmx
- .getUserAttributes(), newJmxConnectionJmx
- .getOperationalAttributes());
+ AddOperationBasis addOp = new AddOperationBasis(
+ getRootConnection(), nextOperationID(), nextMessageID(), null, newJmxConnectionJmx);
addOp.run();
Thread.sleep(200);
OpendsJmxConnector newJmxConnector = connect(
@@ -329,10 +317,8 @@
// cleanup client connection
connector.close();
jmxcDisabled.close();
- DeleteOperationBasis delOp = new DeleteOperationBasis(connection,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null,
- newJmxConnectionJmx.getName());
+ DeleteOperationBasis delOp = new DeleteOperationBasis(
+ getRootConnection(), nextOperationID(), nextMessageID(), null, newJmxConnectionJmx.getName());
delOp.run();
}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
index 0853fc8..ec55768 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
@@ -524,9 +524,7 @@
// Try to add the entry. If this fails with the proxy control, then add it
// with a root connection so we can do other things with it.
- AddOperationBasis addOp = new AddOperationBasis(
- conn, conn.nextOperationID(), conn.nextMessageID(), controls,
- e.getName(), e.getObjectClasses(), e.getUserAttributes(), e.getOperationalAttributes());
+ AddOperationBasis addOp = new AddOperationBasis(conn, conn.nextOperationID(), conn.nextMessageID(), controls, e);
assertSuccess(hasProxyPrivilege, addOp);
if (!hasProxyPrivilege)
{
@@ -636,9 +634,7 @@
// Try to add the entry. If this fails with the proxy control, then add it
// with a root connection so we can do other things with it.
DN authDN = conn.getAuthenticationInfo().getAuthenticationDN();
- AddOperationBasis addOp = new AddOperationBasis(
- conn, conn.nextOperationID(), conn.nextMessageID(), controls,
- e.getName(), e.getObjectClasses(), e.getUserAttributes(), e.getOperationalAttributes());
+ AddOperationBasis addOp = new AddOperationBasis(conn, conn.nextOperationID(), conn.nextMessageID(), controls, e);
assertSuccess(hasProxyPrivilege, authDN, addOp);
if (!hasProxyPrivilege)
{
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/protocol/SynchronizationMsgTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/protocol/SynchronizationMsgTest.java
index cc71a7e..0b3e756 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/protocol/SynchronizationMsgTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/protocol/SynchronizationMsgTest.java
@@ -61,6 +61,7 @@
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.Attributes;
+import org.opends.server.types.Entry;
import org.opends.server.types.LDAPException;
import org.opends.server.types.Modification;
import org.opends.server.types.RawAttribute;
@@ -502,8 +503,8 @@
assertEquals(msg.toString(), generatedMsg.toString());
//Create an Add operation and generate and Add msg from it
- AddOperation addOpB = new AddOperationBasis(conn,
- 1, 1, null, dn, objectClassList, userAttList, opList);
+ Entry e = new Entry(dn, objectClassList, userAttList, opList);
+ AddOperation addOpB = new AddOperationBasis(conn, 1, 1, null, e);
LocalBackendAddOperation localAddOp = new LocalBackendAddOperation(addOpB);
OperationContext opCtx = new AddContext(csn, "thisIsaUniqueID",
"parentUniqueId");
@@ -1206,8 +1207,8 @@
t1 = System.nanoTime();
// create op
- AddOperation addOpB = new AddOperationBasis(connection,
- 1, 1, null, dn, objectClassList, userAttList, opList);
+ Entry e = new Entry(dn, objectClassList, userAttList, opList);
+ AddOperation addOpB = new AddOperationBasis(connection, 1, 1, null, e);
LocalBackendAddOperation addOp = new LocalBackendAddOperation(addOpB);
OperationContext opCtx = new AddContext(csn, "thisIsaUniqueID",
"parentUniqueId");
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java
index 91ccd73..6712e49 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java
@@ -36,9 +36,9 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.requests.ModifyRequest;
-import org.opends.server.TestCaseUtils;
import org.forgerock.opendj.server.config.meta.GlobalCfgDefn.DisabledPrivilege;
import org.forgerock.opendj.server.config.meta.RootDNCfgDefn;
+import org.opends.server.TestCaseUtils;
import org.opends.server.api.ClientConnection;
import org.opends.server.backends.task.Task;
import org.opends.server.backends.task.TaskBackend;
@@ -1155,9 +1155,7 @@
// Try to add the entry. If this fails with the proxy control, then add it
// with a root connection so we can do other things with it.
- AddOperation addOperation = new AddOperationBasis(conn, nextOperationID(), nextMessageID(),
- controls, e.getName(), e.getObjectClasses(),
- e.getUserAttributes(), e.getOperationalAttributes());
+ AddOperation addOperation = new AddOperationBasis(conn, nextOperationID(), nextMessageID(), controls, e);
addOperation.run();
assertProxyPrivilege(addOperation.getResultCode(), hasProxyPrivilege);
@@ -1297,10 +1295,7 @@
// Try to add the entry. If this fails with the proxy control, then add it
// with a root connection so we can do other things with it.
- AddOperation addOperation =
- new AddOperationBasis(conn, nextOperationID(), nextMessageID(),
- controls, e.getName(), e.getObjectClasses(),
- e.getUserAttributes(), e.getOperationalAttributes());
+ AddOperation addOperation = new AddOperationBasis(conn, nextOperationID(), nextMessageID(), controls, e);
addOperation.run();
assertProxyPrivilege(addOperation.getResultCode(), hasProxyPrivilege);
--
Gitblit v1.10.0