diff --git a/NEWS.md b/NEWS.md index 4d155efdf..776416ecc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,6 +23,7 @@ * Apply new date type fields to instance schema [MODINV-1067](https://folio-org.atlassian.net/browse/MODINV-1067) * Extend Authority with Additional fields [MODINV-1071](https://folio-org.atlassian.net/browse/MODINV-1071) * Keep original UUIDs when updating ownership of Holdings/Items [MODINV-1074](https://folio-org.atlassian.net/browse/MODINV-1074) +* API version update [MODINV-1080](https://folio-org.atlassian.net/browse/MODINV-1080) ## 20.2.0 2023-03-20 * Inventory cannot process Holdings with virtual fields ([MODINV-941](https://issues.folio.org/browse/MODINV-941)) diff --git a/src/main/java/org/folio/inventory/domain/instances/Instance.java b/src/main/java/org/folio/inventory/domain/instances/Instance.java index 3efeba9df..5154c30e8 100644 --- a/src/main/java/org/folio/inventory/domain/instances/Instance.java +++ b/src/main/java/org/folio/inventory/domain/instances/Instance.java @@ -2,8 +2,6 @@ import static org.folio.inventory.domain.instances.Dates.datesFromJson; import static org.folio.inventory.domain.instances.Dates.datesToJson; -import static org.folio.inventory.domain.instances.PublicationPeriod.publicationPeriodFromJson; -import static org.folio.inventory.domain.instances.PublicationPeriod.publicationPeriodToJson; import static org.folio.inventory.support.JsonArrayHelper.toListOfStrings; import java.lang.invoke.MethodHandles; @@ -74,7 +72,6 @@ public class Instance { public static final String TAGS_KEY = "tags"; public static final String TAG_LIST_KEY = "tagList"; public static final String NATURE_OF_CONTENT_TERM_IDS_KEY = "natureOfContentTermIds"; - public static final String PUBLICATION_PERIOD_KEY = "publicationPeriod"; public static final String DATES_KEY = "dates"; private final String id; @@ -119,7 +116,6 @@ public class Instance { private Metadata metadata = null; private List tags; private List natureOfContentTermIds = new ArrayList<>(); - private PublicationPeriod publicationPeriod; private Dates dates; protected static final String INVENTORY_PATH = "/inventory"; @@ -192,7 +188,6 @@ public static Instance fromJson(JsonObject instanceJson) { .setStatusUpdatedDate(instanceJson.getString(STATUS_UPDATED_DATE_KEY)) .setTags(getTags(instanceJson)) .setNatureOfContentTermIds(toListOfStrings(instanceJson.getJsonArray(NATURE_OF_CONTENT_TERM_IDS_KEY))) - .setPublicationPeriod(publicationPeriodFromJson(instanceJson.getJsonObject(PUBLICATION_PERIOD_KEY))) .setDates(datesFromJson(instanceJson.getJsonObject(DATES_KEY))); } @@ -241,7 +236,6 @@ public JsonObject getJsonForStorage() { json.put(STATUS_UPDATED_DATE_KEY, statusUpdatedDate); json.put(TAGS_KEY, new JsonObject().put(TAG_LIST_KEY, new JsonArray(getTags() == null ? Collections.emptyList() : getTags()))); json.put(NATURE_OF_CONTENT_TERM_IDS_KEY, natureOfContentTermIds); - putIfNotNull(json, PUBLICATION_PERIOD_KEY, publicationPeriodToJson(publicationPeriod)); putIfNotNull(json, DATES_KEY, datesToJson(dates)); return json; @@ -295,7 +289,6 @@ public JsonObject getJsonForResponse(WebContext context) { putIfNotNull(json, METADATA_KEY, getMetadata()); putIfNotNull(json, TAGS_KEY, new JsonObject().put(TAG_LIST_KEY, new JsonArray(getTags()))); putIfNotNull(json, NATURE_OF_CONTENT_TERM_IDS_KEY, getNatureOfContentTermIds()); - putIfNotNull(json, PUBLICATION_PERIOD_KEY, publicationPeriodToJson(publicationPeriod)); putIfNotNull(json, DATES_KEY, datesToJson(dates)); if (precedingTitles != null) { @@ -759,7 +752,6 @@ public Instance copyWithNewId(String newId) { .setMetadata(metadata) .setTags(tags) .setNatureOfContentTermIds(natureOfContentTermIds) - .setPublicationPeriod(publicationPeriod) .setDates(dates); } @@ -794,7 +786,6 @@ public Instance copyInstance() { .setMetadata(metadata) .setTags(tags) .setNatureOfContentTermIds(natureOfContentTermIds) - .setPublicationPeriod(publicationPeriod) .setDates(dates); } @@ -831,11 +822,6 @@ public Instance removeIdentifier(final String identifierTypeId, final String val return copyInstance().setIdentifiers(newIdentifiers); } - public Instance setPublicationPeriod(PublicationPeriod period) { - this.publicationPeriod = period; - return this; - } - @Override public String toString() { return String.format("Instance ID: %s, HRID: %s, Title: %s", id, hrid, title); diff --git a/src/main/java/org/folio/inventory/domain/instances/PublicationPeriod.java b/src/main/java/org/folio/inventory/domain/instances/PublicationPeriod.java deleted file mode 100644 index f09044917..000000000 --- a/src/main/java/org/folio/inventory/domain/instances/PublicationPeriod.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.folio.inventory.domain.instances; - -import static org.apache.commons.lang3.ObjectUtils.anyNotNull; -import static org.folio.inventory.support.JsonHelper.includeIfPresent; - -import io.vertx.core.json.JsonObject; - -public class PublicationPeriod { - private final Integer start; - private final Integer end; - - public PublicationPeriod(Integer start, Integer end) { - this.start = start; - this.end = end; - } - - public Integer getStart() { - return start; - } - - public Integer getEnd() { - return end; - } - - public static JsonObject publicationPeriodToJson(PublicationPeriod period) { - if (period == null || (period.getStart() == null && period.getEnd() == null)) { - return null; - } - - var json = new JsonObject(); - includeIfPresent(json, "start", period.getStart()); - includeIfPresent(json, "end", period.getEnd()); - - return json; - } - - public static PublicationPeriod publicationPeriodFromJson(JsonObject pubPeriodJson) { - if (pubPeriodJson == null) { - return null; - } - - var start = pubPeriodJson.getInteger("start"); - var end = pubPeriodJson.getInteger("end"); - - return anyNotNull(start, end) ? new PublicationPeriod(start, end) : null; - } -} diff --git a/src/test/java/api/InstancesApiExamples.java b/src/test/java/api/InstancesApiExamples.java index fd41b36ea..457ab9894 100644 --- a/src/test/java/api/InstancesApiExamples.java +++ b/src/test/java/api/InstancesApiExamples.java @@ -18,10 +18,8 @@ import static org.folio.inventory.domain.instances.Dates.datesToJson; import static org.folio.inventory.domain.instances.Instance.DATES_KEY; import static org.folio.inventory.domain.instances.Instance.PRECEDING_TITLES_KEY; -import static org.folio.inventory.domain.instances.Instance.PUBLICATION_PERIOD_KEY; import static org.folio.inventory.domain.instances.Instance.TAGS_KEY; import static org.folio.inventory.domain.instances.Instance.TAG_LIST_KEY; -import static org.folio.inventory.domain.instances.PublicationPeriod.publicationPeriodToJson; import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.is; @@ -46,7 +44,6 @@ import org.folio.inventory.config.InventoryConfiguration; import org.folio.inventory.config.InventoryConfigurationImpl; import org.folio.inventory.domain.instances.Dates; -import org.folio.inventory.domain.instances.PublicationPeriod; import org.folio.inventory.domain.instances.Subject; import org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle; import org.folio.inventory.support.JsonArrayHelper; @@ -102,7 +99,6 @@ public void canCreateInstanceWithoutAnIDAndHRID() .put("administrativeNotes", adminNote) .put("instanceTypeId", ApiTestSuite.getTextInstanceType()) .put(TAGS_KEY, new JsonObject().put(TAG_LIST_KEY, new JsonArray().add(tagNameOne))) - .put(PUBLICATION_PERIOD_KEY, publicationPeriodToJson(new PublicationPeriod(1000, 2000))) .put(DATES_KEY, datesToJson(new Dates(dateTypeId, date1, date2))) .put("natureOfContentTermIds", new JsonArray(asList( @@ -169,10 +165,6 @@ public void canCreateInstanceWithoutAnIDAndHRID() assertThat(createdInstance.getString("hrid"), notNullValue()); - var publicationPeriod = createdInstance.getJsonObject(PUBLICATION_PERIOD_KEY); - assertThat(publicationPeriod.getInteger("start"), is(1000)); - assertThat(publicationPeriod.getInteger("end"), is(2000)); - var dates = createdInstance.getJsonObject(DATES_KEY); assertThat(dates.getString(DATE_TYPE_ID_KEY), is(dateTypeId)); assertThat(dates.getString(DATE1_KEY), is(date1)); @@ -409,7 +401,7 @@ public void canUpdateAnExistingInstance() JsonObject smallAngryPlanet = smallAngryPlanet(id); smallAngryPlanet.put("natureOfContentTermIds", new JsonArray().add(ApiTestSuite.getBibliographyNatureOfContentTermId())); - smallAngryPlanet.put(PUBLICATION_PERIOD_KEY, publicationPeriodToJson(new PublicationPeriod(1000, 2000))); + smallAngryPlanet.put(DATES_KEY, datesToJson(new Dates(null, date1, date2))); JsonObject newInstance = createInstance(smallAngryPlanet); @@ -417,7 +409,6 @@ public void canUpdateAnExistingInstance() JsonObject updateInstanceRequest = newInstance.copy() .put("title", "The Long Way to a Small, Angry Planet") .put(TAGS_KEY, new JsonObject().put(TAG_LIST_KEY, new JsonArray().add(tagNameTwo))) - .put(PUBLICATION_PERIOD_KEY, publicationPeriodToJson(new PublicationPeriod(2000, 2012))) .put(DATES_KEY, datesToJson(new Dates(dateTypeId, date1, date2))) .put("natureOfContentTermIds", new JsonArray().add(ApiTestSuite.getAudiobookNatureOfContentTermId())) @@ -454,10 +445,6 @@ public void canUpdateAnExistingInstance() assertThat(natureOfContentTermIds.size(), is(1)); assertThat(natureOfContentTermIds.getString(0), is(ApiTestSuite.getAudiobookNatureOfContentTermId())); - var publicationPeriod = updatedInstance.getJsonObject(PUBLICATION_PERIOD_KEY); - assertThat(publicationPeriod.getInteger("start"), is(2000)); - assertThat(publicationPeriod.getInteger("end"), is(2012)); - var dates = updatedInstance.getJsonObject(DATES_KEY); assertThat(dates.getString(DATE_TYPE_ID_KEY), is(dateTypeId)); assertThat(dates.getString(DATE1_KEY), is(date1)); @@ -477,7 +464,6 @@ public void canUpdateAnExistingInstanceWithPrecedingSucceedingTitlesMarcSource() JsonObject smallAngryPlanet = smallAngryPlanet(id); smallAngryPlanet.put("natureOfContentTermIds", new JsonArray().add(ApiTestSuite.getBibliographyNatureOfContentTermId())); - smallAngryPlanet.put(PUBLICATION_PERIOD_KEY, publicationPeriodToJson(new PublicationPeriod(1000, 2000))); JsonArray precedingTitles = new JsonArray(); precedingTitles.add( @@ -506,7 +492,6 @@ public void canUpdateAnExistingInstanceWithPrecedingSucceedingTitlesMarcSource() JsonObject updateInstanceRequest = newInstance.copy() .put(TAGS_KEY, new JsonObject().put(TAG_LIST_KEY, new JsonArray().add(tagNameTwo))) - .put(PUBLICATION_PERIOD_KEY, publicationPeriodToJson(new PublicationPeriod(2000, 2012))) .put(PRECEDING_TITLES_KEY, precedingTitles) .put("natureOfContentTermIds", new JsonArray().add(ApiTestSuite.getAudiobookNatureOfContentTermId())); diff --git a/src/test/java/org/folio/inventory/domain/instances/PublicationPeriodTest.java b/src/test/java/org/folio/inventory/domain/instances/PublicationPeriodTest.java deleted file mode 100644 index 65c0a29aa..000000000 --- a/src/test/java/org/folio/inventory/domain/instances/PublicationPeriodTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.folio.inventory.domain.instances; - -import static org.folio.inventory.domain.instances.PublicationPeriod.publicationPeriodFromJson; -import static org.folio.inventory.domain.instances.PublicationPeriod.publicationPeriodToJson; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; - -import io.vertx.core.json.JsonObject; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; -import junitparams.converters.Nullable; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(JUnitParamsRunner.class) -public class PublicationPeriodTest { - - @Parameters({ - "1, 2", - "null, 2", - "1, null", - }) - @Test - public void shouldCreatePublicationPeriodFromJson(@Nullable Integer start, @Nullable Integer end) { - var publicationPeriod = publicationPeriodFromJson(publicationPeriodJson(start, end)); - - assertThat(publicationPeriod.getStart(), is(start)); - assertThat(publicationPeriod.getEnd(), is(end)); - } - - @Test - public void shouldNotCreatePublicationPeriodFromJsonWhenJsonIsNull() { - assertThat(publicationPeriodFromJson(null), nullValue()); - } - - @Test - public void shouldNotCreatePublicationPeriodFromJsonWhenStartAndEndAreNull() { - assertThat(publicationPeriodFromJson(publicationPeriodJson(null, null)), nullValue()); - } - - @Parameters({ - "1, 2", - "null, 2", - "1, null", - }) - @Test - public void shouldConvertPublicationPeriodToJson(@Nullable Integer start, @Nullable Integer end) { - var json = publicationPeriodToJson(new PublicationPeriod(start, end)); - - assertThat(json.getInteger("start"), is(start)); - assertThat(json.getInteger("end"), is(end)); - } - - @Test - public void shouldNotConvertPublicationPeriodToJsonWhenItIsNull() { - assertThat(publicationPeriodToJson(null), nullValue()); - } - - @Test - public void shouldNotConvertPublicationPeriodToJsonWhenStartAndEndAreNull() { - assertThat(publicationPeriodToJson(new PublicationPeriod(null, null)), nullValue()); - } - - private JsonObject publicationPeriodJson(Integer start, Integer end) { - return new JsonObject().put("start", start).put("end", end); - } -}