diff --git a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/resource/BaseCollectionEntityResourceIT.java b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/resource/BaseCollectionEntityResourceIT.java index 6bbdfdb85..331f1ee42 100644 --- a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/resource/BaseCollectionEntityResourceIT.java +++ b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/resource/BaseCollectionEntityResourceIT.java @@ -13,6 +13,9 @@ */ package org.gbif.registry.ws.it.collections.resource; +import java.util.HashMap; +import java.util.Map; + import org.gbif.api.model.collections.Address; import org.gbif.api.model.collections.Batch; import org.gbif.api.model.collections.CollectionEntity; @@ -307,7 +310,9 @@ public void identifiersTest() { when(getMockCollectionEntityService().updateIdentifier(entityKey, updatedIdentifier.getKey(), updatedIdentifier.isPrimary())) .thenReturn(identifierKey); - int updatedIdentifierKeyReturned = baseClient.updateIdentifier(entityKey, identifierKey, updatedIdentifier.isPrimary()); + Map map = new HashMap<>(); + map.put("isPrimary",true); + int updatedIdentifierKeyReturned = baseClient.updateIdentifier(entityKey, identifierKey, map); assertEquals(identifierKey, updatedIdentifierKeyReturned); // Verify the identifier was updated correctly diff --git a/registry-service/src/main/java/org/gbif/registry/service/WithMyBatis.java b/registry-service/src/main/java/org/gbif/registry/service/WithMyBatis.java index 61ea3c7c7..c3e69f2fd 100644 --- a/registry-service/src/main/java/org/gbif/registry/service/WithMyBatis.java +++ b/registry-service/src/main/java/org/gbif/registry/service/WithMyBatis.java @@ -221,7 +221,7 @@ public int updateCollectionIdentifier( PrimaryIdentifiableMapper identifiableMapper, UUID targetEntityKey, Integer identifierKey, - Boolean isPrimary) { + boolean isPrimary) { checkArgument(identifierKey != null, "Unable to update an entity with no key"); checkArgument( Boolean.TRUE.equals(identifiableMapper.areRelated(targetEntityKey, identifierKey)), diff --git a/registry-service/src/main/java/org/gbif/registry/service/collections/BaseCollectionEntityService.java b/registry-service/src/main/java/org/gbif/registry/service/collections/BaseCollectionEntityService.java index fbbc01440..d6e280c3e 100644 --- a/registry-service/src/main/java/org/gbif/registry/service/collections/BaseCollectionEntityService.java +++ b/registry-service/src/main/java/org/gbif/registry/service/collections/BaseCollectionEntityService.java @@ -188,7 +188,7 @@ public List listIdentifiers(UUID key) { @Transactional @Validated({PrePersist.class, Default.class}) @Override - public int updateIdentifier(UUID entityKey, int identifierKey, Boolean isPrimary) { + public int updateIdentifier(UUID entityKey, int identifierKey, boolean isPrimary) { int key = withMyBatis.updateCollectionIdentifier(baseMapper, entityKey, identifierKey, isPrimary); eventManager.post(SubEntityCollectionEvent.newInstance( entityKey, objectClass, Identifier.class, (long) identifierKey, EventType.UPDATE)); diff --git a/registry-ws-client/src/main/java/org/gbif/registry/ws/client/collections/BaseCollectionEntityClient.java b/registry-ws-client/src/main/java/org/gbif/registry/ws/client/collections/BaseCollectionEntityClient.java index 3fae624b0..3c558ab0b 100644 --- a/registry-ws-client/src/main/java/org/gbif/registry/ws/client/collections/BaseCollectionEntityClient.java +++ b/registry-ws-client/src/main/java/org/gbif/registry/ws/client/collections/BaseCollectionEntityClient.java @@ -13,6 +13,8 @@ */ package org.gbif.registry.ws.client.collections; +import java.util.Map; + import org.gbif.api.model.collections.CollectionEntity; import org.gbif.api.model.collections.Contact; import org.gbif.api.model.collections.MasterSourceMetadata; @@ -76,7 +78,7 @@ void deleteIdentifier( value = "{key}/identifier/{identifierKey}", consumes = MediaType.APPLICATION_JSON_VALUE) int updateIdentifier( - @PathVariable("key") UUID entityKey, @PathVariable("identifierKey") Integer identifierKey, @RequestBody Boolean isPrimary); + @PathVariable("key") UUID entityKey, @PathVariable("identifierKey") Integer identifierKey, @RequestBody Map isPrimaryMap); @RequestMapping( method = RequestMethod.POST, diff --git a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/BaseCollectionEntityResource.java b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/BaseCollectionEntityResource.java index daf61149a..7592741b0 100644 --- a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/BaseCollectionEntityResource.java +++ b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/BaseCollectionEntityResource.java @@ -13,6 +13,9 @@ */ package org.gbif.registry.ws.resources.collections; +import io.swagger.v3.oas.annotations.media.ExampleObject; + +import java.util.Map; import java.util.Objects; import static com.google.common.base.Preconditions.checkArgument; @@ -659,9 +662,20 @@ public List listIdentifiers(@PathVariable UUID key) { @Operation( operationId = "updateIdentifier", summary = "Update an identifier for a specified entity", + description = "Updates the `isPrimary` status of an identifier. The request body should be a JSON object with a single key `isPrimary`.", + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "A JSON object containing the `isPrimary` field.", + required = true, + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(name = "isPrimary", type = "boolean", example = "true"), + examples = @ExampleObject(value = "{\"isPrimary\": true}") + ) + ), extensions = @Extension( name = "Order", - properties = @ExtensionProperty(name = "Order", value = "0436"))) + properties = @ExtensionProperty(name = "Order", value = "0436")) + ) @Docs.DefaultEntityKeyParameter @ApiResponse(responseCode = "204", description = "Identifier updated") @Docs.DefaultUnsuccessfulReadResponses @@ -671,12 +685,12 @@ public List listIdentifiers(@PathVariable UUID key) { public int updateIdentifier( @PathVariable("key") UUID entityKey, @PathVariable("identifierKey") Integer identifierKey, - @RequestBody Boolean isPrimary) { + @RequestBody Map isPrimaryMap) { checkArgument( - Objects.nonNull(isPrimary), + Objects.nonNull(isPrimaryMap.get("isPrimary")), "The 'isPrimary' parameter must not be null." ); - return collectionEntityService.updateIdentifier(entityKey, identifierKey, isPrimary); + return collectionEntityService.updateIdentifier(entityKey, identifierKey, isPrimaryMap.get("isPrimary")); } @Operation(