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

Issue:
Remove the node "organisations" in PATCH organisation endpoint
In the body of `PATCH /collections/{collection}/organisations` :

- [ ] Remove the "organisations" node to avoid redundancy


Discussion / hints:

Fix patch:
diff --git a/arlas-core/src/main/java/io/arlas/server/core/services/CollectionReferenceService.java b/arlas-core/src/main/java/io/arlas/server/core/services/CollectionReferenceService.java
index 988ccb59c..380291709 100644
--- a/arlas-core/src/main/java/io/arlas/server/core/services/CollectionReferenceService.java
+++ b/arlas-core/src/main/java/io/arlas/server/core/services/CollectionReferenceService.java
@@ -24,6 +24,7 @@
 import io.arlas.commons.utils.StringUtil;
 import io.arlas.server.core.exceptions.CollectionUnavailableException;
 import io.arlas.server.core.managers.CacheManager;
+import io.arlas.server.core.model.CollectionDisplayNames;
 import io.arlas.server.core.model.CollectionReference;
 import io.arlas.server.core.model.CollectionReferenceParameters;
 import io.arlas.server.core.model.response.CollectionReferenceDescription;
@@ -108,7 +109,24 @@ public CollectionReference putCollectionReference(CollectionReference collection
         return collectionReference;
     }
 
-    public CollectionReference updateCollectionReference(String collection,
+    public CollectionReference updateCollectionDisplayNameCollectionReference(String collection,
+                                                          String organisations,
+                                                          String columnFilter, String displayName)
+            throws ArlasException {
+        CollectionReference collectionReference = getCollectionReference(collection, Optional.ofNullable(organisations));
+        ColumnFilterUtil.assertCollectionsAllowed(Optional.ofNullable(columnFilter), List.of(collectionReference));
+        checkIfAllowedForOrganisations(collectionReference, Optional.ofNullable(organisations), true);
+        if (collectionReference.params.collectionDisplayNames == null) {
+            collectionReference.params.collectionDisplayNames = new CollectionDisplayNames();
+        }
+        collectionReference.params.collectionDisplayNames.collection = displayName;
+        putCollectionReferenceWithDao(collectionReference);
+        cacheManager.removeCollectionReference(collectionReference.collectionName);
+        cacheManager.removeMapping(collectionReference.params.indexName);
+        return collectionReference;
+    }
+
+    public CollectionReference updateOrganisationsParamsCollectionReference(String collection,
                                                          String organisations,
                                                          String columnFilter,
                                                          boolean isPublic,
diff --git a/arlas-rest/src/main/java/io/arlas/server/rest/collections/CollectionService.java b/arlas-rest/src/main/java/io/arlas/server/rest/collections/CollectionService.java
index 598c9151a..f1e7c0a92 100644
--- a/arlas-rest/src/main/java/io/arlas/server/rest/collections/CollectionService.java
+++ b/arlas-rest/src/main/java/io/arlas/server/rest/collections/CollectionService.java
@@ -315,10 +315,10 @@ public Response patch(
                     required = true)
             @PathParam(value = "collection") String collection,
 
-            @Parameter(name = "collectionParamsUpdate",
-                    description = "collectionParamsUpdate",
+            @Parameter(name = "organisationsParamsUpdate",
+                    description = "organisationsParamsUpdate",
                     required = true)
-            @NotNull CollectionReferenceUpdate cru,
+            @NotNull CollectionReferenceUpdateOrg opu,
 
             @Parameter(hidden = true)
             @HeaderParam(value = COLUMN_FILTER) String columnFilter,
@@ -337,7 +337,59 @@ public Response patch(
         if (collection != null && collection.equals(META_COLLECTION_NAME)) {
             throw new NotAllowedException("'" + META_COLLECTION_NAME + "' cannot be updated");
         }
-        return ResponseFormatter.getResultResponse(collectionReferenceService.updateCollectionReference(collection, organisations, columnFilter, cru.organisations.isPublic, cru.organisations.sharedWith));
+        return ResponseFormatter.getResultResponse(collectionReferenceService.updateOrganisationsParamsCollectionReference(collection, organisations, columnFilter, opu.isPublic, opu.sharedWith));
+    }
+
+
+    @Timed
+    @Path("{collection}/display_names/collection")
+    @PATCH
+    @Produces(UTF8JSON)
+    @Consumes(UTF8JSON)
+    @Operation(
+            summary = "Update a collection reference's display collection name attribute.",
+            description = "Update a collection reference's display collection name attribute."
+    )
+    @ApiResponses(value = {
+            @ApiResponse(responseCode = "200", description = "Successful operation",
+                    content = @Content(schema = @Schema(implementation = CollectionReference.class))),
+            @ApiResponse(responseCode = "400", description = "JSON parameter malformed.",
+                    content = @Content(schema = @Schema(implementation = Error.class))),
+            @ApiResponse(responseCode = "404", description = "Collection not found.",
+                    content = @Content(schema = @Schema(implementation = Error.class))),
+            @ApiResponse(responseCode = "500", description = "Arlas Server Error.",
+                    content = @Content(schema = @Schema(implementation = Error.class)))
+    })
+    public Response patchCollectionDisplayName(
+            @Context HttpHeaders headers,
+            @Parameter(name = "collection",
+                    description = "collection",
+                    required = true)
+            @PathParam(value = "collection") String collection,
+
+            @Parameter(name = "collectionDisplayName",
+                    description = "collectionDisplayName",
+                    required = true)
+            @NotNull String collectionDisplayName,
+
+            @Parameter(hidden = true)
+            @HeaderParam(value = COLUMN_FILTER) String columnFilter,
+
+            @Parameter(hidden = true)
+            @HeaderParam(value = ARLAS_ORGANISATION) String organisations,
+            // --------------------------------------------------------
+            // ----------------------- FORM -----------------------
+            // --------------------------------------------------------
+            @Parameter(name = "pretty",
+                    description = Documentation.FORM_PRETTY,
+                    schema = @Schema(defaultValue = "false"))
+            @QueryParam(value = "pretty") Boolean pretty
+
+    ) throws ArlasException {
+        if (collection != null && collection.equals(META_COLLECTION_NAME)) {
+            throw new NotAllowedException("'" + META_COLLECTION_NAME + "' cannot be updated");
+        }
+        return ResponseFormatter.getResultResponse(collectionReferenceService.updateCollectionDisplayNameCollectionReference(collection, organisations, columnFilter,collectionDisplayName ));
     }
 
     public CollectionReference save(String collection, CollectionReferenceParameters collectionReferenceParameters,


Test patch:
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 86125447c..663c339f9 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
@@ -389,7 +389,7 @@ public void test09Organisations() throws Exception {
 
         // PATCH collection
         given().contentType("application/json")
-                .body(Map.of("organisations", getOrgAsMap(null, List.of("foo.com"), Boolean.TRUE)))
+                .body(getOrgAsMap(null, List.of("foo.com"), Boolean.TRUE))
                 .when().patch(arlasPath + "collections/bar/organisations")
                 .then().statusCode(200)
                 .body("collection_name", equalTo("bar"))
@@ -410,6 +410,58 @@ public void test09Organisations() throws Exception {
 
     }
 
+
+    @Test
+    public void test10DisplayName() throws Exception {
+        Map<String, Object> jsonAsMap = getJsonAsMap("bar.com", null, false);
+        jsonAsMap.put(CollectionReference.INSPIRE_PATH, getInspireJsonAsMap());
+        jsonAsMap.put(CollectionReference.DUBLIN_CORE_PATH, getDublinJsonAsMap());
+
+        // PUT new collection
+        given().contentType("application/json")
+                .body(jsonAsMap)
+                .when().put(arlasPath + "collections/bar")
+                .then().statusCode(200);
+
+        // GET collection
+        when().get(arlasPath + "collections/bar")
+                .then().statusCode(200)
+                .body("collection_name", equalTo("bar"))
+                .body("params.index_name", equalTo(DataSetTool.DATASET_INDEX_NAME))
+                .body("params.id_path", equalTo(DataSetTool.DATASET_ID_PATH))
+                .body("params.geometry_path", equalTo(DataSetTool.DATASET_GEOMETRY_PATH))
+                .body("params.centroid_path", equalTo(DataSetTool.DATASET_CENTROID_PATH))
+                .body("params.timestamp_path", equalTo(DataSetTool.DATASET_TIMESTAMP_PATH))
+                .body("params.exclude_fields", equalTo(DataSetTool.DATASET_EXCLUDE_FIELDS))
+                .body("params.exclude_wfs_fields", equalTo(DataSetTool.DATASET_EXCLUDE_WFS_FIELDS))
+                .body("params.organisations.owner", equalTo("bar.com"))
+                .body("params.organisations.shared", hasSize(0))
+                .body("params.organisations.public", equalTo(Boolean.FALSE));
+
+        // PATCH collection display name
+        given().contentType("application/json")
+                .body("My New Awesome collection")
+                .when().patch(arlasPath + "collections/bar/display_names/collection")
+                .then().statusCode(200)
+                .body("collection_name", equalTo("bar"))
+                .body("params.display_names.collection", equalTo("My New Awesome collection"))
+                .body("params.index_name", equalTo(DataSetTool.DATASET_INDEX_NAME))
+                .body("params.id_path", equalTo(DataSetTool.DATASET_ID_PATH))
+                .body("params.geometry_path", equalTo(DataSetTool.DATASET_GEOMETRY_PATH))
+                .body("params.centroid_path", equalTo(DataSetTool.DATASET_CENTROID_PATH))
+                .body("params.timestamp_path", equalTo(DataSetTool.DATASET_TIMESTAMP_PATH))
+                .body("params.exclude_fields", equalTo(DataSetTool.DATASET_EXCLUDE_FIELDS))
+                .body("params.exclude_wfs_fields", equalTo(DataSetTool.DATASET_EXCLUDE_WFS_FIELDS))
+                .body("params.organisations.owner", equalTo("bar.com"))
+                .body("params.organisations.shared", hasSize(0))
+                .body("params.organisations.public", equalTo(Boolean.FALSE));
+
+        // DELETE collection
+        when().delete(arlasPath + "collections/bar")
+                .then().statusCode(200);
+
+    }
+
     private void handleInvalidCollectionParameters(ValidatableResponse then) throws Exception {
         then.statusCode(400);
     }