From ae66a13bcce1ff99f9bca88371b892461eb69926 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 23 Jun 2016 13:59:36 +0000
Subject: [PATCH] SchemaBackend.java: extract method applyModifications()
---
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java | 48 ++++++++++++++++++++++--------------------------
1 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index e71dc63..de3279e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -623,18 +623,15 @@
public void replaceEntry(Entry oldEntry, Entry newEntry,
ModifyOperation modifyOperation) throws DirectoryException
{
- // Make sure that the authenticated user has the necessary UPDATE_SCHEMA
- // privilege.
+ // Make sure that the authenticated user has the necessary UPDATE_SCHEMA privilege.
ClientConnection clientConnection = modifyOperation.getClientConnection();
- if (! clientConnection.hasPrivilege(Privilege.UPDATE_SCHEMA,
- modifyOperation))
+ if (!clientConnection.hasPrivilege(Privilege.UPDATE_SCHEMA, modifyOperation))
{
LocalizableMessage message = ERR_SCHEMA_MODIFY_INSUFFICIENT_PRIVILEGES.get();
- throw new DirectoryException(ResultCode.INSUFFICIENT_ACCESS_RIGHTS,
- message);
+ throw new DirectoryException(ResultCode.INSUFFICIENT_ACCESS_RIGHTS, message);
}
- ArrayList<Modification> mods = new ArrayList<>(modifyOperation.getModifications());
+ List<Modification> mods = new ArrayList<>(modifyOperation.getModifications());
if (mods.isEmpty())
{
// There aren't any modifications, so we don't need to do anything.
@@ -643,7 +640,23 @@
Schema newSchema = DirectoryServer.getSchema().duplicate();
TreeSet<String> modifiedSchemaFiles = new TreeSet<>();
+ applyModifications(newSchema, mods, modifiedSchemaFiles, modifyOperation.isSynchronizationOperation());
+ updateSchemaFiles(newSchema, modifiedSchemaFiles);
+ DirectoryServer.setSchema(newSchema);
+ DN authzDN = modifyOperation.getAuthorizationDN();
+ if (authzDN == null)
+ {
+ authzDN = DN.rootDN();
+ }
+
+ modifiersName = ByteString.valueOfUtf8(authzDN.toString());
+ modifyTimestamp = createGeneralizedTimeValue(System.currentTimeMillis());
+ }
+
+ private void applyModifications(Schema newSchema, List<Modification> mods, Set<String> modifiedSchemaFiles,
+ boolean isSynchronizationOperation) throws DirectoryException
+ {
int pos = -1;
for (Modification m : mods)
{
@@ -666,8 +679,7 @@
break;
case REPLACE:
- if (!m.isInternal()
- && !modifyOperation.isSynchronizationOperation())
+ if (!m.isInternal() && !isSynchronizationOperation)
{
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
ERR_SCHEMA_INVALID_MODIFICATION_TYPE.get(m.getModificationType()));
@@ -686,26 +698,10 @@
break;
default:
- throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
ERR_SCHEMA_INVALID_MODIFICATION_TYPE.get(m.getModificationType()));
}
}
-
- // If we've gotten here, then everything looks OK, re-write all the
- // modified Schema Files.
- updateSchemaFiles(newSchema, modifiedSchemaFiles);
-
- // Finally set DirectoryServer to use the new Schema.
- DirectoryServer.setSchema(newSchema);
-
- DN authzDN = modifyOperation.getAuthorizationDN();
- if (authzDN == null)
- {
- authzDN = DN.rootDN();
- }
-
- modifiersName = ByteString.valueOfUtf8(authzDN.toString());
- modifyTimestamp = createGeneralizedTimeValue(System.currentTimeMillis());
}
private void addAttribute(Schema newSchema, Attribute a, Set<String> modifiedSchemaFiles) throws DirectoryException
--
Gitblit v1.10.0