Skip to content

Commit

Permalink
MLT-0073 Define categories (#53)
Browse files Browse the repository at this point in the history
Use an enum to define product categories in the system
  • Loading branch information
anotheroneofthese authored Dec 13, 2024
1 parent 4cdddca commit 0b2d750
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nb/mlt/wls/domain/model/Item.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/no/nb/mlt/wls/domain/model/ItemCategory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package no.nb.mlt.wls.domain.model

enum class ItemCategory {
PAPER,
DISC,
FILM,
PHOTO,
EQUIPMENT,
BULK_ITEMS,
MAGNETIC_TAPE
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"
}
}
3 changes: 2 additions & 1 deletion src/test/kotlin/no/nb/mlt/wls/TraillingSlashRedirectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "")
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 0b2d750

Please sign in to comment.