Skip to content

Commit

Permalink
create identifier when creating a collection and institution from a s…
Browse files Browse the repository at this point in the history
…uggestion

(#579)
  • Loading branch information
ahakanzn committed Aug 12, 2024
1 parent 20b9e13 commit c9fbd6d
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +50,7 @@ public class CollectionChangeSuggestionService

private final ChangeSuggestionMapper changeSuggestionMapper;
private final InstitutionService institutionService;
private final CollectionService collectionService;

@Autowired
public CollectionChangeSuggestionService(
Expand Down Expand Up @@ -77,6 +80,7 @@ public CollectionChangeSuggestionService(
collectionsMailConfigurationProperties);
this.changeSuggestionMapper = changeSuggestionMapper;
this.institutionService = institutionService;
this.collectionService = collectionService;
}

@Override
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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());
Expand Down

0 comments on commit c9fbd6d

Please sign in to comment.