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

feat: require physical items to have container ID (TT-1740) #97

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,15 @@ class CollectionsControllerExceptionHandler {

return problemDetail
}

@ExceptionHandler(CollectionsPhysicalItemMissingContainer::class)
fun handleCollectionsPhysicalItemMissingContainerException(exception: CollectionsPhysicalItemMissingContainer): ProblemDetail {
logger().warn("CollectionsPhysicalItemMissingContainer occurred: ${exception.message}")

val problemDetail = ProblemDetail.forStatus(HttpStatus.BAD_REQUEST)
problemDetail.detail = "Physical item is missing container: ${exception.message}"
problemDetail.addDefaultProperties()

return problemDetail
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package no.nb.bikube.catalogue.collections.exception

class CollectionsPhysicalItemMissingContainer(message: String?) : CollectionsException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ class NewspaperService (
if (item.digital == false && !item.containerId.isNullOrBlank()) {
collectionsLocationService.createContainerIfNotExists(item.containerId, item.username)
.then(createLinkedNewspaperItem(item, manifestationId))
} else if (item.digital == false && item.containerId.isNullOrBlank()) {
Mono.error(CollectionsPhysicalItemMissingContainer("Physical item must have a container ID"))
pierrebeauguitte marked this conversation as resolved.
Show resolved Hide resolved
} else {
createLinkedNewspaperItem(item, manifestationId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import no.nb.bikube.catalogue.collections.enum.CollectionsFormat
import no.nb.bikube.catalogue.collections.enum.CollectionsRecordType
import no.nb.bikube.catalogue.collections.exception.CollectionsException
import no.nb.bikube.catalogue.collections.exception.CollectionsManifestationNotFound
import no.nb.bikube.catalogue.collections.exception.CollectionsPhysicalItemMissingContainer
import no.nb.bikube.catalogue.collections.exception.CollectionsTitleNotFound
import no.nb.bikube.catalogue.collections.model.*
import no.nb.bikube.catalogue.collections.model.dto.*
Expand Down Expand Up @@ -134,7 +135,8 @@ class NewspaperServiceTest {
inputDate = LocalDate.now().toString(),
inputTime = mockedTime.format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString(),
dataset = "texts",
partOfReference = newspaperItemMockB.catalogueId
partOfReference = newspaperItemMockB.catalogueId,
currentLocationName = collectionsLocationObjectMock.priRef
))

private val titleEncodedDto = Json.encodeToString(TitleDto(
Expand Down Expand Up @@ -518,10 +520,14 @@ class NewspaperServiceTest {
@Test
fun `createNewspaperItem should ignore URN if is is a physical item`() {
every { collectionsRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockItemB)
every { collectionsRepository.getSingleCollectionsModel(any()) } returns Mono.just(collectionsModelMockItemB)
every { collectionsRepository.getSingleCollectionsModelWithoutChildren(any()) } returns Mono.just(collectionsModelMockItemB)
every { collectionsRepository.getSingleCollectionsModel(any()) } returns Mono.just(collectionsModelMockItemB)
every { collectionsRepository.getManifestations(any(), any(), any()) } returns Mono.just(collectionsModelMockManifestationB)
newspaperService.createNewspaperItem(newspaperInputDtoItemMockB.copy(digital = false))
every { collectionLocationService.createContainerIfNotExists(any(), any()) } returns Mono.just(collectionsLocationObjectMock)

newspaperService.createNewspaperItem(
newspaperInputDtoItemMockB.copy(digital = false, containerId = collectionsLocationObjectMock.priRef)
)
.test()
.expectSubscription()
.expectNextCount(1)
Expand Down Expand Up @@ -575,7 +581,7 @@ class NewspaperServiceTest {
}

@Test
fun `createNewspaperItem should not get or create container if item is physical and does not have container ID`() {
fun `createNewspaperItem should return CollectionsPhysicalItemMissingContainer if item is physical and does not have container ID`() {
every { collectionsRepository.getSingleCollectionsModelWithoutChildren(any()) } returns Mono.just(collectionsModelMockItemB)
every { collectionsRepository.getSingleCollectionsModel(any()) } returns Mono.just(collectionsModelMockItemB)
every { collectionsRepository.getManifestations(any(), any(), any()) } returns Mono.just(collectionsModelMockManifestationB)
Expand All @@ -588,11 +594,11 @@ class NewspaperServiceTest {
newspaperService.createNewspaperItem(testItem)
.test()
.expectSubscription()
.expectNextCount(1)
.verifyComplete()

// Then a container should not be created
verify (exactly = 0) { collectionLocationService.createContainerIfNotExists(any(), any()) }
.expectErrorMatches {
it is CollectionsPhysicalItemMissingContainer &&
it.message!!.contains("Physical item must have a container ID")
}
.verify()
}

@Test
Expand Down