-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orcid: get contributor info from orcid
- Loading branch information
Showing
22 changed files
with
461 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ORCIDAffiliation> 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<? super ORCIDAffiliation> 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; | ||
}); | ||
} |
32 changes: 0 additions & 32 deletions
32
src/main/java/at/ac/tuwien/damap/rest/persons/orcid/ORCIDPersonMapper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDActivitiesSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ORCIDEmploymentSummary> employments; | ||
|
||
@JsonProperty | ||
ORCIDAffiliationGroup<ORCIDEducationSummary> educations; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<S extends ORCIDAffiliationSummary> { | ||
@JsonProperty(value = "affiliation-group") | ||
@JsonSetter(nulls = Nulls.AS_EMPTY) | ||
List<ORCIDGroup<S>> affiliationGroup; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/at/ac/tuwien/damap/rest/persons/orcid/models/ORCIDAffiliationSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
Oops, something went wrong.