From 39a420d9aa3817dbe2dc9eff52464e5b464dbdde Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 06 Oct 2016 15:33:04 +0000
Subject: [PATCH] OPENDJ-2860: add support for JSON property mapping in Rest2LDAP
---
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java | 29 ++++++++++++++++++-----------
1 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
index 83dc801..dc52087 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
@@ -26,6 +26,7 @@
import static org.forgerock.opendj.ldap.schema.CoreSchema.getGeneralizedTimeSyntax;
import static org.forgerock.opendj.ldap.schema.CoreSchema.getIntegerSyntax;
import static org.forgerock.opendj.rest2ldap.Rest2ldapMessages.ERR_UNRECOGNIZED_JSON_VALUE;
+import static org.forgerock.opendj.rest2ldap.schema.JsonSchema.getJsonSyntax;
import java.util.Collection;
import java.util.Collections;
@@ -45,6 +46,7 @@
import org.forgerock.opendj.ldap.GeneralizedTime;
import org.forgerock.opendj.ldap.LinkedAttribute;
import org.forgerock.opendj.ldap.schema.Syntax;
+import org.forgerock.opendj.rest2ldap.schema.JsonSchema;
import org.forgerock.services.context.Context;
import org.forgerock.util.Function;
import org.forgerock.util.promise.NeverThrowsException;
@@ -54,8 +56,8 @@
*/
final class Utils {
- private static final Function<Object, ByteString, NeverThrowsException> BASE64_TO_BYTESTRING =
- new Function<Object, ByteString, NeverThrowsException>() {
+ private static final Function<Object, ByteString, LocalizedIllegalArgumentException> BASE64_TO_BYTESTRING =
+ new Function<Object, ByteString, LocalizedIllegalArgumentException>() {
@Override
public ByteString apply(final Object value) {
return ByteString.valueOfBase64(String.valueOf(value));
@@ -70,7 +72,7 @@
}
};
- static Function<Object, ByteString, NeverThrowsException> base64ToByteString() {
+ static Function<Object, ByteString, LocalizedIllegalArgumentException> base64ToByteString() {
return BASE64_TO_BYTESTRING;
}
@@ -78,8 +80,9 @@
return BYTESTRING_TO_BASE64;
}
- static Function<ByteString, Object, NeverThrowsException> byteStringToJson(final AttributeDescription ad) {
- return new Function<ByteString, Object, NeverThrowsException>() {
+ static Function<ByteString, Object, LocalizedIllegalArgumentException> byteStringToJson(
+ final AttributeDescription ad) {
+ return new Function<ByteString, Object, LocalizedIllegalArgumentException>() {
@Override
public Object apply(final ByteString value) {
final Syntax syntax = ad.getAttributeType().getSyntax();
@@ -88,8 +91,9 @@
} else if (syntax.equals(getIntegerSyntax())) {
return byteStringToLong().apply(value);
} else if (syntax.equals(getGeneralizedTimeSyntax())) {
- return printDateTime(byteStringToGeneralizedTime().apply(value)
- .toCalendar());
+ return printDateTime(byteStringToGeneralizedTime().apply(value).toCalendar());
+ } else if (syntax.equals(getJsonSyntax())) {
+ return JsonSchema.byteStringToJson().apply(value);
} else {
return byteStringToString().apply(value);
}
@@ -120,17 +124,20 @@
}
}
- static Function<Object, ByteString, NeverThrowsException> jsonToByteString(final AttributeDescription ad) {
- return new Function<Object, ByteString, NeverThrowsException>() {
+ static Function<Object, ByteString, Exception> jsonToByteString(
+ final AttributeDescription ad) {
+ return new Function<Object, ByteString, Exception>() {
@Override
- public ByteString apply(final Object value) {
+ public ByteString apply(final Object value) throws Exception {
+ final Syntax syntax = ad.getAttributeType().getSyntax();
if (isJsonPrimitive(value)) {
- final Syntax syntax = ad.getAttributeType().getSyntax();
if (syntax.equals(getGeneralizedTimeSyntax())) {
return ByteString.valueOfObject(GeneralizedTime.valueOf(parseDateTime(value.toString())));
} else {
return ByteString.valueOfObject(value);
}
+ } else if (syntax.equals(getJsonSyntax())) {
+ return JsonSchema.jsonToByteString().apply(value);
} else {
throw new LocalizedIllegalArgumentException(ERR_UNRECOGNIZED_JSON_VALUE.get(value.getClass()
.getName()));
--
Gitblit v1.10.0