From 9dfaafaf9bd8b3ffa508d1f7948e9d565b100b8a Mon Sep 17 00:00:00 2001 From: David Eckhard Date: Wed, 13 Dec 2023 15:30:14 +0100 Subject: [PATCH] orcid: get contributor info from orcid --- .../damap/rest/dmp/service/DmpService.java | 68 +++++++--- .../damap/rest/persons/orcid/ORCIDMapper.java | 121 ++++++++++++++++++ .../rest/persons/orcid/ORCIDPersonMapper.java | 32 ----- .../persons/orcid/ORCIDPersonServiceImpl.java | 5 +- .../persons/orcid/OrcidPersonService.java | 7 +- .../orcid/models/ORCIDActivitiesSummary.java | 16 +++ .../orcid/models/ORCIDAffiliationGroup.java | 18 +++ .../orcid/models/ORCIDAffiliationSummary.java | 7 + .../orcid/models/ORCIDEducationSummary.java | 15 +++ .../persons/orcid/models/ORCIDEmails.java | 19 +++ .../orcid/models/ORCIDEmploymentSummary.java | 12 ++ .../ORCIDExpandedSearchPerson.java} | 12 +- .../ORCIDExpandedSearchResult.java | 7 +- .../rest/persons/orcid/models/ORCIDGroup.java | 16 +++ .../orcid/models/ORCIDOrganization.java | 14 ++ .../persons/orcid/models/ORCIDPerson.java | 17 +++ .../persons/orcid/models/ORCIDPersonName.java | 29 +++++ .../persons/orcid/models/ORCIDRecord.java | 16 +++ .../orcid/models/base/ORCIDAffiliation.java | 26 ++++ .../persons/orcid/models/base/ORCIDDate.java | 30 +++++ .../persons/orcid/models/base/ORCIDEmail.java | 19 +++ .../orcid/models/base/ORCIDValueType.java | 19 +++ 22 files changed, 461 insertions(+), 64 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDMapper.java delete mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonMapper.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDActivitiesSummary.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationGroup.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationSummary.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEducationSummary.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmails.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmploymentSummary.java rename src/main/java/at/ac/tuwien/damap/rest/persons/orcid/{ORCIDPerson.java => models/ORCIDExpandedSearchPerson.java} (57%) rename src/main/java/at/ac/tuwien/damap/rest/persons/orcid/{ => models}/ORCIDExpandedSearchResult.java (60%) create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDGroup.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDOrganization.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPerson.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPersonName.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDRecord.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDAffiliation.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDDate.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDEmail.java create mode 100644 src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDValueType.java diff --git a/src/main/java/at/ac/tuwien/damap/rest/dmp/service/DmpService.java b/src/main/java/at/ac/tuwien/damap/rest/dmp/service/DmpService.java index d7075c20..92a9722b 100644 --- a/src/main/java/at/ac/tuwien/damap/rest/dmp/service/DmpService.java +++ b/src/main/java/at/ac/tuwien/damap/rest/dmp/service/DmpService.java @@ -1,39 +1,44 @@ package at.ac.tuwien.damap.rest.dmp.service; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; +import javax.validation.Valid; + +import org.hibernate.envers.AuditReader; +import org.hibernate.envers.AuditReaderFactory; + import at.ac.tuwien.damap.domain.Access; import at.ac.tuwien.damap.domain.Contributor; import at.ac.tuwien.damap.domain.Dmp; import at.ac.tuwien.damap.enums.EContributorRole; import at.ac.tuwien.damap.enums.EFunctionRole; +import at.ac.tuwien.damap.enums.EIdentifierType; import at.ac.tuwien.damap.repo.AccessRepo; import at.ac.tuwien.damap.repo.DmpRepo; import at.ac.tuwien.damap.rest.dmp.domain.ContributorDO; import at.ac.tuwien.damap.rest.dmp.domain.DmpDO; import at.ac.tuwien.damap.rest.dmp.domain.DmpListItemDO; +import at.ac.tuwien.damap.rest.dmp.domain.IdentifierDO; import at.ac.tuwien.damap.rest.dmp.domain.ProjectDO; import at.ac.tuwien.damap.rest.dmp.mapper.ContributorDOMapper; import at.ac.tuwien.damap.rest.dmp.mapper.DmpDOMapper; import at.ac.tuwien.damap.rest.dmp.mapper.DmpListItemDOMapper; import at.ac.tuwien.damap.rest.dmp.mapper.MapperService; import at.ac.tuwien.damap.rest.dmp.mapper.ProjectSupplementDOMapper; +import at.ac.tuwien.damap.rest.persons.orcid.ORCIDPersonServiceImpl; import at.ac.tuwien.damap.rest.projects.ProjectService; import at.ac.tuwien.damap.rest.projects.ProjectSupplementDO; import at.ac.tuwien.damap.rest.version.VersionDO; import at.ac.tuwien.damap.rest.version.VersionService; import lombok.extern.jbosslog.JBossLog; -import org.hibernate.envers.AuditReader; -import org.hibernate.envers.AuditReaderFactory; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; -import javax.validation.Valid; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.Optional; @ApplicationScoped @JBossLog @@ -54,6 +59,9 @@ public class DmpService { @Inject VersionService versionService; + @Inject + ORCIDPersonServiceImpl orcidPersonService; + public List getAll() { List dmpList = dmpRepo.getAll(); @@ -83,6 +91,7 @@ public DmpDO create(@Valid DmpDO dmpDO, String editedBy) { DmpConsistencyUtility.enforceDmpConsistency(dmpDO); Dmp dmp = DmpDOMapper.mapDOtoEntity(dmpDO, new Dmp(), mapperService); dmp.setCreated(new Date()); + fetchORCIDContributorInfo(dmp); updateDmpSupplementalInfo(dmp); updateProjectLead(dmp); dmp.persistAndFlush(); @@ -98,6 +107,7 @@ public DmpDO update(@Valid DmpDO dmpDO) { boolean projectSelectionChanged = projectSelectionChanged(dmp, dmpDO); DmpDOMapper.mapDOtoEntity(dmpDO, dmp, mapperService); dmp.setModified(new Date()); + fetchORCIDContributorInfo(dmp); if (projectSelectionChanged) { updateDmpSupplementalInfo(dmp); updateProjectLead(dmp); @@ -145,8 +155,10 @@ public String getDefaultFileName(long id) { Dmp dmp = dmpRepo.findById(id); if (dmp != null) { if (dmp.getProject() != null) { - if (dmp.getProject().getUniversityId() != null && projectService.read(dmp.getProject().getUniversityId()) != null) { - filename = "DMP_" + projectService.read(dmp.getProject().getUniversityId()).getAcronym() + "_" + formatter.format(date); + if (dmp.getProject().getUniversityId() != null + && projectService.read(dmp.getProject().getUniversityId()) != null) { + filename = "DMP_" + projectService.read(dmp.getProject().getUniversityId()).getAcronym() + "_" + + formatter.format(date); } else if (dmp.getProject().getTitle() != null) filename = "DMP_" + dmp.getProject().getTitle() + "_" + formatter.format(date); } else { @@ -174,8 +186,9 @@ public List checkExistingDmps(List projectDOList) { return projectDOList; } - // This method will retrieve the Project Supplement values from the connected CRIS System - // and it will reset them to null in case the project is not from a connected system. + // This method will retrieve the Project Supplement values from the connected + // CRIS System and it will reset them to null in case the project is not from a + // connected system. private void updateDmpSupplementalInfo(Dmp dmp) { if (dmp.getProject() != null) { ProjectSupplementDO projectSupplementDO = null; @@ -199,8 +212,7 @@ private void updateProjectLead(Dmp dmp) { if (dmp.getProject() == null || dmp.getProject().getUniversityId() == null) return; - ContributorDO projectLeaderDO = - projectService.getProjectLeader(dmp.getProject().getUniversityId()); + ContributorDO projectLeaderDO = projectService.getProjectLeader(dmp.getProject().getUniversityId()); if (projectLeaderDO == null) return; @@ -211,8 +223,7 @@ private void updateProjectLead(Dmp dmp) { projectLeaderDO.getUniversityId())) .findFirst(); - Contributor projectLeaderContributor = - alreadyExistingContributorLeader.orElse(new Contributor()); + Contributor projectLeaderContributor = alreadyExistingContributorLeader.orElse(new Contributor()); // Adding project leader as contributor if it was not there yet. if (alreadyExistingContributorLeader.isEmpty()) { @@ -234,6 +245,21 @@ private void updateProjectLead(Dmp dmp) { } } + private void fetchORCIDContributorInfo(Dmp dmp) { + dmp.getContributorList().forEach(contributor -> { + // Existing contributor? Do not fetch data. + if (contributor.id != null) { + return; + } + + var identifier = contributor.getPersonIdentifier(); + if (identifier != null + && identifier.getIdentifierType().equals(EIdentifierType.ORCID)) { + ContributorDOMapper.mapDOtoEntity(orcidPersonService.read(identifier.getIdentifier()), contributor); + } + }); + } + private boolean projectSelectionChanged(Dmp dmp, DmpDO dmpDO) { if (dmpDO.getProject() == null) diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDMapper.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDMapper.java new file mode 100644 index 00000000..d30e6910 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDMapper.java @@ -0,0 +1,121 @@ +package at.ac.tuwien.damap.rest.persons.orcid; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import at.ac.tuwien.damap.enums.EIdentifierType; +import at.ac.tuwien.damap.rest.dmp.domain.ContributorDO; +import at.ac.tuwien.damap.rest.dmp.domain.IdentifierDO; +import at.ac.tuwien.damap.rest.persons.orcid.models.ORCIDExpandedSearchPerson; +import at.ac.tuwien.damap.rest.persons.orcid.models.ORCIDRecord; +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDAffiliation; +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDDate; +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDEmail; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class ORCIDMapper { + public ContributorDO mapExpandedSearchPersonEntityToDO(ORCIDExpandedSearchPerson orcidPerson, + ContributorDO contributorDO) { + + contributorDO.setId(null); + contributorDO.setFirstName(orcidPerson.getGivenNames()); + contributorDO.setLastName(orcidPerson.getFamilyNames()); + + String firstMail = orcidPerson.getEmails().isEmpty() ? null : orcidPerson.getEmails().get(0); + contributorDO.setMbox(firstMail); + + String firstAffiliation = orcidPerson.getAffiliations().isEmpty() ? null + : orcidPerson.getAffiliations().get(0); + contributorDO.setAffiliation(firstAffiliation); + + IdentifierDO identifierContributorDO = new IdentifierDO(); + identifierContributorDO.setIdentifier(orcidPerson.getOrcidId()); + identifierContributorDO.setType(EIdentifierType.ORCID); + + contributorDO.setPersonId(identifierContributorDO); + + return contributorDO; + } + + public ContributorDO mapRecordEntityToPersonDO(ORCIDRecord orcidRecord, + ContributorDO contributorDO) { + + contributorDO.setId(null); + contributorDO.setFirstName(orcidRecord.getPerson().getName().getGivenNames().getValue()); + contributorDO.setLastName(orcidRecord.getPerson().getName().getFamilyName().getValue()); + + var primaryMail = orcidRecord.getPerson().getEmails().getEmail().stream().filter(ORCIDEmail::isPrimary) + .findFirst(); + contributorDO.setMbox(primaryMail.isPresent() ? primaryMail.get().getEmail() : null); + + List affiliations = new ArrayList<>(); + + for (var groupListItem : List.of( + orcidRecord.getActivitiesSummary().getEducations().getAffiliationGroup(), + orcidRecord.getActivitiesSummary().getEmployments().getAffiliationGroup())) { + + for (var group : groupListItem) { + + for (var summary : group.getSummaries()) { + affiliations.add(summary.getSummary()); + } + } + + } + + if (!affiliations.isEmpty()) { + affiliations.sort(sortByCurrentStartDate); + contributorDO.setAffiliation(affiliations.get(affiliations.size() - 1).getOrganization().getName()); + } + + IdentifierDO identifierContributorDO = new IdentifierDO(); + identifierContributorDO.setIdentifier(orcidRecord.getPerson().getName().getPath()); + identifierContributorDO.setType(EIdentifierType.ORCID); + + contributorDO.setPersonId(identifierContributorDO); + return contributorDO; + } + + private final Comparator sortByCurrentStartDate = ((ORCIDAffiliation a, + ORCIDAffiliation b) -> { + ORCIDDate aEndDate = a.getEndDate(); + ORCIDDate bEndDate = b.getEndDate(); + + // both end dates set, so we can directly compare + if (aEndDate != null && bEndDate != null) { + return aEndDate.getAsDate().compareTo(bEndDate.getAsDate()); + } + + // if only one is set, it means the other is current + if (aEndDate != null || bEndDate != null) { + if (aEndDate == null) + return 1; + if (bEndDate == null) + return -1; + } + + // both end dates are null. lets compare via start date + ORCIDDate aStartDate = a.getStartDate(); + ORCIDDate bStartDate = b.getStartDate(); + + // both start dates set. compare directly + if (aStartDate != null && bStartDate != null) { + return aStartDate.getAsDate().compareTo(bStartDate.getAsDate()); + } + + // basically nothing set. considered equal + if (aStartDate == null && bStartDate == null) + return 0; + + // one not set. + if (aStartDate == null) + return 1; + if (bStartDate == null) + return -1; + + // fall back. Should never reach this. + return 0; + }); +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonMapper.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonMapper.java deleted file mode 100644 index a7ea1f6c..00000000 --- a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package at.ac.tuwien.damap.rest.persons.orcid; - -import at.ac.tuwien.damap.enums.EIdentifierType; -import at.ac.tuwien.damap.rest.dmp.domain.ContributorDO; -import at.ac.tuwien.damap.rest.dmp.domain.IdentifierDO; -import lombok.experimental.UtilityClass; - -@UtilityClass -public class ORCIDPersonMapper { - - public ContributorDO mapEntityToDO(ORCIDPerson orcidPerson, ContributorDO contributorDO) { - - contributorDO.setId(null); - contributorDO.setFirstName(orcidPerson.getGivenNames()); - contributorDO.setLastName(orcidPerson.getFamilyNames()); - - String firstMail = orcidPerson.getEmails().isEmpty() ? null : orcidPerson.getEmails().get(0); - contributorDO.setMbox(firstMail); - - String firstAffiliation = orcidPerson.getAffiliations().isEmpty() ? null - : orcidPerson.getAffiliations().get(0); - contributorDO.setAffiliation(firstAffiliation); - - IdentifierDO identifierContributorDO = new IdentifierDO(); - identifierContributorDO.setIdentifier(orcidPerson.orcidId); - identifierContributorDO.setType(EIdentifierType.ORCID); - - contributorDO.setPersonId(identifierContributorDO); - - return contributorDO; - } -} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonServiceImpl.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonServiceImpl.java index 0da910fd..82fc0605 100644 --- a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonServiceImpl.java +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonServiceImpl.java @@ -25,7 +25,7 @@ public class ORCIDPersonServiceImpl implements PersonService { @Override public ContributorDO read(String id, MultivaluedMap queryParams) { - return ORCIDPersonMapper.mapEntityToDO(orcidRestClient.get(id), new ContributorDO()); + return ORCIDMapper.mapRecordEntityToPersonDO(orcidRestClient.get(id), new ContributorDO()); } @Override @@ -39,7 +39,7 @@ public ResultList search(MultivaluedMap queryPara if (orcidSearch.getNumFound() > 0 && orcidSearch.getPersons() != null) { contributors = orcidSearch.getPersons().stream().map(o -> { var c = new ContributorDO(); - ORCIDPersonMapper.mapEntityToDO(o, c); + ORCIDMapper.mapExpandedSearchPersonEntityToDO(o, c); return c; }).collect(Collectors.toList()); } @@ -48,6 +48,5 @@ public ResultList search(MultivaluedMap queryPara } return ResultList.fromItemsAndSearch(contributors, search); - } } diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/OrcidPersonService.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/OrcidPersonService.java index 89bde951..8f044d0f 100644 --- a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/OrcidPersonService.java +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/OrcidPersonService.java @@ -10,6 +10,9 @@ import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; +import at.ac.tuwien.damap.rest.persons.orcid.models.ORCIDExpandedSearchResult; +import at.ac.tuwien.damap.rest.persons.orcid.models.ORCIDRecord; + @RegisterRestClient(configKey = "rest.orcid.search") @Path("/v3.0") @Produces(MediaType.APPLICATION_JSON) @@ -20,8 +23,8 @@ public interface OrcidPersonService { @ClientHeaderParam(name = "accept", value = MediaType.APPLICATION_JSON) ORCIDExpandedSearchResult getAll(@QueryParam("q") String query, @QueryParam("rows") int rows); - @Path("/{orcid}/person") + @Path("/{orcid}/record") @GET @ClientHeaderParam(name = "accept", value = MediaType.APPLICATION_JSON) - ORCIDPerson get(@PathParam(value = "orcid") String orcid); + ORCIDRecord get(@PathParam(value = "orcid") String orcid); } diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDActivitiesSummary.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDActivitiesSummary.java new file mode 100644 index 00000000..77b73ebc --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDActivitiesSummary.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDActivitiesSummary { + @JsonProperty + ORCIDAffiliationGroup employments; + + @JsonProperty + ORCIDAffiliationGroup educations; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationGroup.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationGroup.java new file mode 100644 index 00000000..c89ba850 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationGroup.java @@ -0,0 +1,18 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDAffiliationGroup { + @JsonProperty(value = "affiliation-group") + @JsonSetter(nulls = Nulls.AS_EMPTY) + List> affiliationGroup; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationSummary.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationSummary.java new file mode 100644 index 00000000..fc3550fb --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationSummary.java @@ -0,0 +1,7 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDAffiliation; + +public interface ORCIDAffiliationSummary { + ORCIDAffiliation getSummary(); +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEducationSummary.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEducationSummary.java new file mode 100644 index 00000000..d5c072b1 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEducationSummary.java @@ -0,0 +1,15 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonSetter; + +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDAffiliation; +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDEducationSummary implements ORCIDAffiliationSummary { + + @JsonSetter(value = "education-summary") + ORCIDAffiliation summary; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmails.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmails.java new file mode 100644 index 00000000..c985b8fd --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmails.java @@ -0,0 +1,19 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; + +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDEmail; +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDEmails { + @JsonProperty + @JsonSetter(nulls = Nulls.AS_EMPTY) + List email = List.of(); +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmploymentSummary.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmploymentSummary.java new file mode 100644 index 00000000..e049de04 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDEmploymentSummary.java @@ -0,0 +1,12 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDAffiliation; +import lombok.Data; + +@Data +public class ORCIDEmploymentSummary implements ORCIDAffiliationSummary { + @JsonProperty(value = "employment-summary") + ORCIDAffiliation summary; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPerson.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDExpandedSearchPerson.java similarity index 57% rename from src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPerson.java rename to src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDExpandedSearchPerson.java index 962c8cfd..ba3599a9 100644 --- a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPerson.java +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDExpandedSearchPerson.java @@ -1,14 +1,16 @@ -package at.ac.tuwien.damap.rest.persons.orcid; +package at.ac.tuwien.damap.rest.persons.orcid.models; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; import lombok.Data; @Data @JsonIgnoreProperties(ignoreUnknown = true) -public class ORCIDPerson { +public class ORCIDExpandedSearchPerson { @JsonProperty(value = "orcid-id") String orcidId; @@ -20,8 +22,10 @@ public class ORCIDPerson { String familyNames; @JsonProperty(value = "email") - List emails; + @JsonSetter(nulls = Nulls.AS_EMPTY) + List emails = List.of(); @JsonProperty(value = "institution-name") - List affiliations; + @JsonSetter(nulls = Nulls.AS_EMPTY) + List affiliations = List.of(); } diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDExpandedSearchResult.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDExpandedSearchResult.java similarity index 60% rename from src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDExpandedSearchResult.java rename to src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDExpandedSearchResult.java index 7abfd612..b97e1f24 100644 --- a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDExpandedSearchResult.java +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDExpandedSearchResult.java @@ -1,9 +1,11 @@ -package at.ac.tuwien.damap.rest.persons.orcid; +package at.ac.tuwien.damap.rest.persons.orcid.models; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; import lombok.Data; @@ -12,7 +14,8 @@ public class ORCIDExpandedSearchResult { @JsonProperty(value = "expanded-result") - private List persons; + @JsonSetter(nulls = Nulls.AS_EMPTY) + private List persons; @JsonProperty(value = "num-found") private long numFound; diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDGroup.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDGroup.java new file mode 100644 index 00000000..4503f3b7 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDGroup.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDGroup { + @JsonSetter(nulls = Nulls.AS_EMPTY) + List summaries = List.of(); +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDOrganization.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDOrganization.java new file mode 100644 index 00000000..a1454793 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDOrganization.java @@ -0,0 +1,14 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDOrganization { + @JsonProperty + String name; + +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPerson.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPerson.java new file mode 100644 index 00000000..45ab4ef8 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPerson.java @@ -0,0 +1,17 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDPerson { + + @JsonProperty(value = "name") + ORCIDPersonName name; + + @JsonProperty + ORCIDEmails emails; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPersonName.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPersonName.java new file mode 100644 index 00000000..97a672fa --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDPersonName.java @@ -0,0 +1,29 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; + +import at.ac.tuwien.damap.rest.persons.orcid.models.base.ORCIDValueType; +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDPersonName { + + @JsonProperty(value = "given-names") + @JsonSetter(nulls = Nulls.SKIP) + ORCIDValueType givenNames = new ORCIDValueType(); + + @JsonProperty(value = "family-name") + @JsonSetter(nulls = Nulls.SKIP) + ORCIDValueType familyName = new ORCIDValueType(); + + @JsonProperty(value = "credit-name") + @JsonSetter(nulls = Nulls.SKIP) + ORCIDValueType creditName = new ORCIDValueType(); + + @JsonProperty + String path; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDRecord.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDRecord.java new file mode 100644 index 00000000..dfaa67e8 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDRecord.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDRecord { + @JsonProperty + ORCIDPerson person; + + @JsonProperty(value = "activities-summary") + ORCIDActivitiesSummary activitiesSummary; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDAffiliation.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDAffiliation.java new file mode 100644 index 00000000..58bb6d0b --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDAffiliation.java @@ -0,0 +1,26 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models.base; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import at.ac.tuwien.damap.rest.persons.orcid.models.ORCIDOrganization; +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDAffiliation { + @JsonProperty(value = "department-name") + String departmentName; + + @JsonProperty(value = "role-title") + String roleTitle; + + @JsonProperty(value = "start-date") + ORCIDDate startDate; + + @JsonProperty(value = "end-date") + ORCIDDate endDate; + + @JsonProperty + ORCIDOrganization organization; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDDate.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDDate.java new file mode 100644 index 00000000..0a87c0fb --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDDate.java @@ -0,0 +1,30 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models.base; + +import java.util.Calendar; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDDate { + @JsonProperty + ORCIDValueType year; + + @JsonProperty + ORCIDValueType month; + + @JsonProperty + ORCIDValueType day; + + public Date getAsDate() { + Calendar c = Calendar.getInstance(); + c.set(Calendar.YEAR, year == null ? 0 : year.asInt()); + c.set(Calendar.MONTH, month == null ? 0 : month.asInt() - 1); + c.set(Calendar.DATE, day == null ? 1 : day.asInt()); + return c.getTime(); + } +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDEmail.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDEmail.java new file mode 100644 index 00000000..4d62d540 --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDEmail.java @@ -0,0 +1,19 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models.base; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ORCIDEmail { + @JsonProperty + String email; + + @JsonProperty + boolean verified; + + @JsonProperty + boolean primary; +} diff --git a/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDValueType.java b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDValueType.java new file mode 100644 index 00000000..61fe111c --- /dev/null +++ b/src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/base/ORCIDValueType.java @@ -0,0 +1,19 @@ +package at.ac.tuwien.damap.rest.persons.orcid.models.base; + +import lombok.Data; + +@Data +public class ORCIDValueType { + String value; + + public Integer asInt() { + Integer converted = null; + try { + converted = Integer.parseInt(value, 10); + } catch (Exception e) { + // will return null + } + + return converted; + } +}