From 0d97a7da226d93b8b87467efde523aa2120ceabc Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Fri, 07 Jun 2013 14:08:13 +0000
Subject: [PATCH] Fix for OPENDJ-925, OPENDJ-926, and overall schema management. Review CR-1806. Back a few years ago, when we did the SVR4 package, we split the schema into read-only (Install) and writable (Instance). With the template model in 2.6, the whole schema is under config, and we should never edit/change the one in the template. So, I've removed all code related to the 2 locations for schema, reverted some I10N messages to their previous versions, and tidy up code and tests. All unit-tests are passing. And it's also possible to change the instance.loc and run setup and have a fully functioning server :-)
---
opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java | 68 ++++++++++-----------------------
1 files changed, 21 insertions(+), 47 deletions(-)
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java b/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
index a670029..81e0aec 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
@@ -23,13 +23,14 @@
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
+ * Portions Copyright 2013 ForgeRock AS.
*/
-
package org.opends.guitools.controlpanel.task;
import static org.opends.messages.AdminToolMessages.*;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -68,6 +69,7 @@
import org.opends.server.types.SchemaFileElement;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.LDIFWriter;
+import org.opends.server.util.StaticUtils;
/**
* The task that is launched when a schema element must be deleted.
@@ -149,6 +151,7 @@
}
}
+ assert allOcsToDelete != null;
ArrayList<ObjectClass> lOcsToDelete =
new ArrayList<ObjectClass>(allOcsToDelete);
for (int i = lOcsToDelete.size() - 1; i >= 0; i--)
@@ -406,46 +409,29 @@
new LDIFExportConfig(schemaFile,
ExistingFileBehavior.OVERWRITE);
LDIFReader reader = null;
- Entry schemaEntry = null;
+ LDIFWriter writer = null;
try
{
reader = new LDIFReader(new LDIFImportConfig(schemaFile));
- schemaEntry = reader.readEntry();
+ Entry schemaEntry = reader.readEntry();
Modification mod = new Modification(ModificationType.DELETE,
Attributes.create(
getSchemaFileAttributeName(schemaElement).toLowerCase(),
getSchemaFileAttributeValue(schemaElement)));
schemaEntry.applyModification(mod);
- LDIFWriter writer = new LDIFWriter(exportConfig);
+ writer = new LDIFWriter(exportConfig);
writer.writeEntry(schemaEntry);
exportConfig.getWriter().newLine();
}
- catch (Throwable t)
+ catch (IOException e)
{
+ throw new OfflineUpdateException(
+ ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(e.toString()), e);
}
finally
{
- if (reader != null)
- {
- try
- {
- reader.close();
- }
- catch (Throwable t)
- {
- }
- }
- if (exportConfig != null)
- {
- try
- {
- exportConfig.close();
- }
- catch (Throwable t)
- {
- }
- }
+ StaticUtils.close(reader, exportConfig, writer);
}
}
@@ -465,14 +451,8 @@
if (!f.isAbsolute())
{
f = new File(
- DirectoryServer.getEnvironmentConfig().getSchemaDirectory(false),
- schemaFile);
- if (f == null || ! f.exists() || f.isDirectory())
- {
- f = new File(
- DirectoryServer.getEnvironmentConfig().getSchemaDirectory(true),
- schemaFile);
- }
+ DirectoryServer.getEnvironmentConfig().getSchemaDirectory(),
+ schemaFile);
}
schemaFile = f.getAbsolutePath();
return schemaFile;
@@ -480,10 +460,10 @@
/**
* Returns the attribute name in the schema entry that corresponds to the
- * profived schema element.
+ * provided schema element.
* @param element the schema element.
* @return the attribute name in the schema entry that corresponds to the
- * profived schema element.
+ * provided schema element.
*/
private String getSchemaFileAttributeName(CommonSchemaElements element)
{
@@ -565,14 +545,13 @@
}
StringBuilder sb = new StringBuilder();
- sb.append(
- msg+"<br><b>");
+ sb.append(msg).append("<br><b>");
sb.append(equiv);
sb.append("<br>");
sb.append("dn: cn=schema<br>");
sb.append("changetype: modify<br>");
- sb.append("delete: "+attrName+"<br>");
- sb.append(attrName+": "+attrValue);
+ sb.append("delete: ").append(attrName).append("<br>");
+ sb.append(attrName).append(": ").append(attrValue);
sb.append("</b><br><br>");
getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(),
ColorAndFontConstants.progressFont));
@@ -583,13 +562,12 @@
{
AttributeType attrToAdd;
boolean isSuperior = false;
- AttributeType newSuperior = attrToDelete.getSuperiorType();
for (AttributeType attr : providedAttrsToDelete)
{
if (attr.equals(attrToDelete.getSuperiorType()))
{
isSuperior = true;
- newSuperior = attr.getSuperiorType();
+ AttributeType newSuperior = attr.getSuperiorType();
while (newSuperior != null &&
providedAttrsToDelete.contains(newSuperior))
{
@@ -718,12 +696,8 @@
private Set<ObjectClass> getNewSuperiors(ObjectClass currentSup)
{
Set<ObjectClass> newSuperiors = new LinkedHashSet<ObjectClass>();
- if (currentSup.getSuperiorClasses() == null ||
- currentSup.getSuperiorClasses().isEmpty())
- {
- // Nothing to do
- }
- else
+ if (currentSup.getSuperiorClasses() != null &&
+ !currentSup.getSuperiorClasses().isEmpty())
{
for (ObjectClass o : currentSup.getSuperiorClasses())
{
--
Gitblit v1.10.0