Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create identifier when creating a collection and institution from a s… #608

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -135,10 +148,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 +165,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
Loading