diff --git a/orcid-core/src/main/java/org/orcid/core/model/Employment.java b/orcid-core/src/main/java/org/orcid/core/model/Employment.java index ba9293d41cc..0f5579a6600 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/Employment.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Employment.java @@ -1,22 +1,100 @@ package org.orcid.core.model; +import java.io.Serializable; +import java.util.Objects; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; -import org.orcid.jaxb.model.v3.release.record.AffiliationType; +import org.orcid.jaxb.model.v3.release.common.FuzzyDate; import io.swagger.v3.oas.annotations.media.Schema; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = { "putCode", "endDate", "organizationName", "validated" }) +@XmlType(propOrder = { "putCode", "organizationName", "role", "url", "startDate", "endDate", "validated" }) @XmlRootElement(name = "employment", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Employment") -public class Employment extends ProfessionalActivity { - @XmlTransient - private String type = AffiliationType.EMPLOYMENT.name(); - - +public class Employment implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + @XmlElement(name = "put-code", namespace = "http://www.orcid.org/ns/summary") + protected Long putCode; + @XmlElement(name = "start-date", namespace = "http://www.orcid.org/ns/common") + protected FuzzyDate startDate; + @XmlElement(name = "end-date", namespace = "http://www.orcid.org/ns/common") + protected FuzzyDate endDate; + @XmlElement(name = "organization-name", namespace = "http://www.orcid.org/ns/summary") + protected String organizationName; + @XmlElement(name = "role", namespace = "http://www.orcid.org/ns/summary") + protected String role; + @XmlElement(name = "url", namespace = "http://www.orcid.org/ns/summary") + protected String url; + @XmlElement(name = "validated", namespace = "http://www.orcid.org/ns/summary") + protected boolean validated; + public Long getPutCode() { + return putCode; + } + public void setPutCode(Long putCode) { + this.putCode = putCode; + } + public FuzzyDate getStartDate() { + return startDate; + } + public void setStartDate(FuzzyDate startDate) { + this.startDate = startDate; + } + public FuzzyDate getEndDate() { + return endDate; + } + public void setEndDate(FuzzyDate endDate) { + this.endDate = endDate; + } + public String getOrganizationName() { + return organizationName; + } + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + public String getRole() { + return role; + } + public void setRole(String role) { + this.role = role; + } + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + public boolean isValidated() { + return validated; + } + public void setValidated(boolean validated) { + this.validated = validated; + } + public static long getSerialversionuid() { + return serialVersionUID; + } + @Override + public int hashCode() { + return Objects.hash(endDate, organizationName, putCode, role, startDate, url, validated); + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Employment other = (Employment) obj; + return Objects.equals(endDate, other.endDate) && Objects.equals(organizationName, other.organizationName) && Objects.equals(putCode, other.putCode) + && Objects.equals(role, other.role) && Objects.equals(startDate, other.startDate) && Objects.equals(url, other.url) && validated == other.validated; + } } diff --git a/orcid-core/src/main/java/org/orcid/core/model/Employments.java b/orcid-core/src/main/java/org/orcid/core/model/Employments.java index d1d8bac30db..102ee8dad07 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/Employments.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Employments.java @@ -1,5 +1,6 @@ package org.orcid.core.model; +import java.io.Serializable; import java.util.List; import java.util.Objects; @@ -15,10 +16,14 @@ @XmlType(propOrder = { "count", "employments" }) @XmlRootElement(name = "employments", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Employments list") -public class Employments { - @XmlElement(name = "count", namespace = "http://www.orcid.org/ns/activities") +public class Employments implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + @XmlElement(name = "count", namespace = "http://www.orcid.org/ns/summary") private Integer count; - @XmlElement(name = "employment", namespace = "http://www.orcid.org/ns/activities") + @XmlElement(name = "employment", namespace = "http://www.orcid.org/ns/summary") private List employments; public Integer getCount() { diff --git a/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifier.java b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifier.java index f215b9d2ce5..a2c6d01ffa1 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifier.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifier.java @@ -15,15 +15,15 @@ @XmlRootElement(name = "external-identifier", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "External identifier") public class ExternalIdentifier { - @XmlElement(name = "put-code", namespace = "http://www.orcid.org/ns/activities") + @XmlElement(name = "put-code", namespace = "http://www.orcid.org/ns/summary") private Long putCode; - @XmlElement(name = "external-id-type", namespace = "http://www.orcid.org/ns/activities") + @XmlElement(name = "external-id-type", namespace = "http://www.orcid.org/ns/summary") private String externalIdType; - @XmlElement(name = "external-id-value", namespace = "http://www.orcid.org/ns/activities") + @XmlElement(name = "external-id-value", namespace = "http://www.orcid.org/ns/summary") private String externalIdValue; - @XmlElement(name = "external-id-url", namespace = "http://www.orcid.org/ns/activities") + @XmlElement(name = "external-id-url", namespace = "http://www.orcid.org/ns/summary") private String externalIdUrl; - @XmlElement(name = "validated", namespace = "http://www.orcid.org/ns/activities") + @XmlElement(name = "validated", namespace = "http://www.orcid.org/ns/summary") private boolean validated; public Long getPutCode() { diff --git a/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifiers.java b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifiers.java index 4c721c6b0f6..c6b0894ff43 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifiers.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifiers.java @@ -1,5 +1,6 @@ package org.orcid.core.model; +import java.io.Serializable; import java.util.List; import java.util.Objects; @@ -15,8 +16,12 @@ @XmlType(propOrder = { "externalIdentifiers" }) @XmlRootElement(name = "external-identifiers", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "External identifiers list") -public class ExternalIdentifiers { - @XmlElement(name = "external-identifier", namespace = "http://www.orcid.org/ns/activities") +public class ExternalIdentifiers implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + @XmlElement(name = "external-identifier", namespace = "http://www.orcid.org/ns/summary") List externalIdentifiers; public List getExternalIdentifiers() { diff --git a/orcid-core/src/main/java/org/orcid/core/model/Fundings.java b/orcid-core/src/main/java/org/orcid/core/model/Fundings.java index 5ca2b4d7185..628c6ce7735 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/Fundings.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Fundings.java @@ -1,11 +1,18 @@ package org.orcid.core.model; +import java.io.Serializable; + import javax.xml.bind.annotation.XmlRootElement; import io.swagger.v3.oas.annotations.media.Schema; @XmlRootElement(name = "fundings", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Fundings") -public class Fundings extends ItemsCount { +public class Fundings extends ItemsCount implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; } diff --git a/orcid-core/src/main/java/org/orcid/core/model/PeerReviews.java b/orcid-core/src/main/java/org/orcid/core/model/PeerReviews.java index 07e49e15536..0dd0c61b285 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/PeerReviews.java +++ b/orcid-core/src/main/java/org/orcid/core/model/PeerReviews.java @@ -1,5 +1,6 @@ package org.orcid.core.model; +import java.io.Serializable; import java.util.Objects; import javax.xml.bind.annotation.XmlAccessType; @@ -11,10 +12,14 @@ import io.swagger.v3.oas.annotations.media.Schema; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = { "peer-review-publication-grants", "self-asserted-count", "total" }) +@XmlType(propOrder = { "peerReviewPublicationGrants", "selfAssertedCount", "total" }) @XmlRootElement(name = "peer-reviews", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Peer reviews") -public class PeerReviews { +public class PeerReviews implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; @XmlElement(name = "peer-review-publication-grants", namespace = "http://www.orcid.org/ns/summary") private Integer peerReviewPublicationGrants; @XmlElement(name = "self-asserted-count", namespace = "http://www.orcid.org/ns/summary") diff --git a/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivities.java b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivities.java index 127f1a9a6be..ab0fbcd795e 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivities.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivities.java @@ -1,5 +1,6 @@ package org.orcid.core.model; +import java.io.Serializable; import java.util.List; import java.util.Objects; @@ -15,10 +16,14 @@ @XmlType(propOrder = { "count", "professionalActivities" }) @XmlRootElement(name = "professional-activities", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Professional activities list") -public class ProfessionalActivities { - @XmlElement(name = "count", namespace = "http://www.orcid.org/ns/activities") +public class ProfessionalActivities implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + @XmlElement(name = "count", namespace = "http://www.orcid.org/ns/summary") private Integer count; - @XmlElement(name = "professional-activity", namespace = "http://www.orcid.org/ns/activities") + @XmlElement(name = "professional-activity", namespace = "http://www.orcid.org/ns/summary") private List professionalActivities; public Integer getCount() { diff --git a/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivity.java b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivity.java index 0467b80a086..fb2a1e8e01f 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivity.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivity.java @@ -13,26 +13,26 @@ import io.swagger.v3.oas.annotations.media.Schema; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = { "putCode", "type", "organizationName", "role", "url", "validated" }) +@XmlType(propOrder = { "putCode", "type", "organizationName", "role", "url", "startDate", "endDate", "validated" }) @XmlRootElement(name = "professional-activity", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Professional activity") public class ProfessionalActivity { @XmlElement(name = "put-code", namespace = "http://www.orcid.org/ns/summary") - private Long putCode; + protected Long putCode; @XmlElement(name = "start-date", namespace = "http://www.orcid.org/ns/common") - private FuzzyDate startDate; + protected FuzzyDate startDate; @XmlElement(name = "end-date", namespace = "http://www.orcid.org/ns/common") - private FuzzyDate endDate; + protected FuzzyDate endDate; @XmlElement(name = "type", namespace = "http://www.orcid.org/ns/summary") - private String type; + protected String type; @XmlElement(name = "organization-name", namespace = "http://www.orcid.org/ns/summary") - private String organizationName; + protected String organizationName; @XmlElement(name = "role", namespace = "http://www.orcid.org/ns/summary") - private String role; + protected String role; @XmlElement(name = "url", namespace = "http://www.orcid.org/ns/summary") - private String url; + protected String url; @XmlElement(name = "validated", namespace = "http://www.orcid.org/ns/summary") - private boolean validated; + protected boolean validated; public Long getPutCode() { return putCode; diff --git a/orcid-core/src/main/java/org/orcid/core/model/RecordSummary.java b/orcid-core/src/main/java/org/orcid/core/model/RecordSummary.java index 59285b85d41..0dba0f03e5c 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/RecordSummary.java +++ b/orcid-core/src/main/java/org/orcid/core/model/RecordSummary.java @@ -1,5 +1,6 @@ package org.orcid.core.model; +import java.io.Serializable; import java.util.Objects; import javax.annotation.Resource; @@ -7,25 +8,27 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; -import javax.xml.datatype.XMLGregorianCalendar; import org.orcid.core.manager.impl.OrcidUrlManager; -import org.orcid.jaxb.model.common_v2.SourceClientId; import org.orcid.jaxb.model.v3.release.common.CreatedDate; import org.orcid.jaxb.model.v3.release.common.LastModifiedDate; import org.orcid.jaxb.model.v3.release.common.OrcidIdentifier; -import org.orcid.pojo.summary.AffiliationSummary; -import org.orcid.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = { "createdDate", "lastModifiedDate", "creditName", "orcidIdentifier", "orcidIdentifier", "externalIdentifiers", "employments", "profilessionalActivities", "fundings", +@XmlType(propOrder = { "createdDate", "lastModifiedDate", "creditName", "orcidIdentifier", "externalIdentifiers", "employments", "professionalActivities", "fundings", "works", "peerReviews" }) -@XmlRootElement(name = "work-summary", namespace = "http://www.orcid.org/ns/work") +@XmlRootElement(name = "record-summary", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Record summary") -public class RecordSummary { +public class RecordSummary implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + @XmlTransient @Resource private OrcidUrlManager orcidUrlManager; @XmlElement(name = "last-modified-date", namespace = "http://www.orcid.org/ns/common") diff --git a/orcid-core/src/main/java/org/orcid/core/model/Works.java b/orcid-core/src/main/java/org/orcid/core/model/Works.java index 3fea14cdc29..1404d68aa15 100644 --- a/orcid-core/src/main/java/org/orcid/core/model/Works.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Works.java @@ -1,11 +1,18 @@ package org.orcid.core.model; +import java.io.Serializable; + import javax.xml.bind.annotation.XmlRootElement; import io.swagger.v3.oas.annotations.media.Schema; @XmlRootElement(name = "works", namespace = "http://www.orcid.org/ns/summary") @Schema(description = "Works") -public class Works extends ItemsCount { +public class Works extends ItemsCount implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; } diff --git a/orcid-core/src/main/java/org/orcid/core/model/package-info.java b/orcid-core/src/main/java/org/orcid/core/model/package-info.java new file mode 100644 index 00000000000..75d5bd31108 --- /dev/null +++ b/orcid-core/src/main/java/org/orcid/core/model/package-info.java @@ -0,0 +1,7 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.orcid.org/ns/record", xmlns = { + @javax.xml.bind.annotation.XmlNs(prefix = "activities", namespaceURI = "http://www.orcid.org/ns/activities"), + @javax.xml.bind.annotation.XmlNs(prefix = "common", namespaceURI = "http://www.orcid.org/ns/common"), + @javax.xml.bind.annotation.XmlNs(prefix = "summary", namespaceURI = "http://www.orcid.org/ns/summary")}, + elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +package org.orcid.core.model; + diff --git a/orcid-core/src/test/java/org/orcid/core/model/RecordSummaryMarshallingTest.java b/orcid-core/src/test/java/org/orcid/core/model/RecordSummaryMarshallingTest.java index cf0a5ccaa36..a2de2996071 100644 --- a/orcid-core/src/test/java/org/orcid/core/model/RecordSummaryMarshallingTest.java +++ b/orcid-core/src/test/java/org/orcid/core/model/RecordSummaryMarshallingTest.java @@ -1,13 +1,17 @@ package org.orcid.core.model; -import java.io.InputStream; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; +import org.apache.commons.io.IOUtils; import org.junit.Test; import org.orcid.jaxb.model.v3.release.common.CreatedDate; import org.orcid.jaxb.model.v3.release.common.Day; @@ -16,26 +20,22 @@ import org.orcid.jaxb.model.v3.release.common.Month; import org.orcid.jaxb.model.v3.release.common.OrcidIdentifier; import org.orcid.jaxb.model.v3.release.common.Year; -import org.orcid.jaxb.model.v3.release.record.Work; import org.orcid.utils.DateUtils; public class RecordSummaryMarshallingTest { @Test - public void marshallingTest() throws JAXBException { + public void marshallingTest() throws JAXBException, IOException { JAXBContext context = JAXBContext.newInstance(new Class[] { RecordSummary.class }); - Marshaller marshaller = context.createMarshaller(); - String name = "/summary_3.0/samples/summary-3.0.xml"; - InputStream inputStream = getClass().getResourceAsStream(name); - - + Marshaller marshaller = context.createMarshaller(); + String expectedText = IOUtils.toString(getClass().getResourceAsStream("summary-3.0.xml"), StandardCharsets.UTF_8); RecordSummary recordSummary = getRecordSummary(); StringWriter stringWriter = new StringWriter(); marshaller.marshal(recordSummary, stringWriter); - System.out.println(stringWriter.toString()); - + String realText = stringWriter.toString(); + assertEquals(expectedText, realText); } private RecordSummary getRecordSummary() { @@ -60,9 +60,9 @@ private RecordSummary getRecordSummary() { Employments employments = new Employments(); employments.setCount(5); employments.setEmployments(new ArrayList<>()); - employments.getEmployments().add((Employment) getProfessionalActivity(1, "Org # 1", "Fake role title", "https://www.ipp.pt/", null, false)); - employments.getEmployments().add((Employment) getProfessionalActivity(2, "Org # 2", "Fake role title 2", "https://www.ipp.pt/2", null, false)); - employments.getEmployments().add((Employment) getProfessionalActivity(3, "Org # 3", "Fake role title 3", "https://www.ipp.pt/3", null, true)); + employments.getEmployments().add(getEmployment(1, "Org # 1", "Fake role title 1", "https://test.orcid.org/1", false)); + employments.getEmployments().add(getEmployment(2, "Org # 2", "Fake role title 2", "https://test.orcid.org/2", false)); + employments.getEmployments().add(getEmployment(3, "Org # 3", "Fake role title 3", "https://test.orcid.org/3", true)); // Set the employments record.setEmployments(employments); @@ -70,7 +70,7 @@ private RecordSummary getRecordSummary() { ProfessionalActivities professionalActivities = new ProfessionalActivities(); professionalActivities.setCount(5); professionalActivities.setProfessionalActivities(new ArrayList<>()); - professionalActivities.getProfessionalActivities().add(getProfessionalActivity(1, "Org # 1", "Fake role title", "https://www.ipp.pt/", "distinction", false)); + professionalActivities.getProfessionalActivities().add(getProfessionalActivity(1, "Org # 1", "Fake role title", "https://test.orcid.org/", "distinction", false)); // Set the professional activities record.setProfessionalActivities(professionalActivities); @@ -99,11 +99,23 @@ private ExternalIdentifier getExternalIdentifier(String type, int putCode, boole ei1.setPutCode(Long.valueOf(putCode)); ei1.setExternalIdType(type); ei1.setExternalIdValue(String.valueOf(putCode)); - ei1.setExternalIdUrl("https://example.com/" + putCode); + ei1.setExternalIdUrl("https://test.orcid.org/" + putCode); ei1.setValidated(validated); return ei1; } + private Employment getEmployment(int putCode, String role, String org, String url, boolean validated) { + Employment e = new Employment(); + e.setPutCode(Long.valueOf(putCode)); + e.setEndDate(getEndDate()); + e.setStartDate(getStartDate()); + e.setOrganizationName(org); + e.setRole(role); + e.setUrl(url); + e.setValidated(validated); + return e; + } + private ProfessionalActivity getProfessionalActivity(int putCode, String role, String org, String url, String type, boolean validated) { ProfessionalActivity pa = new ProfessionalActivity(); pa.setPutCode(Long.valueOf(putCode)); diff --git a/orcid-core/src/test/resources/org/orcid/core/model/summary-3.0.xml b/orcid-core/src/test/resources/org/orcid/core/model/summary-3.0.xml new file mode 100644 index 00000000000..e20c83889e4 --- /dev/null +++ b/orcid-core/src/test/resources/org/orcid/core/model/summary-3.0.xml @@ -0,0 +1 @@ +2024-01-01T12:00:002024-01-01T12:00:00User credited namehttps://orcid.org/8888-8888-8888-88808888-8888-8888-8880orcid.org1Scopus1https://test.orcid.org/1true2ResearcherID2https://test.orcid.org/2true3Other3https://test.orcid.org/3true51Fake role title 1Org # 1https://test.orcid.org/12020010120241231false2Fake role title 2Org # 2https://test.orcid.org/22020010120241231false3Fake role title 3Org # 3https://test.orcid.org/32020010120241231true51distinctionFake role titleOrg # 1https://test.orcid.org/2020010120241231false0101606 \ No newline at end of file