From c865a97e6eec7f757af36688f95893ef520d8023 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Mon, 11 Feb 2013 10:13:29 +0000
Subject: [PATCH] Changes for OPENDJ-691: Implement add/create support * add toLDAP support for default mapper * code cleanup.
---
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/DefaultAttributeMapper.java | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/DefaultAttributeMapper.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/DefaultAttributeMapper.java
index 030055b..3d29ddc 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/DefaultAttributeMapper.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/DefaultAttributeMapper.java
@@ -133,24 +133,27 @@
@Override
void toLDAP(final Context c, final JsonValue v, final ResultHandler<List<Attribute>> h) {
if (v.isMap()) {
- List<Attribute> result = new ArrayList<Attribute>(v.size());
- for (Map.Entry<String, Object> field : v.asMap().entrySet()) {
+ final List<Attribute> result = new ArrayList<Attribute>(v.size());
+ for (final Map.Entry<String, Object> field : v.asMap().entrySet()) {
+ if (!isIncludedAttribute(field.getKey())) {
+ continue;
+ }
final AttributeDescription ad;
try {
ad = AttributeDescription.valueOf(field.getKey(), c.getConfig().schema());
- } catch (Exception e) {
+ } catch (final Exception e) {
// FIXME: improve error message.
h.handleError(new BadRequestException("The field " + field.getKey()
+ " is invalid"));
return;
}
- Object value = field.getValue();
+ final Object value = field.getValue();
if (isJSONPrimitive(value)) {
result.add(Attributes.singletonAttribute(ad, value));
} else if (value instanceof Collection<?>) {
- Attribute a =
+ final Attribute a =
c.getConfig().decodeOptions().getAttributeFactory().newAttribute(ad);
- for (Object o : (Collection<?>) value) {
+ for (final Object o : (Collection<?>) value) {
if (isJSONPrimitive(o)) {
a.add(o);
} else {
@@ -174,10 +177,6 @@
}
}
- private boolean isJSONPrimitive(Object value) {
- return value instanceof String || value instanceof Boolean || value instanceof Number;
- }
-
private boolean isIncludedAttribute(final String name) {
final String lowerName = toLowerCase(name);
@@ -193,4 +192,8 @@
return false;
}
+
+ private boolean isJSONPrimitive(final Object value) {
+ return value instanceof String || value instanceof Boolean || value instanceof Number;
+ }
}
--
Gitblit v1.10.0