From c520106f2afde65bb5fd3e0f7d9888199347bbca Mon Sep 17 00:00:00 2001 From: ahakanzn Date: Thu, 26 Sep 2024 10:06:52 +0200 Subject: [PATCH] Allow modification of change suggestions created by ih-sync --- .../mapper/collections/ChangeSuggestionMapper.xml | 3 ++- .../suggestions/BaseChangeSuggestionService.java | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) 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 9560e9a4a..549325a32 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 @@ -53,7 +53,8 @@ discarded_by = #{discardedBy,jdbcType=INTEGER}, applied = #{applied,jdbcType=OTHER}, applied_by = #{appliedBy,jdbcType=INTEGER}, - entity_key = #{entityKey,jdbcType=INTEGER} + entity_key = #{entityKey,jdbcType=INTEGER}, + create_institution = #{createInstitution,jdbcType=BOOLEAN} 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 a81c2e283..4ba82286d 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 @@ -66,6 +66,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static org.gbif.registry.security.UserRoles.*; +import static org.gbif.registry.service.collections.utils.MasterSourceUtils.IH_SYNC_USER; import static org.gbif.registry.service.collections.utils.MasterSourceUtils.hasExternalMasterSource; public abstract class BaseChangeSuggestionService< @@ -304,9 +305,9 @@ protected ChangeSuggestionDto createMergeSuggestionDto(R changeSuggestion) { public void updateChangeSuggestion(R updatedChangeSuggestion) { ChangeSuggestionDto dto = changeSuggestionMapper.get(updatedChangeSuggestion.getKey()); - checkArgument( - updatedChangeSuggestion.getComments().size() > dto.getComments().size(), - "A comment is required"); + //checkArgument( + //updatedChangeSuggestion.getComments().size() > dto.getComments().size(), + //"A comment is required"); if (dto.getType() == Type.CREATE || dto.getType() == Type.UPDATE) { // we get the current entity from the DB to update the suggested entity with the current state @@ -324,7 +325,12 @@ public void updateChangeSuggestion(R updatedChangeSuggestion) { .forEach(c -> c.setOverwritten(true)); dto.getChanges().add(newChange); } - + if (updatedChangeSuggestion.getSuggestedEntity() instanceof Collection && updatedChangeSuggestion.getProposedBy().equals(IH_SYNC_USER)) { + Collection collection = (Collection) updatedChangeSuggestion.getSuggestedEntity(); + if (collection.getInstitutionKey() != null) { + dto.setCreateInstitution(false); + } + } dto.setSuggestedEntity(toJson(updatedChangeSuggestion.getSuggestedEntity())); }