From 466099595df8ac3d0e39f54cf9622a18f04462de Mon Sep 17 00:00:00 2001 From: brinxmat <789709+brinxmat@users.noreply.github.com> Date: Thu, 2 Feb 2023 20:29:16 +0100 Subject: [PATCH 1/6] Migrate BookMonograph to discrete subtypes based on content type --- .../instancetypes/PublicationInstance.java | 11 + .../instancetypes/book/AcademicMonograph.java | 14 ++ .../instancetypes/book/BookMonograph.java | 112 ++++----- .../book/BookMonographContentType.java | 1 + .../instancetypes/book/Encyclopedia.java | 14 ++ .../instancetypes/book/ExhibitionCatalog.java | 14 ++ .../book/NonFictionMonograph.java | 14 ++ .../book/PopularScienceMonograph.java | 14 ++ .../model/instancetypes/book/Textbook.java | 14 ++ .../main/resources/publication-ontology.ttl | 32 ++- .../MigrationBookMonographSubtypesTest.java | 213 ++++++++++++++++++ .../testing/PublicationContextBuilder.java | 6 + .../testing/PublicationInstanceBuilder.java | 52 ++++- 13 files changed, 444 insertions(+), 67 deletions(-) create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java create mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java index 84550ea90..c67185776 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java @@ -11,9 +11,14 @@ import no.unit.nva.model.instancetypes.artistic.music.MusicPerformance; import no.unit.nva.model.instancetypes.artistic.performingarts.PerformingArts; import no.unit.nva.model.instancetypes.artistic.visualarts.VisualArts; +import no.unit.nva.model.instancetypes.book.AcademicMonograph; import no.unit.nva.model.instancetypes.book.BookAbstracts; import no.unit.nva.model.instancetypes.book.BookAnthology; import no.unit.nva.model.instancetypes.book.BookMonograph; +import no.unit.nva.model.instancetypes.book.Encyclopedia; +import no.unit.nva.model.instancetypes.book.ExhibitionCatalog; +import no.unit.nva.model.instancetypes.book.NonFictionMonograph; +import no.unit.nva.model.instancetypes.book.Textbook; import no.unit.nva.model.instancetypes.chapter.ChapterArticle; import no.unit.nva.model.instancetypes.chapter.ChapterConferenceAbstract; import no.unit.nva.model.instancetypes.chapter.ChapterInReport; @@ -79,6 +84,12 @@ @JsonSubTypes.Type(name = "JournalReview", value = JournalReview.class), @JsonSubTypes.Type(name = "BookAbstracts", value = BookAbstracts.class), @JsonSubTypes.Type(name = "BookMonograph", value = BookMonograph.class), + @JsonSubTypes.Type(name = "AcademicMonograph", value = AcademicMonograph.class), + @JsonSubTypes.Type(name = "Encyclopedia", value = Encyclopedia.class), + @JsonSubTypes.Type(name = "ExhibitionCatalog", value = ExhibitionCatalog.class), + @JsonSubTypes.Type(name = "NonFictionMonograph", value = NonFictionMonograph.class), + @JsonSubTypes.Type(name = "PopularScienceArticle", value = PopularScienceArticle.class), + @JsonSubTypes.Type(name = "Textbook", value = Textbook.class), @JsonSubTypes.Type(name = "BookAnthology", value = BookAnthology.class), @JsonSubTypes.Type(name = "DegreeBachelor", value = DegreeBachelor.class), @JsonSubTypes.Type(name = "DegreeMaster", value = DegreeMaster.class), diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java new file mode 100644 index 000000000..ff0215300 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.book; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.MonographPages; + +public class AcademicMonograph extends BookMonograph { + + private static final boolean ORIGINAL_RESEARCH = true; + + public AcademicMonograph(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, ORIGINAL_RESEARCH, peerReviewed); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java index 6ba5f119e..111da5843 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java @@ -1,79 +1,79 @@ package no.unit.nva.model.instancetypes.book; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.instancetypes.PeerReviewedMonograph; import no.unit.nva.model.pages.MonographPages; +import nva.commons.core.JacocoGenerated; + +import java.util.Objects; + +import static java.util.Objects.isNull; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class BookMonograph extends PeerReviewedMonograph { - private BookMonographContentType contentType; - private boolean originalResearch; - - public BookMonographContentType getContentType() { - return contentType; + public static final String PAGES_FIELD = "pages"; + private static final String CONTENT_TYPE_FIELD = "contentType"; + public static final String ORIGINAL_RESEARCH_FIELD = "originalResearch"; + public static final String PEER_REVIEWED_FIELD = "peerReviewed"; + private final boolean originalResearch; + + public BookMonograph(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(ORIGINAL_RESEARCH_FIELD) boolean originalResearch, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed); + this.originalResearch = originalResearch; } - public void setContentType(BookMonographContentType contentType) { - this.contentType = contentType; + @JsonCreator + public static BookMonograph fromJson(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(CONTENT_TYPE_FIELD) BookMonographContentType contentType, + @JsonProperty(ORIGINAL_RESEARCH_FIELD) boolean originalResearch, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + if (BookMonographContentType.ACADEMIC_MONOGRAPH.equals(contentType)) { + return new AcademicMonograph(pages, peerReviewed); + } else if (BookMonographContentType.ENCYCLOPEDIA.equals(contentType)) { + return new Encyclopedia(pages, peerReviewed); + } else if (BookMonographContentType.EXHIBITION_CATALOG.equals(contentType)) { + return new ExhibitionCatalog(pages, peerReviewed); + } else if (BookMonographContentType.NON_FICTION_MONOGRAPH.equals(contentType)) { + return new NonFictionMonograph(pages, peerReviewed); + } else if (BookMonographContentType.POPULAR_SCIENCE_MONOGRAPH.equals(contentType)) { + return new PopularScienceMonograph(pages, peerReviewed); + } else if (BookMonographContentType.TEXTBOOK.equals(contentType)) { + return new Textbook(pages, peerReviewed); + } else if (isNull(contentType)) { + return new AcademicMonograph(pages, peerReviewed); + } else { + throw new UnsupportedOperationException("The Book Monograph subtype is unknown"); + } } public boolean isOriginalResearch() { return originalResearch; } - public void setOriginalResearch(boolean originalResearch) { - if (isOriginalResearchCandidate()) { - this.originalResearch = originalResearch; + @Override + @JacocoGenerated + public boolean equals(Object o) { + if (this == o) { + return true; } - } - - private boolean isOriginalResearchCandidate() { - return contentType == null || contentType == BookMonographContentType.ACADEMIC_MONOGRAPH; - } - - - public BookMonograph() { - super(); - } - - private BookMonograph(Builder builder) { - super(builder.pages, builder.peerReviewed); - setContentType(builder.contentType); - setOriginalResearch(builder.originalResearch); - } - - public static final class Builder { - private boolean peerReviewed; - private MonographPages pages; - private BookMonographContentType contentType; - private boolean originalResearch; - - public Builder() { - } - - public Builder withPeerReviewed(boolean peerReviewed) { - this.peerReviewed = peerReviewed; - return this; + if (!(o instanceof BookMonograph)) { + return false; } - - public Builder withPages(MonographPages pages) { - this.pages = pages; - return this; - } - - public Builder withContentType(BookMonographContentType contentType) { - this.contentType = contentType; - return this; - } - - public Builder withOriginalResearch(boolean originalResearch) { - this.originalResearch = originalResearch; - return this; + if (!super.equals(o)) { + return false; } + BookMonograph that = (BookMonograph) o; + return isOriginalResearch() == that.isOriginalResearch(); + } - public BookMonograph build() { - return new BookMonograph(this); - } + @Override + @JacocoGenerated + public int hashCode() { + return Objects.hash(super.hashCode(), isOriginalResearch()); } } diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java index 30dfbdd2b..633bfd822 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java @@ -10,6 +10,7 @@ * Content Type options for "Monograph" subtype when the creator chooses the Resource type as "Book" while doing the * registration. */ +@Deprecated public enum BookMonographContentType { ACADEMIC_MONOGRAPH("AcademicMonograph", "Academic Monograph"), NON_FICTION_MONOGRAPH("NonFictionMonograph", "Non-fiction Monograph"), diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java new file mode 100644 index 000000000..4f6ce119e --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.book; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.MonographPages; + +public class Encyclopedia extends BookMonograph { + + private static final boolean ORIGINAL_RESEARCH = false; + + public Encyclopedia(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, ORIGINAL_RESEARCH, peerReviewed); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java new file mode 100644 index 000000000..157efa6ec --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.book; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.MonographPages; + +public class ExhibitionCatalog extends BookMonograph { + + private static final boolean ORIGINAL_RESEARCH = false; + + public ExhibitionCatalog(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, ORIGINAL_RESEARCH, peerReviewed); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java new file mode 100644 index 000000000..398ffdb4c --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.book; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.MonographPages; + +public class NonFictionMonograph extends BookMonograph { + + private static final boolean ORIGINAL_RESEARCH = false; + + public NonFictionMonograph(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, ORIGINAL_RESEARCH, peerReviewed); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java new file mode 100644 index 000000000..a66bb4ec0 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.book; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.MonographPages; + +public class PopularScienceMonograph extends BookMonograph { + + private static final boolean ORIGINAL_RESEARCH = false; + + public PopularScienceMonograph(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, ORIGINAL_RESEARCH, peerReviewed); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java new file mode 100644 index 000000000..dbc74d9fb --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.book; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.MonographPages; + +public class Textbook extends BookMonograph { + + private static final boolean ORIGINAL_RESEARCH = false; + + public Textbook(@JsonProperty(PAGES_FIELD) MonographPages pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, ORIGINAL_RESEARCH, peerReviewed); + } +} diff --git a/nva-datamodel-java/src/main/resources/publication-ontology.ttl b/nva-datamodel-java/src/main/resources/publication-ontology.ttl index ae4a289fe..b64970c03 100644 --- a/nva-datamodel-java/src/main/resources/publication-ontology.ttl +++ b/nva-datamodel-java/src/main/resources/publication-ontology.ttl @@ -417,7 +417,37 @@ nva:BookMonograph a rdfs:Class ; rdfs:comment "" ; rdfs:isDefinedBy nva: ; rdfs:subClassOf nva:Book . - + +nva:AcademicMonograph a rdfs:Class ; + rdfs:comment "A long-form scholarly text" ; + rdfs:isDefinedBy nva: ; + rdfs:subClassOf nva:BookMonograph . + +nva:Encyclopedia a rdfs:Class ; + rdfs:comment "A collection of shorter articles typically on a single topic domain serving as a reference work" ; + rdfs:isDefinedBy nva: ; + rdfs:subClassOf nva:BookMonograph . + +nva:ExhibitionCatalog a rdfs:Class ; + rdfs:comment "A list of exhibits at an organized event" ; + rdfs:isDefinedBy nva: ; + rdfs:subClassOf nva:BookMonograph . + +nva:NonFictionMonograph a rdfs:Class ; + rdfs:comment "A long-form text on a real-world topic" ; + rdfs:isDefinedBy nva: ; + rdfs:subClassOf nva:BookMonograph . + +nva:PopularScienceMonograph a rdfs:Class ; + rdfs:comment "A long-form text on a scientific topic for a non-academic audience" ; + rdfs:isDefinedBy nva: ; + rdfs:subClassOf nva:BookMonograph . + +nva:Textbook a rdfs:Class ; + rdfs:comment "A long-form text on created for the purposes of education" ; + rdfs:isDefinedBy nva: ; + rdfs:subClassOf nva:BookMonograph . + nva:DegreeMaster a rdfs:Class ; rdfs:comment "" ; rdfs:isDefinedBy nva: ; diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java new file mode 100644 index 000000000..80ec6050c --- /dev/null +++ b/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java @@ -0,0 +1,213 @@ +package no.unit.nva; + +import no.unit.nva.commons.json.JsonUtils; +import no.unit.nva.model.Publication; +import no.unit.nva.model.instancetypes.book.BookMonographContentType; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import static nva.commons.core.attempt.Try.attempt; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; + +class MigrationBookMonographSubtypesTest { + @ParameterizedTest + @EnumSource(BookMonographContentType.class) + void shouldDeserializeOldSubtypeBookMonographContentTypeAsType(BookMonographContentType content) { + var type = content.getValue(); + var json = generateFullBookMonographWithContentType(type); + var bookMonograph = attempt(() -> JsonUtils.dtoObjectMapper.readValue(json, Publication.class)) + .orElseThrow(); + var actual = bookMonograph.getEntityDescription() + .getReference().getPublicationInstance().getClass().getSimpleName(); + assertThat(actual, is(equalTo(type))); + } + + private String generateFullBookMonographWithContentType(String type) { + return "{\n" + + " \"type\" : \"Publication\",\n" + + " \"identifier\" : \"c443030e-9d56-43d8-afd1-8c89105af555\",\n" + + " \"status\" : \"NEW\",\n" + + " \"resourceOwner\" : {\n" + + " \"owner\" : \"tB62sIFYKg\",\n" + + " \"ownerAffiliation\" : \"https://www.example.org/commodiut\"\n" + + " },\n" + + " \"publisher\" : {\n" + + " \"type\" : \"Organization\",\n" + + " \"id\" : \"https://www.example.org/suscipitat\",\n" + + " \"labels\" : {\n" + + " \"ru\" : \"mrH4HAV6aEDjGNRJ2\"\n" + + " }\n" + + " },\n" + + " \"createdDate\" : \"1972-05-08T00:12:05.315Z\",\n" + + " \"modifiedDate\" : \"2019-09-28T13:25:15.960Z\",\n" + + " \"publishedDate\" : \"1975-01-08T02:19:20.777Z\",\n" + + " \"indexedDate\" : \"2007-03-21T06:29:45.706Z\",\n" + + " \"handle\" : \"https://www.example.org/expeditaaliquam\",\n" + + " \"doi\" : \"https://doi.org/10.1234/voluptas\",\n" + + " \"link\" : \"https://www.example.org/hicsoluta\",\n" + + " \"entityDescription\" : {\n" + + " \"type\" : \"EntityDescription\",\n" + + " \"mainTitle\" : \"TJiBWzUbcYOsg1Bh6ar\",\n" + + " \"alternativeTitles\" : {\n" + + " \"pl\" : \"u6W8XtFlErl7CT20H\"\n" + + " },\n" + + " \"language\" : \"http://lexvo.org/id/iso639-3/und\",\n" + + " \"date\" : {\n" + + " \"type\" : \"PublicationDate\",\n" + + " \"year\" : \"tYcREtuLoDw5l9YZV\",\n" + + " \"month\" : \"gMzfA9CfARP0qdRT\",\n" + + " \"day\" : \"EiJQbxbLQZj\"\n" + + " },\n" + + " \"contributors\" : [ {\n" + + " \"type\" : \"Contributor\",\n" + + " \"identity\" : {\n" + + " \"type\" : \"Identity\",\n" + + " \"id\" : \"https://www.example.com/GqttyV980NRYL8Pfp\",\n" + + " \"name\" : \"rA6GkyIRJGv2di\",\n" + + " \"nameType\" : \"Personal\",\n" + + " \"orcId\" : \"9DtRI5qSVrxx\"\n" + + " },\n" + + " \"affiliations\" : [ {\n" + + " \"type\" : \"Organization\",\n" + + " \"id\" : \"https://www.example.com/O9IL4Q16jMMTmyFa\",\n" + + " \"labels\" : {\n" + + " \"af\" : \"A3H5OIKOwrqriOct\"\n" + + " }\n" + + " } ],\n" + + " \"role\" : \"ContactPerson\",\n" + + " \"sequence\" : 7,\n" + + " \"correspondingAuthor\" : false\n" + + " }, {\n" + + " \"type\" : \"Contributor\",\n" + + " \"identity\" : {\n" + + " \"type\" : \"Identity\",\n" + + " \"id\" : \"https://www.example.com/Ele611kKvbKnqeL\",\n" + + " \"name\" : \"TIE6zIiWCWLpfvK\",\n" + + " \"nameType\" : \"Organizational\",\n" + + " \"orcId\" : \"aJ1pvnZ8FVOh5\"\n" + + " },\n" + + " \"affiliations\" : [ {\n" + + " \"type\" : \"Organization\",\n" + + " \"id\" : \"https://www.example.com/CszMv40Wx2OX\",\n" + + " \"labels\" : {\n" + + " \"af\" : \"CCP5RUwJlFTQTzL\"\n" + + " }\n" + + " } ],\n" + + " \"role\" : \"Dramatist\",\n" + + " \"sequence\" : 0,\n" + + " \"correspondingAuthor\" : false\n" + + " } ],\n" + + " \"npiSubjectHeading\" : \"RCjSANi9tVDH0X1lEN\",\n" + + " \"tags\" : [ \"gyNAMEiHlZuJT\" ],\n" + + " \"description\" : \"TBlPsIoaVroQdh\",\n" + + " \"reference\" : {\n" + + " \"type\" : \"Reference\",\n" + + " \"publicationContext\" : {\n" + + " \"type\" : \"Book\",\n" + + " \"series\" : {\n" + + " \"type\" : \"Series\",\n" + + " \"id\" : \"https://api.dev.nva.aws.unit.no/publication-channels/gTApbmIXv6\"\n" + + " },\n" + + " \"seriesNumber\" : \"wmHi1PgzWPm86KCe6\",\n" + + " \"publisher\" : {\n" + + " \"type\" : \"Publisher\",\n" + + " \"id\" : \"https://api.dev.nva.aws.unit.no/publication-channels/rLViYfagIJ\"\n" + + " },\n" + + " \"isbnList\" : [ \"9790094516099\" ]\n" + + " },\n" + + " \"doi\" : \"https://www.example.com/FbubVFoXuT\",\n" + + " \"publicationInstance\" : {\n" + + " \"type\" : \"BookMonograph\",\n" + + " \"contentType\" : \"" + type + "\",\n" + + " \"originalResearch\" : false,\n" + + " \"peerReviewed\" : false,\n" + + " \"pages\" : {\n" + + " \"type\" : \"MonographPages\",\n" + + " \"introduction\" : {\n" + + " \"type\" : \"Range\",\n" + + " \"begin\" : \"9n2jMU0p6vPI9pcqQyi\",\n" + + " \"end\" : \"QAYvjiCUvm\"\n" + + " },\n" + + " \"pages\" : \"rXSsjeWG62j\",\n" + + " \"illustrated\" : false\n" + + " }\n" + + " }\n" + + " },\n" + + " \"metadataSource\" : \"https://www.example.com/TJrqCkHQVrIt0j\",\n" + + " \"abstract\" : \"TRcbF8cf89PgTuBk\"\n" + + " },\n" + + " \"projects\" : [ {\n" + + " \"type\" : \"ResearchProject\",\n" + + " \"id\" : \"https://www.example.org/perferendisharum\",\n" + + " \"name\" : \"ESFpOgIIS4q9dW6\",\n" + + " \"approvals\" : [ {\n" + + " \"type\" : \"Approval\",\n" + + " \"date\" : \"1993-11-28T10:21:43.195Z\",\n" + + " \"approvedBy\" : \"NARA\",\n" + + " \"approvalStatus\" : \"APPLIED\",\n" + + " \"applicationCode\" : \"UZlpisZwYl0NJVz6lLy\"\n" + + " } ]\n" + + " } ],\n" + + " \"fundings\" : [ {\n" + + " \"type\" : \"UnconfirmedFunding\",\n" + + " \"source\" : \"https://www.example.org/eamagnam\",\n" + + " \"identifier\" : \"0kIBfGDot4QwO2kb\",\n" + + " \"labels\" : {\n" + + " \"it\" : \"JF3ZSl24zL\"\n" + + " },\n" + + " \"fundingAmount\" : {\n" + + " \"currency\" : \"USD\",\n" + + " \"amount\" : 1138272242\n" + + " },\n" + + " \"activeFrom\" : \"2003-11-07T09:15:50.695Z\",\n" + + " \"activeTo\" : \"2015-08-01T19:20:16.941Z\"\n" + + " }, {\n" + + " \"type\" : \"ConfirmedFunding\",\n" + + " \"source\" : \"https://www.example.org/fugiatsapiente\",\n" + + " \"id\" : \"https://www.example.org/suntmagni\",\n" + + " \"identifier\" : \"BNo5moC50NfbNBo\",\n" + + " \"labels\" : {\n" + + " \"sv\" : \"q7am4xSOFZpHduBza\"\n" + + " },\n" + + " \"fundingAmount\" : {\n" + + " \"currency\" : \"EUR\",\n" + + " \"amount\" : 873582428\n" + + " },\n" + + " \"activeFrom\" : \"1974-04-25T00:39:51.618Z\",\n" + + " \"activeTo\" : \"2018-06-05T01:03:44.768Z\"\n" + + " } ],\n" + + " \"additionalIdentifiers\" : [ {\n" + + " \"type\" : \"AdditionalIdentifier\",\n" + + " \"source\" : \"fakesource\",\n" + + " \"value\" : \"1234\"\n" + + " } ],\n" + + " \"subjects\" : [ \"https://www.example.org/quaeratdolorem\" ],\n" + + " \"associatedArtifacts\" : [ {\n" + + " \"type\" : \"PublishedFile\",\n" + + " \"identifier\" : \"86406e82-636e-4ddb-8e07-fd6619ec3aa0\",\n" + + " \"name\" : \"bNvv7O5PyKT\",\n" + + " \"mimeType\" : \"gVDXmTw9H2gqBRm\",\n" + + " \"size\" : 838225864,\n" + + " \"license\" : {\n" + + " \"type\" : \"License\",\n" + + " \"identifier\" : \"Y1VBFAUQrmps39Lg\",\n" + + " \"labels\" : {\n" + + " \"bg\" : \"uhHKMW0QVPFmPcluDo\"\n" + + " },\n" + + " \"link\" : \"https://www.example.com/LwqTEw9Ulq\"\n" + + " },\n" + + " \"administrativeAgreement\" : false,\n" + + " \"publisherAuthority\" : true,\n" + + " \"visibleForNonOwner\" : true\n" + + " }, {\n" + + " \"type\" : \"AssociatedLink\",\n" + + " \"id\" : \"https://www.example.com/qlvWdNWNyFWfvk5qg6X\",\n" + + " \"name\" : \"Otvp1638EBdF0mJ\",\n" + + " \"description\" : \"ewjrLNbRKEdzqKM\"\n" + + " } ],\n" + + " \"modelVersion\" : \"0.19.29\"\n" + + "}"; + } +} diff --git a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java index acd6eb056..1a68090de 100644 --- a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java +++ b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java @@ -77,6 +77,12 @@ public static PublicationContext randomPublicationContext(Class publicationIn case "JournalLeader": case "JournalReview": return randomJournal(); + case "AcademicMonograph": + case "Encyclopedia": + case "ExhibitionCatalog": + case "NonFictionMonograph": + case "PopularScienceMonograph": + case "Textbook": case "BookAnthology": case "BookAbstracts": case "BookMonograph": diff --git a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java index e4a9ebda0..0fcca6543 100644 --- a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java +++ b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java @@ -57,10 +57,14 @@ import no.unit.nva.model.instancetypes.artistic.visualarts.VisualArtsSubtype; import no.unit.nva.model.instancetypes.artistic.visualarts.VisualArtsSubtypeEnum; import no.unit.nva.model.instancetypes.artistic.visualarts.VisualArtsSubtypeOther; +import no.unit.nva.model.instancetypes.book.AcademicMonograph; import no.unit.nva.model.instancetypes.book.BookAbstracts; import no.unit.nva.model.instancetypes.book.BookAnthology; -import no.unit.nva.model.instancetypes.book.BookMonograph; -import no.unit.nva.model.instancetypes.book.BookMonographContentType; +import no.unit.nva.model.instancetypes.book.Encyclopedia; +import no.unit.nva.model.instancetypes.book.ExhibitionCatalog; +import no.unit.nva.model.instancetypes.book.NonFictionMonograph; +import no.unit.nva.model.instancetypes.book.PopularScienceMonograph; +import no.unit.nva.model.instancetypes.book.Textbook; import no.unit.nva.model.instancetypes.chapter.ChapterArticle; import no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType; import no.unit.nva.model.instancetypes.chapter.ChapterConferenceAbstract; @@ -200,7 +204,18 @@ public static PublicationInstance randomPublicationInstance(Cla case "BookAbstracts": return generateBookAbstracts(); case "BookMonograph": - return generateBookMonograph(); + case "AcademicMonograph": + return generateAcademicMonograph(); + case "NonFictionMonograph": + return generateNonFictionMonograph(); + case "PopularScienceMonograph": + return generatePopularScienceMonograph(); + case "Textbook": + return generateTextbook(); + case "Encyclopedia": + return generateEncyclopedia(); + case "ExhibitionCatalog": + return generateExhibitionCatalog(); case "DegreeBachelor": return generateDegreeBachelor(); case "DegreeMaster": @@ -491,13 +506,30 @@ private static DegreeBachelor generateDegreeBachelor() { .build(); } - private static BookMonograph generateBookMonograph() { - return new BookMonograph.Builder() - .withPages(randomMonographPages()) - .withContentType(randomElement(BookMonographContentType.values())) - .withOriginalResearch(randomBoolean()) - .withPeerReviewed(randomBoolean()) - .build(); + private static AcademicMonograph generateAcademicMonograph() { + return new AcademicMonograph(randomMonographPages(), randomBoolean()); + } + + + private static ExhibitionCatalog generateExhibitionCatalog() { + return new ExhibitionCatalog(randomMonographPages(), randomBoolean()); + } + + private static Encyclopedia generateEncyclopedia() { + return new Encyclopedia(randomMonographPages(), randomBoolean()); + + } + + private static Textbook generateTextbook() { + return new Textbook(randomMonographPages(), randomBoolean()); + } + + private static PopularScienceMonograph generatePopularScienceMonograph() { + return new PopularScienceMonograph(randomMonographPages(), randomBoolean()); + } + + private static NonFictionMonograph generateNonFictionMonograph() { + return new NonFictionMonograph(randomMonographPages(), randomBoolean()); } private static BookAbstracts generateBookAbstracts() { From f4ce3277f50627496d54d06016b4c2e492963b5b Mon Sep 17 00:00:00 2001 From: brinxmat <789709+brinxmat@users.noreply.github.com> Date: Thu, 2 Feb 2023 20:40:28 +0100 Subject: [PATCH 2/6] Mark test as deprecated --- .../java/no/unit/nva/MigrationBookMonographSubtypesTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java index 80ec6050c..6c287c818 100644 --- a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java +++ b/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java @@ -11,6 +11,7 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; +@Deprecated class MigrationBookMonographSubtypesTest { @ParameterizedTest @EnumSource(BookMonographContentType.class) From 38cdd24450673b493c822fff5b0bf92a593bd529 Mon Sep 17 00:00:00 2001 From: brinxmat <789709+brinxmat@users.noreply.github.com> Date: Thu, 2 Feb 2023 21:23:45 +0100 Subject: [PATCH 3/6] Migrate chapter article to discrete subtypes based on content type --- .../instancetypes/PublicationInstance.java | 14 ++ .../chapter/AcademicChapter.java | 16 ++ .../instancetypes/chapter/ChapterArticle.java | 81 +++---- .../chapter/ChapterArticleContentType.java | 1 + .../chapter/EncyclopediaChapter.java | 14 ++ .../chapter/ExhibitionCatalogChapter.java | 16 ++ .../instancetypes/chapter/Introduction.java | 16 ++ .../chapter/NonFictionChapter.java | 16 ++ .../chapter/PopularScienceChapter.java | 16 ++ .../chapter/TextbookChapter.java | 14 ++ .../MigrateChapterArticleSubtypesTest.java | 199 ++++++++++++++++++ .../testing/PublicationContextBuilder.java | 7 + .../testing/PublicationInstanceBuilder.java | 58 ++++- 13 files changed, 411 insertions(+), 57 deletions(-) create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/AcademicChapter.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/EncyclopediaChapter.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ExhibitionCatalogChapter.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/Introduction.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/NonFictionChapter.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/PopularScienceChapter.java create mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/TextbookChapter.java create mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java index c67185776..266e02425 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java @@ -19,9 +19,16 @@ import no.unit.nva.model.instancetypes.book.ExhibitionCatalog; import no.unit.nva.model.instancetypes.book.NonFictionMonograph; import no.unit.nva.model.instancetypes.book.Textbook; +import no.unit.nva.model.instancetypes.chapter.AcademicChapter; import no.unit.nva.model.instancetypes.chapter.ChapterArticle; import no.unit.nva.model.instancetypes.chapter.ChapterConferenceAbstract; import no.unit.nva.model.instancetypes.chapter.ChapterInReport; +import no.unit.nva.model.instancetypes.chapter.EncyclopediaChapter; +import no.unit.nva.model.instancetypes.chapter.ExhibitionCatalogChapter; +import no.unit.nva.model.instancetypes.chapter.Introduction; +import no.unit.nva.model.instancetypes.chapter.NonFictionChapter; +import no.unit.nva.model.instancetypes.chapter.PopularScienceChapter; +import no.unit.nva.model.instancetypes.chapter.TextbookChapter; import no.unit.nva.model.instancetypes.degree.DegreeBachelor; import no.unit.nva.model.instancetypes.degree.DegreeLicentiate; import no.unit.nva.model.instancetypes.degree.DegreeMaster; @@ -101,6 +108,13 @@ @JsonSubTypes.Type(name = "ReportWorkingPaper", value = ReportWorkingPaper.class), @JsonSubTypes.Type(name = "ReportBookOfAbstract", value = ReportBookOfAbstract.class), @JsonSubTypes.Type(name = "ChapterArticle", value = ChapterArticle.class), + @JsonSubTypes.Type(name = "AcademicChapter", value = AcademicChapter.class), + @JsonSubTypes.Type(name = "EncyclopediaChapter", value = EncyclopediaChapter.class), + @JsonSubTypes.Type(name = "ExhibitionCatalogChapter", value = ExhibitionCatalogChapter.class), + @JsonSubTypes.Type(name = "Introduction", value = Introduction.class), + @JsonSubTypes.Type(name = "NonFictionChapter", value = NonFictionChapter.class), + @JsonSubTypes.Type(name = "PopularScienceChapter", value = PopularScienceChapter.class), + @JsonSubTypes.Type(name = "TextbookChapter", value = TextbookChapter.class), @JsonSubTypes.Type(name = "ChapterConferenceAbstract", value = ChapterConferenceAbstract.class), @JsonSubTypes.Type(name = "ChapterInReport", value = ChapterInReport.class), @JsonSubTypes.Type(name = "OtherStudentWork", value = OtherStudentWork.class), diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/AcademicChapter.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/AcademicChapter.java new file mode 100644 index 000000000..2774b8f0a --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/AcademicChapter.java @@ -0,0 +1,16 @@ +package no.unit.nva.model.instancetypes.chapter; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import no.unit.nva.model.pages.Range; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +public class AcademicChapter extends ChapterArticle { + + private static final boolean ORIGINAL_RESEARCH = true; + + public AcademicChapter(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed, ORIGINAL_RESEARCH); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java index 5aa367f39..c4a364b52 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java @@ -1,62 +1,49 @@ package no.unit.nva.model.instancetypes.chapter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.instancetypes.PeerReviewedPaper; import no.unit.nva.model.pages.Range; +import static java.util.Objects.isNull; + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class ChapterArticle extends PeerReviewedPaper { - private ChapterArticleContentType contentType; - - public ChapterArticle() { - super(); - } - - private ChapterArticle(Builder builder) { - super(builder.pages, builder.peerReviewed, builder.originalResearch); - setContentType(builder.contentType); - } - - public void setContentType(ChapterArticleContentType contentType) { - this.contentType = contentType; - } + public static final String PAGES_FIELD = "pages"; + public static final String PEER_REVIEWED_FIELD = "peerReviewed"; - public ChapterArticleContentType getContentType() { - return contentType; + public ChapterArticle(Range pages, + boolean peerReviewed, + boolean originalResearch) { + super(pages, peerReviewed, originalResearch); } - public static final class Builder { - private boolean peerReviewed; - private Range pages; - private boolean originalResearch; - private ChapterArticleContentType contentType; - - public Builder() { - } - - public Builder withPeerReviewed(boolean peerReviewed) { - this.peerReviewed = peerReviewed; - return this; - } - - public Builder withPages(Range pages) { - this.pages = pages; - return this; - } - - public Builder withOriginalResearch(boolean originalResearch) { - this.originalResearch = originalResearch; - return this; - } - - public Builder withContentType(ChapterArticleContentType contentType) { - this.contentType = contentType; - return this; - } - - public ChapterArticle build() { - return new ChapterArticle(this); + @JsonCreator + public static ChapterArticle fromJson(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed, + @JsonProperty("originalResearch") boolean originalResearch, + @JsonProperty("contentType") ChapterArticleContentType contentType) { + if (ChapterArticleContentType.ACADEMIC_CHAPTER.equals(contentType)) { + return new AcademicChapter(pages, peerReviewed); + } else if (ChapterArticleContentType.ENCYCLOPEDIA_CHAPTER.equals(contentType)) { + return new EncyclopediaChapter(pages, peerReviewed); + } else if (ChapterArticleContentType.EXHIBITION_CATALOG_CHAPTER.equals(contentType)) { + return new ExhibitionCatalogChapter(pages, peerReviewed); + } else if (ChapterArticleContentType.INTRODUCTION.equals(contentType)) { + return new Introduction(pages, peerReviewed); + } else if (ChapterArticleContentType.NON_FICTION_CHAPTER.equals(contentType)) { + return new NonFictionChapter(pages, peerReviewed); + } else if (ChapterArticleContentType.POPULAR_SCIENCE_CHAPTER.equals(contentType)) { + return new PopularScienceChapter(pages, peerReviewed); + } else if (ChapterArticleContentType.TEXTBOOK_CHAPTER.equals(contentType)) { + return new TextbookChapter(pages, peerReviewed); + } else if (isNull(contentType)) { + return new AcademicChapter(pages, peerReviewed); + } else { + throw new UnsupportedOperationException("The Chapter article subtype is unknown"); } } + } diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java index 70ad38d68..9c482164f 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java @@ -10,6 +10,7 @@ * Content type for 'Chapter in Anthology' resource subtype when the creator chooses, 'Chapter' Resource type while * registering a publication. */ +@Deprecated public enum ChapterArticleContentType { ACADEMIC_CHAPTER("AcademicChapter", "Academic Chapter"), NON_FICTION_CHAPTER("NonFictionChapter", "Non-fiction Chapter"), diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/EncyclopediaChapter.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/EncyclopediaChapter.java new file mode 100644 index 000000000..e7e49c9a7 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/EncyclopediaChapter.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.chapter; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.Range; + +public class EncyclopediaChapter extends ChapterArticle { + + private static final boolean ORIGINAL_RESEARCH = false; + + public EncyclopediaChapter(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed, ORIGINAL_RESEARCH); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ExhibitionCatalogChapter.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ExhibitionCatalogChapter.java new file mode 100644 index 000000000..d38dfc2b4 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ExhibitionCatalogChapter.java @@ -0,0 +1,16 @@ +package no.unit.nva.model.instancetypes.chapter; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import no.unit.nva.model.pages.Range; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +public class ExhibitionCatalogChapter extends ChapterArticle { + + private static final boolean ORIGINAL_RESEARCH = false; + + public ExhibitionCatalogChapter(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed, ORIGINAL_RESEARCH); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/Introduction.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/Introduction.java new file mode 100644 index 000000000..6ac474424 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/Introduction.java @@ -0,0 +1,16 @@ +package no.unit.nva.model.instancetypes.chapter; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import no.unit.nva.model.pages.Range; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +public class Introduction extends ChapterArticle { + + private static final boolean ORIGINAL_RESEARCH = false; + + public Introduction(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed, ORIGINAL_RESEARCH); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/NonFictionChapter.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/NonFictionChapter.java new file mode 100644 index 000000000..19f32a427 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/NonFictionChapter.java @@ -0,0 +1,16 @@ +package no.unit.nva.model.instancetypes.chapter; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import no.unit.nva.model.pages.Range; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +public class NonFictionChapter extends ChapterArticle { + + private static final boolean ORIGINAL_RESEARCH = false; + + public NonFictionChapter(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed, ORIGINAL_RESEARCH); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/PopularScienceChapter.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/PopularScienceChapter.java new file mode 100644 index 000000000..5b0467ba3 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/PopularScienceChapter.java @@ -0,0 +1,16 @@ +package no.unit.nva.model.instancetypes.chapter; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import no.unit.nva.model.pages.Range; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +public class PopularScienceChapter extends ChapterArticle { + + private static final boolean ORIGINAL_RESEARCH = false; + + public PopularScienceChapter(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed, ORIGINAL_RESEARCH); + } +} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/TextbookChapter.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/TextbookChapter.java new file mode 100644 index 000000000..e43d5b527 --- /dev/null +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/TextbookChapter.java @@ -0,0 +1,14 @@ +package no.unit.nva.model.instancetypes.chapter; + +import com.fasterxml.jackson.annotation.JsonProperty; +import no.unit.nva.model.pages.Range; + +public class TextbookChapter extends ChapterArticle { + + private static final boolean ORIGINAL_RESEARCH = false; + + public TextbookChapter(@JsonProperty(PAGES_FIELD) Range pages, + @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + super(pages, peerReviewed, ORIGINAL_RESEARCH); + } +} diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java new file mode 100644 index 000000000..35bb98275 --- /dev/null +++ b/nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java @@ -0,0 +1,199 @@ +package no.unit.nva; + +import no.unit.nva.commons.json.JsonUtils; +import no.unit.nva.model.Publication; +import no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import static nva.commons.core.attempt.Try.attempt; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; + +class MigrateChapterArticleSubtypesTest { + @ParameterizedTest + @EnumSource(ChapterArticleContentType.class) + void shouldDeserializeOldSubtypeBookMonographContentTypeAsType(ChapterArticleContentType content) { + var type = content.getValue(); + var json = generateFullChapterArticleWithContentType(type); + var chapterArticle = attempt(() -> JsonUtils.dtoObjectMapper.readValue(json, Publication.class)) + .orElseThrow(); + var actual = chapterArticle.getEntityDescription() + .getReference().getPublicationInstance().getClass().getSimpleName(); + assertThat(actual, is(equalTo(type))); + } + + private String generateFullChapterArticleWithContentType(String type) { + return "{\n" + + " \"type\" : \"Publication\",\n" + + " \"identifier\" : \"c443030e-9d56-43d8-afd1-8c89105af555\",\n" + + " \"status\" : \"NEW\",\n" + + " \"resourceOwner\" : {\n" + + " \"owner\" : \"RuYrbdooUL32\",\n" + + " \"ownerAffiliation\" : \"https://www.example.org/repellateum\"\n" + + " },\n" + + " \"publisher\" : {\n" + + " \"type\" : \"Organization\",\n" + + " \"id\" : \"https://www.example.org/errorrem\",\n" + + " \"labels\" : {\n" + + " \"bg\" : \"ttgW11eA97cznnf4GC4\"\n" + + " }\n" + + " },\n" + + " \"createdDate\" : \"2020-07-28T09:09:48.320Z\",\n" + + " \"modifiedDate\" : \"2002-08-03T23:05:35.416Z\",\n" + + " \"publishedDate\" : \"1991-09-28T07:19:46.957Z\",\n" + + " \"indexedDate\" : \"1983-09-18T05:29:53.500Z\",\n" + + " \"handle\" : \"https://www.example.org/repudiandaeullam\",\n" + + " \"doi\" : \"https://doi.org/10.1234/dolore\",\n" + + " \"link\" : \"https://www.example.org/reprehenderitsaepe\",\n" + + " \"entityDescription\" : {\n" + + " \"type\" : \"EntityDescription\",\n" + + " \"mainTitle\" : \"BLYSKI1nfdbkv\",\n" + + " \"alternativeTitles\" : {\n" + + " \"el\" : \"zm6679gekbLZW\"\n" + + " },\n" + + " \"language\" : \"http://lexvo.org/id/iso639-3/und\",\n" + + " \"date\" : {\n" + + " \"type\" : \"PublicationDate\",\n" + + " \"year\" : \"XXAhi6akNONu\",\n" + + " \"month\" : \"HEQzNoatbd6NSMKHRg0\",\n" + + " \"day\" : \"2ESjpduz4r7bS\"\n" + + " },\n" + + " \"contributors\" : [ {\n" + + " \"type\" : \"Contributor\",\n" + + " \"identity\" : {\n" + + " \"type\" : \"Identity\",\n" + + " \"id\" : \"https://www.example.com/XhSa9gtoce12\",\n" + + " \"name\" : \"75efqCBNvlir7c\",\n" + + " \"nameType\" : \"Organizational\",\n" + + " \"orcId\" : \"t5ZYTi4TYLff\"\n" + + " },\n" + + " \"affiliations\" : [ {\n" + + " \"type\" : \"Organization\",\n" + + " \"id\" : \"https://www.example.com/6HhoBSEkueTu2Z\",\n" + + " \"labels\" : {\n" + + " \"cs\" : \"x4Pn570F0gnE\"\n" + + " }\n" + + " } ],\n" + + " \"role\" : \"Curator\",\n" + + " \"sequence\" : 0,\n" + + " \"correspondingAuthor\" : false\n" + + " }, {\n" + + " \"type\" : \"Contributor\",\n" + + " \"identity\" : {\n" + + " \"type\" : \"Identity\",\n" + + " \"id\" : \"https://www.example.com/XzqAR37csm9zWJ\",\n" + + " \"name\" : \"4R2jeB61pvak8IWqj8H\",\n" + + " \"nameType\" : \"Organizational\",\n" + + " \"orcId\" : \"Aog7SFb5e54M\"\n" + + " },\n" + + " \"affiliations\" : [ {\n" + + " \"type\" : \"Organization\",\n" + + " \"id\" : \"https://www.example.com/N6MywIzDqqmSv4k4\",\n" + + " \"labels\" : {\n" + + " \"en\" : \"OL3z1bGqeL0LzNza\"\n" + + " }\n" + + " } ],\n" + + " \"role\" : \"Artist\",\n" + + " \"sequence\" : 5,\n" + + " \"correspondingAuthor\" : false\n" + + " } ],\n" + + " \"npiSubjectHeading\" : \"Rk8MXIukbIzwqLP6\",\n" + + " \"tags\" : [ \"S4dKS7Cn5r6\" ],\n" + + " \"description\" : \"w2BzLiBJVxLFuROrnY\",\n" + + " \"reference\" : {\n" + + " \"type\" : \"Reference\",\n" + + " \"publicationContext\" : {\n" + + " \"type\" : \"Chapter\",\n" + + " \"partOf\" : \"https://www.example.com/8Fj6K3c2Eyx\"\n" + + " },\n" + + " \"doi\" : \"https://www.example.com/TVeL0ieitk1mLBbMH\",\n" + + " \"publicationInstance\" : {\n" + + " \"type\" : \"ChapterArticle\",\n" + + " \"contentType\" : \"" + type + "\",\n" + + " \"peerReviewed\" : true,\n" + + " \"originalResearch\" : true,\n" + + " \"pages\" : {\n" + + " \"type\" : \"Range\",\n" + + " \"begin\" : \"qDEY1GhYXtxTVxAdE\",\n" + + " \"end\" : \"r3L4UKe6bg10Sqoj\"\n" + + " }\n" + + " }\n" + + " },\n" + + " \"metadataSource\" : \"https://www.example.com/Ag6Qro62b8DvL9p4\",\n" + + " \"abstract\" : \"CBLk1w1sHe\"\n" + + " },\n" + + " \"projects\" : [ {\n" + + " \"type\" : \"ResearchProject\",\n" + + " \"id\" : \"https://www.example.org/aliassaepe\",\n" + + " \"name\" : \"LOumMwmN3JQmFxCY8Ha\",\n" + + " \"approvals\" : [ {\n" + + " \"type\" : \"Approval\",\n" + + " \"date\" : \"2023-01-08T09:20:28.086Z\",\n" + + " \"approvedBy\" : \"REK\",\n" + + " \"approvalStatus\" : \"DECLINED\",\n" + + " \"applicationCode\" : \"xwWwEn0awmly\"\n" + + " } ]\n" + + " } ],\n" + + " \"fundings\" : [ {\n" + + " \"type\" : \"UnconfirmedFunding\",\n" + + " \"source\" : \"https://www.example.org/voluptatemsed\",\n" + + " \"identifier\" : \"Ue3A2hsgEG\",\n" + + " \"labels\" : {\n" + + " \"fr\" : \"gUeWn5rgnIaZ902P0Gm\"\n" + + " },\n" + + " \"fundingAmount\" : {\n" + + " \"currency\" : \"USD\",\n" + + " \"amount\" : 161825051\n" + + " },\n" + + " \"activeFrom\" : \"2011-05-05T00:03:24.088Z\",\n" + + " \"activeTo\" : \"2019-03-27T14:38:32.956Z\"\n" + + " }, {\n" + + " \"type\" : \"ConfirmedFunding\",\n" + + " \"source\" : \"https://www.example.org/laboriosamneque\",\n" + + " \"id\" : \"https://www.example.org/nullaquia\",\n" + + " \"identifier\" : \"Dl1wT7xbmq4C2I4sQKx\",\n" + + " \"labels\" : {\n" + + " \"da\" : \"H1ERfelmzeBQxdSs\"\n" + + " },\n" + + " \"fundingAmount\" : {\n" + + " \"currency\" : \"GBP\",\n" + + " \"amount\" : 981864134\n" + + " },\n" + + " \"activeFrom\" : \"1973-04-26T21:20:47.124Z\",\n" + + " \"activeTo\" : \"2018-03-07T11:19:24.360Z\"\n" + + " } ],\n" + + " \"additionalIdentifiers\" : [ {\n" + + " \"type\" : \"AdditionalIdentifier\",\n" + + " \"source\" : \"fakesource\",\n" + + " \"value\" : \"1234\"\n" + + " } ],\n" + + " \"subjects\" : [ \"https://www.example.org/maximevel\" ],\n" + + " \"associatedArtifacts\" : [ {\n" + + " \"type\" : \"PublishedFile\",\n" + + " \"identifier\" : \"46725458-c60c-44a6-a952-41d25c9e5de3\",\n" + + " \"name\" : \"gEUP4JgMXh1Q\",\n" + + " \"mimeType\" : \"orcFMiw4ZnM\",\n" + + " \"size\" : 1581080284,\n" + + " \"license\" : {\n" + + " \"type\" : \"License\",\n" + + " \"identifier\" : \"7PYHmgVdvENJTYWcm\",\n" + + " \"labels\" : {\n" + + " \"fi\" : \"0SwxwFiSVRwQvz5ijCd\"\n" + + " },\n" + + " \"link\" : \"https://www.example.com/PSyujG3bq4ccWVvdhL\"\n" + + " },\n" + + " \"administrativeAgreement\" : false,\n" + + " \"publisherAuthority\" : true,\n" + + " \"visibleForNonOwner\" : true\n" + + " }, {\n" + + " \"type\" : \"AssociatedLink\",\n" + + " \"id\" : \"https://www.example.com/GclXAVyGmqRrJ\",\n" + + " \"name\" : \"XS2oxVRgVr\",\n" + + " \"description\" : \"xRPrvEVJRdwxZ\"\n" + + " } ],\n" + + " \"modelVersion\" : \"0.19.29\"\n" + + "}"; + } +} diff --git a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java index 1a68090de..534329a4a 100644 --- a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java +++ b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java @@ -94,6 +94,13 @@ public static PublicationContext randomPublicationContext(Class publicationIn case "DegreeLicentiate": return attempt(PublicationContextBuilder::randomDegree).orElseThrow(); case "ChapterArticle": + case "AcademicChapter": + case "NonFictionChapter": + case "PopularScienceChapter": + case "TextbookChapter": + case "EncyclopediaChapter": + case "Introduction": + case "ExhibitionCatalogChapter": case "ChapterConferenceAbstract": case "ChapterInReport": return randomChapter(); diff --git a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java index 0fcca6543..940e43198 100644 --- a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java +++ b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java @@ -65,10 +65,15 @@ import no.unit.nva.model.instancetypes.book.NonFictionMonograph; import no.unit.nva.model.instancetypes.book.PopularScienceMonograph; import no.unit.nva.model.instancetypes.book.Textbook; -import no.unit.nva.model.instancetypes.chapter.ChapterArticle; -import no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType; +import no.unit.nva.model.instancetypes.chapter.AcademicChapter; import no.unit.nva.model.instancetypes.chapter.ChapterConferenceAbstract; import no.unit.nva.model.instancetypes.chapter.ChapterInReport; +import no.unit.nva.model.instancetypes.chapter.EncyclopediaChapter; +import no.unit.nva.model.instancetypes.chapter.ExhibitionCatalogChapter; +import no.unit.nva.model.instancetypes.chapter.Introduction; +import no.unit.nva.model.instancetypes.chapter.NonFictionChapter; +import no.unit.nva.model.instancetypes.chapter.PopularScienceChapter; +import no.unit.nva.model.instancetypes.chapter.TextbookChapter; import no.unit.nva.model.instancetypes.degree.DegreeBachelor; import no.unit.nva.model.instancetypes.degree.DegreeLicentiate; import no.unit.nva.model.instancetypes.degree.DegreeMaster; @@ -188,7 +193,20 @@ public static PublicationInstance randomPublicationInstance(Cla case "BookAnthology": return generateBookAnthology(); case "ChapterArticle": - return generateChapterArticle(); + case "AcademicChapter": + return generateAcademicChapter(); + case "NonFictionChapter": + return generateNonFictionChapter(); + case "PopularScienceChapter": + return generatePopularScienceChapter(); + case "TextbookChapter": + return generateTextbookChapter(); + case "EncyclopediaChapter": + return generateEncyclopediaChapter(); + case "Introduction": + return generateIntroduction(); + case "ExhibitionCatalogChapter": + return generateExhibitionCatalogChapter(); case "ChapterConferenceAbstract": return generateChapterConferenceAbstract(); case "ChapterInReport": @@ -574,13 +592,33 @@ private static JournalInterview generateJournalInterview() { .build(); } - private static ChapterArticle generateChapterArticle() { - return new ChapterArticle.Builder() - .withPages(randomRange()) - .withPeerReviewed(randomBoolean()) - .withOriginalResearch(randomBoolean()) - .withContentType(randomElement(ChapterArticleContentType.values())) - .build(); + private static AcademicChapter generateAcademicChapter() { + return new AcademicChapter(randomRange(), randomBoolean()); + } + + + private static ExhibitionCatalogChapter generateExhibitionCatalogChapter() { + return new ExhibitionCatalogChapter(randomRange(), randomBoolean()); + } + + private static Introduction generateIntroduction() { + return new Introduction(randomRange(), randomBoolean()); + } + + private static EncyclopediaChapter generateEncyclopediaChapter() { + return new EncyclopediaChapter(randomRange(), randomBoolean()); + } + + private static TextbookChapter generateTextbookChapter() { + return new TextbookChapter(randomRange(), randomBoolean()); + } + + private static PopularScienceChapter generatePopularScienceChapter() { + return new PopularScienceChapter(randomRange(), randomBoolean()); + } + + private static NonFictionChapter generateNonFictionChapter() { + return new NonFictionChapter(randomRange(), randomBoolean()); } private static ChapterConferenceAbstract generateChapterConferenceAbstract() { From ffa196b3d651125c229b05d442d84a3a4b60cb91 Mon Sep 17 00:00:00 2001 From: brinxmat <789709+brinxmat@users.noreply.github.com> Date: Thu, 2 Feb 2023 21:27:31 +0100 Subject: [PATCH 4/6] Add jackson type info annotations --- .../no/unit/nva/model/instancetypes/book/AcademicMonograph.java | 2 ++ .../java/no/unit/nva/model/instancetypes/book/Encyclopedia.java | 2 ++ .../no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java | 2 ++ .../unit/nva/model/instancetypes/book/NonFictionMonograph.java | 2 ++ .../nva/model/instancetypes/book/PopularScienceMonograph.java | 2 ++ .../java/no/unit/nva/model/instancetypes/book/Textbook.java | 2 ++ 6 files changed, 12 insertions(+) diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java index ff0215300..d3d23313f 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/AcademicMonograph.java @@ -1,8 +1,10 @@ package no.unit.nva.model.instancetypes.book; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.pages.MonographPages; +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class AcademicMonograph extends BookMonograph { private static final boolean ORIGINAL_RESEARCH = true; diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java index 4f6ce119e..bd25470d1 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Encyclopedia.java @@ -1,8 +1,10 @@ package no.unit.nva.model.instancetypes.book; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.pages.MonographPages; +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class Encyclopedia extends BookMonograph { private static final boolean ORIGINAL_RESEARCH = false; diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java index 157efa6ec..90a90407f 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/ExhibitionCatalog.java @@ -1,8 +1,10 @@ package no.unit.nva.model.instancetypes.book; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.pages.MonographPages; +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class ExhibitionCatalog extends BookMonograph { private static final boolean ORIGINAL_RESEARCH = false; diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java index 398ffdb4c..7ff23775b 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/NonFictionMonograph.java @@ -1,8 +1,10 @@ package no.unit.nva.model.instancetypes.book; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.pages.MonographPages; +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class NonFictionMonograph extends BookMonograph { private static final boolean ORIGINAL_RESEARCH = false; diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java index a66bb4ec0..e8c497c82 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/PopularScienceMonograph.java @@ -1,8 +1,10 @@ package no.unit.nva.model.instancetypes.book; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.pages.MonographPages; +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class PopularScienceMonograph extends BookMonograph { private static final boolean ORIGINAL_RESEARCH = false; diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java index dbc74d9fb..f1eaf3691 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/Textbook.java @@ -1,8 +1,10 @@ package no.unit.nva.model.instancetypes.book; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.pages.MonographPages; +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class Textbook extends BookMonograph { private static final boolean ORIGINAL_RESEARCH = false; From 99b7a07064ffed2a32480709f0579df49af04322 Mon Sep 17 00:00:00 2001 From: brinxmat <789709+brinxmat@users.noreply.github.com> Date: Thu, 2 Feb 2023 21:30:03 +0100 Subject: [PATCH 5/6] Bump version --- buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle b/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle index 1beaa04e0..c803deb9b 100644 --- a/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle +++ b/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle @@ -10,7 +10,7 @@ plugins { group 'com.github.bibsysdev' -version '0.19.29' +version '0.19.30' repositories { mavenCentral() From 94052354ecad5ab047b5b3df0bb47767c422ff4e Mon Sep 17 00:00:00 2001 From: brinxmat <789709+brinxmat@users.noreply.github.com> Date: Thu, 2 Feb 2023 22:18:20 +0100 Subject: [PATCH 6/6] Remove migration code to crete new release --- .../nvadatamodel.java-conventions.gradle | 2 +- .../instancetypes/PublicationInstance.java | 6 - .../UnconfirmedPublisherMigrator.java | 18 -- .../artistic/film/realization/Broadcast.java | 14 +- .../film/realization/OtherRelease.java | 19 +- .../music/AudioVisualPublication.java | 23 +- .../artistic/music/MusicScore.java | 20 +- .../instancetypes/book/BookMonograph.java | 38 +--- .../book/BookMonographContentType.java | 63 ------ .../instancetypes/chapter/ChapterArticle.java | 33 --- .../chapter/ChapterArticleContentType.java | 67 ------ .../instancetypes/journal/JournalArticle.java | 88 ------- .../journal/JournalArticleContentType.java | 56 ----- .../MigrateChapterArticleSubtypesTest.java | 199 ---------------- .../MigrationBookMonographSubtypesTest.java | 214 ------------------ .../nva/MigrationJournalArticleSubtypes.java | 192 ---------------- .../MigrationTestingUnconfirmedPublisher.java | 152 ------------- .../book/BookMonographContentTypeTest.java | 75 ------ .../ChapterArticleContentTypeTest.java | 83 ------- .../JournalArticleContentTypeTest.java | 50 ---- .../testing/PublicationContextBuilder.java | 3 - .../testing/PublicationInstanceBuilder.java | 3 - 22 files changed, 17 insertions(+), 1401 deletions(-) delete mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/UnconfirmedPublisherMigrator.java delete mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java delete mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java delete mode 100644 nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentType.java delete mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java delete mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java delete mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/MigrationJournalArticleSubtypes.java delete mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/MigrationTestingUnconfirmedPublisher.java delete mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/book/BookMonographContentTypeTest.java delete mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentTypeTest.java delete mode 100644 nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentTypeTest.java diff --git a/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle b/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle index c803deb9b..08f18cba8 100644 --- a/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle +++ b/buildSrc/src/main/groovy/nvadatamodel.java-conventions.gradle @@ -10,7 +10,7 @@ plugins { group 'com.github.bibsysdev' -version '0.19.30' +version '0.20.0' repositories { mavenCentral() diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java index 266e02425..bd3466dc0 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/PublicationInstance.java @@ -14,13 +14,11 @@ import no.unit.nva.model.instancetypes.book.AcademicMonograph; import no.unit.nva.model.instancetypes.book.BookAbstracts; import no.unit.nva.model.instancetypes.book.BookAnthology; -import no.unit.nva.model.instancetypes.book.BookMonograph; import no.unit.nva.model.instancetypes.book.Encyclopedia; import no.unit.nva.model.instancetypes.book.ExhibitionCatalog; import no.unit.nva.model.instancetypes.book.NonFictionMonograph; import no.unit.nva.model.instancetypes.book.Textbook; import no.unit.nva.model.instancetypes.chapter.AcademicChapter; -import no.unit.nva.model.instancetypes.chapter.ChapterArticle; import no.unit.nva.model.instancetypes.chapter.ChapterConferenceAbstract; import no.unit.nva.model.instancetypes.chapter.ChapterInReport; import no.unit.nva.model.instancetypes.chapter.EncyclopediaChapter; @@ -43,7 +41,6 @@ import no.unit.nva.model.instancetypes.journal.CaseReport; import no.unit.nva.model.instancetypes.journal.ConferenceAbstract; import no.unit.nva.model.instancetypes.journal.FeatureArticle; -import no.unit.nva.model.instancetypes.journal.JournalArticle; import no.unit.nva.model.instancetypes.journal.JournalCorrigendum; import no.unit.nva.model.instancetypes.journal.JournalInterview; import no.unit.nva.model.instancetypes.journal.JournalIssue; @@ -77,7 +74,6 @@ @JsonSubTypes.Type(name = "FeatureArticle", value = FeatureArticle.class), @JsonSubTypes.Type(name = "MovingPicture", value = MovingPicture.class), @JsonSubTypes.Type(name = "PerformingArts", value = PerformingArts.class), - @JsonSubTypes.Type(name = "JournalArticle", value = JournalArticle.class), @JsonSubTypes.Type(name = "AcademicArticle", value = AcademicArticle.class), @JsonSubTypes.Type(name = "AcademicLiteratureReview", value = AcademicLiteratureReview.class), @JsonSubTypes.Type(name = "CaseReport", value = CaseReport.class), @@ -90,7 +86,6 @@ @JsonSubTypes.Type(name = "JournalLeader", value = JournalLeader.class), @JsonSubTypes.Type(name = "JournalReview", value = JournalReview.class), @JsonSubTypes.Type(name = "BookAbstracts", value = BookAbstracts.class), - @JsonSubTypes.Type(name = "BookMonograph", value = BookMonograph.class), @JsonSubTypes.Type(name = "AcademicMonograph", value = AcademicMonograph.class), @JsonSubTypes.Type(name = "Encyclopedia", value = Encyclopedia.class), @JsonSubTypes.Type(name = "ExhibitionCatalog", value = ExhibitionCatalog.class), @@ -107,7 +102,6 @@ @JsonSubTypes.Type(name = "ReportResearch", value = ReportResearch.class), @JsonSubTypes.Type(name = "ReportWorkingPaper", value = ReportWorkingPaper.class), @JsonSubTypes.Type(name = "ReportBookOfAbstract", value = ReportBookOfAbstract.class), - @JsonSubTypes.Type(name = "ChapterArticle", value = ChapterArticle.class), @JsonSubTypes.Type(name = "AcademicChapter", value = AcademicChapter.class), @JsonSubTypes.Type(name = "EncyclopediaChapter", value = EncyclopediaChapter.class), @JsonSubTypes.Type(name = "ExhibitionCatalogChapter", value = ExhibitionCatalogChapter.class), diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/UnconfirmedPublisherMigrator.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/UnconfirmedPublisherMigrator.java deleted file mode 100644 index 88dc05cf0..000000000 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/UnconfirmedPublisherMigrator.java +++ /dev/null @@ -1,18 +0,0 @@ -package no.unit.nva.model.instancetypes.artistic; - -import com.fasterxml.jackson.databind.ObjectMapper; -import no.unit.nva.commons.json.JsonUtils; -import no.unit.nva.model.contexttypes.PublishingHouse; - -import static nva.commons.core.attempt.Try.attempt; - -@Deprecated -public interface UnconfirmedPublisherMigrator { - - ObjectMapper MAPPER = JsonUtils.dtoObjectMapper; - - static PublishingHouse toPublisher(Object candidate) { - var publisherString = attempt(() -> MAPPER.writeValueAsString(candidate)).orElseThrow(); - return attempt(() -> MAPPER.readValue(publisherString, PublishingHouse.class)).orElseThrow(); - } -} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/Broadcast.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/Broadcast.java index 22669e078..092416338 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/Broadcast.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/Broadcast.java @@ -4,15 +4,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.contexttypes.PublishingHouse; -import no.unit.nva.model.contexttypes.UnconfirmedPublisher; -import no.unit.nva.model.instancetypes.artistic.UnconfirmedPublisherMigrator; import no.unit.nva.model.time.Instant; import nva.commons.core.JacocoGenerated; import java.util.Objects; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -public class Broadcast implements MovingPictureOutput, UnconfirmedPublisherMigrator { +public class Broadcast implements MovingPictureOutput { public static final String PUBLISHER_FIELD = "publisher"; public static final String DATE_FIELD = "date"; @@ -24,17 +22,7 @@ public class Broadcast implements MovingPictureOutput, UnconfirmedPublisherMigra @JsonProperty(SEQUENCE_FIELD) private final int sequence; - @Deprecated @JsonCreator - public static Broadcast fromJson(@JsonProperty(PUBLISHER_FIELD) Object publisher, - @JsonProperty(DATE_FIELD) Instant date, - @JsonProperty(SEQUENCE_FIELD) int sequence) { - if (publisher instanceof String) { - return new Broadcast(new UnconfirmedPublisher((String) publisher), date, sequence); - } - return new Broadcast(UnconfirmedPublisherMigrator.toPublisher(publisher), date, sequence); - } - public Broadcast(@JsonProperty(PUBLISHER_FIELD) PublishingHouse publisher, @JsonProperty(DATE_FIELD) Instant date, @JsonProperty(SEQUENCE_FIELD) int sequence) { diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/OtherRelease.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/OtherRelease.java index c74d4941d..da558fc2d 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/OtherRelease.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/film/realization/OtherRelease.java @@ -3,16 +3,15 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import java.util.Objects; import no.unit.nva.model.contexttypes.PublishingHouse; -import no.unit.nva.model.contexttypes.UnconfirmedPublisher; import no.unit.nva.model.contexttypes.place.UnconfirmedPlace; -import no.unit.nva.model.instancetypes.artistic.UnconfirmedPublisherMigrator; import no.unit.nva.model.time.Instant; import nva.commons.core.JacocoGenerated; +import java.util.Objects; + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -public class OtherRelease implements MovingPictureOutput, UnconfirmedPublisherMigrator { +public class OtherRelease implements MovingPictureOutput { public static final String DESCRIPTION_FIELD = "description"; public static final String PLACE_FIELD = "place"; public static final String PUBLISHER_FIELD = "publisher"; @@ -29,19 +28,7 @@ public class OtherRelease implements MovingPictureOutput, UnconfirmedPublisherMi @JsonProperty(SEQUENCE_FIELD) private final int sequence; - @Deprecated @JsonCreator - public static OtherRelease fromJson(@JsonProperty(DESCRIPTION_FIELD) String description, - @JsonProperty(PLACE_FIELD) UnconfirmedPlace place, - @JsonProperty(PUBLISHER_FIELD) Object publisher, - @JsonProperty(DATE_FIELD) Instant date, - @JsonProperty(SEQUENCE_FIELD) int sequence) { - var publishingHouse = publisher instanceof String - ? new UnconfirmedPublisher((String) publisher) - : UnconfirmedPublisherMigrator.toPublisher(publisher); - return new OtherRelease(description, place, publishingHouse, date, sequence); - } - public OtherRelease(@JsonProperty(DESCRIPTION_FIELD) String description, @JsonProperty(PLACE_FIELD) UnconfirmedPlace place, @JsonProperty(PUBLISHER_FIELD) PublishingHouse publisher, diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/AudioVisualPublication.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/AudioVisualPublication.java index d7f6e272c..2b1936991 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/AudioVisualPublication.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/AudioVisualPublication.java @@ -1,18 +1,18 @@ package no.unit.nva.model.instancetypes.artistic.music; -import static no.unit.nva.model.util.SerializationUtils.nullListAsEmpty; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import java.util.List; -import java.util.Objects; import no.unit.nva.model.contexttypes.PublishingHouse; -import no.unit.nva.model.contexttypes.UnconfirmedPublisher; -import no.unit.nva.model.instancetypes.artistic.UnconfirmedPublisherMigrator; import nva.commons.core.JacocoGenerated; +import java.util.List; +import java.util.Objects; + +import static no.unit.nva.model.util.SerializationUtils.nullListAsEmpty; + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -public class AudioVisualPublication implements MusicPerformanceManifestation, UnconfirmedPublisherMigrator { +public class AudioVisualPublication implements MusicPerformanceManifestation { public static final String MEDIA_TYPE_FIELD = "mediaType"; public static final String PUBLISHER_FIELD = "publisher"; @@ -28,18 +28,7 @@ public class AudioVisualPublication implements MusicPerformanceManifestation, Un @JsonProperty(TRACK_LIST_FIELD) private final List trackList; - @Deprecated @JsonCreator - public static AudioVisualPublication fromJson(@JsonProperty(MEDIA_TYPE_FIELD) MusicMediaType mediaType, - @JsonProperty(PUBLISHER_FIELD) Object publisher, - @JsonProperty(CATALOGUE_NUMBER_FIELD) String catalogueNumber, - @JsonProperty(TRACK_LIST_FIELD) List trackList) { - var publishingHouse = publisher instanceof String - ? new UnconfirmedPublisher((String) publisher) - : UnconfirmedPublisherMigrator.toPublisher(publisher); - return new AudioVisualPublication(mediaType, publishingHouse, catalogueNumber, trackList); - } - public AudioVisualPublication(@JsonProperty(MEDIA_TYPE_FIELD) MusicMediaType mediaType, @JsonProperty(PUBLISHER_FIELD) PublishingHouse publisher, @JsonProperty(CATALOGUE_NUMBER_FIELD) String catalogueNumber, diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/MusicScore.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/MusicScore.java index 93ed722a3..2a6efb33b 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/MusicScore.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/artistic/music/MusicScore.java @@ -4,14 +4,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; -import java.util.Objects; import no.unit.nva.model.contexttypes.PublishingHouse; -import no.unit.nva.model.contexttypes.UnconfirmedPublisher; -import no.unit.nva.model.instancetypes.artistic.UnconfirmedPublisherMigrator; import nva.commons.core.JacocoGenerated; +import java.util.Objects; + @JsonTypeInfo(use = Id.NAME, property = "type") -public class MusicScore implements MusicPerformanceManifestation, UnconfirmedPublisherMigrator { +public class MusicScore implements MusicPerformanceManifestation { public static final String ENSEMBLE_FIELD = "ensemble"; public static final String MOVEMENTS_FIELD = "movements"; @@ -34,25 +33,12 @@ public class MusicScore implements MusicPerformanceManifestation, UnconfirmedPub private final Isrc isrc; @JsonCreator - public static MusicScore fromJson(@JsonProperty(ENSEMBLE_FIELD) String ensemble, - @JsonProperty(MOVEMENTS_FIELD) String movements, - @JsonProperty(EXTENT_FIELD) String extent, - @JsonProperty(PUBLISHER_FIELD) Object publisher, - @JsonProperty(ISMN_FIELD) Ismn ismn, - @JsonProperty(ISRC_FIELD) Isrc isrc) { - var publishingHouse = publisher instanceof String - ? new UnconfirmedPublisher((String) publisher) - : UnconfirmedPublisherMigrator.toPublisher(publisher); - return new MusicScore(ensemble, movements, extent, publishingHouse, ismn, isrc); - } - public MusicScore(@JsonProperty(ENSEMBLE_FIELD) String ensemble, @JsonProperty(MOVEMENTS_FIELD) String movements, @JsonProperty(EXTENT_FIELD) String extent, @JsonProperty(PUBLISHER_FIELD) PublishingHouse publisher, @JsonProperty(ISMN_FIELD) Ismn ismn, @JsonProperty(ISRC_FIELD) Isrc isrc) { - this.ensemble = ensemble; this.movements = movements; this.extent = extent; diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java index 111da5843..6c15365df 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonograph.java @@ -1,56 +1,24 @@ package no.unit.nva.model.instancetypes.book; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.instancetypes.PeerReviewedMonograph; import no.unit.nva.model.pages.MonographPages; import nva.commons.core.JacocoGenerated; import java.util.Objects; -import static java.util.Objects.isNull; - -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class BookMonograph extends PeerReviewedMonograph { public static final String PAGES_FIELD = "pages"; - private static final String CONTENT_TYPE_FIELD = "contentType"; - public static final String ORIGINAL_RESEARCH_FIELD = "originalResearch"; public static final String PEER_REVIEWED_FIELD = "peerReviewed"; private final boolean originalResearch; - public BookMonograph(@JsonProperty(PAGES_FIELD) MonographPages pages, - @JsonProperty(ORIGINAL_RESEARCH_FIELD) boolean originalResearch, - @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { + public BookMonograph(MonographPages pages, + boolean originalResearch, + boolean peerReviewed) { super(pages, peerReviewed); this.originalResearch = originalResearch; } - @JsonCreator - public static BookMonograph fromJson(@JsonProperty(PAGES_FIELD) MonographPages pages, - @JsonProperty(CONTENT_TYPE_FIELD) BookMonographContentType contentType, - @JsonProperty(ORIGINAL_RESEARCH_FIELD) boolean originalResearch, - @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed) { - if (BookMonographContentType.ACADEMIC_MONOGRAPH.equals(contentType)) { - return new AcademicMonograph(pages, peerReviewed); - } else if (BookMonographContentType.ENCYCLOPEDIA.equals(contentType)) { - return new Encyclopedia(pages, peerReviewed); - } else if (BookMonographContentType.EXHIBITION_CATALOG.equals(contentType)) { - return new ExhibitionCatalog(pages, peerReviewed); - } else if (BookMonographContentType.NON_FICTION_MONOGRAPH.equals(contentType)) { - return new NonFictionMonograph(pages, peerReviewed); - } else if (BookMonographContentType.POPULAR_SCIENCE_MONOGRAPH.equals(contentType)) { - return new PopularScienceMonograph(pages, peerReviewed); - } else if (BookMonographContentType.TEXTBOOK.equals(contentType)) { - return new Textbook(pages, peerReviewed); - } else if (isNull(contentType)) { - return new AcademicMonograph(pages, peerReviewed); - } else { - throw new UnsupportedOperationException("The Book Monograph subtype is unknown"); - } - } - public boolean isOriginalResearch() { return originalResearch; } diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java deleted file mode 100644 index 633bfd822..000000000 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/book/BookMonographContentType.java +++ /dev/null @@ -1,63 +0,0 @@ -package no.unit.nva.model.instancetypes.book; - -import static java.lang.String.format; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Content Type options for "Monograph" subtype when the creator chooses the Resource type as "Book" while doing the - * registration. - */ -@Deprecated -public enum BookMonographContentType { - ACADEMIC_MONOGRAPH("AcademicMonograph", "Academic Monograph"), - NON_FICTION_MONOGRAPH("NonFictionMonograph", "Non-fiction Monograph"), - POPULAR_SCIENCE_MONOGRAPH("PopularScienceMonograph", "Popular Science Monograph"), - TEXTBOOK("Textbook", "Textbook"), - ENCYCLOPEDIA("Encyclopedia", "Encyclopedia"), - /** - * Enum Type Exhibition catalogue represents: A book published for a specific art or museum exhibition. Contains a - * list of exhibits at the exhibition. - */ - EXHIBITION_CATALOG("ExhibitionCatalog", "Exhibition catalog"); - - public static final String ERROR_MESSAGE_TEMPLATE = "%s not a valid BookMonographContentType, expected one of: %s"; - public static final String DELIMITER = ", "; - - private final String value; - private final String deprecatedValue; - - BookMonographContentType(String value, String deprecatedValue) { - this.value = value; - this.deprecatedValue = deprecatedValue; - } - - @JsonCreator - public static BookMonographContentType lookup(String value) { - return stream(values()) - .filter(nameType -> equalsCurrentOrDeprecatedValue(value, nameType)) - .findAny() - .orElseThrow(() -> new IllegalArgumentException(createErrorMessage(value))); - } - - @JsonValue - public String getValue() { - return value; - } - - private String getDeprecatedValue() { - return deprecatedValue; - } - - private static boolean equalsCurrentOrDeprecatedValue(String value, BookMonographContentType nameType) { - return nameType.getValue().equalsIgnoreCase(value) - || nameType.getDeprecatedValue().equalsIgnoreCase(value); - } - - private static String createErrorMessage(String value) { - return format(ERROR_MESSAGE_TEMPLATE, value, stream(BookMonographContentType.values()) - .map(BookMonographContentType::toString).collect(joining(DELIMITER))); - } -} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java index c4a364b52..761df670b 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticle.java @@ -1,14 +1,8 @@ package no.unit.nva.model.instancetypes.chapter; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.instancetypes.PeerReviewedPaper; import no.unit.nva.model.pages.Range; -import static java.util.Objects.isNull; - -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class ChapterArticle extends PeerReviewedPaper { public static final String PAGES_FIELD = "pages"; @@ -19,31 +13,4 @@ public ChapterArticle(Range pages, boolean originalResearch) { super(pages, peerReviewed, originalResearch); } - - @JsonCreator - public static ChapterArticle fromJson(@JsonProperty(PAGES_FIELD) Range pages, - @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed, - @JsonProperty("originalResearch") boolean originalResearch, - @JsonProperty("contentType") ChapterArticleContentType contentType) { - if (ChapterArticleContentType.ACADEMIC_CHAPTER.equals(contentType)) { - return new AcademicChapter(pages, peerReviewed); - } else if (ChapterArticleContentType.ENCYCLOPEDIA_CHAPTER.equals(contentType)) { - return new EncyclopediaChapter(pages, peerReviewed); - } else if (ChapterArticleContentType.EXHIBITION_CATALOG_CHAPTER.equals(contentType)) { - return new ExhibitionCatalogChapter(pages, peerReviewed); - } else if (ChapterArticleContentType.INTRODUCTION.equals(contentType)) { - return new Introduction(pages, peerReviewed); - } else if (ChapterArticleContentType.NON_FICTION_CHAPTER.equals(contentType)) { - return new NonFictionChapter(pages, peerReviewed); - } else if (ChapterArticleContentType.POPULAR_SCIENCE_CHAPTER.equals(contentType)) { - return new PopularScienceChapter(pages, peerReviewed); - } else if (ChapterArticleContentType.TEXTBOOK_CHAPTER.equals(contentType)) { - return new TextbookChapter(pages, peerReviewed); - } else if (isNull(contentType)) { - return new AcademicChapter(pages, peerReviewed); - } else { - throw new UnsupportedOperationException("The Chapter article subtype is unknown"); - } - } - } diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java deleted file mode 100644 index 9c482164f..000000000 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentType.java +++ /dev/null @@ -1,67 +0,0 @@ -package no.unit.nva.model.instancetypes.chapter; - -import static java.lang.String.format; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Content type for 'Chapter in Anthology' resource subtype when the creator chooses, 'Chapter' Resource type while - * registering a publication. - */ -@Deprecated -public enum ChapterArticleContentType { - ACADEMIC_CHAPTER("AcademicChapter", "Academic Chapter"), - NON_FICTION_CHAPTER("NonFictionChapter", "Non-fiction Chapter"), - POPULAR_SCIENCE_CHAPTER("PopularScienceChapter", "Popular Science Chapter"), - TEXTBOOK_CHAPTER("TextbookChapter", "Textbook Chapter"), - ENCYCLOPEDIA_CHAPTER("EncyclopediaChapter", "Encyclopedia Chapter"), - /** - * Introduction in anthology: Introductory chapter in an anthology. - */ - INTRODUCTION("Introduction", "Introduction"), - /** - * Chapter in Exhibition catalogue: A chapter in an exhibition catalogue, if it is written as an anthology and not a - * monograph. - */ - EXHIBITION_CATALOG_CHAPTER("ExhibitionCatalogChapter", "Exhibition Catalog Chapter"); - - public static final String ERROR_MESSAGE_TEMPLATE = "%s not a valid ChapterContentType, expected one of: %s"; - public static final String DELIMITER = ", "; - - private final String value; - private final String deprecatedValue; - - ChapterArticleContentType(String value, String deprecatedValue) { - this.value = value; - this.deprecatedValue = deprecatedValue; - } - - @JsonCreator - public static ChapterArticleContentType lookup(String value) { - return stream(values()) - .filter(nameType -> equalsCurrentOrDeprecatedValue(value, nameType)) - .findAny() - .orElseThrow(() -> new IllegalArgumentException(createErrorMessage(value))); - } - - @JsonValue - public String getValue() { - return value; - } - - private String getDeprecatedValue() { - return deprecatedValue; - } - - private static boolean equalsCurrentOrDeprecatedValue(String value, ChapterArticleContentType nameType) { - return nameType.getValue().equalsIgnoreCase(value) - || nameType.getDeprecatedValue().equalsIgnoreCase(value); - } - - private static String createErrorMessage(String value) { - return format(ERROR_MESSAGE_TEMPLATE, value, stream(ChapterArticleContentType.values()) - .map(ChapterArticleContentType::toString).collect(joining(DELIMITER))); - } -} diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticle.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticle.java index 7ec5ce4c1..58b916551 100644 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticle.java +++ b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticle.java @@ -1,26 +1,18 @@ package no.unit.nva.model.instancetypes.journal; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import no.unit.nva.model.instancetypes.PeerReviewedPaper; import no.unit.nva.model.pages.Range; import nva.commons.core.JacocoGenerated; import java.util.Objects; -import static java.util.Objects.isNull; - -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public class JournalArticle extends PeerReviewedPaper { public static final String PAGES_FIELD = "pages"; public static final String PEER_REVIEWED_FIELD = "peerReviewed"; - public static final String ORIGINAL_RESEARCH_FIELD = "originalResearch"; public static final String TYPE = "type"; public static final String VOLUME_FIELD = "volume"; public static final String ISSUE_FIELD = "issue"; public static final String ARTICLE_NUMBER_FIELD = "articleNumber"; - public static final String CONTENT_TYPE_FIELD = "contentType"; private String volume; private String issue; private String articleNumber; @@ -37,33 +29,6 @@ protected JournalArticle(Range pages, this.articleNumber = articleNumber; } - @JsonCreator - public static JournalArticle fromJson(@JsonProperty(PAGES_FIELD) Range pages, - @JsonProperty(PEER_REVIEWED_FIELD) boolean peerReviewed, - @JsonProperty(ORIGINAL_RESEARCH_FIELD) boolean originalResearch, - @JsonProperty(VOLUME_FIELD) String volume, - @JsonProperty(ISSUE_FIELD) String issue, - @JsonProperty(ARTICLE_NUMBER_FIELD) String articleNumber, - @JsonProperty(CONTENT_TYPE_FIELD) JournalArticleContentType contentType) { - if (JournalArticleContentType.ACADEMIC_ARTICLE.equals(contentType)) { - return new AcademicArticle(pages, peerReviewed, volume, issue, articleNumber); - } else if (JournalArticleContentType.ACADEMIC_LITERATURE_REVIEW.equals(contentType)) { - return new AcademicLiteratureReview(pages, peerReviewed, volume, issue, articleNumber); - } else if (JournalArticleContentType.CASE_REPORT.equals(contentType)) { - return new CaseReport(pages, peerReviewed, volume, issue, articleNumber); - } else if (JournalArticleContentType.POPULAR_SCIENCE_ARTICLE.equals(contentType)) { - return new PopularScienceArticle(pages, peerReviewed, volume, issue, articleNumber); - } else if (JournalArticleContentType.PROFESSIONAL_ARTICLE.equals(contentType)) { - return new ProfessionalArticle(pages, peerReviewed, volume, issue, articleNumber); - } else if (JournalArticleContentType.STUDY_PROTOCOL.equals(contentType)) { - return new StudyProtocol(pages, peerReviewed, volume, issue, articleNumber); - } else if (isNull(contentType)) { - return new AcademicArticle(pages, peerReviewed, volume, issue, articleNumber); - } else { - throw new UnsupportedOperationException("The Journal article subtype is unknown"); - } - } - public String getVolume() { return volume; } @@ -123,57 +88,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(super.hashCode(), getVolume(), getIssue(), getArticleNumber()); } - - public static final class Builder { - private boolean peerReviewed; - private boolean originalResearch; - private Range pages; - private JournalArticleContentType type; - private String volume; - private String issue; - private String articleNumber; - - public Builder() { - } - - public Builder withPeerReviewed(boolean peerReviewed) { - this.peerReviewed = peerReviewed; - return this; - } - - public Builder withOriginalResearch(boolean originalResearch) { - this.originalResearch = originalResearch; - return this; - } - - public Builder withPages(Range pages) { - this.pages = pages; - return this; - } - - public Builder withType(JournalArticleContentType type) { - this.type = type; - return this; - } - - public Builder withVolume(String volume) { - this.volume = volume; - return this; - } - - public Builder withIssue(String issue) { - this.issue = issue; - return this; - } - - public Builder withArticleNumber(String articleNumber) { - this.articleNumber = articleNumber; - return this; - } - - public JournalArticle build() { - return new JournalArticle(pages, peerReviewed, originalResearch, volume, - issue, articleNumber); - } - } } diff --git a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentType.java b/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentType.java deleted file mode 100644 index 62bbee54c..000000000 --- a/nva-datamodel-java/src/main/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentType.java +++ /dev/null @@ -1,56 +0,0 @@ -package no.unit.nva.model.instancetypes.journal; - -import static java.lang.String.format; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -@Deprecated -public enum JournalArticleContentType { - ACADEMIC_ARTICLE("AcademicArticle", "Research article"), - ACADEMIC_LITERATURE_REVIEW("AcademicLiteratureReview", "Review article"), - CASE_REPORT("CaseReport", "Case report"), - STUDY_PROTOCOL("StudyProtocol", "Study protocol"), - PROFESSIONAL_ARTICLE("ProfessionalArticle", "Professional article"), - POPULAR_SCIENCE_ARTICLE("PopularScienceArticle", "Popular science article"); - - public static final String ERROR_MESSAGE_TEMPLATE = "%s not a valid JournalArticleContentType, expected one of: %s"; - public static final String DELIMITER = ", "; - - private final String value; - private final String deprecatedValue; - - JournalArticleContentType(String value, String deprecatedValue) { - this.deprecatedValue = deprecatedValue; - this.value = value; - } - - @JsonCreator - public static JournalArticleContentType lookup(String value) { - return stream(values()) - .filter(nameType -> equalsCurrentOrDeprecatedValue(value, nameType)) - .findAny() - .orElseThrow(() -> new IllegalArgumentException(createErrorMessage(value))); - } - - @JsonValue - public String getValue() { - return value; - } - - @Deprecated - private String getDeprecatedValue() { - return deprecatedValue; - } - - private static boolean equalsCurrentOrDeprecatedValue(String value, JournalArticleContentType nameType) { - return nameType.getValue().equalsIgnoreCase(value) - || nameType.getDeprecatedValue().equalsIgnoreCase(value); - } - - private static String createErrorMessage(String value) { - return format(ERROR_MESSAGE_TEMPLATE, value, stream(JournalArticleContentType.values()) - .map(JournalArticleContentType::toString).collect(joining(DELIMITER))); - } -} diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java deleted file mode 100644 index 35bb98275..000000000 --- a/nva-datamodel-java/src/test/java/no/unit/nva/MigrateChapterArticleSubtypesTest.java +++ /dev/null @@ -1,199 +0,0 @@ -package no.unit.nva; - -import no.unit.nva.commons.json.JsonUtils; -import no.unit.nva.model.Publication; -import no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -import static nva.commons.core.attempt.Try.attempt; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; - -class MigrateChapterArticleSubtypesTest { - @ParameterizedTest - @EnumSource(ChapterArticleContentType.class) - void shouldDeserializeOldSubtypeBookMonographContentTypeAsType(ChapterArticleContentType content) { - var type = content.getValue(); - var json = generateFullChapterArticleWithContentType(type); - var chapterArticle = attempt(() -> JsonUtils.dtoObjectMapper.readValue(json, Publication.class)) - .orElseThrow(); - var actual = chapterArticle.getEntityDescription() - .getReference().getPublicationInstance().getClass().getSimpleName(); - assertThat(actual, is(equalTo(type))); - } - - private String generateFullChapterArticleWithContentType(String type) { - return "{\n" - + " \"type\" : \"Publication\",\n" - + " \"identifier\" : \"c443030e-9d56-43d8-afd1-8c89105af555\",\n" - + " \"status\" : \"NEW\",\n" - + " \"resourceOwner\" : {\n" - + " \"owner\" : \"RuYrbdooUL32\",\n" - + " \"ownerAffiliation\" : \"https://www.example.org/repellateum\"\n" - + " },\n" - + " \"publisher\" : {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.org/errorrem\",\n" - + " \"labels\" : {\n" - + " \"bg\" : \"ttgW11eA97cznnf4GC4\"\n" - + " }\n" - + " },\n" - + " \"createdDate\" : \"2020-07-28T09:09:48.320Z\",\n" - + " \"modifiedDate\" : \"2002-08-03T23:05:35.416Z\",\n" - + " \"publishedDate\" : \"1991-09-28T07:19:46.957Z\",\n" - + " \"indexedDate\" : \"1983-09-18T05:29:53.500Z\",\n" - + " \"handle\" : \"https://www.example.org/repudiandaeullam\",\n" - + " \"doi\" : \"https://doi.org/10.1234/dolore\",\n" - + " \"link\" : \"https://www.example.org/reprehenderitsaepe\",\n" - + " \"entityDescription\" : {\n" - + " \"type\" : \"EntityDescription\",\n" - + " \"mainTitle\" : \"BLYSKI1nfdbkv\",\n" - + " \"alternativeTitles\" : {\n" - + " \"el\" : \"zm6679gekbLZW\"\n" - + " },\n" - + " \"language\" : \"http://lexvo.org/id/iso639-3/und\",\n" - + " \"date\" : {\n" - + " \"type\" : \"PublicationDate\",\n" - + " \"year\" : \"XXAhi6akNONu\",\n" - + " \"month\" : \"HEQzNoatbd6NSMKHRg0\",\n" - + " \"day\" : \"2ESjpduz4r7bS\"\n" - + " },\n" - + " \"contributors\" : [ {\n" - + " \"type\" : \"Contributor\",\n" - + " \"identity\" : {\n" - + " \"type\" : \"Identity\",\n" - + " \"id\" : \"https://www.example.com/XhSa9gtoce12\",\n" - + " \"name\" : \"75efqCBNvlir7c\",\n" - + " \"nameType\" : \"Organizational\",\n" - + " \"orcId\" : \"t5ZYTi4TYLff\"\n" - + " },\n" - + " \"affiliations\" : [ {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.com/6HhoBSEkueTu2Z\",\n" - + " \"labels\" : {\n" - + " \"cs\" : \"x4Pn570F0gnE\"\n" - + " }\n" - + " } ],\n" - + " \"role\" : \"Curator\",\n" - + " \"sequence\" : 0,\n" - + " \"correspondingAuthor\" : false\n" - + " }, {\n" - + " \"type\" : \"Contributor\",\n" - + " \"identity\" : {\n" - + " \"type\" : \"Identity\",\n" - + " \"id\" : \"https://www.example.com/XzqAR37csm9zWJ\",\n" - + " \"name\" : \"4R2jeB61pvak8IWqj8H\",\n" - + " \"nameType\" : \"Organizational\",\n" - + " \"orcId\" : \"Aog7SFb5e54M\"\n" - + " },\n" - + " \"affiliations\" : [ {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.com/N6MywIzDqqmSv4k4\",\n" - + " \"labels\" : {\n" - + " \"en\" : \"OL3z1bGqeL0LzNza\"\n" - + " }\n" - + " } ],\n" - + " \"role\" : \"Artist\",\n" - + " \"sequence\" : 5,\n" - + " \"correspondingAuthor\" : false\n" - + " } ],\n" - + " \"npiSubjectHeading\" : \"Rk8MXIukbIzwqLP6\",\n" - + " \"tags\" : [ \"S4dKS7Cn5r6\" ],\n" - + " \"description\" : \"w2BzLiBJVxLFuROrnY\",\n" - + " \"reference\" : {\n" - + " \"type\" : \"Reference\",\n" - + " \"publicationContext\" : {\n" - + " \"type\" : \"Chapter\",\n" - + " \"partOf\" : \"https://www.example.com/8Fj6K3c2Eyx\"\n" - + " },\n" - + " \"doi\" : \"https://www.example.com/TVeL0ieitk1mLBbMH\",\n" - + " \"publicationInstance\" : {\n" - + " \"type\" : \"ChapterArticle\",\n" - + " \"contentType\" : \"" + type + "\",\n" - + " \"peerReviewed\" : true,\n" - + " \"originalResearch\" : true,\n" - + " \"pages\" : {\n" - + " \"type\" : \"Range\",\n" - + " \"begin\" : \"qDEY1GhYXtxTVxAdE\",\n" - + " \"end\" : \"r3L4UKe6bg10Sqoj\"\n" - + " }\n" - + " }\n" - + " },\n" - + " \"metadataSource\" : \"https://www.example.com/Ag6Qro62b8DvL9p4\",\n" - + " \"abstract\" : \"CBLk1w1sHe\"\n" - + " },\n" - + " \"projects\" : [ {\n" - + " \"type\" : \"ResearchProject\",\n" - + " \"id\" : \"https://www.example.org/aliassaepe\",\n" - + " \"name\" : \"LOumMwmN3JQmFxCY8Ha\",\n" - + " \"approvals\" : [ {\n" - + " \"type\" : \"Approval\",\n" - + " \"date\" : \"2023-01-08T09:20:28.086Z\",\n" - + " \"approvedBy\" : \"REK\",\n" - + " \"approvalStatus\" : \"DECLINED\",\n" - + " \"applicationCode\" : \"xwWwEn0awmly\"\n" - + " } ]\n" - + " } ],\n" - + " \"fundings\" : [ {\n" - + " \"type\" : \"UnconfirmedFunding\",\n" - + " \"source\" : \"https://www.example.org/voluptatemsed\",\n" - + " \"identifier\" : \"Ue3A2hsgEG\",\n" - + " \"labels\" : {\n" - + " \"fr\" : \"gUeWn5rgnIaZ902P0Gm\"\n" - + " },\n" - + " \"fundingAmount\" : {\n" - + " \"currency\" : \"USD\",\n" - + " \"amount\" : 161825051\n" - + " },\n" - + " \"activeFrom\" : \"2011-05-05T00:03:24.088Z\",\n" - + " \"activeTo\" : \"2019-03-27T14:38:32.956Z\"\n" - + " }, {\n" - + " \"type\" : \"ConfirmedFunding\",\n" - + " \"source\" : \"https://www.example.org/laboriosamneque\",\n" - + " \"id\" : \"https://www.example.org/nullaquia\",\n" - + " \"identifier\" : \"Dl1wT7xbmq4C2I4sQKx\",\n" - + " \"labels\" : {\n" - + " \"da\" : \"H1ERfelmzeBQxdSs\"\n" - + " },\n" - + " \"fundingAmount\" : {\n" - + " \"currency\" : \"GBP\",\n" - + " \"amount\" : 981864134\n" - + " },\n" - + " \"activeFrom\" : \"1973-04-26T21:20:47.124Z\",\n" - + " \"activeTo\" : \"2018-03-07T11:19:24.360Z\"\n" - + " } ],\n" - + " \"additionalIdentifiers\" : [ {\n" - + " \"type\" : \"AdditionalIdentifier\",\n" - + " \"source\" : \"fakesource\",\n" - + " \"value\" : \"1234\"\n" - + " } ],\n" - + " \"subjects\" : [ \"https://www.example.org/maximevel\" ],\n" - + " \"associatedArtifacts\" : [ {\n" - + " \"type\" : \"PublishedFile\",\n" - + " \"identifier\" : \"46725458-c60c-44a6-a952-41d25c9e5de3\",\n" - + " \"name\" : \"gEUP4JgMXh1Q\",\n" - + " \"mimeType\" : \"orcFMiw4ZnM\",\n" - + " \"size\" : 1581080284,\n" - + " \"license\" : {\n" - + " \"type\" : \"License\",\n" - + " \"identifier\" : \"7PYHmgVdvENJTYWcm\",\n" - + " \"labels\" : {\n" - + " \"fi\" : \"0SwxwFiSVRwQvz5ijCd\"\n" - + " },\n" - + " \"link\" : \"https://www.example.com/PSyujG3bq4ccWVvdhL\"\n" - + " },\n" - + " \"administrativeAgreement\" : false,\n" - + " \"publisherAuthority\" : true,\n" - + " \"visibleForNonOwner\" : true\n" - + " }, {\n" - + " \"type\" : \"AssociatedLink\",\n" - + " \"id\" : \"https://www.example.com/GclXAVyGmqRrJ\",\n" - + " \"name\" : \"XS2oxVRgVr\",\n" - + " \"description\" : \"xRPrvEVJRdwxZ\"\n" - + " } ],\n" - + " \"modelVersion\" : \"0.19.29\"\n" - + "}"; - } -} diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java deleted file mode 100644 index 6c287c818..000000000 --- a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationBookMonographSubtypesTest.java +++ /dev/null @@ -1,214 +0,0 @@ -package no.unit.nva; - -import no.unit.nva.commons.json.JsonUtils; -import no.unit.nva.model.Publication; -import no.unit.nva.model.instancetypes.book.BookMonographContentType; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -import static nva.commons.core.attempt.Try.attempt; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; - -@Deprecated -class MigrationBookMonographSubtypesTest { - @ParameterizedTest - @EnumSource(BookMonographContentType.class) - void shouldDeserializeOldSubtypeBookMonographContentTypeAsType(BookMonographContentType content) { - var type = content.getValue(); - var json = generateFullBookMonographWithContentType(type); - var bookMonograph = attempt(() -> JsonUtils.dtoObjectMapper.readValue(json, Publication.class)) - .orElseThrow(); - var actual = bookMonograph.getEntityDescription() - .getReference().getPublicationInstance().getClass().getSimpleName(); - assertThat(actual, is(equalTo(type))); - } - - private String generateFullBookMonographWithContentType(String type) { - return "{\n" - + " \"type\" : \"Publication\",\n" - + " \"identifier\" : \"c443030e-9d56-43d8-afd1-8c89105af555\",\n" - + " \"status\" : \"NEW\",\n" - + " \"resourceOwner\" : {\n" - + " \"owner\" : \"tB62sIFYKg\",\n" - + " \"ownerAffiliation\" : \"https://www.example.org/commodiut\"\n" - + " },\n" - + " \"publisher\" : {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.org/suscipitat\",\n" - + " \"labels\" : {\n" - + " \"ru\" : \"mrH4HAV6aEDjGNRJ2\"\n" - + " }\n" - + " },\n" - + " \"createdDate\" : \"1972-05-08T00:12:05.315Z\",\n" - + " \"modifiedDate\" : \"2019-09-28T13:25:15.960Z\",\n" - + " \"publishedDate\" : \"1975-01-08T02:19:20.777Z\",\n" - + " \"indexedDate\" : \"2007-03-21T06:29:45.706Z\",\n" - + " \"handle\" : \"https://www.example.org/expeditaaliquam\",\n" - + " \"doi\" : \"https://doi.org/10.1234/voluptas\",\n" - + " \"link\" : \"https://www.example.org/hicsoluta\",\n" - + " \"entityDescription\" : {\n" - + " \"type\" : \"EntityDescription\",\n" - + " \"mainTitle\" : \"TJiBWzUbcYOsg1Bh6ar\",\n" - + " \"alternativeTitles\" : {\n" - + " \"pl\" : \"u6W8XtFlErl7CT20H\"\n" - + " },\n" - + " \"language\" : \"http://lexvo.org/id/iso639-3/und\",\n" - + " \"date\" : {\n" - + " \"type\" : \"PublicationDate\",\n" - + " \"year\" : \"tYcREtuLoDw5l9YZV\",\n" - + " \"month\" : \"gMzfA9CfARP0qdRT\",\n" - + " \"day\" : \"EiJQbxbLQZj\"\n" - + " },\n" - + " \"contributors\" : [ {\n" - + " \"type\" : \"Contributor\",\n" - + " \"identity\" : {\n" - + " \"type\" : \"Identity\",\n" - + " \"id\" : \"https://www.example.com/GqttyV980NRYL8Pfp\",\n" - + " \"name\" : \"rA6GkyIRJGv2di\",\n" - + " \"nameType\" : \"Personal\",\n" - + " \"orcId\" : \"9DtRI5qSVrxx\"\n" - + " },\n" - + " \"affiliations\" : [ {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.com/O9IL4Q16jMMTmyFa\",\n" - + " \"labels\" : {\n" - + " \"af\" : \"A3H5OIKOwrqriOct\"\n" - + " }\n" - + " } ],\n" - + " \"role\" : \"ContactPerson\",\n" - + " \"sequence\" : 7,\n" - + " \"correspondingAuthor\" : false\n" - + " }, {\n" - + " \"type\" : \"Contributor\",\n" - + " \"identity\" : {\n" - + " \"type\" : \"Identity\",\n" - + " \"id\" : \"https://www.example.com/Ele611kKvbKnqeL\",\n" - + " \"name\" : \"TIE6zIiWCWLpfvK\",\n" - + " \"nameType\" : \"Organizational\",\n" - + " \"orcId\" : \"aJ1pvnZ8FVOh5\"\n" - + " },\n" - + " \"affiliations\" : [ {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.com/CszMv40Wx2OX\",\n" - + " \"labels\" : {\n" - + " \"af\" : \"CCP5RUwJlFTQTzL\"\n" - + " }\n" - + " } ],\n" - + " \"role\" : \"Dramatist\",\n" - + " \"sequence\" : 0,\n" - + " \"correspondingAuthor\" : false\n" - + " } ],\n" - + " \"npiSubjectHeading\" : \"RCjSANi9tVDH0X1lEN\",\n" - + " \"tags\" : [ \"gyNAMEiHlZuJT\" ],\n" - + " \"description\" : \"TBlPsIoaVroQdh\",\n" - + " \"reference\" : {\n" - + " \"type\" : \"Reference\",\n" - + " \"publicationContext\" : {\n" - + " \"type\" : \"Book\",\n" - + " \"series\" : {\n" - + " \"type\" : \"Series\",\n" - + " \"id\" : \"https://api.dev.nva.aws.unit.no/publication-channels/gTApbmIXv6\"\n" - + " },\n" - + " \"seriesNumber\" : \"wmHi1PgzWPm86KCe6\",\n" - + " \"publisher\" : {\n" - + " \"type\" : \"Publisher\",\n" - + " \"id\" : \"https://api.dev.nva.aws.unit.no/publication-channels/rLViYfagIJ\"\n" - + " },\n" - + " \"isbnList\" : [ \"9790094516099\" ]\n" - + " },\n" - + " \"doi\" : \"https://www.example.com/FbubVFoXuT\",\n" - + " \"publicationInstance\" : {\n" - + " \"type\" : \"BookMonograph\",\n" - + " \"contentType\" : \"" + type + "\",\n" - + " \"originalResearch\" : false,\n" - + " \"peerReviewed\" : false,\n" - + " \"pages\" : {\n" - + " \"type\" : \"MonographPages\",\n" - + " \"introduction\" : {\n" - + " \"type\" : \"Range\",\n" - + " \"begin\" : \"9n2jMU0p6vPI9pcqQyi\",\n" - + " \"end\" : \"QAYvjiCUvm\"\n" - + " },\n" - + " \"pages\" : \"rXSsjeWG62j\",\n" - + " \"illustrated\" : false\n" - + " }\n" - + " }\n" - + " },\n" - + " \"metadataSource\" : \"https://www.example.com/TJrqCkHQVrIt0j\",\n" - + " \"abstract\" : \"TRcbF8cf89PgTuBk\"\n" - + " },\n" - + " \"projects\" : [ {\n" - + " \"type\" : \"ResearchProject\",\n" - + " \"id\" : \"https://www.example.org/perferendisharum\",\n" - + " \"name\" : \"ESFpOgIIS4q9dW6\",\n" - + " \"approvals\" : [ {\n" - + " \"type\" : \"Approval\",\n" - + " \"date\" : \"1993-11-28T10:21:43.195Z\",\n" - + " \"approvedBy\" : \"NARA\",\n" - + " \"approvalStatus\" : \"APPLIED\",\n" - + " \"applicationCode\" : \"UZlpisZwYl0NJVz6lLy\"\n" - + " } ]\n" - + " } ],\n" - + " \"fundings\" : [ {\n" - + " \"type\" : \"UnconfirmedFunding\",\n" - + " \"source\" : \"https://www.example.org/eamagnam\",\n" - + " \"identifier\" : \"0kIBfGDot4QwO2kb\",\n" - + " \"labels\" : {\n" - + " \"it\" : \"JF3ZSl24zL\"\n" - + " },\n" - + " \"fundingAmount\" : {\n" - + " \"currency\" : \"USD\",\n" - + " \"amount\" : 1138272242\n" - + " },\n" - + " \"activeFrom\" : \"2003-11-07T09:15:50.695Z\",\n" - + " \"activeTo\" : \"2015-08-01T19:20:16.941Z\"\n" - + " }, {\n" - + " \"type\" : \"ConfirmedFunding\",\n" - + " \"source\" : \"https://www.example.org/fugiatsapiente\",\n" - + " \"id\" : \"https://www.example.org/suntmagni\",\n" - + " \"identifier\" : \"BNo5moC50NfbNBo\",\n" - + " \"labels\" : {\n" - + " \"sv\" : \"q7am4xSOFZpHduBza\"\n" - + " },\n" - + " \"fundingAmount\" : {\n" - + " \"currency\" : \"EUR\",\n" - + " \"amount\" : 873582428\n" - + " },\n" - + " \"activeFrom\" : \"1974-04-25T00:39:51.618Z\",\n" - + " \"activeTo\" : \"2018-06-05T01:03:44.768Z\"\n" - + " } ],\n" - + " \"additionalIdentifiers\" : [ {\n" - + " \"type\" : \"AdditionalIdentifier\",\n" - + " \"source\" : \"fakesource\",\n" - + " \"value\" : \"1234\"\n" - + " } ],\n" - + " \"subjects\" : [ \"https://www.example.org/quaeratdolorem\" ],\n" - + " \"associatedArtifacts\" : [ {\n" - + " \"type\" : \"PublishedFile\",\n" - + " \"identifier\" : \"86406e82-636e-4ddb-8e07-fd6619ec3aa0\",\n" - + " \"name\" : \"bNvv7O5PyKT\",\n" - + " \"mimeType\" : \"gVDXmTw9H2gqBRm\",\n" - + " \"size\" : 838225864,\n" - + " \"license\" : {\n" - + " \"type\" : \"License\",\n" - + " \"identifier\" : \"Y1VBFAUQrmps39Lg\",\n" - + " \"labels\" : {\n" - + " \"bg\" : \"uhHKMW0QVPFmPcluDo\"\n" - + " },\n" - + " \"link\" : \"https://www.example.com/LwqTEw9Ulq\"\n" - + " },\n" - + " \"administrativeAgreement\" : false,\n" - + " \"publisherAuthority\" : true,\n" - + " \"visibleForNonOwner\" : true\n" - + " }, {\n" - + " \"type\" : \"AssociatedLink\",\n" - + " \"id\" : \"https://www.example.com/qlvWdNWNyFWfvk5qg6X\",\n" - + " \"name\" : \"Otvp1638EBdF0mJ\",\n" - + " \"description\" : \"ewjrLNbRKEdzqKM\"\n" - + " } ],\n" - + " \"modelVersion\" : \"0.19.29\"\n" - + "}"; - } -} diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationJournalArticleSubtypes.java b/nva-datamodel-java/src/test/java/no/unit/nva/MigrationJournalArticleSubtypes.java deleted file mode 100644 index 29ca2c15c..000000000 --- a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationJournalArticleSubtypes.java +++ /dev/null @@ -1,192 +0,0 @@ -package no.unit.nva; - -import no.unit.nva.commons.json.JsonUtils; -import no.unit.nva.model.Publication; -import no.unit.nva.model.instancetypes.journal.JournalArticleContentType; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -import static nva.commons.core.attempt.Try.attempt; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; - -@Deprecated -class MigrationJournalArticleSubtypes { - - @ParameterizedTest - @EnumSource(JournalArticleContentType.class) - void shouldDeserializeOldSubtypeJournalArticleContentTypeAsType(JournalArticleContentType content) { - var type = content.getValue(); - var json = generateFullJournalArticleWithContentType(type); - var journalArticle = attempt(() -> JsonUtils.dtoObjectMapper.readValue(json, Publication.class)) - .orElseThrow(); - var actual = journalArticle.getEntityDescription() - .getReference().getPublicationInstance().getClass().getSimpleName(); - assertThat(actual, is(equalTo(type))); - } - - private static String generateFullJournalArticleWithContentType(String contentType) { - return "{\n" - + " \"type\" : \"Publication\",\n" - + " \"identifier\" : \"c443030e-9d56-43d8-afd1-8c89105af555\",\n" - + " \"status\" : \"PUBLISHED_METADATA\",\n" - + " \"resourceOwner\" : {\n" - + " \"owner\" : \"4TmBjGCN1AmmBB4I3j\",\n" - + " \"ownerAffiliation\" : \"https://www.example.org/nobisqui\"\n" - + " },\n" - + " \"publisher\" : {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.org/amolestiae\",\n" - + " \"labels\" : {\n" - + " \"it\" : \"M2qeYhojtzlFhOf\"\n" - + " }\n" - + " },\n" - + " \"createdDate\" : \"1972-09-01T04:35:34.770Z\",\n" - + " \"modifiedDate\" : \"2001-08-13T14:29:04.580Z\",\n" - + " \"publishedDate\" : \"2020-12-23T06:01:38.371Z\",\n" - + " \"indexedDate\" : \"1980-08-06T18:33:15.367Z\",\n" - + " \"handle\" : \"https://www.example.org/ipsaea\",\n" - + " \"doi\" : \"https://doi.org/10.1234/eaque\",\n" - + " \"link\" : \"https://www.example.org/utvoluptatem\",\n" - + " \"entityDescription\" : {\n" - + " \"type\" : \"EntityDescription\",\n" - + " \"mainTitle\" : \"qIZNaXDKymx\",\n" - + " \"alternativeTitles\" : {\n" - + " \"is\" : \"Z9zlbat2Klf\"\n" - + " },\n" - + " \"language\" : \"http://lexvo.org/id/iso639-3/und\",\n" - + " \"date\" : {\n" - + " \"type\" : \"PublicationDate\",\n" - + " \"year\" : \"WhMPvnAqZD8c\",\n" - + " \"month\" : \"XkeaMca9UppPjCVvRK4\",\n" - + " \"day\" : \"wkAWmWCQ3M1brzNZiI\"\n" - + " },\n" - + " \"contributors\" : [ {\n" - + " \"type\" : \"Contributor\",\n" - + " \"identity\" : {\n" - + " \"type\" : \"Identity\",\n" - + " \"id\" : \"https://www.example.com/X4wvTuNwAc8QqQeB\",\n" - + " \"name\" : \"cpH3rsLYy2O9qzfP\",\n" - + " \"nameType\" : \"Organizational\",\n" - + " \"orcId\" : \"jhOSXlkR3PpeG4N\"\n" - + " },\n" - + " \"affiliations\" : [ {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.com/SHf08a2UT8yiL4\",\n" - + " \"labels\" : {\n" - + " \"hu\" : \"hzppegUya2siCVvvVJ\"\n" - + " }\n" - + " } ],\n" - + " \"role\" : \"Writer\",\n" - + " \"sequence\" : 4,\n" - + " \"correspondingAuthor\" : false\n" - + " }, {\n" - + " \"type\" : \"Contributor\",\n" - + " \"identity\" : {\n" - + " \"type\" : \"Identity\",\n" - + " \"id\" : \"https://www.example.com/7oS1BcncWcDwx2JP\",\n" - + " \"name\" : \"oVR3pdbUvaepV\",\n" - + " \"nameType\" : \"Organizational\",\n" - + " \"orcId\" : \"SKr9XyTuIi\"\n" - + " },\n" - + " \"affiliations\" : [ {\n" - + " \"type\" : \"Organization\",\n" - + " \"id\" : \"https://www.example.com/MeBieb0Tyihiy\",\n" - + " \"labels\" : {\n" - + " \"ca\" : \"Sto0PAY8C0\"\n" - + " }\n" - + " } ],\n" - + " \"role\" : \"Soloist\",\n" - + " \"sequence\" : 5,\n" - + " \"correspondingAuthor\" : false\n" - + " } ],\n" - + " \"npiSubjectHeading\" : \"GuBHWYxnyMn2gU\",\n" - + " \"tags\" : [ \"xpdNqJyRETrdW\" ],\n" - + " \"description\" : \"WIQwOUiT9Qu8HNQA\",\n" - + " \"reference\" : {\n" - + " \"type\" : \"Reference\",\n" - + " \"publicationContext\" : {\n" - + " \"type\" : \"Journal\",\n" - + " \"id\" : \"https://api.dev.nva.aws.unit.no/publication-channels/eujd55boZtis7Ql0\"\n" - + " },\n" - + " \"doi\" : \"https://www.example.com/aFCyqrhxxyTnOW\",\n" - + " \"publicationInstance\" : {\n" - + " \"type\" : \"JournalArticle\",\n" - + " \"volume\" : \"d8lgJKdVnFH51\",\n" - + " \"issue\" : \"1SOozXNuiS8uojXSO\",\n" - + " \"articleNumber\" : \"BtGFNkZzVs1CKwjJLz\",\n" - + " \"contentType\" : \"" + contentType + "\",\n" - + " \"peerReviewed\" : true,\n" - + " \"originalResearch\" : false,\n" - + " \"pages\" : {\n" - + " \"type\" : \"Range\",\n" - + " \"begin\" : \"OiCuLxrY5vHYhtB0\",\n" - + " \"end\" : \"cs3eFzfcJ9lzs\"\n" - + " }\n" - + " }\n" - + " },\n" - + " \"metadataSource\" : \"https://www.example.com/Q86zpd2W9M\",\n" - + " \"abstract\" : \"SzqBaTsSA44k\"\n" - + " },\n" - + " \"projects\" : [ {\n" - + " \"type\" : \"ResearchProject\",\n" - + " \"id\" : \"https://www.example.org/assumendaeum\",\n" - + " \"name\" : \"qr9KS9w6G67SrtUzGmv\",\n" - + " \"approvals\" : [ {\n" - + " \"type\" : \"Approval\",\n" - + " \"date\" : \"2020-08-30T12:38:40.124Z\",\n" - + " \"approvedBy\" : \"DIRHEALTH\",\n" - + " \"approvalStatus\" : \"NOTAPPLIED\",\n" - + " \"applicationCode\" : \"bK0XmCJlYNwE0oUNb\"\n" - + " } ]\n" - + " } ],\n" - + " \"fundings\" : [ {\n" - + " \"type\" : \"ConfirmedFunding\",\n" - + " \"source\" : \"https://www.example.org/atvoluptatibus\",\n" - + " \"id\" : \"https://www.example.org/cupiditatevoluptas\",\n" - + " \"identifier\" : \"5INZCCOTpFiP8YNFmCJ\",\n" - + " \"name\" : \"7kTCaw7kUQIgeI0SXDG\",\n" - + " \"alternativeName\" : {\n" - + " \"en\" : \"QNy99yR6zoqCFq\"\n" - + " },\n" - + " \"fundingAmount\" : {\n" - + " \"currency\" : \"EUR\",\n" - + " \"amount\" : 973238067\n" - + " },\n" - + " \"activeFrom\" : \"2011-06-06T01:00:52.156Z\",\n" - + " \"activeTo\" : \"2019-05-04T03:50:10.791Z\"\n" - + " } ],\n" - + " \"additionalIdentifiers\" : [ {\n" - + " \"type\" : \"AdditionalIdentifier\",\n" - + " \"source\" : \"fakesource\",\n" - + " \"value\" : \"1234\"\n" - + " } ],\n" - + " \"subjects\" : [ \"https://www.example.org/harumquasi\" ],\n" - + " \"associatedArtifacts\" : [ {\n" - + " \"type\" : \"PublishedFile\",\n" - + " \"identifier\" : \"d8c5785c-2100-4097-b461-a7269d78bf03\",\n" - + " \"name\" : \"63IPVTamuKud3NP\",\n" - + " \"mimeType\" : \"QBk86jTCqlPBH\",\n" - + " \"size\" : 463477975,\n" - + " \"license\" : {\n" - + " \"type\" : \"License\",\n" - + " \"identifier\" : \"nmTcPkIZJPrTYF7iGE\",\n" - + " \"labels\" : {\n" - + " \"pt\" : \"XrgMENjWTy\"\n" - + " },\n" - + " \"link\" : \"https://www.example.com/w8VjoRRwdEYOUK0\"\n" - + " },\n" - + " \"administrativeAgreement\" : false,\n" - + " \"publisherAuthority\" : true,\n" - + " \"visibleForNonOwner\" : true\n" - + " }, {\n" - + " \"type\" : \"AssociatedLink\",\n" - + " \"id\" : \"https://www.example.com/Y9CEp5BhRSsNG57Ve1G\",\n" - + " \"name\" : \"sz5x297ukf2\",\n" - + " \"description\" : \"mVzLj4RXFc5Zd6DBZ7o\"\n" - + " } ],\n" - + " \"modelVersion\" : \"0.19.28\"\n" - + "}"; - } -} diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationTestingUnconfirmedPublisher.java b/nva-datamodel-java/src/test/java/no/unit/nva/MigrationTestingUnconfirmedPublisher.java deleted file mode 100644 index 527b68d08..000000000 --- a/nva-datamodel-java/src/test/java/no/unit/nva/MigrationTestingUnconfirmedPublisher.java +++ /dev/null @@ -1,152 +0,0 @@ -package no.unit.nva; - -import com.fasterxml.jackson.core.JsonProcessingException; -import no.unit.nva.commons.json.JsonUtils; -import no.unit.nva.model.instancetypes.artistic.film.realization.Broadcast; -import no.unit.nva.model.instancetypes.artistic.film.realization.OtherRelease; -import no.unit.nva.model.instancetypes.artistic.music.AudioVisualPublication; -import no.unit.nva.model.instancetypes.artistic.music.MusicScore; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - -@Deprecated -public class MigrationTestingUnconfirmedPublisher { - - @ParameterizedTest - @ValueSource(strings = {"{\n" - + " \"type\": \"Broadcast\",\n" - + " \"publisher\": \"My publisher\",\n" - + " \"date\": {\n" - + " \"type\": \"Instant\",\n" - + " \"value\": \"2022-03-23T00:00:00.000000Z\"\n" - + " },\n" - + " \"sequence\": \"1\"\n" - + "}", - "{\n" - + " \"type\": \"Broadcast\",\n" - + " \"publisher\": {\n" - + " \"type\": \"UnconfirmedPublisher\",\n" - + " \"name\": \"My publisher\"\n" - + " },\n" - + " \"date\": {\n" - + " \"type\": \"Instant\",\n" - + " \"value\": \"2022-03-23T00:00:00.000000Z\"\n" - + " },\n" - + " \"sequence\": \"1\"\n" - + "}"}) - void shouldMigrateBroadcastPublishers(String value) { - assertDoesNotThrow(() -> JsonUtils.dtoObjectMapper.readValue(value, Broadcast.class)); - - } - - @ParameterizedTest - @ValueSource(strings = {"{\n" - + " \"type\" : \"OtherRelease\",\n" - + " \"description\" : \"SmM4g4sYfz\",\n" - + " \"place\" : {\n" - + " \"type\" : \"UnconfirmedPlace\",\n" - + " \"label\" : \"dc6zWFBfBcmnzlwN1z\",\n" - + " \"country\" : \"LEQElC2GRpVi75IbqI\"\n" - + " },\n" - + " \"publisher\" : {\n" - + " \"type\" : \"UnconfirmedPublisher\",\n" - + " \"name\" : \"o3XnSxNZkyprTM7DWoQ\"\n" - + " },\n" - + " \"date\" : {\n" - + " \"type\" : \"Instant\",\n" - + " \"value\" : \"2016-01-09T00:59:20.264Z\"\n" - + " },\n" - + " \"sequence\" : 191312365\n" - + "}", - "{\n" - + " \"type\" : \"OtherRelease\",\n" - + " \"description\" : \"SmM4g4sYfz\",\n" - + " \"place\" : {\n" - + " \"type\" : \"UnconfirmedPlace\",\n" - + " \"label\" : \"dc6zWFBfBcmnzlwN1z\",\n" - + " \"country\" : \"LEQElC2GRpVi75IbqI\"\n" - + " },\n" - + " \"publisher\" : \"o3XnSxNZkyprTM7DWoQ\",\n" - + " \"date\" : {\n" - + " \"type\" : \"Instant\",\n" - + " \"value\" : \"2016-01-09T00:59:20.264Z\"\n" - + " },\n" - + " \"sequence\" : 191312365\n" - + "}"}) - void shouldMigrateOtherRelease(String value) { - assertDoesNotThrow(() -> JsonUtils.dtoObjectMapper.readValue(value, OtherRelease.class)); - } - - @ParameterizedTest - @ValueSource(strings = {"{\n" - + " \"type\" : \"AudioVisualPublication\",\n" - + " \"mediaType\" : \"DigitalFile\",\n" - + " \"publisher\" : {\n" - + " \"type\" : \"UnconfirmedPublisher\",\n" - + " \"name\" : \"zqbVxPvPBPY\"\n" - + " },\n" - + " \"catalogueNumber\" : \"qVMAjQwGCTw\",\n" - + " \"trackList\" : [ {\n" - + " \"type\" : \"MusicTrack\",\n" - + " \"title\" : \"prvhN5ATlNDbcAAX0G\",\n" - + " \"composer\" : \"DtePAk2ZjLw8Lzr\",\n" - + " \"extent\" : \"GuJRYj8fAOMcQPQSMI\"\n" - + " }]}", "{\n" - + " \"type\": \"AudioVisualPublication\",\n" - + " \"mediaType\": \"DigitalFile\",\n" - + " \"publisher\": \"UnconfirmedPublisher\",\n" - + " \"catalogueNumber\": \"qVMAjQwGCTw\",\n" - + " \"trackList\": [\n" - + " {\n" - + " \"type\": \"MusicTrack\",\n" - + " \"title\": \"prvhN5ATlNDbcAAX0G\",\n" - + " \"composer\": \"DtePAk2ZjLw8Lzr\",\n" - + " \"extent\": \"GuJRYj8fAOMcQPQSMI\"\n" - + " }\n" - + " ]\n" - + "}"}) - void shouldMigrateAudioVisualPublication(String value) { - assertDoesNotThrow(() -> JsonUtils.dtoObjectMapper.readValue(value, AudioVisualPublication.class)); - } - - @ParameterizedTest - @ValueSource(strings = {"{\n" - + " \"type\" : \"MusicScore\",\n" - + " \"ensemble\" : \"e2d9YoIg1eVxFiTZV\",\n" - + " \"movements\" : \"ID9aYllhE3N5SZ\",\n" - + " \"extent\" : \"26CJRjrfrUqOzP\",\n" - + " \"publisher\" : {\n" - + " \"type\" : \"UnconfirmedPublisher\",\n" - + " \"name\" : \"OVuxPTXnSLd7jcg\"\n" - + " },\n" - + " \"ismn\" : {\n" - + " \"type\" : \"Ismn\",\n" - + " \"value\" : \"M230671187\",\n" - + " \"formatted\" : \"M-2306-7118-7\"\n" - + " },\n" - + " \"isrc\" : {\n" - + " \"type\" : \"Isrc\",\n" - + " \"value\" : \"USRC17607839\"\n" - + " }\n" - + " }", "{\n" - + " \"type\" : \"MusicScore\",\n" - + " \"ensemble\" : \"e2d9YoIg1eVxFiTZV\",\n" - + " \"movements\" : \"ID9aYllhE3N5SZ\",\n" - + " \"extent\" : \"26CJRjrfrUqOzP\",\n" - + " \"publisher\" : \"OVuxPTXnSLd7jcg\",\n" - + " \"ismn\" : {\n" - + " \"type\" : \"Ismn\",\n" - + " \"value\" : \"M230671187\",\n" - + " \"formatted\" : \"M-2306-7118-7\"\n" - + " },\n" - + " \"isrc\" : {\n" - + " \"type\" : \"Isrc\",\n" - + " \"value\" : \"USRC17607839\"\n" - + " }\n" - + "}"}) - void shouldMigratePublisherInMusicScore(String value) { - assertDoesNotThrow(() -> JsonUtils.dtoObjectMapper.readValue(value, MusicScore.class)); - } -} diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/book/BookMonographContentTypeTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/book/BookMonographContentTypeTest.java deleted file mode 100644 index 8c48c3cc4..000000000 --- a/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/book/BookMonographContentTypeTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package no.unit.nva.model.instancetypes.book; - -import static java.lang.String.format; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; -import static no.unit.nva.model.instancetypes.book.BookMonographContentType.ACADEMIC_MONOGRAPH; -import static no.unit.nva.model.instancetypes.book.BookMonographContentType.DELIMITER; -import static no.unit.nva.model.instancetypes.book.BookMonographContentType.ERROR_MESSAGE_TEMPLATE; -import static no.unit.nva.model.instancetypes.book.BookMonographContentType.NON_FICTION_MONOGRAPH; -import static no.unit.nva.model.instancetypes.book.BookMonographContentType.POPULAR_SCIENCE_MONOGRAPH; -import static no.unit.nva.model.instancetypes.book.BookMonographContentType.values; -import static no.unit.nva.testutils.RandomDataGenerator.randomString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.exc.ValueInstantiationException; -import java.util.stream.Stream; -import no.unit.nva.commons.json.JsonUtils; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.MethodSource; - -class BookMonographContentTypeTest { - - public static Stream deprecatedValuesProvider() { - return Stream.of(Arguments.of("Academic Monograph", ACADEMIC_MONOGRAPH), - Arguments.of("Non-fiction Monograph", NON_FICTION_MONOGRAPH), - Arguments.of("Popular Science Monograph", POPULAR_SCIENCE_MONOGRAPH) - ); - } - - @ParameterizedTest - @EnumSource(BookMonographContentType.class) - void shouldReturnBookMonographContentTypeWhenInputIsCurrentValue(BookMonographContentType bookMonographContentType) - throws JsonProcessingException { - var currentValue = "\"" + bookMonographContentType.getValue() + "\""; - var expectedBookMonographContentType = JsonUtils.dtoObjectMapper.readValue(currentValue, - BookMonographContentType.class); - assertEquals(expectedBookMonographContentType, bookMonographContentType); - } - - @ParameterizedTest(name = "should return BookMonographContentType when input is {0}") - @MethodSource("deprecatedValuesProvider") - void shouldReturnBookMonographContentTypeWhenInputIsDeprecatedValue( - String deprecatedValue, - BookMonographContentType bookMonographContentType) - throws JsonProcessingException { - var deprecated = "\"" + deprecatedValue + "\""; - var expectedBookMonographContentType = JsonUtils.dtoObjectMapper.readValue(deprecated, - BookMonographContentType.class); - assertEquals(expectedBookMonographContentType, bookMonographContentType); - } - - @Test - void shouldThrowErrorWithProperErrorMessageWhenInvalidInputValueSupplied() { - var invalidInput = randomString(); - var inputJsonValue = "\"" + invalidInput + "\""; - Executable handleRequest = () -> JsonUtils.dtoObjectMapper.readValue(inputJsonValue, - BookMonographContentType.class); - - var response = assertThrows(ValueInstantiationException.class, handleRequest); - var actualErrorMessage = createErrorMessage(invalidInput); - assertThat(response.getMessage(), containsString(actualErrorMessage)); - } - - private static String createErrorMessage(String value) { - return format(ERROR_MESSAGE_TEMPLATE, value, stream(values()) - .map(BookMonographContentType::toString).collect(joining(DELIMITER))); - } -} \ No newline at end of file diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentTypeTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentTypeTest.java deleted file mode 100644 index 3de85f3f8..000000000 --- a/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/chapter/ChapterArticleContentTypeTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package no.unit.nva.model.instancetypes.chapter; - -import static java.lang.String.format; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.ACADEMIC_CHAPTER; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.DELIMITER; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.ENCYCLOPEDIA_CHAPTER; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.ERROR_MESSAGE_TEMPLATE; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.EXHIBITION_CATALOG_CHAPTER; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.INTRODUCTION; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.NON_FICTION_CHAPTER; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.POPULAR_SCIENCE_CHAPTER; -import static no.unit.nva.model.instancetypes.chapter.ChapterArticleContentType.TEXTBOOK_CHAPTER; -import static no.unit.nva.testutils.RandomDataGenerator.randomString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.exc.ValueInstantiationException; -import java.util.stream.Stream; -import no.unit.nva.commons.json.JsonUtils; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.MethodSource; - -class ChapterArticleContentTypeTest { - - public static Stream deprecatedValuesProvider() { - return Stream.of( - Arguments.of(ACADEMIC_CHAPTER, "Academic Chapter"), - Arguments.of(NON_FICTION_CHAPTER, "Non-fiction Chapter"), - Arguments.of(POPULAR_SCIENCE_CHAPTER, "Popular Science Chapter"), - Arguments.of(TEXTBOOK_CHAPTER, "Textbook Chapter"), - Arguments.of(ENCYCLOPEDIA_CHAPTER, "Encyclopedia Chapter"), - Arguments.of(INTRODUCTION, "Introduction"), - Arguments.of(EXHIBITION_CATALOG_CHAPTER, "Exhibition Catalog Chapter") - ); - } - - @ParameterizedTest - @EnumSource(ChapterArticleContentType.class) - void shouldReturnChapterArticleContentTypeWhenInputIsCurrentValue( - ChapterArticleContentType chapterArticleContentType) - throws JsonProcessingException { - var currentValue = "\"" + chapterArticleContentType.getValue() + "\""; - var expectedChapterArticleContentType = JsonUtils.dtoObjectMapper.readValue(currentValue, - ChapterArticleContentType.class); - assertEquals(expectedChapterArticleContentType, chapterArticleContentType); - } - - @ParameterizedTest(name = "should return ChapterArticleContentType when input is {0}") - @MethodSource("deprecatedValuesProvider") - void shouldReturnChapterArticleContentTypeWhenInputIsDeprecatedValue( - ChapterArticleContentType chapterArticleContentType,String deprecatedValue) - throws JsonProcessingException { - var deprecated = "\"" + deprecatedValue + "\""; - var expectedChapterArticleContentType = JsonUtils.dtoObjectMapper.readValue(deprecated, - ChapterArticleContentType.class); - assertEquals(expectedChapterArticleContentType, chapterArticleContentType); - } - - @Test - void shouldThrowErrorWithProperErrorMessageWhenInvalidInputValueSupplied() { - var invalidInput = randomString(); - var inputJsonValue = "\"" + invalidInput + "\""; - Executable handleRequest = () -> JsonUtils.dtoObjectMapper.readValue(inputJsonValue, - ChapterArticleContentType.class); - - var response = assertThrows(ValueInstantiationException.class, handleRequest); - var actualErrorMessage = createErrorMessage(invalidInput); - assertThat(response.getMessage(), containsString(actualErrorMessage)); - } - - private static String createErrorMessage(String value) { - return format(ERROR_MESSAGE_TEMPLATE, value, stream(ChapterArticleContentType.values()) - .map(ChapterArticleContentType::toString).collect(joining(DELIMITER))); - } -} \ No newline at end of file diff --git a/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentTypeTest.java b/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentTypeTest.java deleted file mode 100644 index 26c3a6032..000000000 --- a/nva-datamodel-java/src/test/java/no/unit/nva/model/instancetypes/journal/JournalArticleContentTypeTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package no.unit.nva.model.instancetypes.journal; - -import static no.unit.nva.model.instancetypes.journal.JournalArticleContentType.ACADEMIC_ARTICLE; -import static no.unit.nva.model.instancetypes.journal.JournalArticleContentType.ACADEMIC_LITERATURE_REVIEW; -import static no.unit.nva.model.instancetypes.journal.JournalArticleContentType.CASE_REPORT; -import static no.unit.nva.model.instancetypes.journal.JournalArticleContentType.POPULAR_SCIENCE_ARTICLE; -import static no.unit.nva.model.instancetypes.journal.JournalArticleContentType.PROFESSIONAL_ARTICLE; -import static no.unit.nva.model.instancetypes.journal.JournalArticleContentType.STUDY_PROTOCOL; -import static org.junit.jupiter.api.Assertions.assertEquals; -import com.fasterxml.jackson.core.JsonProcessingException; -import no.unit.nva.commons.json.JsonUtils; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.stream.Stream; - -class JournalArticleContentTypeTest { - - @ParameterizedTest - @EnumSource(JournalArticleContentType.class) - void shouldReturnEnumerationWhenInputIsCurrentName(JournalArticleContentType journalArticleContentType) - throws JsonProcessingException { - var currentValue = "\"" + journalArticleContentType.getValue() + "\""; - var output = JsonUtils.dtoObjectMapper.readValue(currentValue, JournalArticleContentType.class); - assertEquals(output, journalArticleContentType); - } - - @ParameterizedTest(name = "Should return JournalArticleContentType when value is {0}") - @MethodSource("deprecatedJournalArticleContentTypeProvider") - void shouldReturnEnumerationWhenInputIsDeprecatedName(String deprecatedValue, - JournalArticleContentType journalArticleContentType) - throws JsonProcessingException { - var deprecated = "\"" + deprecatedValue + "\""; - var output = JsonUtils.dtoObjectMapper.readValue(deprecated, JournalArticleContentType.class); - assertEquals(output, journalArticleContentType); - } - - public static Stream deprecatedJournalArticleContentTypeProvider() { - return Stream.of( - Arguments.of("Research article", ACADEMIC_ARTICLE), - Arguments.of("Review article", ACADEMIC_LITERATURE_REVIEW), - Arguments.of("Case report", CASE_REPORT), - Arguments.of("Study protocol", STUDY_PROTOCOL), - Arguments.of("Professional article", PROFESSIONAL_ARTICLE), - Arguments.of("Popular science article", POPULAR_SCIENCE_ARTICLE) - ); - } -} \ No newline at end of file diff --git a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java index 534329a4a..ee464973e 100644 --- a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java +++ b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationContextBuilder.java @@ -65,7 +65,6 @@ public static PublicationContext randomPublicationContext(Class publicationIn case "ConferenceAbstract": case "FeatureArticle": case "JournalCorrigendum": - case "JournalArticle": case "AcademicArticle": case "AcademicLiteratureReview": case "CaseReport": @@ -85,7 +84,6 @@ public static PublicationContext randomPublicationContext(Class publicationIn case "Textbook": case "BookAnthology": case "BookAbstracts": - case "BookMonograph": case "OtherStudentWork": return attempt(PublicationContextBuilder::randomBook).orElseThrow(); case "DegreeBachelor": @@ -93,7 +91,6 @@ public static PublicationContext randomPublicationContext(Class publicationIn case "DegreePhd": case "DegreeLicentiate": return attempt(PublicationContextBuilder::randomDegree).orElseThrow(); - case "ChapterArticle": case "AcademicChapter": case "NonFictionChapter": case "PopularScienceChapter": diff --git a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java index 940e43198..ebe13fec8 100644 --- a/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java +++ b/nva-datamodel-testutils/src/main/java/no/unit/nva/model/testing/PublicationInstanceBuilder.java @@ -177,7 +177,6 @@ public static PublicationInstance randomPublicationInstance(Cla return generateFeatureArticle(); case "JournalCorrigendum": return generateJournalCorrigendum(); - case "JournalArticle": case "AcademicArticle": return generateAcademicArticle(); case "AcademicLiteratureReview": @@ -192,7 +191,6 @@ public static PublicationInstance randomPublicationInstance(Cla return generatePopularScienceArticle(); case "BookAnthology": return generateBookAnthology(); - case "ChapterArticle": case "AcademicChapter": return generateAcademicChapter(); case "NonFictionChapter": @@ -221,7 +219,6 @@ public static PublicationInstance randomPublicationInstance(Cla return generateJournalReview(); case "BookAbstracts": return generateBookAbstracts(); - case "BookMonograph": case "AcademicMonograph": return generateAcademicMonograph(); case "NonFictionMonograph":