From f303dd91c4c81b0b2fb9d9479671657a204b577b Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 15 Jun 2016 09:57:33 +0000
Subject: [PATCH] code cleanups
---
opendj-server-legacy/src/main/java/org/opends/server/config/JMXMBean.java | 54 ++++------
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java | 69 +++----------
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java | 33 ++----
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/Authorizations.java | 1
opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java | 32 +++--
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java | 47 +++++----
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java | 59 +++++------
7 files changed, 119 insertions(+), 176 deletions(-)
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/Authorizations.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/Authorizations.java
index 5fc5524..e732b81 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/Authorizations.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/Authorizations.java
@@ -15,7 +15,6 @@
*/
package org.forgerock.opendj.rest2ldap.authz;
-import static org.forgerock.opendj.rest2ldap.Rest2ldapMessages.*;
import static org.forgerock.opendj.rest2ldap.authz.ConditionalFilters.asConditionalFilter;
import static org.forgerock.opendj.rest2ldap.authz.ConditionalFilters.newConditionalFilter;
import static org.forgerock.util.promise.Promises.newResultPromise;
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 0d5c8ff..2953dbb 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
@@ -48,6 +48,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.regex.Pattern;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -122,8 +123,7 @@
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
/** The fully-qualified name of this class. */
- private static final String CLASS_NAME =
- "org.opends.server.backends.SchemaBackend";
+ private static final String CLASS_NAME = "org.opends.server.backends.SchemaBackend";
private static final String CONFIG_SCHEMA_ELEMENTS_FILE = "02-config.ldif";
private static final String CORE_SCHEMA_ELEMENTS_FILE = "00-core.ldif";
@@ -137,9 +137,6 @@
private static final AttributeType nameFormsType = getNameFormsAttributeType();
private static final AttributeType objectClassesType = getObjectClassesAttributeType();
- /** The set of user-defined attributes that will be included in the schema entry. */
- private ArrayList<Attribute> userDefinedAttributes;
-
/** The value containing DN of the user we'll say created the configuration. */
private ByteString creatorsName;
/** The value containing the DN of the last user to modify the configuration. */
@@ -148,33 +145,26 @@
private ByteString createTimestamp;
/** The timestamp that will be used for the latest schema modification time. */
private ByteString modifyTimestamp;
-
- /**
- * Indicates whether the attributes of the schema entry should always be
- * treated as user attributes even if they are defined as operational.
- */
- private boolean showAllAttributes;
+ /** The time that the schema was last modified. */
+ private long modifyTime;
/** The DN of the configuration entry for this backend. */
private DN configEntryDN;
-
/** The current configuration state. */
private SchemaBackendCfg currentConfig;
-
/** The set of base DNs for this backend. */
private Set<DN> baseDNs;
+ /** The set of user-defined attributes that will be included in the schema entry. */
+ private List<Attribute> userDefinedAttributes;
/** The set of objectclasses that will be used in the schema entry. */
- private HashMap<ObjectClass,String> schemaObjectClasses;
-
- /** The time that the schema was last modified. */
- private long modifyTime;
+ private Map<ObjectClass, String> schemaObjectClasses;
/**
* Regular expression used to strip minimum upper bound value from syntax
* Attribute Type Description. The value looks like: {count}.
*/
- private String stripMinUpperBoundRegEx = "\\{\\d+\\}";
+ private final Pattern stripMinUpperBoundRegEx = Pattern.compile("\\{\\d+\\}");
private ServerContext serverContext;
@@ -218,7 +208,6 @@
ByteString newBaseDN = ByteString.valueOfUtf8(baseDNs.iterator().next().toString());
creatorsName = newBaseDN;
modifiersName = newBaseDN;
-
createTimestamp = createGeneralizedTimeValue(getSchema().getOldestModificationTime());
modifyTimestamp = createGeneralizedTimeValue(getSchema().getYoungestModificationTime());
@@ -229,8 +218,6 @@
addAllNonSchemaConfigAttributes(userDefinedAttributes, configEntry.getUserAttributes().values());
addAllNonSchemaConfigAttributes(userDefinedAttributes, configEntry.getOperationalAttributes().values());
- showAllAttributes = cfg.isShowAllAttributes();
-
currentConfig = cfg;
}
@@ -449,15 +436,11 @@
* Generates and returns a schema entry for the Directory Server.
*
* @param entryDN The DN to use for the generated entry.
- * @param includeSchemaFile A boolean indicating if the X-SCHEMA-FILE
- * extension should be used when generating
- * the entry.
- *
* @return The schema entry that was generated.
*/
- public Entry getSchemaEntry(DN entryDN, boolean includeSchemaFile)
+ public Entry getSchemaEntry(DN entryDN)
{
- return getSchemaEntry(entryDN, includeSchemaFile, false);
+ return getSchemaEntry(entryDN, false, false);
}
/**
@@ -595,7 +578,7 @@
if (stripSyntaxMinimumUpperBound && value.indexOf('{') != -1)
{
// Strip the minimum upper bound value from the attribute value.
- value = value.replaceFirst(stripMinUpperBoundRegEx, "");
+ value = stripMinUpperBoundRegEx.matcher(value).replaceFirst("");
}
builder.add(value);
}
@@ -603,7 +586,7 @@
Attribute attribute = builder.toAttribute();
AttributeType attrType = attribute.getAttributeDescription().getAttributeType();
if (attrType.isOperational()
- && (ignoreShowAllOption || !showAllAttributes))
+ && (ignoreShowAllOption || !showAllAttributes()))
{
operationalAttrs.put(attrType, newArrayList(attribute));
}
@@ -2742,7 +2725,7 @@
// Get the schema entry and see if it matches the filter. If so, then send
// it to the client.
- Entry schemaEntry = getSchemaEntry(baseDN, false);
+ Entry schemaEntry = getSchemaEntry(baseDN);
SearchFilter filter = searchOperation.getFilter();
if (filter.matchesEntry(schemaEntry))
{
@@ -3089,12 +3072,8 @@
newBaseDNs = null;
}
- // Check to see if we should change the behavior regarding whether to show
- // all schema attributes.
- boolean newShowAllAttributes = backendCfg.isShowAllAttributes();
-
// Check to see if there is a new set of user-defined attributes.
- ArrayList<Attribute> newUserAttrs = new ArrayList<>();
+ List<Attribute> newUserAttrs = new ArrayList<>();
try
{
Entry configEntry = DirectoryServer.getConfigEntry(configEntryDN);
@@ -3158,11 +3137,8 @@
}
}
- showAllAttributes = newShowAllAttributes;
-
userDefinedAttributes = newUserAttrs;
- LocalizableMessage message = INFO_SCHEMA_USING_NEW_USER_ATTRS.get();
- ccr.addMessage(message);
+ ccr.addMessage(INFO_SCHEMA_USING_NEW_USER_ATTRS.get());
}
currentConfig = backendCfg;
@@ -3192,20 +3168,7 @@
*/
boolean showAllAttributes()
{
- return showAllAttributes;
- }
-
- /**
- * Specifies whether to treat common schema attributes like user attributes
- * rather than operational attributes.
- *
- * @param showAllAttributes Specifies whether to treat common schema
- * attributes like user attributes rather than
- * operational attributes.
- */
- void setShowAllAttributes(boolean showAllAttributes)
- {
- this.showAllAttributes = showAllAttributes;
+ return this.currentConfig.isShowAllAttributes();
}
@Override
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/JMXMBean.java b/opendj-server-legacy/src/main/java/org/opends/server/config/JMXMBean.java
index 0eed9ba..0485e02 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/JMXMBean.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/JMXMBean.java
@@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -44,8 +45,8 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.schema.AttributeType;
-import org.forgerock.util.Utils;
import org.forgerock.opendj.server.config.server.MonitorProviderCfg;
+import org.forgerock.util.Utils;
import org.opends.server.api.AlertGenerator;
import org.opends.server.api.ClientConnection;
import org.opends.server.api.DirectoryServerMBean;
@@ -80,22 +81,16 @@
{
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
- /**
- * The fully-qualified name of this class.
- */
+ /** The fully-qualified name of this class. */
private static final String CLASS_NAME = "org.opends.server.config.JMXMBean";
-
/** The set of alert generators for this MBean. */
private List<AlertGenerator> alertGenerators;
-
/** The set of monitor providers for this MBean. */
private List<MonitorProvider<? extends MonitorProviderCfg>> monitorProviders;
-
/** The DN of the configuration entry with which this MBean is associated. */
private DN configEntryDN;
-
/** The object name for this MBean. */
private ObjectName objectName;
@@ -252,8 +247,8 @@
* @param generator The alert generator to remove from the set of alert
* generators for this JMX MBean.
*
- * @return <CODE>true</CODE> if the alert generator was removed, or
- * <CODE>false</CODE> if it was not associated with this MBean.
+ * @return {@code true} if the alert generator was removed,
+ * or {@code false} if it was not associated with this MBean.
*/
public boolean removeAlertGenerator(AlertGenerator generator)
{
@@ -283,8 +278,7 @@
* @param component The component to add to the set of monitor providers
* for this JMX MBean.
*/
- public void addMonitorProvider(MonitorProvider<? extends MonitorProviderCfg>
- component)
+ public void addMonitorProvider(MonitorProvider<? extends MonitorProviderCfg> component)
{
synchronized (monitorProviders)
{
@@ -304,8 +298,8 @@
* @param component The component to remove from the set of monitor
* providers for this JMX MBean.
*
- * @return <CODE>true</CODE> if the specified component was successfully
- * removed, or <CODE>false</CODE> if not.
+ * @return {@code true} if the specified component was successfully removed,
+ * or {@code false} if not.
*/
public boolean removeMonitorProvider(MonitorProvider<?> component)
{
@@ -322,7 +316,7 @@
*
* @param name The name of the configuration attribute to retrieve.
*
- * @return The specified configuration attribute, or <CODE>null</CODE> if
+ * @return The specified configuration attribute, or {@code null} if
* there is no such attribute.
*/
private Attribute getJmxAttribute(String name)
@@ -342,14 +336,14 @@
}
Iterator<ByteString> iterator = a.iterator();
- ByteString value = iterator.next();
+ ByteString firstValue = iterator.next();
if (iterator.hasNext())
{
- List<String> stringValues = newArrayList(value.toString());
+ List<String> stringValues = newArrayList(firstValue.toString());
while (iterator.hasNext())
{
- value = iterator.next();
+ ByteString value = iterator.next();
stringValues.add(value.toString());
}
@@ -358,7 +352,7 @@
}
else
{
- return new Attribute(name, value.toString());
+ return new Attribute(name, firstValue.toString());
}
}
}
@@ -557,7 +551,7 @@
StringBuilder buffer = new StringBuilder();
buffer.append(actionName);
buffer.append("(");
- Utils.joinAsString(", ", (Object[]) signature);
+ Utils.joinAsString(buffer, ", ", (Object[]) signature);
buffer.append(")");
LocalizableMessage message = ERR_CONFIG_JMX_NO_METHOD.get(buffer, configEntryDN);
@@ -571,7 +565,7 @@
* Provides the exposed attributes and actions of the Dynamic MBean using an
* MBeanInfo object.
*
- * @return An instance of <CODE>MBeanInfo</CODE> allowing all attributes and
+ * @return An instance of {@code MBeanInfo} allowing all attributes and
* actions exposed by this Dynamic MBean to be retrieved.
*/
@Override
@@ -601,10 +595,10 @@
String className = generator.getClassName();
Map<String, String> alerts = generator.getAlerts();
- for (String type : alerts.keySet())
+ for (Entry<String, String> mapEntry : alerts.entrySet())
{
- String[] types = { type };
- String description = alerts.get(type);
+ String[] types = { mapEntry.getKey() };
+ String description = mapEntry.getValue();
notifications.add(new MBeanNotificationInfo(types, className, description));
}
}
@@ -629,23 +623,19 @@
*/
private ClientConnection getClientConnection()
{
- ClientConnection clientConnection = null;
- java.security.AccessControlContext acc = java.security.AccessController
- .getContext();
+ java.security.AccessControlContext acc = java.security.AccessController.getContext();
try
{
- javax.security.auth.Subject subject = javax.security.auth.Subject
- .getSubject(acc);
+ javax.security.auth.Subject subject = javax.security.auth.Subject.getSubject(acc);
if (subject != null)
{
Set<?> privateCreds = subject.getPrivateCredentials(Credential.class);
- clientConnection = ((Credential) privateCreds.iterator().next())
- .getClientConnection();
+ return ((Credential) privateCreds.iterator().next()).getClientConnection();
}
}
catch (Exception e)
{
}
- return clientConnection;
+ return null;
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
index c066d85..43dda75 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -271,18 +271,13 @@
final ProgressNotificationCallback pnc = new ProgressNotificationCallback(INFORMATION, summary, 20);
context.notifyProgress(pnc);
- final File schemaFileTemplate =
- new File(templateConfigSchemaDirectory, fileName);
-
+ final File schemaFileTemplate = new File(templateConfigSchemaDirectory, fileName);
final File pathDestination = new File(configSchemaDirectory, fileName);
try
{
- final int changeCount =
- updateSchemaFile(schemaFileTemplate, pathDestination,
- attributeOids, null);
+ final int changeCount = updateSchemaFile(schemaFileTemplate, pathDestination, attributeOids, null);
- displayChangeCount(pathDestination.getPath(), changeCount);
-
+ displayChangeCount(pathDestination, changeCount);
context.notifyProgress(pnc.setProgress(100));
}
catch (final IOException | IllegalStateException e)
@@ -330,21 +325,15 @@
final ProgressNotificationCallback pnc = new ProgressNotificationCallback(INFORMATION, summary, 20);
context.notifyProgress(pnc);
- final File schemaFileTemplate =
- new File(templateConfigSchemaDirectory, fileName);
-
+ final File schemaFileTemplate = new File(templateConfigSchemaDirectory, fileName);
final File pathDestination = new File(configSchemaDirectory, fileName);
-
context.notifyProgress(pnc.setProgress(20));
try
{
- final int changeCount =
- updateSchemaFile(schemaFileTemplate, pathDestination,
- null, objectClassesOids);
+ final int changeCount = updateSchemaFile(schemaFileTemplate, pathDestination, null, objectClassesOids);
- displayChangeCount(pathDestination.getPath(), changeCount);
-
+ displayChangeCount(pathDestination, changeCount);
context.notifyProgress(pnc.setProgress(100));
}
catch (final IOException e)
@@ -714,7 +703,7 @@
List<String> args = new ArrayList<>(baseArgs);
args.add("--configFile");
- args.add(CONFIG_FILE_PATH);
+ args.add(configFile.getAbsolutePath());
for (final String be : baseDNs)
{
args.add("--baseDN");
@@ -1147,9 +1136,9 @@
}
}
- private static void displayChangeCount(final String fileName,
- final int changeCount)
+ private static void displayChangeCount(final File configfile, final int changeCount)
{
+ String fileName = configfile.getAbsolutePath();
if (changeCount != 0)
{
logger.debug(INFO_UPGRADE_CHANGE_DONE_IN_SPECIFIC_FILE, fileName, changeCount);
@@ -1218,8 +1207,8 @@
try
{
final Filter filterVal = filter != null ? Filter.valueOf(filter) : null;
- final int changeCount = updateConfigFile(CONFIG_FILE_PATH, filterVal, changeOperationType, ldif);
- displayChangeCount(CONFIG_FILE_PATH, changeCount);
+ final int changeCount = updateConfigFile(configFile, filterVal, changeOperationType, ldif);
+ displayChangeCount(configFile, changeCount);
context.notifyProgress(pnc.setProgress(100));
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java
index f6fdd6c..09f561a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java
@@ -23,7 +23,6 @@
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -45,7 +44,6 @@
import org.forgerock.opendj.ldap.LinkedHashMapEntry;
import org.forgerock.opendj.ldap.Matcher;
import org.forgerock.opendj.ldap.SearchScope;
-import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.ModifyRequest;
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.requests.SearchRequest;
@@ -74,28 +72,27 @@
{
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
- /** The config folder of the current instance. */
+ /** The {@code config} folder of the current instance. */
static final File configDirectory = new File(getInstancePath(), CONFIG_PATH_RELATIVE);
- /** The config/schema folder of the current instance. */
+ /** The {@code config/schema} folder of the current instance. */
static final File configSchemaDirectory = new File(configDirectory, SCHEMA_PATH_RELATIVE);
- /** The template folder of the current installation. */
+ /** The {@code template} folder of the current installation. */
private static final File templateDirectory = new File(getInstallationPath(), TEMPLATE_RELATIVE_PATH);
- /** The template/config folder of the current installation. */
+ /** The {@code template/config} folder of the current installation. */
static final File templateConfigDirectory = new File(templateDirectory, CONFIG_PATH_RELATIVE);
- /** The template/config/schema folder of the current installation. */
+ /** The {@code template/config/schema} folder of the current installation. */
static final File templateConfigSchemaDirectory = new File(templateConfigDirectory, SCHEMA_PATH_RELATIVE);
- /** The config/snmp/security folder of the current instance. */
+ /** The {@code config/snmp/security} folder of the current instance. */
static final File configSnmpSecurityDirectory = new File(
configDirectory + File.separator + SNMP_PATH_RELATIVE + File.separator + SECURITY_PATH_RELATIVE);
- /** The lib folder of the current installation. */
+ /** The {@code lib} folder of the current installation. */
static final File libDirectory = new File(getInstallationPath(), LIB_RELATIVE_PATH);
- /** The bin folder of the current installation. */
+ /** The {@code bin} folder of the current installation. */
static final File binDirectory = new File(getInstallationPath(), UNIX_BINARIES_PATH_RELATIVE);
- /** The bat folder of the current installation. */
+ /** The {@code bat} folder of the current installation. */
static final File batDirectory = new File(getInstallationPath(), WINDOWS_BINARIES_PATH_RELATIVE);
/** The server configuration file path. */
- static final String CONFIG_FILE_PATH =
- Paths.get(configDirectory.getAbsolutePath(), CURRENT_CONFIG_FILE_NAME).toString();
+ static final File configFile = new File(configDirectory, CURRENT_CONFIG_FILE_NAME);
/**
* Returns the path of the installation of the directory server. Note that
@@ -302,42 +299,41 @@
return baseDNs;
}
- static EntryReader searchConfigFile(final SearchRequest sr) throws FileNotFoundException
+ static EntryReader searchConfigFile(final SearchRequest searchRequest) throws FileNotFoundException
{
final Schema schema = getUpgradeSchema();
final File configFile = new File(configDirectory, CURRENT_CONFIG_FILE_NAME);
final LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile)).setSchema(schema);
- return LDIF.search(entryReader, sr, schema);
+ return LDIF.search(entryReader, searchRequest, schema);
}
/**
* Updates the config file during the upgrade process.
*
- * @param configPath
+ * @param configFile
* The original path to the file.
* @param filter
* The filter to select entries. Only useful for modify change type.
* @param changeType
* The change type which must be applied to ldif lines.
* @param ldifLines
- * The change record ldif lines.
- * For ADD change type, the first line must be the dn.
- * For DELETE change type, the first and only line must be the dn.
+ * The change record ldif lines. For ADD change type, the first line must be the dn. For
+ * DELETE change type, the first and only line must be the dn.
* @throws IOException
* If an Exception occurs during the input output methods.
* @return The changes number that have occurred.
*/
- static int updateConfigFile(final String configPath,
+ static int updateConfigFile(final File configFile,
final Filter filter, final ChangeOperationType changeType,
final String... ldifLines) throws IOException
{
- final File original = new File(configPath);
+ final File original = configFile;
final File copyConfig =
File.createTempFile("copyConfig", ".tmp", original.getParentFile());
int changeCount = 0;
final Schema schema = getUpgradeSchema();
- try (LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configPath)).setSchema(schema);
+ try (LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile)).setSchema(schema);
LDIFEntryWriter writer = new LDIFEntryWriter(new FileOutputStream(copyConfig)))
{
writer.setWrapColumn(80);
@@ -414,8 +410,7 @@
if (changeType == ADD && !entryAlreadyExist)
{
- final AddRequest ar = Requests.newAddRequest(ldifLines);
- writer.writeEntry(ar);
+ writer.writeEntry(Requests.newAddRequest(ldifLines));
logger.debug(LocalizableMessage.raw("Entry successfully added %s in %s", ldifDN, original.getAbsolutePath()));
changeCount++;
}
@@ -431,7 +426,8 @@
try
{
// Renaming the file, overwriting previous one.
- rename(copyConfig, new File(configPath));
+ rename(copyConfig, configFile);
+ return changeCount;
}
catch (IOException e)
{
@@ -439,8 +435,6 @@
deleteRecursively(original);
throw e;
}
-
- return changeCount;
}
private static String removeDnPrefix(String dnLine)
@@ -608,14 +602,13 @@
{
throw new IllegalStateException(e);
}
- throw new IllegalStateException(ERR_UPGRADE_UNKNOWN_OC_ATT.get(type, oid)
- .toString());
+ throw new IllegalStateException(ERR_UPGRADE_UNKNOWN_OC_ATT.get(type, oid).toString());
}
/**
- * Creates a new file in the config/upgrade folder. The new file is a
- * concatenation of entries of all files contained in the config/schema
- * folder.
+ * Creates a new file in The {@code config/upgrade} folder.
+ * The new file is a concatenation of entries of all files contained in the
+ * {@code config/schema} folder.
*
* @param folder
* The folder containing the schema files.
@@ -740,7 +733,7 @@
static List<String> filterExistingIndexes(final Set<String> candidateIndexes, final String backendID)
{
final List<String> indexesToRebuild = new ArrayList<>();
- try (final LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(CONFIG_FILE_PATH)))
+ try (final LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile)))
{
while (entryReader.hasNext())
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java b/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
index 7a56b59..046d728 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
@@ -1583,24 +1583,20 @@
File configFile = new File(DirectoryServer.getConfigFile());
- File configDirectory = configFile.getParentFile();
+ File configDirectory = configFile.getParentFile();
File upgradeDirectory = new File(configDirectory, "upgrade");
upgradeDirectory.mkdir();
- File concatFile = new File(upgradeDirectory,
- SCHEMA_CONCAT_FILE_NAME);
+ File concatFile = new File(upgradeDirectory, SCHEMA_CONCAT_FILE_NAME);
concatFilePath = concatFile.getAbsolutePath();
File tempFile = new File(concatFilePath + ".tmp");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile, false)))
{
- writer.write("dn: " + DirectoryServer.getSchemaDN());
- writer.newLine();
- writer.write("objectClass: top");
- writer.newLine();
- writer.write("objectClass: ldapSubentry");
- writer.newLine();
- writer.write("objectClass: subschema");
- writer.newLine();
+ writeLines(writer,
+ "dn: " + DirectoryServer.getSchemaDN(),
+ "objectClass: top",
+ "objectClass: ldapSubentry",
+ "objectClass: subschema");
writeLines(writer, ATTR_ATTRIBUTE_TYPES, attributeTypes);
writeLines(writer, ATTR_OBJECTCLASSES, objectClasses);
@@ -1630,6 +1626,15 @@
}
}
+ private static void writeLines(BufferedWriter writer, String... lines) throws IOException
+ {
+ for (String line : lines)
+ {
+ writer.write(line);
+ writer.newLine();
+ }
+ }
+
private static void writeLines(BufferedWriter writer, String beforeColumn, Set<String> lines) throws IOException
{
for (String line : lines)
@@ -1641,8 +1646,6 @@
}
}
-
-
/**
* Reads the files contained in the schema directory and generates a
* concatenated view of their contents in the provided sets.
@@ -1845,6 +1848,9 @@
{
if (definition.startsWith("::"))
{
+ // See OPENDJ-2792: the definition of the ds-cfg-csv-delimiter-char attribute type
+ // had a space accidentally added after the closing parenthesis.
+ // This was unfortunately interpreted as base64
definition = ByteString.wrap(Base64.decode(definition.substring(2).trim())).toString();
}
else if (definition.startsWith(":"))
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
index f4ae6ab..29e9ec6 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
@@ -18,6 +18,7 @@
import static org.forgerock.opendj.ldap.ResultCode.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
+import static org.mockito.Mockito.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
@@ -47,6 +48,7 @@
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldap.schema.Schema;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
+import org.forgerock.opendj.server.config.server.SchemaBackendCfg;
import org.forgerock.util.Utils;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.AddOperation;
@@ -171,11 +173,10 @@
* @throws Exception If an unexpected problem occurs.
*/
@Test
- public void testGetSchemaEntry()
- throws Exception
+ public void testGetSchemaEntry() throws Exception
{
DN schemaDN = DN.valueOf("cn=schema");
- Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false);
+ Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN);
assertNotNull(schemaEntry);
assertEquals(schemaEntry.getName(), schemaDN);
@@ -185,7 +186,7 @@
assertTrue(schemaEntry.hasAttribute(getMatchingRulesAttributeType()));
schemaDN = DN.valueOf("cn=subschema");
- schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false);
+ schemaEntry = schemaBackend.getSchemaEntry(schemaDN);
assertNotNull(schemaEntry);
assertEquals(schemaEntry.getName(), schemaDN);
@@ -237,9 +238,9 @@
{
DN schemaDN = DN.valueOf("cn=schema");
- DeleteOperationBasis deleteOperation =
- new DeleteOperationBasis(getRootConnection(), nextOperationID(), nextMessageID(),
- null, schemaDN);
+ DeleteOperationBasis deleteOperation = new DeleteOperationBasis(
+ getRootConnection(), nextOperationID(), nextMessageID(),
+ null, schemaDN);
schemaBackend.deleteEntry(schemaDN, deleteOperation);
}
@@ -252,16 +253,12 @@
DN currentSchemaDN = DN.valueOf("cn=schema");
DN newSchemaDN = DN.valueOf("cn=newschema");
- InternalClientConnection conn = getRootConnection();
- ModifyDNOperationBasis modifyDNOperation =
- new ModifyDNOperationBasis(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null,
- currentSchemaDN, newSchemaDN.rdn(),
- true, null);
+ ModifyDNOperationBasis modifyDNOperation = new ModifyDNOperationBasis(
+ getRootConnection(), nextOperationID(), nextMessageID(),
+ null, currentSchemaDN, newSchemaDN.rdn(), true, null);
- schemaBackend.renameEntry(currentSchemaDN,
- schemaBackend.getSchemaEntry(newSchemaDN, false),
- modifyDNOperation);
+ Entry newSchemaEntry = schemaBackend.getSchemaEntry(newSchemaDN);
+ schemaBackend.renameEntry(currentSchemaDN, newSchemaEntry, modifyDNOperation);
}
/**
@@ -377,29 +374,35 @@
AttributeType s = getLDAPSyntaxesAttributeType();
assertFalse(schemaBackend.showAllAttributes());
- Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false);
+ Entry schemaEntry = schemaBackend.getSchemaEntry(schemaDN);
assertTrue(schemaEntry.hasOperationalAttribute(a));
assertTrue(schemaEntry.hasOperationalAttribute(o));
assertTrue(schemaEntry.hasOperationalAttribute(m));
assertTrue(schemaEntry.hasOperationalAttribute(s));
- schemaBackend.setShowAllAttributes(true);
- assertTrue(schemaBackend.showAllAttributes());
- schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false);
+ setShowAllAttributes(schemaBackend, true);
+ schemaEntry = schemaBackend.getSchemaEntry(schemaDN);
assertFalse(schemaEntry.hasOperationalAttribute(a));
assertFalse(schemaEntry.hasOperationalAttribute(o));
assertFalse(schemaEntry.hasOperationalAttribute(m));
assertTrue(schemaEntry.hasOperationalAttribute(s));
- schemaBackend.setShowAllAttributes(false);
+ setShowAllAttributes(schemaBackend, false);
assertFalse(schemaBackend.showAllAttributes());
- schemaEntry = schemaBackend.getSchemaEntry(schemaDN, false);
+ schemaEntry = schemaBackend.getSchemaEntry(schemaDN);
assertTrue(schemaEntry.hasOperationalAttribute(a));
assertTrue(schemaEntry.hasOperationalAttribute(o));
assertTrue(schemaEntry.hasOperationalAttribute(m));
assertTrue(schemaEntry.hasOperationalAttribute(s));
}
+ private void setShowAllAttributes(SchemaBackend schemaBackend, boolean showAllAttributes)
+ {
+ SchemaBackendCfg cfg = spy(SchemaBackendCfg.class);
+ when(cfg.isShowAllAttributes()).thenReturn(showAllAttributes);
+ schemaBackend.applyConfigurationChange(cfg);
+ }
+
/**
* Tests the behavior of the schema backend when attempting to add a new
* attribute type that is not allowed to be altered.
--
Gitblit v1.10.0