Skip to content

Commit

Permalink
Merge pull request #979 from gisaia/feature/patchCollection
Browse files Browse the repository at this point in the history
Feat:patch collection display name
  • Loading branch information
mbarbet authored Sep 2, 2024
2 parents 177a40f + 8e9f97d commit c8406a0
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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);
}
Expand Down

0 comments on commit c8406a0

Please sign in to comment.