From 0b2d750a114b0d64b845702a27e81139b9481d94 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 13 Dec 2024 09:49:41 +0100 Subject: [PATCH] MLT-0073 Define categories (#53) Use an enum to define product categories in the system --- .../application/hostapi/item/ApiItemPayload.kt | 13 +++++++------ .../kotlin/no/nb/mlt/wls/domain/model/Item.kt | 2 +- .../no/nb/mlt/wls/domain/model/ItemCategory.kt | 11 +++++++++++ .../nb/mlt/wls/domain/ports/inbound/AddNewItem.kt | 3 ++- .../callbacks/NotificationItemPayload.kt | 9 +++++++-- .../infrastructure/repositories/item/MongoItem.kt | 3 ++- .../wls/infrastructure/synq/SynqProductPayload.kt | 15 ++++++++++++++- .../no/nb/mlt/wls/TraillingSlashRedirectTest.kt | 3 ++- .../kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt | 3 ++- .../mlt/wls/item/controller/ItemControllerTest.kt | 5 +++-- .../mlt/wls/item/model/ItemModelConversionTest.kt | 10 ++++++---- .../mlt/wls/item/model/ItemModelValidationTest.kt | 15 ++------------- .../wls/order/controller/OrderControllerTest.kt | 3 ++- .../mlt/wls/synq/controller/SynqControllerTest.kt | 5 +++-- 14 files changed, 64 insertions(+), 36 deletions(-) create mode 100644 src/main/kotlin/no/nb/mlt/wls/domain/model/ItemCategory.kt diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/item/ApiItemPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/item/ApiItemPayload.kt index 56c0b5f9..ce81d5c7 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/item/ApiItemPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/item/ApiItemPayload.kt @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging import no.nb.mlt.wls.domain.ports.inbound.ItemMetadata @@ -45,11 +46,15 @@ data class ApiItemPayload( examples = ["Tyven, tyven skal du hete", "Avisa Hemnes", "Kill Buljo"] ) val description: String, + // TODO - Update this schema to reflect new categories @Schema( description = "What kind of item category the item belongs to, e.g. Books, Issues, Films, etc.", - examples = ["BOOK", "ISSUE", "Arkivmateriale", "Film_Frys"] + examples = [ + "safetyfilm", "nitratfilm", "film", "plater", "fotografier", "papir", + "gjenstand", "lydbånd", "videobånd", "sekkepost", "magnetbånd" + ] ) - val itemCategory: String, + val itemCategory: ItemCategory, @Schema( description = "What kind of environment the item should be stored in, e.g. NONE, FRYS, MUGG_CELLE, etc.", examples = ["NONE", "FRYS"] @@ -125,10 +130,6 @@ data class ApiItemPayload( throw ValidationException("The item's description is required, and it cannot be blank") } - if (itemCategory.isBlank()) { - throw ValidationException("The item's category is required, and it cannot be blank") - } - if (location != null && location.isBlank()) { throw ValidationException("The item's location cannot be blank if set") } diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Item.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Item.kt index 313c1576..9d651da7 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Item.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Item.kt @@ -8,7 +8,7 @@ data class Item( val hostId: String, val hostName: HostName, val description: String, - val itemCategory: String, + val itemCategory: ItemCategory, val preferredEnvironment: Environment, val packaging: Packaging, val owner: Owner, diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/ItemCategory.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/ItemCategory.kt new file mode 100644 index 00000000..4166f905 --- /dev/null +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/ItemCategory.kt @@ -0,0 +1,11 @@ +package no.nb.mlt.wls.domain.model + +enum class ItemCategory { + PAPER, + DISC, + FILM, + PHOTO, + EQUIPMENT, + BULK_ITEMS, + MAGNETIC_TAPE +} diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/AddNewItem.kt b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/AddNewItem.kt index 0925a764..52534155 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/AddNewItem.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/AddNewItem.kt @@ -3,6 +3,7 @@ package no.nb.mlt.wls.domain.ports.inbound import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging @@ -14,7 +15,7 @@ data class ItemMetadata( val hostId: String, val hostName: HostName, val description: String, - val itemCategory: String, + val itemCategory: ItemCategory, val preferredEnvironment: Environment, val packaging: Packaging, val owner: Owner, diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationItemPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationItemPayload.kt index 67997308..18d2531e 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationItemPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationItemPayload.kt @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging @@ -26,11 +27,15 @@ data class NotificationItemPayload( examples = ["Tyven, tyven skal du hete", "Avisa Hemnes", "Kill Buljo"] ) val description: String, + // TODO - Update this schema to reflect new categories @Schema( description = "What kind of item category the item belongs to, e.g. Books, Issues, Films, etc.", - examples = ["BOOK", "ISSUE", "Arkivmateriale", "Film_Frys"] + examples = [ + "safetyfilm", "nitratfilm", "film", "plater", "fotografier", "papir", + "gjenstand", "lydbånd", "videobånd", "sekkepost", "magnetbånd" + ] ) - val itemCategory: String, + val itemCategory: ItemCategory, @Schema( description = "What kind of environment the item should be stored in, e.g. NONE, FRYS, MUGG_CELLE, etc.", examples = ["NONE", "FRYS"] diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/item/MongoItem.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/item/MongoItem.kt index 4224e6f7..3e1afff8 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/item/MongoItem.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/item/MongoItem.kt @@ -3,6 +3,7 @@ package no.nb.mlt.wls.infrastructure.repositories.item import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging import org.springframework.data.mongodb.core.mapping.Document @@ -12,7 +13,7 @@ data class MongoItem( val hostId: String, val hostName: HostName, val description: String, - val itemCategory: String, + val itemCategory: ItemCategory, val preferredEnvironment: Environment, val packaging: Packaging, val owner: Owner, diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqProductPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqProductPayload.kt index cc17ccde..c9720a4c 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqProductPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqProductPayload.kt @@ -1,6 +1,7 @@ package no.nb.mlt.wls.infrastructure.synq import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory data class SynqProductPayload( val productId: String, @@ -28,8 +29,20 @@ fun Item.toSynqPayload() = owner = owner.toSynqOwner(), barcode = SynqProductPayload.Barcode(hostId), description = description, - productCategory = itemCategory, + productCategory = toSynqCategory(itemCategory), productUom = SynqProductPayload.ProductUom(packaging.toSynqPackaging()), confidential = false, hostName = hostName.toString() ) + +fun toSynqCategory(category: ItemCategory): String { + return when (category) { + ItemCategory.PAPER -> "papir" + ItemCategory.DISC -> "plater" + ItemCategory.FILM -> "film" + ItemCategory.PHOTO -> "foto" + ItemCategory.EQUIPMENT -> "gjenstand" + ItemCategory.BULK_ITEMS -> "sekkepost" + ItemCategory.MAGNETIC_TAPE -> "magnetbånd" + } +} diff --git a/src/test/kotlin/no/nb/mlt/wls/TraillingSlashRedirectTest.kt b/src/test/kotlin/no/nb/mlt/wls/TraillingSlashRedirectTest.kt index 69c37294..b8d89e33 100644 --- a/src/test/kotlin/no/nb/mlt/wls/TraillingSlashRedirectTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/TraillingSlashRedirectTest.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.test.runTest import no.nb.mlt.wls.application.hostapi.item.ApiItemPayload import no.nb.mlt.wls.domain.model.Environment.NONE import no.nb.mlt.wls.domain.model.HostName +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging import no.nb.mlt.wls.infrastructure.repositories.item.ItemMongoRepository @@ -82,7 +83,7 @@ class TraillingSlashRedirectTest( hostId = "item-12346", hostName = HostName.AXIELL, description = "Tyv etter loven", - itemCategory = "BOOK", + itemCategory = ItemCategory.PAPER, preferredEnvironment = NONE, packaging = Packaging.NONE, owner = Owner.NB, diff --git a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt index da3ff1e8..f2ed835e 100644 --- a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.test.runTest import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Order import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging @@ -413,7 +414,7 @@ class WLSServiceTest { hostName = HostName.AXIELL, hostId = "12345", description = "Tyven, tyven skal du hete", - itemCategory = "BOOK", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.NONE, packaging = Packaging.NONE, owner = Owner.NB, diff --git a/src/test/kotlin/no/nb/mlt/wls/item/controller/ItemControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/item/controller/ItemControllerTest.kt index 6e08b59b..336dfa82 100644 --- a/src/test/kotlin/no/nb/mlt/wls/item/controller/ItemControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/item/controller/ItemControllerTest.kt @@ -10,6 +10,7 @@ import no.nb.mlt.wls.EnableTestcontainers import no.nb.mlt.wls.application.hostapi.item.ApiItemPayload import no.nb.mlt.wls.domain.model.Environment.NONE import no.nb.mlt.wls.domain.model.HostName +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging import no.nb.mlt.wls.infrastructure.repositories.item.ItemMongoRepository @@ -239,7 +240,7 @@ class ItemControllerTest( hostId = "mlt-420", hostName = HostName.AXIELL, description = "Ringenes Herre samling", - itemCategory = "BOOK", + itemCategory = ItemCategory.PAPER, preferredEnvironment = NONE, packaging = Packaging.BOX, owner = Owner.NB, @@ -256,7 +257,7 @@ class ItemControllerTest( hostId = "item-12346", hostName = HostName.AXIELL, description = "Tyv etter loven", - itemCategory = "BOOK", + itemCategory = ItemCategory.PAPER, preferredEnvironment = NONE, packaging = Packaging.NONE, owner = Owner.NB, diff --git a/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelConversionTest.kt index 8155896e..fd2a135f 100644 --- a/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelConversionTest.kt @@ -5,12 +5,14 @@ import no.nb.mlt.wls.application.hostapi.item.toApiPayload import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging import no.nb.mlt.wls.infrastructure.callbacks.NotificationItemPayload import no.nb.mlt.wls.infrastructure.callbacks.toNotificationItemPayload import no.nb.mlt.wls.infrastructure.synq.SynqOwner import no.nb.mlt.wls.infrastructure.synq.SynqProductPayload +import no.nb.mlt.wls.infrastructure.synq.toSynqCategory import no.nb.mlt.wls.infrastructure.synq.toSynqPayload import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -21,7 +23,7 @@ class ItemModelConversionTest { hostId = "mlt-test-1234", hostName = HostName.AXIELL, description = "Tyven skal du hete", - itemCategory = "NONE", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.NONE, packaging = Packaging.NONE, owner = Owner.NB, @@ -35,7 +37,7 @@ class ItemModelConversionTest { hostId = "mlt-test-1234", hostName = HostName.AXIELL, description = "Tyven skal du hete", - itemCategory = "NONE", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.NONE, packaging = Packaging.NONE, owner = Owner.NB, @@ -50,7 +52,7 @@ class ItemModelConversionTest { owner = SynqOwner.NB, barcode = SynqProductPayload.Barcode("mlt-test-1234"), description = "Tyven skal du hete", - productCategory = "NONE", + productCategory = toSynqCategory(ItemCategory.PAPER), productUom = SynqProductPayload.ProductUom(SynqProductPayload.SynqPackaging.OBJ), false, hostName = HostName.AXIELL.toString() @@ -61,7 +63,7 @@ class ItemModelConversionTest { hostId = "mlt-test-1234", hostName = HostName.AXIELL, description = "Tyven skal du hete", - itemCategory = "NONE", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.NONE, packaging = Packaging.NONE, owner = Owner.NB, diff --git a/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelValidationTest.kt index 95a9286e..3a6599bb 100644 --- a/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/item/model/ItemModelValidationTest.kt @@ -3,6 +3,7 @@ package no.nb.mlt.wls.item.model import no.nb.mlt.wls.application.hostapi.item.ApiItemPayload import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging import no.nb.mlt.wls.domain.ports.inbound.ValidationException @@ -56,18 +57,6 @@ class ItemModelValidationTest { .hasMessageContaining("description") } - @Test - fun `item with blank itemCategory should fail validation`() { - val item = validItem.copy(itemCategory = "") - - val thrown = catchThrowable(item::validate) - - then(thrown) - .isNotNull() - .isInstanceOf(ValidationException::class.java) - .hasMessageContaining("category") - } - @Test fun `item with blank location should fail validation`() { val item = validItem.copy(location = "") @@ -113,7 +102,7 @@ class ItemModelValidationTest { hostId = "mlt-test-1234", hostName = HostName.AXIELL, description = "Tyven skal du hete", - itemCategory = "NONE", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.NONE, packaging = Packaging.NONE, owner = Owner.NB, diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index 162b460b..cca8bebb 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -15,6 +15,7 @@ import no.nb.mlt.wls.application.hostapi.order.OrderLine import no.nb.mlt.wls.application.hostapi.order.toApiOrderPayload import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Order import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging @@ -547,7 +548,7 @@ class OrderControllerTest( hostId = it.hostId, hostName = testOrderPayload.hostName, description = "description", - itemCategory = "itemCategory", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.NONE, packaging = Packaging.NONE, owner = Owner.NB, diff --git a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt index 261bc955..d0c4098a 100644 --- a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt @@ -18,6 +18,7 @@ import no.nb.mlt.wls.application.synqapi.synq.SynqOrderStatusUpdatePayload import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Item +import no.nb.mlt.wls.domain.model.ItemCategory import no.nb.mlt.wls.domain.model.Order import no.nb.mlt.wls.domain.model.Owner import no.nb.mlt.wls.domain.model.Packaging @@ -361,7 +362,7 @@ class SynqControllerTest( hostName = HostName.AXIELL, owner = Owner.NB, description = "Test item", - itemCategory = "Test category", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.FRYS, packaging = Packaging.BOX, callbackUrl = "https://callback.com/item", @@ -375,7 +376,7 @@ class SynqControllerTest( hostName = HostName.AXIELL, owner = Owner.NB, description = "Item test", - itemCategory = "Category test", + itemCategory = ItemCategory.PAPER, preferredEnvironment = Environment.FRYS, packaging = Packaging.BOX, callbackUrl = "https://callback.com/item",