Repository: gisaia/ARLAS-server (language: python)

Issue:
Add key,value map in collection definition to define human readable label for mapping field
As arlas-server administrator
I want to specify key,value map to my collection
To obtain human readable label on export service


Discussion / hints:

Fix patch:
diff --git a/arlas-core/src/main/java/io/arlas/server/core/model/CollectionDescription.java b/arlas-core/src/main/java/io/arlas/server/core/model/CollectionDescription.java
new file mode 100644
index 000000000..2cb16be84
--- /dev/null
+++ b/arlas-core/src/main/java/io/arlas/server/core/model/CollectionDescription.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to Gisaïa under one or more contributor
+ * license agreements. See the NOTICE.txt file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Gisaïa licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.arlas.server.core.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public class CollectionDescription implements Serializable {
+    private static final long serialVersionUID = 7438255714694047836L;
+
+    @JsonProperty(value = "field_descriptions", required = false)
+    public Map<String, String> fieldDescriptions = null;
+}
diff --git a/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReference.java b/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReference.java
index 2d7e54ece..4ea0cd003 100644
--- a/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReference.java
+++ b/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReference.java
@@ -37,6 +37,8 @@ public class CollectionReference implements Serializable {
     public static final String DEFAULT_TIMESTAMP_FORMAT = "strict_date_optional_time||epoch_millis";
     public static final String EXCLUDE_FIELDS = "exclude_fields";
     public static final String EXCLUDE_WFS_FIELDS = "exclude_wfs_fields";
+    public static final String COLLECTION_DESCRIPTION = "collection_description";
+    public static final String FIELD_DESCRIPTIONS = "field_descriptions";
     public static final String INSPIRE_PATH = "inspire";
     public static final String DUBLIN_CORE_PATH = "dublin_core_element_name";
     public static final String INSPIRE_LINEAGE = "lineage";
diff --git a/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReferenceParameters.java b/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReferenceParameters.java
index 5a4133032..8003515fb 100644
--- a/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReferenceParameters.java
+++ b/arlas-core/src/main/java/io/arlas/server/core/model/CollectionReferenceParameters.java
@@ -72,6 +72,9 @@ public class CollectionReferenceParameters implements Serializable {
     @JsonProperty(value = "custom_params")
     public Map<String, String> customParams = null;
 
+    @JsonProperty(value = "collection_description")
+    public CollectionDescription collectionDescription = null;
+
     @JsonProperty(value = "atom_feed")
     public Feed atomFeed = null;
 
diff --git a/docs/arlas-collection-model.md b/docs/arlas-collection-model.md
index 73a451ad2..0bfedc183 100644
--- a/docs/arlas-collection-model.md
+++ b/docs/arlas-collection-model.md
@@ -25,6 +25,9 @@ A Collection has the following structure :
     "include_fields": "string",
     "exclude_fields": "string",
     "custom_params": {},
+    "collection_description": {
+      "field_description": {}
+    },
     "atom_feed": {
       ...
     },


Test patch:
diff --git a/arlas-tests/src/test/java/io/arlas/server/tests/DataSetTool.java b/arlas-tests/src/test/java/io/arlas/server/tests/DataSetTool.java
index 1a3d50e84..70949101d 100644
--- a/arlas-tests/src/test/java/io/arlas/server/tests/DataSetTool.java
+++ b/arlas-tests/src/test/java/io/arlas/server/tests/DataSetTool.java
@@ -19,7 +19,6 @@
 
 package io.arlas.server.tests;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.uber.h3core.H3Core;
 import io.arlas.server.core.app.ElasticConfiguration;
@@ -49,12 +48,16 @@ public class DataSetTool {
 
     public final static String DATASET_INDEX_NAME="dataset";
     public final static String DATASET_ID_PATH="id";
+    public final static String DATASET_ID_DESC = "object identifier";
     public final static String DATASET_GEO_PARAMS="geo_params";
     public final static String DATASET_GEOMETRY_PATH="geo_params.geometry";
+    public final static String DATASET_GEOMETRY_DESC = "object geometry";
     public final static String DATASET_WKT_GEOMETRY_PATH="geo_params.wktgeometry";
     public final static String DATASET_CENTROID_PATH="geo_params.centroid";
+    public final static String DATASET_CENTROID_DESC = "object centroid";
     public final static String DATASET_H3_PATH="geo_params.h3";
     public final static String DATASET_TIMESTAMP_PATH="params.startdate";
+    public final static String DATASET_TIMESTAMP_DESC = "record timestamp";
     public final static String DATASET_EXCLUDE_FIELDS = "params.ci*";
     public final static String DATASET_EXCLUDE_WFS_FIELDS="params.country";
     public final static String DATASET_TIMESTAMP_FORMAT = "epoch_millis";
diff --git a/arlas-tests/src/test/java/io/arlas/server/tests/rest/collections/CollectionServiceIT.java b/arlas-tests/src/test/java/io/arlas/server/tests/rest/collections/CollectionServiceIT.java
index 997a2e3b3..803a87d28 100644
--- a/arlas-tests/src/test/java/io/arlas/server/tests/rest/collections/CollectionServiceIT.java
+++ b/arlas-tests/src/test/java/io/arlas/server/tests/rest/collections/CollectionServiceIT.java
@@ -19,9 +19,9 @@
 
 package io.arlas.server.tests.rest.collections;
 
+import io.arlas.server.core.model.CollectionReference;
 import io.arlas.server.tests.AbstractTestWithCollection;
 import io.arlas.server.tests.DataSetTool;
-import io.arlas.server.core.model.CollectionReference;
 import io.restassured.response.ValidatableResponse;
 import io.restassured.specification.RequestSpecification;
 import org.junit.FixMethodOrder;
@@ -265,6 +265,31 @@ public void test06InvalidInspireDublinCollectionParameters() throws Exception {
         handleInvalidCollectionParameters(put(jsonAsMap));
     }
 
+    @Test
+    public void test07CollectionWithDescription() throws Exception {
+        Map<String, Object> jsonAsMap = getJsonAsMap();
+        jsonAsMap.put(CollectionReference.INSPIRE_PATH, getInspireJsonAsMap());
+        jsonAsMap.put(CollectionReference.DUBLIN_CORE_PATH, getDublinJsonAsMap());
+        jsonAsMap.put(CollectionReference.COLLECTION_DESCRIPTION, getCollectionDescriptionJsonAsMap());
+
+        // PUT new collection
+        given().contentType("application/json").body(jsonAsMap)
+                .when().put(arlasPath + "collections/foo_described")
+                .then().statusCode(200);
+
+        // GET collection
+        when().get(arlasPath + "collections/foo_described")
+                .then().statusCode(200)
+                .body("collection_name", equalTo("foo_described"))
+                .body("params.collection_description.field_descriptions['"+DataSetTool.DATASET_ID_PATH+"']", equalTo(DataSetTool.DATASET_ID_DESC))
+                .body("params.collection_description.field_descriptions['"+DataSetTool.DATASET_CENTROID_PATH+"']", equalTo(DataSetTool.DATASET_CENTROID_DESC))
+                .body("params.collection_description.field_descriptions['"+DataSetTool.DATASET_GEOMETRY_PATH+"']", equalTo(DataSetTool.DATASET_GEOMETRY_DESC))
+                .body("params.collection_description.field_descriptions['"+DataSetTool.DATASET_TIMESTAMP_PATH+"']", equalTo(DataSetTool.DATASET_TIMESTAMP_DESC));
+
+        // DELETE collection
+        when().delete(arlasPath + "collections/foo_described")
+                .then().statusCode(200);
+    }
 
     @Test
     public void test08WithCollectionFilter() throws Exception {
@@ -348,6 +373,21 @@ private Map<String, Object> getJsonAsMap() {
         return jsonAsMap;
     }
 
+    private Object getCollectionDescriptionJsonAsMap() {
+        Map<String, Object> jsonAsMap = new HashMap<>();
+        jsonAsMap.put(CollectionReference.FIELD_DESCRIPTIONS, getFieldDescriptionsJsonAsMap());
+        return jsonAsMap;
+    }
+
+    private Object getFieldDescriptionsJsonAsMap() {
+        Map<String, Object> jsonAsMap = new HashMap<>();
+        jsonAsMap.put(DataSetTool.DATASET_ID_PATH, DataSetTool.DATASET_ID_DESC);
+        jsonAsMap.put(DataSetTool.DATASET_CENTROID_PATH, DataSetTool.DATASET_CENTROID_DESC);
+        jsonAsMap.put(DataSetTool.DATASET_GEOMETRY_PATH, DataSetTool.DATASET_GEOMETRY_DESC);
+        jsonAsMap.put(DataSetTool.DATASET_TIMESTAMP_PATH, DataSetTool.DATASET_TIMESTAMP_DESC);
+        return jsonAsMap;
+    }
+
     private Map<String, Object> getDublinJsonAsMap() {
         Map<String, Object> dublinSubJsonAsMap = new HashMap<>();
         dublinSubJsonAsMap.put(CollectionReference.DUBLIN_CORE_TITLE, DataSetTool.DATASET_DUBLIN_CORE_TITLE);