-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* np-45284: new field PersonNvi in GET Person Test code for it's nested field verifiedBy * np-45284: mapped verifiedAt field * np-45284: mapped verifiedDate field
- Loading branch information
Showing
12 changed files
with
429 additions
and
5 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...son/src/main/java/no/unit/nva/cristin/person/model/cristin/CristinNviInstitutionUnit.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,40 @@ | ||
package no.unit.nva.cristin.person.model.cristin; | ||
|
||
import static no.unit.nva.cristin.model.JsonPropertyNames.INSTITUTION; | ||
import static no.unit.nva.cristin.model.JsonPropertyNames.UNIT; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import no.unit.nva.cristin.model.CristinUnit; | ||
import no.unit.nva.model.Organization; | ||
|
||
public record CristinNviInstitutionUnit(@JsonProperty(INSTITUTION) CristinPersonNviInstitution institution, | ||
@JsonProperty(UNIT) CristinUnit unit) { | ||
|
||
public Organization toOrganization() { | ||
var organization = Optional.ofNullable(unit).map(CristinUnit::toOrganization); | ||
|
||
if (organization.isPresent()) { | ||
var present = organization.get(); | ||
var builder = new Organization.Builder(); | ||
|
||
builder.withId(present.getId()); | ||
builder.withLabels(present.getLabels()); | ||
builder.withAcronym(present.getAcronym()); | ||
topLevel().ifPresent(top -> builder.withPartOf(convertToSet(top))); | ||
builder.withCountry(present.getCountry()); | ||
|
||
return builder.build(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
private Set<Organization> convertToSet(Organization organization) { | ||
return Set.of(organization); | ||
} | ||
|
||
private Optional<Organization> topLevel() { | ||
return Optional.ofNullable(institution).map(CristinPersonNviInstitution::toOrganization); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
cristin-person/src/main/java/no/unit/nva/cristin/person/model/cristin/CristinPersonNvi.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,32 @@ | ||
package no.unit.nva.cristin.person.model.cristin; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.time.Instant; | ||
import java.util.Optional; | ||
import no.unit.nva.commons.json.JsonSerializable; | ||
import no.unit.nva.cristin.person.model.nva.PersonNvi; | ||
|
||
public record CristinPersonNvi(@JsonProperty(VERIFIED_BY) CristinPersonSummary verifiedBy, | ||
@JsonProperty(VERIFIED_AT) CristinNviInstitutionUnit verifiedAt, | ||
@JsonProperty(VERIFIED_DATE) Instant verifiedDate) | ||
implements JsonSerializable { | ||
|
||
public static final String VERIFIED_BY = "verified_by"; | ||
public static final String VERIFIED_AT = "verified_at"; | ||
public static final String VERIFIED_DATE = "verified_date"; | ||
|
||
public PersonNvi toPersonNvi() { | ||
var personSummary = Optional.ofNullable(verifiedBy) | ||
.map(CristinPersonSummary::toPersonSummary); | ||
|
||
var organization = Optional.ofNullable(verifiedAt) | ||
.map(CristinNviInstitutionUnit::toOrganization); | ||
|
||
if (personSummary.isPresent() || organization.isPresent()) { | ||
return new PersonNvi(personSummary.orElse(null), organization.orElse(null), verifiedDate); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...n/src/main/java/no/unit/nva/cristin/person/model/cristin/CristinPersonNviInstitution.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,33 @@ | ||
package no.unit.nva.cristin.person.model.cristin; | ||
|
||
import static no.unit.nva.cristin.model.Constants.ORGANIZATION_PATH; | ||
import static no.unit.nva.cristin.model.JsonPropertyNames.ACRONYM; | ||
import static no.unit.nva.cristin.model.JsonPropertyNames.COUNTRY; | ||
import static no.unit.nva.utils.UriUtils.getNvaApiId; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import no.unit.nva.cristin.model.CristinUnit; | ||
import no.unit.nva.model.Organization; | ||
|
||
public record CristinPersonNviInstitution(@JsonProperty(ACRONYM) String acronym, @JsonProperty(COUNTRY) String country, | ||
@JsonProperty(CORRESPONDING_UNIT) CristinUnit correspondingUnit, | ||
@JsonProperty(INSTITUTION_NAME) Map<String, String> institutionName) { | ||
|
||
public static final String CORRESPONDING_UNIT = "corresponding_unit"; | ||
public static final String INSTITUTION_NAME = "institution_name"; | ||
|
||
public Organization toOrganization() { | ||
return new Organization.Builder() | ||
.withId(getNvaApiId(getCorrespondingUnitIdentifier(), ORGANIZATION_PATH)) | ||
.withAcronym(acronym) | ||
.withCountry(country) | ||
.withLabels(institutionName) | ||
.build(); | ||
} | ||
|
||
private String getCorrespondingUnitIdentifier() { | ||
return Optional.ofNullable(correspondingUnit).map(CristinUnit::getCristinUnitId).orElse(null); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...n-person/src/main/java/no/unit/nva/cristin/person/model/cristin/CristinPersonSummary.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,71 @@ | ||
package no.unit.nva.cristin.person.model.cristin; | ||
|
||
import static java.util.Objects.nonNull; | ||
import static no.unit.nva.cristin.model.Constants.BASE_PATH; | ||
import static no.unit.nva.cristin.model.Constants.DOMAIN_NAME; | ||
import static no.unit.nva.cristin.model.Constants.HTTPS; | ||
import static no.unit.nva.cristin.model.Constants.PERSON_PATH_NVA; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.net.URI; | ||
import no.unit.nva.cristin.person.model.nva.PersonSummary; | ||
import nva.commons.core.paths.UriWrapper; | ||
|
||
public record CristinPersonSummary(@JsonProperty(FIRST_NAME) String firstName, | ||
@JsonProperty(SURNAME) String surname, | ||
@JsonProperty(URL_FIELD_NAME) String url, | ||
@JsonProperty(CRISTIN_PERSON_ID) String cristinPersonId) { | ||
|
||
public static final String FIRST_NAME = "first_name"; | ||
public static final String SURNAME = "surname"; | ||
public static final String URL_FIELD_NAME = "url"; | ||
public static final String CRISTIN_PERSON_ID = "cristin_person_id"; | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder { | ||
|
||
private String firstName; | ||
private String surname; | ||
private String url; | ||
private String cristinPersonId; | ||
|
||
private Builder() { | ||
} | ||
|
||
public Builder withFirstName(String firstName) { | ||
this.firstName = firstName; | ||
return this; | ||
} | ||
|
||
public Builder withSurname(String surname) { | ||
this.surname = surname; | ||
return this; | ||
} | ||
|
||
public Builder withUrl(String url) { | ||
this.url = url; | ||
return this; | ||
} | ||
|
||
public Builder withCristinPersonId(String cristinPersonId) { | ||
this.cristinPersonId = cristinPersonId; | ||
return this; | ||
} | ||
|
||
public CristinPersonSummary build() { | ||
return new CristinPersonSummary(firstName, surname, url, cristinPersonId); | ||
} | ||
} | ||
|
||
public PersonSummary toPersonSummary() { | ||
return nonNull(cristinPersonId) ? new PersonSummary(extractIdUri(), firstName, surname) : null; | ||
} | ||
|
||
private URI extractIdUri() { | ||
return new UriWrapper(HTTPS, DOMAIN_NAME).addChild(BASE_PATH).addChild(PERSON_PATH_NVA) | ||
.addChild(cristinPersonId).getUri(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.