diff --git a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/BaseChangeSuggestionServiceIT.java b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/BaseChangeSuggestionServiceIT.java index e982516c74..4683f8ca94 100644 --- a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/BaseChangeSuggestionServiceIT.java +++ b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/BaseChangeSuggestionServiceIT.java @@ -32,7 +32,6 @@ import org.gbif.api.vocabulary.Country; import org.gbif.registry.database.TestCaseDatabaseInitializer; import org.gbif.registry.search.test.EsManageServer; -import org.gbif.registry.service.collections.suggestions.InstitutionChangeSuggestionService; import org.gbif.registry.ws.it.BaseItTest; import org.gbif.ws.client.filter.SimplePrincipalProvider; @@ -47,25 +46,24 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -/** Tests the {@link InstitutionChangeSuggestionService}. */ +/** Tests the {@link ChangeSuggestionService}. */ public abstract class BaseChangeSuggestionServiceIT< - T extends CollectionEntity & Contactable & LenientEquals> + T extends CollectionEntity & Contactable & LenientEquals, R extends ChangeSuggestion> extends BaseItTest { protected static final String PROPOSER = "proposer"; protected static final Pageable DEFAULT_PAGE = new PagingRequest(0L, 5); @RegisterExtension - protected TestCaseDatabaseInitializer databaseRule = - TestCaseDatabaseInitializer.builder().dataSource(database.getTestDatabase()).build(); + protected TestCaseDatabaseInitializer databaseRule = new TestCaseDatabaseInitializer(); - private final ChangeSuggestionService changeSuggestionService; + private final ChangeSuggestionService changeSuggestionService; private final CrudService crudService; protected BaseChangeSuggestionServiceIT( SimplePrincipalProvider simplePrincipalProvider, EsManageServer esServer, - ChangeSuggestionService changeSuggestionService, + ChangeSuggestionService changeSuggestionService, CrudService crudService) { super(simplePrincipalProvider, esServer); this.changeSuggestionService = changeSuggestionService; @@ -81,7 +79,7 @@ public void newEntitySuggestionTest() { address.setCountry(Country.DENMARK); entity.setAddress(address); - ChangeSuggestion suggestion = createEmptyChangeSuggestion(); + R suggestion = createEmptyChangeSuggestion(); suggestion.setSuggestedEntity(entity); suggestion.setType(Type.CREATE); suggestion.setProposedBy(PROPOSER); @@ -141,7 +139,7 @@ public void changeInstitutionSuggestionTest() { int numberChanges = updateEntity(entity); address.setCity("city"); - ChangeSuggestion suggestion = createEmptyChangeSuggestion(); + R suggestion = createEmptyChangeSuggestion(); suggestion.setSuggestedEntity(entity); suggestion.setType(Type.UPDATE); suggestion.setEntityKey(entityKey); @@ -191,7 +189,7 @@ public void deleteInstitutionSuggestionTest() { T entity = createEntity(); UUID entityKey = crudService.create(entity); - ChangeSuggestion suggestion = createEmptyChangeSuggestion(); + R suggestion = createEmptyChangeSuggestion(); suggestion.setSuggestedEntity(entity); suggestion.setType(Type.DELETE); suggestion.setEntityKey(entityKey); @@ -227,7 +225,7 @@ public void mergeInstitutionSuggestionTest() { T entity2 = createEntity(); UUID entity2Key = crudService.create(entity2); - ChangeSuggestion suggestion = createEmptyChangeSuggestion(); + R suggestion = createEmptyChangeSuggestion(); suggestion.setSuggestedEntity(entity); suggestion.setType(Type.MERGE); suggestion.setEntityKey(entityKey); @@ -262,7 +260,7 @@ public void discardSuggestionTest() { // State T entity = createEntity(); - ChangeSuggestion suggestion = createEmptyChangeSuggestion(); + R suggestion = createEmptyChangeSuggestion(); suggestion.setSuggestedEntity(entity); suggestion.setType(Type.CREATE); suggestion.setProposedBy(PROPOSER); @@ -290,7 +288,7 @@ public void discardSuggestionTest() { public void listTest() { // State T entity = createEntity(); - ChangeSuggestion suggestion = createEmptyChangeSuggestion(); + R suggestion = createEmptyChangeSuggestion(); suggestion.setSuggestedEntity(entity); suggestion.setType(Type.CREATE); suggestion.setProposedBy(PROPOSER); @@ -300,7 +298,7 @@ public void listTest() { T entity2 = createEntity(); UUID entity2Key = crudService.create(entity2); - ChangeSuggestion suggestion2 = createEmptyChangeSuggestion(); + R suggestion2 = createEmptyChangeSuggestion(); suggestion2.setSuggestedEntity(entity2); suggestion2.setEntityKey(entity2Key); suggestion2.setType(Type.UPDATE); @@ -310,7 +308,7 @@ public void listTest() { int suggKey2 = changeSuggestionService.createChangeSuggestion(suggestion2); // When - PagingResponse> results = + PagingResponse results = changeSuggestionService.list(Status.APPLIED, null, null, null, null, DEFAULT_PAGE); // Then assertEquals(0, results.getResults().size()); @@ -337,7 +335,7 @@ public void listTest() { assertEquals(0, results.getCount()); } - protected void assertCreatedSuggestion(ChangeSuggestion created) { + protected void assertCreatedSuggestion(R created) { assertEquals(Status.PENDING, created.getStatus()); assertNull(created.getApplied()); assertNull(created.getDiscarded()); @@ -362,5 +360,5 @@ protected UUID getReplacedByValue(T entity) { abstract int reviewEntity(T entity); - abstract ChangeSuggestion createEmptyChangeSuggestion(); + abstract R createEmptyChangeSuggestion(); } diff --git a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/CollectionChangeSuggestionServiceIT.java b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/CollectionChangeSuggestionServiceIT.java index ae2836cb3b..eadf3ba85b 100644 --- a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/CollectionChangeSuggestionServiceIT.java +++ b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/CollectionChangeSuggestionServiceIT.java @@ -32,7 +32,8 @@ import org.springframework.beans.factory.annotation.Autowired; /** Tests the {@link CollectionChangeSuggestionService}. */ -public class CollectionChangeSuggestionServiceIT extends BaseChangeSuggestionServiceIT { +public class CollectionChangeSuggestionServiceIT + extends BaseChangeSuggestionServiceIT { @Autowired public CollectionChangeSuggestionServiceIT( diff --git a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/InstitutionChangeSuggestionServiceIT.java b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/InstitutionChangeSuggestionServiceIT.java index 9ed37882bf..7f87baa883 100644 --- a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/InstitutionChangeSuggestionServiceIT.java +++ b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/suggestions/InstitutionChangeSuggestionServiceIT.java @@ -39,7 +39,7 @@ /** Tests the {@link InstitutionChangeSuggestionService}. */ public class InstitutionChangeSuggestionServiceIT - extends BaseChangeSuggestionServiceIT { + extends BaseChangeSuggestionServiceIT { private final InstitutionChangeSuggestionService institutionChangeSuggestionService; private final InstitutionService institutionService; diff --git a/registry-persistence/src/main/resources/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.xml b/registry-persistence/src/main/resources/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.xml index 8ddf991b70..32b2fab4ca 100644 --- a/registry-persistence/src/main/resources/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.xml +++ b/registry-persistence/src/main/resources/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.xml @@ -41,6 +41,7 @@ suggested_entity = #{suggestedEntity,jdbcType=OTHER}::jsonb, + status = #{status,jdbcType=OTHER}, comments = #{comments,jdbcType=OTHER,typeHandler=StringArrayTypeHandler}, changes = #{changes,jdbcType=OTHER,typeHandler=SuggestedChangesTypeHandler}::jsonb, modified = now(), diff --git a/registry-service/src/main/java/org/gbif/registry/service/collections/ExtendedCollectionService.java b/registry-service/src/main/java/org/gbif/registry/service/collections/ExtendedCollectionService.java index c49db8b2a1..10fb5e54ea 100644 --- a/registry-service/src/main/java/org/gbif/registry/service/collections/ExtendedCollectionService.java +++ b/registry-service/src/main/java/org/gbif/registry/service/collections/ExtendedCollectionService.java @@ -90,6 +90,7 @@ public UUID create(T entity) { return entity.getKey(); } + @Override public void update(T entity) { preUpdate(entity); T entityOld = get(entity.getKey()); diff --git a/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/BaseChangeSuggestionService.java b/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/BaseChangeSuggestionService.java index 6211f03853..54494ef9e6 100644 --- a/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/BaseChangeSuggestionService.java +++ b/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/BaseChangeSuggestionService.java @@ -53,8 +53,9 @@ public abstract class BaseChangeSuggestionService< T extends CollectionEntity & Taggable & Identifiable & MachineTaggable & Commentable & Contactable - & OccurrenceMappeable> - implements ChangeSuggestionService { + & OccurrenceMappeable, + R extends ChangeSuggestion> + implements ChangeSuggestionService { private static final Logger LOG = LoggerFactory.getLogger(BaseChangeSuggestionService.class); @@ -105,7 +106,7 @@ protected BaseChangeSuggestionService( } @Override - public int createChangeSuggestion(ChangeSuggestion changeSuggestion) { + public int createChangeSuggestion(R changeSuggestion) { checkArgument(!changeSuggestion.getComments().isEmpty(), "A comment is required"); if (changeSuggestion.getType() == Type.CREATE) { @@ -127,7 +128,7 @@ public int createChangeSuggestion(ChangeSuggestion changeSuggestion) { throw new IllegalArgumentException("Invalid suggestion type: " + changeSuggestion.getType()); } - protected int createUpdateSuggestion(ChangeSuggestion changeSuggestion) { + protected int createUpdateSuggestion(R changeSuggestion) { checkArgument(changeSuggestion.getEntityKey() != null); checkArgument(changeSuggestion.getSuggestedEntity() != null); @@ -143,7 +144,7 @@ protected int createUpdateSuggestion(ChangeSuggestion changeSuggestion) { return dto.getKey(); } - protected int createNewEntitySuggestion(ChangeSuggestion changeSuggestion) { + protected int createNewEntitySuggestion(R changeSuggestion) { checkArgument(changeSuggestion.getSuggestedEntity() != null); ChangeSuggestionDto dto = createBaseChangeSuggestionDto(changeSuggestion); @@ -154,7 +155,7 @@ protected int createNewEntitySuggestion(ChangeSuggestion changeSuggestion) { return dto.getKey(); } - protected int createDeleteSuggestion(ChangeSuggestion changeSuggestion) { + protected int createDeleteSuggestion(R changeSuggestion) { checkArgument(changeSuggestion.getEntityKey() != null); ChangeSuggestionDto dto = createBaseChangeSuggestionDto(changeSuggestion); @@ -166,7 +167,7 @@ protected int createDeleteSuggestion(ChangeSuggestion changeSuggestion) { return dto.getKey(); } - protected int createMergeSuggestion(ChangeSuggestion changeSuggestion) { + protected int createMergeSuggestion(R changeSuggestion) { checkArgument(changeSuggestion.getEntityKey() != null); checkArgument(changeSuggestion.getMergeTargetKey() != null); @@ -181,7 +182,7 @@ protected int createMergeSuggestion(ChangeSuggestion changeSuggestion) { } @Override - public void updateChangeSuggestion(ChangeSuggestion updatedChangeSuggestion) { + public void updateChangeSuggestion(R updatedChangeSuggestion) { ChangeSuggestionDto dto = changeSuggestionMapper.get(updatedChangeSuggestion.getKey()); checkArgument( @@ -191,7 +192,7 @@ public void updateChangeSuggestion(ChangeSuggestion updatedChangeSuggestion) if (dto.getType() == Type.CREATE || dto.getType() == Type.UPDATE) { // we do this to update the suggested entity with the current state and minimize the risk of // having race conditions - ChangeSuggestion changeSuggestion = dtoToChangeSuggestion(dto); + R changeSuggestion = dtoToChangeSuggestion(dto); Set newChanges = extractChanges( @@ -215,11 +216,13 @@ public void discardChangeSuggestion(int key) { changeSuggestionMapper.update(dto); } - public void applyChangeSuggestion(int suggestionKey) { + @Override + public UUID applyChangeSuggestion(int suggestionKey) { ChangeSuggestionDto dto = changeSuggestionMapper.get(suggestionKey); - ChangeSuggestion changeSuggestion = dtoToChangeSuggestion(dto); + R changeSuggestion = dtoToChangeSuggestion(dto); + UUID createdEntity = null; if (dto.getType() == Type.CREATE) { - UUID createdEntity = extendedCollectionService.create(changeSuggestion.getSuggestedEntity()); + createdEntity = extendedCollectionService.create(changeSuggestion.getSuggestedEntity()); dto.setEntityKey(createdEntity); } else if (dto.getType() == Type.UPDATE) { extendedCollectionService.update(changeSuggestion.getSuggestedEntity()); @@ -228,7 +231,7 @@ public void applyChangeSuggestion(int suggestionKey) { } else if (dto.getType() == Type.MERGE) { mergeService.merge(changeSuggestion.getEntityKey(), changeSuggestion.getMergeTargetKey()); } else if (dto.getType() == Type.CONVERSION_TO_COLLECTION) { - applyConversionToCollection(dto); + createdEntity = applyConversionToCollection(dto); } dto.setStatus(Status.APPLIED); @@ -236,10 +239,12 @@ public void applyChangeSuggestion(int suggestionKey) { dto.setApplied(new Date()); dto.setAppliedBy(getUsername()); changeSuggestionMapper.update(dto); + + return createdEntity; } @Override - public PagingResponse> list( + public PagingResponse list( @Nullable Status status, @Nullable Type type, @Nullable Country country, @@ -267,7 +272,7 @@ public PagingResponse> list( newEmptyChangeSuggestion().getProposedBy(), entityKey); - List> changeSuggestions = + List changeSuggestions = dtos.stream().map(this::dtoToChangeSuggestion).collect(Collectors.toList()); return new PagingResponse<>(page, count, changeSuggestions); @@ -321,8 +326,7 @@ private Set extractChanges(T suggestedEntity, T currentEntity) { return changes; } - protected ChangeSuggestionDto createBaseChangeSuggestionDto( - ChangeSuggestion changeSuggestion) { + protected ChangeSuggestionDto createBaseChangeSuggestionDto(R changeSuggestion) { ChangeSuggestionDto dto = new ChangeSuggestionDto(); dto.setEntityKey(changeSuggestion.getEntityKey()); dto.setStatus(Status.PENDING); @@ -356,8 +360,8 @@ protected Country getCountry(T entity) { } } - protected ChangeSuggestion dtoToChangeSuggestion(ChangeSuggestionDto dto) { - ChangeSuggestion suggestion = newEmptyChangeSuggestion(); + protected R dtoToChangeSuggestion(ChangeSuggestionDto dto) { + R suggestion = newEmptyChangeSuggestion(); suggestion.setKey(dto.getKey()); suggestion.setStatus(dto.getStatus()); suggestion.setType(dto.getType()); @@ -435,9 +439,9 @@ protected String toJson(T entity) { } } - protected abstract ChangeSuggestion newEmptyChangeSuggestion(); + protected abstract R newEmptyChangeSuggestion(); - protected abstract int createConvertToCollectionSuggestion(ChangeSuggestion changeSuggestion); + protected abstract int createConvertToCollectionSuggestion(R changeSuggestion); - protected abstract void applyConversionToCollection(ChangeSuggestionDto dto); + protected abstract UUID applyConversionToCollection(ChangeSuggestionDto dto); } diff --git a/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/CollectionChangeSuggestionService.java b/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/CollectionChangeSuggestionService.java index ce32855a06..3208b08ac5 100644 --- a/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/CollectionChangeSuggestionService.java +++ b/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/CollectionChangeSuggestionService.java @@ -1,33 +1,23 @@ package org.gbif.registry.service.collections.suggestions; import org.gbif.api.model.collections.Collection; -import org.gbif.api.model.collections.EntityType; -import org.gbif.api.model.collections.suggestions.ChangeSuggestion; import org.gbif.api.model.collections.suggestions.CollectionChangeSuggestion; -import org.gbif.api.model.collections.suggestions.Status; -import org.gbif.api.model.collections.suggestions.Type; -import org.gbif.api.model.common.paging.Pageable; -import org.gbif.api.model.common.paging.PagingRequest; -import org.gbif.api.model.common.paging.PagingResponse; -import org.gbif.api.vocabulary.Country; import org.gbif.registry.persistence.mapper.collections.ChangeSuggestionMapper; import org.gbif.registry.persistence.mapper.collections.CollectionMapper; import org.gbif.registry.persistence.mapper.collections.dto.ChangeSuggestionDto; import org.gbif.registry.service.collections.DefaultCollectionService; import org.gbif.registry.service.collections.merge.CollectionMergeService; -import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; -import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.fasterxml.jackson.databind.ObjectMapper; @Service -public class CollectionChangeSuggestionService extends BaseChangeSuggestionService { +public class CollectionChangeSuggestionService + extends BaseChangeSuggestionService { private final ChangeSuggestionMapper changeSuggestionMapper; @@ -50,7 +40,7 @@ public CollectionChangeSuggestionService( @Override public CollectionChangeSuggestion getChangeSuggestion(int key) { - return (CollectionChangeSuggestion) dtoToChangeSuggestion(changeSuggestionMapper.get(key)); + return dtoToChangeSuggestion(changeSuggestionMapper.get(key)); } @Override @@ -59,12 +49,12 @@ protected CollectionChangeSuggestion newEmptyChangeSuggestion() { } @Override - protected int createConvertToCollectionSuggestion(ChangeSuggestion changeSuggestion) { + protected int createConvertToCollectionSuggestion(CollectionChangeSuggestion changeSuggestion) { throw new UnsupportedOperationException(); } @Override - protected void applyConversionToCollection(ChangeSuggestionDto dto) { + protected UUID applyConversionToCollection(ChangeSuggestionDto dto) { throw new UnsupportedOperationException(); } } diff --git a/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/InstitutionChangeSuggestionService.java b/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/InstitutionChangeSuggestionService.java index 28bb2878c2..752a52417e 100644 --- a/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/InstitutionChangeSuggestionService.java +++ b/registry-service/src/main/java/org/gbif/registry/service/collections/suggestions/InstitutionChangeSuggestionService.java @@ -1,7 +1,6 @@ package org.gbif.registry.service.collections.suggestions; import org.gbif.api.model.collections.Institution; -import org.gbif.api.model.collections.suggestions.ChangeSuggestion; import org.gbif.api.model.collections.suggestions.InstitutionChangeSuggestion; import org.gbif.api.model.collections.suggestions.Type; import org.gbif.registry.persistence.mapper.collections.ChangeSuggestionMapper; @@ -10,6 +9,8 @@ import org.gbif.registry.service.collections.DefaultInstitutionService; import org.gbif.registry.service.collections.merge.InstitutionMergeService; +import java.util.UUID; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +21,8 @@ import static com.google.common.base.Preconditions.checkArgument; @Service -public class InstitutionChangeSuggestionService extends BaseChangeSuggestionService { +public class InstitutionChangeSuggestionService + extends BaseChangeSuggestionService { private static final Logger LOG = LoggerFactory.getLogger(InstitutionChangeSuggestionService.class); @@ -48,21 +50,19 @@ public InstitutionChangeSuggestionService( this.institutionMergeService = institutionMergeService; } + @Override protected int createConvertToCollectionSuggestion( - ChangeSuggestion changeSuggestion) { - checkArgument(changeSuggestion.getEntityKey() != null); + InstitutionChangeSuggestion institutionChangeSuggestion) { + checkArgument(institutionChangeSuggestion.getEntityKey() != null); - InstitutionChangeSuggestion institutionChangeSuggestion = - (InstitutionChangeSuggestion) changeSuggestion; - - ChangeSuggestionDto dto = createBaseChangeSuggestionDto(changeSuggestion); + ChangeSuggestionDto dto = createBaseChangeSuggestionDto(institutionChangeSuggestion); dto.setType(Type.CONVERSION_TO_COLLECTION); dto.setInstitutionConvertedCollection( institutionChangeSuggestion.getInstitutionForConvertedCollection()); dto.setNameNewInstitutionConvertedCollection( institutionChangeSuggestion.getNameForNewInstitutionForConvertedCollection()); - Institution currentEntity = institutionMapper.get(changeSuggestion.getEntityKey()); + Institution currentEntity = institutionMapper.get(institutionChangeSuggestion.getEntityKey()); dto.setCountry(getCountry(currentEntity)); changeSuggestionMapper.create(dto); @@ -73,8 +73,7 @@ protected int createConvertToCollectionSuggestion( public InstitutionChangeSuggestion getChangeSuggestion(int key) { ChangeSuggestionDto dto = changeSuggestionMapper.get(key); - InstitutionChangeSuggestion suggestion = - (InstitutionChangeSuggestion) dtoToChangeSuggestion(dto); + InstitutionChangeSuggestion suggestion = dtoToChangeSuggestion(dto); suggestion.setInstitutionForConvertedCollection(dto.getInstitutionConvertedCollection()); suggestion.setNameForNewInstitutionForConvertedCollection( dto.getNameNewInstitutionConvertedCollection()); @@ -82,8 +81,9 @@ public InstitutionChangeSuggestion getChangeSuggestion(int key) { return suggestion; } - protected void applyConversionToCollection(ChangeSuggestionDto dto) { - institutionMergeService.convertToCollection( + @Override + protected UUID applyConversionToCollection(ChangeSuggestionDto dto) { + return institutionMergeService.convertToCollection( dto.getEntityKey(), dto.getInstitutionConvertedCollection(), dto.getNameNewInstitutionConvertedCollection()); diff --git a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/CollectionResource.java b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/CollectionResource.java index e88b73ce85..3a5d0109a7 100644 --- a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/CollectionResource.java +++ b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/CollectionResource.java @@ -20,6 +20,7 @@ import org.gbif.api.model.collections.duplicates.DuplicatesRequest; import org.gbif.api.model.collections.duplicates.DuplicatesResult; import org.gbif.api.model.collections.request.CollectionSearchRequest; +import org.gbif.api.model.collections.suggestions.CollectionChangeSuggestion; import org.gbif.api.model.collections.view.CollectionView; import org.gbif.api.model.common.paging.Pageable; import org.gbif.api.model.common.paging.PagingRequest; @@ -65,7 +66,8 @@ @Validated @RestController @RequestMapping(value = "grscicoll/collection", produces = MediaType.APPLICATION_JSON_VALUE) -public class CollectionResource extends ExtendedCollectionEntityResource +public class CollectionResource + extends ExtendedCollectionEntityResource implements CollectionService { private final CollectionMapper collectionMapper; diff --git a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/ExtendedCollectionEntityResource.java b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/ExtendedCollectionEntityResource.java index ce001deeaa..6931acc080 100644 --- a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/ExtendedCollectionEntityResource.java +++ b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/ExtendedCollectionEntityResource.java @@ -92,7 +92,8 @@ public abstract class ExtendedCollectionEntityResource< T extends CollectionEntity & Taggable & Identifiable & MachineTaggable & Contactable & Commentable - & OccurrenceMappeable> + & OccurrenceMappeable, + R extends ChangeSuggestion> extends BaseCollectionEntityResource implements ContactService, OccurrenceMappingService { private final ContactableMapper contactableMapper; @@ -100,7 +101,7 @@ public abstract class ExtendedCollectionEntityResource< private final OccurrenceMappeableMapper occurrenceMappeableMapper; private final MergeService mergeService; private final ExtendedCollectionService extendedCollectionService; - private final ChangeSuggestionService changeSuggestionService; + private final ChangeSuggestionService changeSuggestionService; private final EventManager eventManager; private final Class objectClass; @@ -115,7 +116,7 @@ protected ExtendedCollectionEntityResource( OccurrenceMappeableMapper occurrenceMappeableMapper, MergeService mergeService, ExtendedCollectionService extendedCollectionService, - ChangeSuggestionService changeSuggestionService, + ChangeSuggestionService changeSuggestionService, EventManager eventManager, Class objectClass, WithMyBatis withMyBatis) { @@ -254,23 +255,26 @@ public void merge(@PathVariable("key") UUID entityKey, @RequestBody MergeParams } @PostMapping(value = "changeSuggestion") - public int createChangeSuggestion(@RequestBody ChangeSuggestion createSuggestion) { + public int createChangeSuggestion(@RequestBody R createSuggestion) { return changeSuggestionService.createChangeSuggestion(createSuggestion); } + // TODO: suggestions roles + @PutMapping(value = "changeSuggestion/{key}") - @Secured({GRSCICOLL_ADMIN_ROLE, GRSCICOLL_EDITOR_ROLE}) - public void updateChangeSuggestion(@RequestBody ChangeSuggestion createSuggestion) { - changeSuggestionService.updateChangeSuggestion(createSuggestion); + @Secured({GRSCICOLL_ADMIN_ROLE}) + public void updateChangeSuggestion(@PathVariable("key") int key, @RequestBody R suggestion) { + checkArgument(key == suggestion.getKey()); + changeSuggestionService.updateChangeSuggestion(suggestion); } @GetMapping(value = "changeSuggestion/{key}") - public ChangeSuggestion getChangeSuggestion(@PathVariable("key") int key) { + public R getChangeSuggestion(@PathVariable("key") int key) { return changeSuggestionService.getChangeSuggestion(key); } @GetMapping(value = "changeSuggestion") - public PagingResponse> listChangeSuggestion( + public PagingResponse listChangeSuggestion( @Nullable @RequestParam(value = "status", required = false) Status status, @Nullable @RequestParam(value = "type", required = false) Type type, @Nullable Country country, @@ -281,14 +285,29 @@ public PagingResponse> listChangeSuggestion( } @PutMapping(value = "changeSuggestion/{key}/discard") - @Secured({GRSCICOLL_ADMIN_ROLE, GRSCICOLL_EDITOR_ROLE}) + @Secured({GRSCICOLL_ADMIN_ROLE}) public void discardChangeSuggestion(@PathVariable("key") int key) { changeSuggestionService.discardChangeSuggestion(key); } @PutMapping(value = "changeSuggestion/{key}/apply") - @Secured({GRSCICOLL_ADMIN_ROLE, GRSCICOLL_EDITOR_ROLE}) - public void applyChangeSuggestion(@PathVariable("key") int key) { - changeSuggestionService.applyChangeSuggestion(key); + @Secured({GRSCICOLL_ADMIN_ROLE}) + public ApplySuggestionResult applyChangeSuggestion(@PathVariable("key") int key) { + UUID entityCreatedKey = changeSuggestionService.applyChangeSuggestion(key); + ApplySuggestionResult result = new ApplySuggestionResult(); + result.setEntityCreatedKey(entityCreatedKey); + return result; + } + + public static class ApplySuggestionResult { + private UUID entityCreatedKey; + + public UUID getEntityCreatedKey() { + return entityCreatedKey; + } + + public void setEntityCreatedKey(UUID entityCreatedKey) { + this.entityCreatedKey = entityCreatedKey; + } } } diff --git a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/InstitutionResource.java b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/InstitutionResource.java index 490ee33ab6..69decf83e5 100644 --- a/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/InstitutionResource.java +++ b/registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/InstitutionResource.java @@ -21,6 +21,7 @@ import org.gbif.api.model.collections.duplicates.DuplicatesResult; import org.gbif.api.model.collections.merge.ConvertToCollectionParams; import org.gbif.api.model.collections.request.InstitutionSearchRequest; +import org.gbif.api.model.collections.suggestions.InstitutionChangeSuggestion; import org.gbif.api.model.common.paging.Pageable; import org.gbif.api.model.common.paging.PagingRequest; import org.gbif.api.model.common.paging.PagingResponse; @@ -69,7 +70,8 @@ @Validated @RestController @RequestMapping(value = "grscicoll/institution", produces = MediaType.APPLICATION_JSON_VALUE) -public class InstitutionResource extends ExtendedCollectionEntityResource +public class InstitutionResource + extends ExtendedCollectionEntityResource implements InstitutionService { private final InstitutionMapper institutionMapper;