From 5daf59a304761abcff57e9117b759bff515ca623 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 29 Mar 2016 18:56:34 +0000
Subject: [PATCH] Prep work for OPENDJ-2803 Migrate Attribute
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java | 15 ++--
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java | 64 ++------------------
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java | 57 ++++--------------
3 files changed, 28 insertions(+), 108 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
index 732a2a9..96c149e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
@@ -34,6 +34,7 @@
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchResult;
+import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.schema.AttributeType;
@@ -283,15 +284,14 @@
for (String wholeName : getAttributeNames())
{
- final org.opends.server.types.Attribute attribute =
- LDIFReader.parseAttrDescription(wholeName);
- final String attrName = attribute.getAttributeDescription().getNameOrOID();
+ final AttributeDescription attrDesc = LDIFReader.parseAttrDescription(wholeName);
+ final AttributeType attrType = attrDesc.getAttributeType();
// See if this is an objectclass or an attribute. Then get the
// corresponding definition and add the value to the appropriate hash.
- if (attrName.equalsIgnoreCase("objectclass"))
+ if (attrType.isObjectClass())
{
- for (Object value : getAttributeValues(attrName))
+ for (Object value : getAttributeValues(attrType.getNameOrOID()))
{
String ocName = value.toString().trim();
String lowerOCName = toLowerCase(ocName);
@@ -308,9 +308,8 @@
}
else
{
- AttributeType attrType = DirectoryServer.getAttributeType(attrName);
- AttributeBuilder builder = new AttributeBuilder(attribute.getAttributeDescription());
- for (Object value : getAttributeValues(attrName))
+ AttributeBuilder builder = new AttributeBuilder(attrDesc);
+ for (Object value : getAttributeValues(attrType.getNameOrOID()))
{
ByteString bs;
if (value instanceof byte[])
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java
index ee4ac33..9b4810a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java
@@ -19,6 +19,7 @@
import static org.forgerock.util.Utils.*;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.server.util.CollectionUtils.*;
+import static org.opends.server.util.LDIFReader.*;
import static org.opends.server.util.StaticUtils.*;
import java.awt.Component;
@@ -53,6 +54,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.schema.AttributeType;
@@ -640,14 +642,14 @@
for (String wholeName : csr.getAttributeNames())
{
- final Attribute attribute = parseAttrDescription(wholeName);
- final String attrName = attribute.getAttributeDescription().getNameOrOID();
+ final AttributeDescription attrDesc = parseAttrDescription(wholeName);
+ final AttributeType attrType = attrDesc.getAttributeType();
// See if this is an objectclass or an attribute. Then get the
// corresponding definition and add the value to the appropriate hash.
- if ("objectclass".equalsIgnoreCase(attrName))
+ if (attrType.isObjectClass())
{
- for (Object value : csr.getAttributeValues(attrName))
+ for (Object value : csr.getAttributeValues(attrType.getNameOrOID()))
{
String ocName = value.toString().trim();
String lowerOCName = toLowerCase(ocName);
@@ -664,9 +666,8 @@
}
else
{
- AttributeType attrType = DirectoryServer.getAttributeType(attrName);
- AttributeBuilder builder = new AttributeBuilder(attribute.getAttributeDescription());
- for (Object value : csr.getAttributeValues(attrName))
+ AttributeBuilder builder = new AttributeBuilder(attrDesc);
+ for (Object value : csr.getAttributeValues(attrType.getNameOrOID()))
{
ByteString bs;
if (value instanceof byte[])
@@ -696,55 +697,6 @@
}
/**
- * Parse an AttributeDescription (an attribute type name and its
- * options).
- * TODO: make this method in LDIFReader public.
- *
- * @param attrDescr
- * The attribute description to be parsed.
- * @return A new attribute with no values, representing the
- * attribute type and its options.
- */
- private static Attribute parseAttrDescription(String attrDescr)
- {
- AttributeBuilder builder;
- int semicolonPos = attrDescr.indexOf(';');
- if (semicolonPos > 0)
- {
- builder = new AttributeBuilder(attrDescr.substring(0, semicolonPos));
- int nextPos = attrDescr.indexOf(';', semicolonPos + 1);
- while (nextPos > 0)
- {
- String option = attrDescr.substring(semicolonPos + 1, nextPos);
- if (option.length() > 0)
- {
- builder.setOption(option);
- semicolonPos = nextPos;
- nextPos = attrDescr.indexOf(';', semicolonPos + 1);
- }
- }
-
- String option = attrDescr.substring(semicolonPos + 1);
- if (option.length() > 0)
- {
- builder.setOption(option);
- }
- }
- else
- {
- builder = new AttributeBuilder(attrDescr);
- }
-
- if(builder.getAttributeType().getSyntax().isBEREncodingRequired())
- {
- //resetting doesn't hurt and returns false.
- builder.setOption("binary");
- }
-
- return builder.toAttribute();
- }
-
- /**
* The main method to test this panel.
* @param args the arguments.
*/
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java b/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
index a2ac347..f028cb4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
@@ -771,8 +771,7 @@
// Parse the attribute type description.
int colonPos = parseColonPosition(lines, line);
String attrDescr = line.substring(0, colonPos);
- final Attribute attribute = parseAttrDescription(attrDescr);
- final AttributeDescription attrDesc = attribute.getAttributeDescription();
+ final AttributeDescription attrDesc = parseAttrDescription(attrDescr);
final AttributeType attrType = attrDesc.getAttributeType();
final String attrName = attrType.getNameOrOID();
@@ -932,14 +931,13 @@
// Parse the attribute type description.
int colonPos = parseColonPosition(lines, line);
String attrDescr = line.substring(0, colonPos);
- Attribute attribute = parseAttrDescription(attrDescr);
- String attrName = attribute.getAttributeDescription().getNameOrOID();
+ AttributeDescription attrDesc = parseAttrDescription(attrDescr);
+ String attrName = attrDesc.getNameOrOID();
if (attributeName != null)
{
- Attribute expectedAttr = parseAttrDescription(attributeName);
-
- if (!attribute.equals(expectedAttr))
+ AttributeDescription expectedAttrDesc = parseAttrDescription(attributeName);
+ if (!attrDesc.equals(expectedAttrDesc))
{
LocalizableMessage message = ERR_LDIF_INVALID_CHANGERECORD_ATTRIBUTE.get(
attrDescr, attributeName);
@@ -951,7 +949,7 @@
ByteString value = parseSingleValue(lines, line, entryDN,
colonPos, attrName);
- AttributeBuilder builder = new AttributeBuilder(attribute.getAttributeDescription());
+ AttributeBuilder builder = new AttributeBuilder(attrDesc);
builder.add(value);
return builder.toAttribute();
}
@@ -1077,43 +1075,14 @@
* @return A new attribute with no values, representing the
* attribute type and its options.
*/
- public static Attribute parseAttrDescription(String attrDescr)
+ public static AttributeDescription parseAttrDescription(String attrDescr)
{
- AttributeBuilder builder;
- int semicolonPos = attrDescr.indexOf(';');
- if (semicolonPos > 0)
+ AttributeDescription result = AttributeDescription.valueOf(attrDescr);
+ if (result.getAttributeType().getSyntax().isBEREncodingRequired())
{
- builder = new AttributeBuilder(attrDescr.substring(0, semicolonPos));
- int nextPos = attrDescr.indexOf(';', semicolonPos + 1);
- while (nextPos > 0)
- {
- String option = attrDescr.substring(semicolonPos + 1, nextPos);
- if (option.length() > 0)
- {
- builder.setOption(option);
- semicolonPos = nextPos;
- nextPos = attrDescr.indexOf(';', semicolonPos + 1);
- }
- }
-
- String option = attrDescr.substring(semicolonPos + 1);
- if (option.length() > 0)
- {
- builder.setOption(option);
- }
+ result = result.withOption("binary");
}
- else
- {
- builder = new AttributeBuilder(attrDescr);
- }
-
- if(builder.getAttributeType().getSyntax().isBEREncodingRequired())
- {
- //resetting doesn't hurt and returns false.
- builder.setOption("binary");
- }
-
- return builder.toAttribute();
+ return result;
}
@@ -1331,8 +1300,8 @@
}
// Now go through the rest of the attributes till the "-" line is reached.
- Attribute modAttr = LDIFReader.parseAttrDescription(attrDescr);
- AttributeBuilder builder = new AttributeBuilder(modAttr.getAttributeDescription());
+ AttributeDescription modAttrDesc = LDIFReader.parseAttrDescription(attrDescr);
+ AttributeBuilder builder = new AttributeBuilder(modAttrDesc);
while (! lines.isEmpty())
{
line = lines.remove();
--
Gitblit v1.10.0