Skip to content

Commit

Permalink
Allow modification of change suggestions created by ih-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ahakanzn committed Sep 26, 2024
1 parent 283e33a commit c520106
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
</sql>

<insert id="create" parameterType="ChangeSuggestionDto" useGeneratedKeys="true" keyProperty="key">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -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
Expand All @@ -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()));
}

Expand Down

0 comments on commit c520106

Please sign in to comment.