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: add more fields to object creation (TT-1170) #35

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 25 additions & 2 deletions src/main/kotlin/no/nb/bikube/core/model/dto/ItemDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import kotlinx.serialization.Serializable
import no.nb.bikube.core.enum.AxiellFormat
import no.nb.bikube.core.enum.AxiellRecordType
import no.nb.bikube.core.model.Item
import java.time.LocalDate
import java.time.LocalTime
import java.time.format.DateTimeFormatter

@Serializable
class ItemDto (
Expand All @@ -21,7 +24,22 @@ class ItemDto (
val altNumber: String?,

@SerialName("alternative_number.type")
val altNumberType: String?
val altNumberType: String?,

@SerialName("input.name")
val inputName: String? = null,

@SerialName("input.source")
val inputSource: String? = null,

@SerialName("input.date")
val inputDate: String? = null,

@SerialName("input.time")
val inputTime: String? = null,

@SerialName("dataset_name")
val dataset: String? = null
)

fun createNewspaperItemDto(item: Item): ItemDto {
Expand All @@ -30,6 +48,11 @@ fun createNewspaperItemDto(item: Item): ItemDto {
format = if (item.digital == true) AxiellFormat.DIGITAL.value else AxiellFormat.PHYSICAL.value,
recordType = AxiellRecordType.ITEM.value,
altNumber = item.urn,
altNumberType = if (!item.urn.isNullOrBlank()) "URN" else null
altNumberType = if (!item.urn.isNullOrBlank()) "URN" else null,
inputName = "Bikube API", // TODO: Change when we have authentication in place
inputSource = "texts>texts",
inputDate = LocalDate.now().toString(),
inputTime = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString(),
dataset = "texts"
)
}
27 changes: 25 additions & 2 deletions src/main/kotlin/no/nb/bikube/core/model/dto/TitleDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import no.nb.bikube.core.enum.AxiellDescriptionType
import no.nb.bikube.core.enum.AxiellRecordType
import no.nb.bikube.core.enum.MaterialType
import no.nb.bikube.core.model.Title
import java.time.LocalDate
import java.time.LocalTime
import java.time.format.DateTimeFormatter

@Serializable
class TitleDto(
Expand Down Expand Up @@ -36,7 +39,22 @@ class TitleDto(
val placeOfPublication: String? = null,

@SerialName("language")
val language: String? = null
val language: String? = null,

@SerialName("input.name")
val inputName: String? = null,

@SerialName("input.source")
val inputSource: String? = null,

@SerialName("input.date")
val inputDate: String? = null,

@SerialName("input.time")
val inputTime: String? = null,

@SerialName("dataset_name")
val dataset: String? = null
)

fun createNewspaperTitleDto(title: Title): TitleDto {
Expand All @@ -50,6 +68,11 @@ fun createNewspaperTitleDto(title: Title): TitleDto {
recordType = AxiellRecordType.WORK.value,
descriptionType = AxiellDescriptionType.SERIAL.value,
medium = "Tekst",
subMedium = MaterialType.NEWSPAPER.norwegian
subMedium = MaterialType.NEWSPAPER.norwegian,
inputName = "Bikube API", // TODO: Change when we have authentication in place
inputSource = "texts>texts",
inputDate = LocalDate.now().toString(),
inputTime = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString(),
dataset = "texts"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nb.bikube.newspaper.service

import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import io.mockk.mockkStatic
import io.mockk.verify
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -40,6 +41,9 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import reactor.core.publisher.Mono
import reactor.kotlin.test.test
import java.time.LocalDate
import java.time.LocalTime
import java.time.format.DateTimeFormatter

@SpringBootTest
@ActiveProfiles("test")
Expand All @@ -54,6 +58,8 @@ class AxiellServiceTest(

@Test
fun `createTitle should return Title object with default values from Title with only name and materialType`() {
mockkStatic(LocalTime::class)
every { LocalTime.now() } returns LocalTime.of(9, 30, 0)
every { axiellRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockTitleE)

val body = newspaperTitleMockB.copy()
Expand All @@ -68,7 +74,12 @@ class AxiellServiceTest(
recordType = AxiellRecordType.WORK.value,
descriptionType = AxiellDescriptionType.SERIAL.value,
medium = "Tekst",
subMedium = newspaperTitleMockB.materialType
subMedium = newspaperTitleMockB.materialType,
inputName = "Bikube API",
inputSource = "texts>texts",
inputDate = LocalDate.now().toString(),
inputTime = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString(),
dataset = "texts"
)
)

Expand Down Expand Up @@ -397,6 +408,8 @@ class AxiellServiceTest(

@Test
fun `createTitle should correctly encode the title object sent to json string`() {
mockkStatic(LocalTime::class)
every { LocalTime.now() } returns LocalTime.of(9, 30, 0)
every { axiellRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockTitleE)
val encodedValue = Json.encodeToString(
TitleDto(
Expand All @@ -409,7 +422,12 @@ class AxiellServiceTest(
recordType = AxiellRecordType.WORK.value,
descriptionType = AxiellDescriptionType.SERIAL.value,
medium = "Tekst",
subMedium = newspaperTitleMockB.materialType
subMedium = newspaperTitleMockB.materialType,
inputName = "Bikube API",
inputSource = "texts>texts",
inputDate = LocalDate.now().toString(),
inputTime = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString(),
dataset = "texts"
)
)

Expand Down Expand Up @@ -548,6 +566,8 @@ class AxiellServiceTest(

@Test
fun `createNewspaperItem should correctly encode the item object sent to json string`() {
mockkStatic(LocalTime::class)
every { LocalTime.now() } returns LocalTime.of(9, 30, 0)
every { axiellRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockItemB)

val encodedValue = Json.encodeToString(
Expand All @@ -556,7 +576,12 @@ class AxiellServiceTest(
format = AxiellFormat.DIGITAL.value,
recordType = AxiellRecordType.ITEM.value,
altNumber = newspaperItemMockB.urn,
altNumberType = "URN"
altNumberType = "URN",
inputName = "Bikube API",
inputSource = "texts>texts",
inputDate = LocalDate.now().toString(),
inputTime = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString(),
dataset = "texts"
)
)

Expand Down