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 2b91367 commit 5c7ac6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.registry.Commentable;
import org.gbif.api.model.registry.Identifiable;
import org.gbif.api.model.registry.Identifier;
import org.gbif.api.model.registry.MachineTaggable;
import org.gbif.api.model.registry.Taggable;
import org.gbif.api.service.collections.ChangeSuggestionService;
import org.gbif.api.service.collections.CollectionService;
import org.gbif.api.service.collections.ContactService;
import org.gbif.api.service.collections.CrudService;
import org.gbif.api.vocabulary.Country;
import org.gbif.api.vocabulary.IdentifierType;
import org.gbif.api.vocabulary.UserRole;
import org.gbif.registry.events.EventManager;
import org.gbif.registry.events.collections.EventType;
Expand Down Expand Up @@ -113,6 +116,7 @@ public abstract class BaseChangeSuggestionService<
private final GrSciCollAuthorizationService grSciCollAuthorizationService;
private final CollectionsMailConfigurationProperties collectionsMailConfigurationProperties;
private CollectionEntityType collectionEntityType;
private final CollectionService collectionService;

protected BaseChangeSuggestionService(
ChangeSuggestionMapper changeSuggestionMapper,
Expand All @@ -126,7 +130,8 @@ protected BaseChangeSuggestionService(
CollectionsEmailManager emailManager,
EventManager eventManager,
GrSciCollAuthorizationService grSciCollAuthorizationService,
CollectionsMailConfigurationProperties collectionsMailConfigurationProperties) {
CollectionsMailConfigurationProperties collectionsMailConfigurationProperties,
CollectionService collectionService) {
this.changeSuggestionMapper = changeSuggestionMapper;
this.mergeService = mergeService;
this.crudService = crudService;
Expand All @@ -139,6 +144,7 @@ protected BaseChangeSuggestionService(
this.eventManager = eventManager;
this.grSciCollAuthorizationService = grSciCollAuthorizationService;
this.collectionsMailConfigurationProperties = collectionsMailConfigurationProperties;
this.collectionService = collectionService;

if (clazz == Institution.class) {
collectionEntityType = CollectionEntityType.INSTITUTION;
Expand Down Expand Up @@ -437,6 +443,10 @@ public UUID applyChangeSuggestion(int suggestionKey) {
}
}

if (dto.getProposedBy().equals("ih-sync")){
collectionService.addIdentifier(createdEntity,new Identifier(IdentifierType.IH_IRN,
dto.getIhIdentifier()));
}
return createdEntity;
}

Expand Down
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 @@ -74,7 +76,8 @@ public CollectionChangeSuggestionService(
emailManager,
eventManager,
grSciCollAuthorizationService,
collectionsMailConfigurationProperties);
collectionsMailConfigurationProperties,
collectionService);
this.changeSuggestionMapper = changeSuggestionMapper;
this.institutionService = institutionService;
}
Expand All @@ -96,6 +99,7 @@ public UUID applyChangeSuggestion(int suggestionKey){
Collection suggestedCollection = readJson(dto.getSuggestedEntity(), Collection.class);
suggestedCollection.setInstitutionKey(createdInstitution);
dto.setSuggestedEntity(toJson(suggestedCollection));

changeSuggestionMapper.update(dto);
}
}
Expand Down Expand Up @@ -135,10 +139,12 @@ public UUID createInstitutionForCollectionSuggestion(ChangeSuggestionDto dto){
CollectionChangeSuggestion changeSuggestion = dtoToChangeSuggestion(dto);
UUID createdEntity = null;
if (dto.getType() == Type.CREATE) {

if (dto.getCreateInstitution()) {
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 @@ -150,10 +156,14 @@ private Institution collectionChangeSuggestionToInstitution(ChangeSuggestionDto

if (dto.getSuggestedEntity() != null) {
Collection collection = readJson(dto.getSuggestedEntity(), Collection.class);
institution.setName(collection.getName());

String name = collection.getName();
if(name.startsWith("Herbarium - ")) {
name = name.substring("Herbarium - ".length());
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.gbif.api.model.collections.CollectionEntityType;
import org.gbif.api.model.collections.Institution;
import org.gbif.api.model.collections.suggestions.InstitutionChangeSuggestion;
import org.gbif.api.service.collections.CollectionService;
import org.gbif.api.service.collections.InstitutionService;
import org.gbif.registry.events.EventManager;
import org.gbif.registry.mail.EmailSender;
Expand Down Expand Up @@ -67,7 +68,8 @@ public InstitutionChangeSuggestionService(
CollectionsEmailManager emailManager,
EventManager eventManager,
GrSciCollAuthorizationService grSciCollAuthorizationService,
CollectionsMailConfigurationProperties collectionsMailConfigurationProperties) {
CollectionsMailConfigurationProperties collectionsMailConfigurationProperties,
CollectionService collectionService) {
super(
changeSuggestionMapper,
institutionMergeService,
Expand All @@ -80,7 +82,8 @@ public InstitutionChangeSuggestionService(
emailManager,
eventManager,
grSciCollAuthorizationService,
collectionsMailConfigurationProperties);
collectionsMailConfigurationProperties,
collectionService);
this.changeSuggestionMapper = changeSuggestionMapper;
this.institutionMergeService = institutionMergeService;
this.institutionService = institutionService;
Expand Down

0 comments on commit 5c7ac6a

Please sign in to comment.