diff --git a/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.java b/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.java index da853b6c34..2f74060846 100644 --- a/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.java +++ b/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/ChangeSuggestionMapper.java @@ -25,7 +25,7 @@ public interface ChangeSuggestionMapper { List list( @Param("status") Status status, @Param("type") Type type, - @Param("collectionEntityType") CollectionEntityType collectionEntityType, + @Param("entityType") CollectionEntityType entityType, @Param("country") Country country, @Param("proposerEmail") String proposerEmail, @Param("entityKey") UUID entityKey, @@ -34,7 +34,7 @@ List list( long count( @Param("status") Status status, @Param("type") Type type, - @Param("collectionEntityType") CollectionEntityType collectionEntityType, + @Param("entityType") CollectionEntityType entityType, @Param("country") Country country, @Param("proposerEmail") String proposerEmail, @Param("entityKey") UUID entityKey); diff --git a/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/dto/ChangeSuggestionDto.java b/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/dto/ChangeSuggestionDto.java index 1703ebaac2..8e5ea0e22b 100644 --- a/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/dto/ChangeSuggestionDto.java +++ b/registry-persistence/src/main/java/org/gbif/registry/persistence/mapper/collections/dto/ChangeSuggestionDto.java @@ -18,7 +18,7 @@ public class ChangeSuggestionDto { private Integer key; - private CollectionEntityType collectionEntityType; + private CollectionEntityType entityType; private UUID entityKey; private Type type; private Status status; diff --git a/registry-persistence/src/main/resources/liquibase/094-grscicoll-change-suggestions.xml b/registry-persistence/src/main/resources/liquibase/094-grscicoll-change-suggestions.xml index ead75fdea5..6c383824a3 100644 --- a/registry-persistence/src/main/resources/liquibase/094-grscicoll-change-suggestions.xml +++ b/registry-persistence/src/main/resources/liquibase/094-grscicoll-change-suggestions.xml @@ -17,7 +17,7 @@ type enum_change_suggestion_type NOT NULL, status enum_change_suggestion_status NOT NULL, proposed timestamptz NOT NULL DEFAULT now(), - proposed_by varchar NOT NULL CHECK (assert_min_length(proposed_by, 3)), + proposed_by varchar CHECK (assert_min_length(proposed_by, 3)), proposer_email varchar NOT NULL CHECK (assert_min_length(proposer_email, 3)), applied timestamptz, applied_by varchar CHECK (assert_min_length(applied_by, 3)), 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 e22ff3f2f4..a4a4f49ef6 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 @@ -22,7 +22,7 @@ - #{collectionEntityType,jdbcType=OTHER}, + #{entityType,jdbcType=OTHER}, #{entityKey,jdbcType=OTHER}, #{type,jdbcType=OTHER}, #{status,jdbcType=OTHER}, @@ -78,8 +78,8 @@ AND cs.type = #{type,jdbcType=OTHER} - - AND cs.entity_type = #{collectionEntityType,jdbcType=OTHER} + + AND cs.entity_type = #{entityType,jdbcType=OTHER} AND cs.country = #{country,jdbcType=VARCHAR} @@ -107,8 +107,8 @@ AND cs.type = #{type,jdbcType=OTHER} - - AND cs.entity_type = #{collectionEntityType,jdbcType=OTHER} + + AND cs.entity_type = #{entityType,jdbcType=OTHER} AND cs.country = #{country,jdbcType=VARCHAR} 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 ddd1a844f6..bf79a60912 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 @@ -1,8 +1,17 @@ package org.gbif.registry.service.collections.suggestions; +import org.gbif.api.model.collections.Address; import org.gbif.api.model.collections.Collection; -import org.gbif.api.model.collections.*; -import org.gbif.api.model.collections.suggestions.*; +import org.gbif.api.model.collections.CollectionEntity; +import org.gbif.api.model.collections.CollectionEntityType; +import org.gbif.api.model.collections.Contactable; +import org.gbif.api.model.collections.Institution; +import org.gbif.api.model.collections.OccurrenceMappeable; +import org.gbif.api.model.collections.suggestions.Change; +import org.gbif.api.model.collections.suggestions.ChangeSuggestion; +import org.gbif.api.model.collections.suggestions.ChangeSuggestionService; +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; @@ -25,12 +34,16 @@ import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; -import java.util.*; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,9 +51,12 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import static com.google.common.base.Preconditions.checkArgument; import static org.gbif.registry.security.UserRoles.GRSCICOLL_ADMIN_ROLE; import static org.gbif.registry.security.UserRoles.GRSCICOLL_EDITOR_ROLE; -import static com.google.common.base.Preconditions.checkArgument; public abstract class BaseChangeSuggestionService< T extends @@ -131,8 +147,7 @@ public int createChangeSuggestion(R changeSuggestion) { // send email try { BaseEmailModel emailModel = - emailManager.generateNewChangeSuggestionEmailModel( - dto.getKey(), dto.getCollectionEntityType()); + emailManager.generateNewChangeSuggestionEmailModel(dto.getKey(), dto.getEntityType()); emailSender.send(emailModel); } catch (Exception e) { LOG.error("Couldn't send email for new change suggestion", e); @@ -243,7 +258,7 @@ public void discardChangeSuggestion(int key) { try { BaseEmailModel emailModel = emailManager.generateDiscardedChangeSuggestionEmailModel( - dto.getKey(), dto.getCollectionEntityType()); + dto.getKey(), dto.getEntityType()); emailSender.send(emailModel); } catch (Exception e) { LOG.error("Couldn't send email for discarded change suggestion", e); @@ -285,8 +300,7 @@ public UUID applyChangeSuggestion(int suggestionKey) { // send email try { BaseEmailModel emailModel = - emailManager.generateAppliedChangeSuggestionEmailModel( - dto.getKey(), dto.getCollectionEntityType()); + emailManager.generateAppliedChangeSuggestionEmailModel(dto.getKey(), dto.getEntityType()); emailSender.send(emailModel); } catch (Exception e) { LOG.error("Couldn't send email for applied change suggestion", e); @@ -307,22 +321,11 @@ public PagingResponse list( List dtos = changeSuggestionMapper.list( - status, - type, - collectionEntityType, - country, - proposerEmail, - entityKey, - page); + status, type, collectionEntityType, country, proposerEmail, entityKey, page); long count = changeSuggestionMapper.count( - status, - type, - collectionEntityType, - country, - proposerEmail, - entityKey); + status, type, collectionEntityType, country, proposerEmail, entityKey); List changeSuggestions = dtos.stream().map(this::dtoToChangeSuggestion).collect(Collectors.toList()); @@ -384,7 +387,7 @@ protected ChangeSuggestionDto createBaseChangeSuggestionDto(R changeSuggestion) dto.setStatus(Status.PENDING); dto.setType(changeSuggestion.getType()); dto.setComments(changeSuggestion.getComments()); - dto.setCollectionEntityType(collectionEntityType); + dto.setEntityType(collectionEntityType); dto.setProposerEmail(changeSuggestion.getProposerEmail()); dto.setProposedBy(getUsername()); dto.setModifiedBy(getUsername());