From 4a164f90a4bab55c79314343d6127570a8fbed10 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 19 Sep 2016 09:18:00 +0000
Subject: [PATCH] OPENDJ-3250 Return the CREST descriptor over REST for config endpoint

---
 opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Resource.java |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Resource.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Resource.java
index 07421a0..9aa6c0a 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Resource.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Resource.java
@@ -60,6 +60,7 @@
 import org.forgerock.api.models.Services;
 import org.forgerock.api.models.Update;
 import org.forgerock.http.ApiProducer;
+import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
 import org.forgerock.json.JsonPointer;
 import org.forgerock.json.JsonValue;
@@ -128,12 +129,23 @@
     private volatile Boolean hasSubTypesWithSubResources = null;
     /** The set of actions supported by this resource and its sub-types. */
     private final Set<Action> supportedActions = new HashSet<>();
+    private LocalizableMessage description;
 
     Resource(final String id) {
         this.id = id;
     }
 
     /**
+     * Sets the description of this resource.
+     *
+     * @param description
+     *          the description of this resource
+     */
+    public void description(LocalizableMessage description) {
+        this.description = description;
+    }
+
+    /**
      * Returns the resource ID of this resource.
      *
      * @return The resource ID of this resource.
@@ -507,6 +519,8 @@
 
         org.forgerock.api.models.Resource.Builder resource = org.forgerock.api.models.Resource.
             resource()
+            .title(id)
+            .description(toLS(description))
             .resourceSchema(schemaRef("#/definitions/" + id))
             .mvccSupported(isMvccSupported());
 
@@ -522,6 +536,7 @@
         return ApiDescription.apiDescription()
                       .id("unused").version("unused")
                       .definitions(definitions())
+                      .paths(getPaths())
                       .errors(errors())
                       .build();
     }
@@ -536,6 +551,8 @@
     ApiDescription collectionApi(boolean isReadOnly) {
         org.forgerock.api.models.Resource.Builder resource = org.forgerock.api.models.Resource.
             resource()
+            .title(id)
+            .description(toLS(description))
             .resourceSchema(schemaRef("#/definitions/" + id))
             .mvccSupported(isMvccSupported());
 
@@ -584,6 +601,16 @@
         return definitions.build();
     }
 
+    private LocalizableString toLS(LocalizableMessage msg) {
+        if (msg != null) {
+            if (msg.resourceName() != null) {
+                return new LocalizableString("i18n:" + msg.resourceName() + "#" /* TODO + msg.getKey() */);
+            }
+            return new LocalizableString(msg.toString());
+        }
+        return null;
+    }
+
     /**
      * Returns the api description that describes a resource with sub resources.
      *

--
Gitblit v1.10.0