Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLT-0075 Order Domain changes #52

Merged
merged 22 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
082cedb
Change domain models to include Address and Contact Person
anotheroneofthese Nov 28, 2024
9577f5a
Update codebase to use new domain structure
anotheroneofthese Nov 28, 2024
cad6b98
Update tests to use new domain models
anotheroneofthese Nov 28, 2024
4c96bef
Checkstyle
anotheroneofthese Nov 28, 2024
129e190
Add tests for address
anotheroneofthese Nov 29, 2024
9b6ed6b
Add SwaggerDoc and TODO
anotheroneofthese Nov 29, 2024
69acc95
Add Country to Order.Address
anotheroneofthese Nov 29, 2024
a4f385b
Update schemas with address
anotheroneofthese Nov 29, 2024
dafc04a
Actually allow updating address
anotheroneofthese Nov 29, 2024
c16a472
Validate State
anotheroneofthese Nov 29, 2024
59eed75
Send shipping address to SynQ
anotheroneofthese Nov 29, 2024
3f726f2
Rename Order.Address State -> Region
anotheroneofthese Nov 29, 2024
7608cbb
Rename Order.Address Zipcode -> Postcode
anotheroneofthese Nov 29, 2024
68823dd
Introduce note field in domain model
anotheroneofthese Dec 2, 2024
58285e3
Update tests to include notes
anotheroneofthese Dec 2, 2024
369e255
Update Swagger schemas
anotheroneofthese Dec 2, 2024
1fd0c49
Rename Order.Address name -> recipient
anotheroneofthese Dec 2, 2024
0663f60
Fix test
anotheroneofthese Dec 2, 2024
b36926c
Note that notes in not(e)ifications are noted now
anotheroneofthese Dec 5, 2024
90642c6
Only include shipping address if not null
anotheroneofthese Dec 5, 2024
429f62c
Improve tests, make linter happy
anotheroneofthese Dec 5, 2024
65d621f
Update Address -> SynQ differently
anotheroneofthese Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
MONGO_INITDB_ROOT_PASSWORD: toor
MONGO_INITDB_DATABASE: wls
ports:
- 27017:27017
- "27017:27017"
volumes:
- ./mongo/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro

Expand All @@ -18,7 +18,7 @@ services:
image: mongo-express:1.0.2
restart: always
ports:
- 8081:8081
- "8081:8081"
depends_on:
- mongo-db
environment:
Expand All @@ -41,7 +41,7 @@ services:
KEYCLOAK_ADMIN: root
KEYCLOAK_ADMIN_PASSWORD: toor
ports:
- 8082:8080
- "8082:8080"
command: start-dev --import-realm
volumes:
- ./keycloak/import:/opt/keycloak/data/import
Expand All @@ -50,4 +50,4 @@ services:
image: harbor.nb.no/mlt/dummy-synq:main
restart: always
ports:
- 8181:8181
- "8181:8181"
12 changes: 9 additions & 3 deletions docker/mongo/mongo-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ db.orders.insertOne({
],
"orderType": "LOAN",
"owner": "NB",
"receiver": {
"name": "Doug Doug",
"address": "Somewhere in the United States"
"contactPerson": "MLT Team",
"address": {
"recipient": "Doug Doug",
"addressLine1": "Somewhere",
"addressLine2": "Behind a cardboard box",
"city": "Las Vegas",
"country": "United States",
"region": "Texas",
"postcode": "TX-55415"
},
"callbackUrl": "https://example.com/send/callback/here",
"_class": "no.nb.mlt.wls.infrastructure.repositories.order.MongoOrder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ import java.net.URI
],
"orderType": "LOAN",
"owner": "NB",
"receiver": {
"name": "Doug Dimmadome",
"address": "Dimmsdale Dimmadome, 21st Ave. Texas"
"contactPerson": "Hermes the Great",
"address": {
"recipient": "Nasjonalbibliotekaren",
"addressLine1": "Henrik Ibsens gate 110",
"city": "Oslo",
"country": "Norway",
"postcode": "0255"
},
"note": "Handle with care",
"callbackUrl": "https://example.com/send/callback/here"
}
"""
Expand Down Expand Up @@ -59,9 +64,29 @@ data class ApiOrderPayload(
)
val orderType: Order.Type,
@Schema(
description = "Who's the receiver of the material in the order."
description = "The name of the person to contact with manners related to this order",
example = "Hermes"
)
val receiver: Receiver,
val contactPerson: String,
@Schema(
description = "Any notes about the order",
example = "This is required in four weeks time"
)
val note: String?,
// TODO - Should this use custom DTO?
@Schema(
description = "The delivery address of this order",
example = """
"address": {
"recipient": "Nasjonalbibliotekaren",
"addressLine1": "Henrik Ibsens gate 110",
"city": "Oslo",
"country": "Norway",
"postcode": "0255"
}
"""
)
val address: Order.Address?,
@Schema(
description = "Callback URL for the order used to update the order information in the host system.",
example = "https://example.com/send/callback/here"
Expand All @@ -75,7 +100,9 @@ data class ApiOrderPayload(
orderLine = orderLine.map { it.toCreateOrderItem() },
orderType = orderType,
owner = owner,
receiver = receiver.toOrderReceiver(),
address = address,
contactPerson = contactPerson,
note = note,
callbackUrl = callbackUrl
)

Expand All @@ -93,7 +120,7 @@ data class ApiOrderPayload(
}

orderLine.forEach(OrderLine::validate)
receiver.validate()
address?.validate()
}

private fun isValidUrl(url: String): Boolean {
Expand All @@ -116,7 +143,9 @@ fun Order.toApiOrderPayload() =
status = status,
orderLine = orderLine.map { it.toApiOrderLine() },
orderType = orderType,
receiver = Receiver(receiver.name, receiver.address),
contactPerson = contactPerson,
address = address,
note = note,
callbackUrl = callbackUrl
)

Expand Down Expand Up @@ -154,41 +183,3 @@ data class OrderLine(
}

fun Order.OrderItem.toApiOrderLine() = OrderLine(hostId, status)

@Schema(
description = "Who's the receiver of the order.",
example = """
{
"name": "Doug Dimmadome",
"address": "Dimmsdale Dimmadome, Apartment 420, 69th Ave. Texas"
}
"""
)
data class Receiver(
@Schema(
description = "Name of the receiver.",
example = "Doug Dimmadome"
)
val name: String,
@Schema(
description = "Address of the receiver.",
example = "Dimmsdale Dimmadome, Apartment 420, 69th Ave. Texas",
required = false
)
val address: String?
) {
fun toOrderReceiver() = Order.Receiver(name, address ?: "")

@Throws(ValidationException::class)
fun validate() {
if (name.isBlank()) {
throw ValidationException("The order's receiver name is required, and can not be blank")
}

if (address != null && address.isBlank()) {
throw ValidationException("The order's receiver address cannot be blank if provided")
}
}
}

fun Order.Receiver.toReceiver() = Receiver(name, address)
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ import kotlin.jvm.Throws
}
],
"orderType": "LOAN",
"receiver": {
"name": "Doug Dimmadome",
"address": "Dimmsdale Dimmadome, 21st Ave. Texas"
"contactPerson": "MLT Team",
"address": {
"recipient": "Doug Dimmadome",
"addressLine1": "Dimmsdale Dimmadome",
"addressLine2": "21st Texan Ave.",
"city": "Dimmsdale",
"country": "United States",
"region": "California",
"postcode": "CA-55415"
},
"note": "Handle with care",
"callbackUrl": "https://example.com/send/callback/here"
}
"""
Expand Down Expand Up @@ -53,7 +60,28 @@ data class ApiUpdateOrderPayload(
@Schema(
description = "Who's the receiver of the material in the order."
)
val receiver: Receiver,
val contactPerson: String,
@Schema(
description = """
The delivery address of the order.
If delivering to a country with states (I.E. the United States), include the state name in the region.
""",
example = """
"address": {
"recipient": "Nasjonalbibliotekaren",
"addressLine1": "Henrik Ibsens gate 110",
"city": "Oslo",
"country": "Norway",
"postcode": "0255"
}
"""
)
val address: Order.Address?,
@Schema(
description = "Any notes about the order",
example = "This is required in four weeks time"
)
val note: String?,
@Schema(
description = "URL to send a callback to when the order is completed.",
example = "https://example.com/send/callback/here"
Expand All @@ -75,8 +103,7 @@ data class ApiUpdateOrderPayload(
}

orderLine.forEach(OrderLine::validate)

receiver.validate()
address?.validate()
}

private fun isValidUrl(url: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ class OrderController(
hostOrderId = payload.hostOrderId,
itemHostIds = payload.orderLine.map { it.hostId },
orderType = payload.orderType,
receiver = payload.receiver.toOrderReceiver(),
contactPerson = payload.contactPerson,
address = payload.address,
note = payload.note,
callbackUrl = payload.callbackUrl
)

Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ class WLSService(
hostOrderId: String,
itemHostIds: List<String>,
orderType: Order.Type,
receiver: Order.Receiver,
contactPerson: String,
address: Order.Address?,
note: String?,
callbackUrl: String
): Order {
val itemIds = itemHostIds.map { ItemId(hostName, it) }
Expand All @@ -163,7 +165,15 @@ class WLSService(

val order = getOrderOrThrow(hostName, hostOrderId)

val updatedOrder = order.updateOrder(itemHostIds, callbackUrl, orderType, receiver)
val updatedOrder =
order.updateOrder(
itemIds = itemHostIds,
callbackUrl = callbackUrl,
orderType = orderType,
address = address ?: order.address,
note = note,
contactPerson = contactPerson
)
val result = storageSystemFacade.updateOrder(updatedOrder)
return orderRepository.updateOrder(result)
}
Expand Down
62 changes: 53 additions & 9 deletions src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nb.mlt.wls.domain.model

import no.nb.mlt.wls.domain.model.Order.Address
import no.nb.mlt.wls.domain.model.Order.OrderItem.Status.FAILED
import no.nb.mlt.wls.domain.model.Order.OrderItem.Status.PICKED
import no.nb.mlt.wls.domain.ports.inbound.IllegalOrderStateException
Expand All @@ -13,7 +14,9 @@ data class Order(
val orderLine: List<OrderItem>,
val orderType: Type,
val owner: Owner,
val receiver: Receiver,
val address: Address?,
val contactPerson: String,
val note: String?,
val callbackUrl: String
) {
private fun setOrderLines(listOfHostIds: List<String>): Order {
Expand Down Expand Up @@ -55,8 +58,8 @@ data class Order(
.updateOrderStatusFromOrderLines()
}

private fun setReceiver(receiver: Receiver): Order {
return this.copy(receiver = receiver)
private fun setContactPerson(contactPerson: String): Order {
return this.copy(contactPerson = contactPerson)
}

private fun setOrderType(orderType: Type): Order {
Expand Down Expand Up @@ -98,16 +101,26 @@ data class Order(
itemIds: List<String>,
callbackUrl: String,
orderType: Type,
receiver: Receiver
address: Address?,
note: String?,
contactPerson: String
anotheroneofthese marked this conversation as resolved.
Show resolved Hide resolved
): Order {
throwIfInProgress()

return this.setOrderLines(itemIds)
.setCallbackUrl(callbackUrl)
.setOrderType(orderType)
.setReceiver(receiver)
.setAddress(address)
.setNote(note)
.setContactPerson(contactPerson)
}

private fun setNote(note: String?): Order {
return this.copy(note = note)
}

private fun setAddress(address: Address?): Order = this.copy(address = address ?: createOrderAddress())

/**
* Delete the order as long as it is possible.
*
Expand Down Expand Up @@ -153,10 +166,39 @@ data class Order(
}
}

data class Receiver(
val name: String,
val address: String?
)
data class Address(
val recipient: String?,
val addressLine1: String?,
val addressLine2: String?,
val postcode: String?,
val city: String?,
val region: String?,
val country: String?
) {
fun validate() {
if (recipient?.isBlank() == true) {
throw ValidationException("Invalid address: recipient must not be blank")
}
if (addressLine1?.isBlank() == true) {
throw ValidationException("Invalid address: address line must not be blank")
}
if (addressLine2?.isBlank() == true) {
throw ValidationException("Invalid address: address line must not be blank")
}
if (postcode?.isBlank() == true) {
throw ValidationException("Invalid address: postcode must not be blank")
}
if (city?.isBlank() == true) {
throw ValidationException("Invalid address: city must not be blank")
}
if (region?.isBlank() == true) {
throw ValidationException("Invalid address: region must not be blank")
}
if (country?.isBlank() == true) {
throw ValidationException("Invalid address: country must not be blank")
}
}
}

enum class Status {
NOT_STARTED,
Expand All @@ -175,3 +217,5 @@ data class Order(
fun Order.OrderItem.isPickedOrFailed(): Boolean {
return this.status == PICKED || this.status == FAILED
}

fun createOrderAddress(): Address = Address(null, null, null, null, null, null, null)
Loading