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 d4e72100d..6a8f52ec8 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 @@ -18,8 +18,10 @@ import org.gbif.api.model.collections.Institution; import org.gbif.api.model.collections.suggestions.CollectionChangeSuggestion; import org.gbif.api.model.collections.suggestions.Type; +import org.gbif.api.model.registry.Identifier; import org.gbif.api.service.collections.CollectionService; import org.gbif.api.service.collections.InstitutionService; +import org.gbif.api.vocabulary.IdentifierType; import org.gbif.registry.events.EventManager; import org.gbif.registry.mail.EmailSender; import org.gbif.registry.mail.collections.CollectionsEmailManager; @@ -48,6 +50,7 @@ public class CollectionChangeSuggestionService private final ChangeSuggestionMapper changeSuggestionMapper; private final InstitutionService institutionService; + private final CollectionService collectionService; @Autowired public CollectionChangeSuggestionService( @@ -77,6 +80,7 @@ public CollectionChangeSuggestionService( collectionsMailConfigurationProperties); this.changeSuggestionMapper = changeSuggestionMapper; this.institutionService = institutionService; + this.collectionService = collectionService; } @Override @@ -96,10 +100,19 @@ public UUID applyChangeSuggestion(int suggestionKey){ Collection suggestedCollection = readJson(dto.getSuggestedEntity(), Collection.class); suggestedCollection.setInstitutionKey(createdInstitution); dto.setSuggestedEntity(toJson(suggestedCollection)); + changeSuggestionMapper.update(dto); } } - return super.applyChangeSuggestion(suggestionKey); + + UUID createdEntity = super.applyChangeSuggestion(suggestionKey); + + if (dto.getIhIdentifier() != null){ + collectionService.addIdentifier(createdEntity,new Identifier(IdentifierType.IH_IRN, + dto.getIhIdentifier())); + } + + return createdEntity; } @Override @@ -137,7 +150,10 @@ public UUID createInstitutionForCollectionSuggestion(ChangeSuggestionDto dto){ if (dto.getType() == Type.CREATE) { if (Boolean.TRUE.equals(dto.getCreateInstitution())) { Institution institution = collectionChangeSuggestionToInstitution(dto); + createdEntity = institutionService.create(institution); + institutionService.addIdentifier(createdEntity,new Identifier(IdentifierType.IH_IRN, + dto.getIhIdentifier())); createContacts(changeSuggestion,createdEntity); } } @@ -157,7 +173,6 @@ private Institution collectionChangeSuggestionToInstitution(ChangeSuggestionDto institution.setName(name); institution.setCode(collection.getCode()); institution.setActive(collection.isActive()); - institution.setAddress(collection.getAddress()); institution.setEmail(collection.getEmail()); institution.setPhone(collection.getPhone());