Skip to content

Commit

Permalink
grscicoll/updateIdentifier fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ahakanzn committed Oct 23, 2024
1 parent 2929a00 commit 9b5111d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Boolean> map = new HashMap<>();
map.put("isPrimary",true);
int updatedIdentifierKeyReturned = baseClient.updateIdentifier(entityKey, identifierKey, map);
assertEquals(identifierKey, updatedIdentifierKeyReturned);

// Verify the identifier was updated correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public List<Identifier> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Boolean> isPrimaryMap);

@RequestMapping(
method = RequestMethod.POST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -659,9 +662,20 @@ public List<Identifier> 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
Expand All @@ -671,12 +685,12 @@ public List<Identifier> listIdentifiers(@PathVariable UUID key) {
public int updateIdentifier(
@PathVariable("key") UUID entityKey,
@PathVariable("identifierKey") Integer identifierKey,
@RequestBody Boolean isPrimary) {
@RequestBody Map<String, Boolean> 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(
Expand Down

0 comments on commit 9b5111d

Please sign in to comment.