diff --git a/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisRecord.kt b/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisRecord.kt index 7777ec8f..bc854096 100644 --- a/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisRecord.kt +++ b/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisRecord.kt @@ -181,7 +181,14 @@ public data class RisRecord( */ public var miscellaneous2: String? = null, - /** M3 */ + /** + * M3 - often used for Type of Work. Alphanumeric field. + */ + public var miscellaneous3: String? = null, + + // TODO remove in #132 + /** M3 - deprecated */ + @Deprecated("Use miscellaneous3 instead", ReplaceWith("miscellaneous3")) public var typeOfWork: String? = null, /** N1 */ @@ -341,8 +348,11 @@ public data class RisRecord( private var label: String? = null private var websiteLink: String? = null private var miscellaneous1: String? = null + // TODO remove in #132 private var number: Long? = null private var miscellaneous2: String? = null + private var miscellaneous3: String? = null + // TODO remove in #132 private var typeOfWork: String? = null private var notes: String? = null private var abstr2: String? = null @@ -467,6 +477,9 @@ public data class RisRecord( @Deprecated("use miscellaneous1(number.toString()) instead", ReplaceWith("miscellaneous1(number.toString())")) public fun number(number: Long?): Builder = apply { this.number = number } public fun miscellaneous2(miscellaneous2: String?): Builder = apply { this.miscellaneous2 = miscellaneous2 } + public fun miscellaneous3(miscellaneous3: String?): Builder = apply { this.miscellaneous3 = miscellaneous3 } + + @Deprecated("use miscellaneous3(String) instead", ReplaceWith("miscellaneous3(typeOfWork)")) public fun typeOfWork(typeOfWork: String?): Builder = apply { this.typeOfWork = typeOfWork } public fun notes(notes: String?): Builder = apply { this.notes = notes } public fun abstr2(abstr2: String?): Builder = apply { this.abstr2 = abstr2 } @@ -557,6 +570,7 @@ public data class RisRecord( miscellaneous1, number, miscellaneous2, + miscellaneous3, typeOfWork, notes, abstr2, diff --git a/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisTag.kt b/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisTag.kt index b41a4cf9..7a06f1ab 100644 --- a/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisTag.kt +++ b/subprojects/kris-core/src/main/kotlin/ch/difty/kris/domain/RisTag.kt @@ -403,11 +403,18 @@ public enum class RisTag( getFrom = { r: RisRecord -> r.miscellaneous2 } ), - /** Type of Work */ + /** Miscellaneous 3. Often used for Type of Work */ + @Suppress("Deprecation") M3( - description = "Type of Work", - setInto = { r, v -> r.typeOfWork = v as String? }, - getFrom = { r: RisRecord -> r.typeOfWork } + description = "Miscellaneous 3 (often Type of Work)", + setInto = { r, v -> + r.miscellaneous3 = v as String? + r.typeOfWork = v + }, + getFrom = { r: RisRecord -> + r.miscellaneous3.takeUnless { it.isNullOrBlank() } + ?: r.typeOfWork + } ), /** Notes */ diff --git a/subprojects/kris-core/src/test/java/ch/difty/kris/domain/RisRecordBuilderTest.java b/subprojects/kris-core/src/test/java/ch/difty/kris/domain/RisRecordBuilderTest.java index f03f60d7..4148aecd 100644 --- a/subprojects/kris-core/src/test/java/ch/difty/kris/domain/RisRecordBuilderTest.java +++ b/subprojects/kris-core/src/test/java/ch/difty/kris/domain/RisRecordBuilderTest.java @@ -57,7 +57,7 @@ class RisRecordBuilderTest { .websiteLink("websiteLink") .miscellaneous1("number") .miscellaneous2("miscellaneous2") - .typeOfWork("typeOfWork") + .miscellaneous3("typeOfWork") .notes("notes") .abstr2("abstr2") .numberOfVolumes("numberOfVolumes") @@ -140,7 +140,7 @@ void canFillAllFieldsIntoDataClassAppropriately() { assertThat(risRecord.getWebsiteLink()).isEqualTo("websiteLink"); assertThat(risRecord.getMiscellaneous1()).isEqualTo("number"); assertThat(risRecord.getMiscellaneous2()).isEqualTo("miscellaneous2"); - assertThat(risRecord.getTypeOfWork()).isEqualTo("typeOfWork"); + assertThat(risRecord.getMiscellaneous3()).isEqualTo("typeOfWork"); assertThat(risRecord.getNotes()).isEqualTo("notes"); assertThat(risRecord.getAbstr2()).isEqualTo("abstr2"); assertThat(risRecord.getNumberOfVolumes()).isEqualTo("numberOfVolumes"); @@ -224,7 +224,7 @@ void emptyRecord() { assertThat(risRecord.getWebsiteLink()).isNull(); assertThat(risRecord.getMiscellaneous1()).isNull(); assertThat(risRecord.getMiscellaneous2()).isNull(); - assertThat(risRecord.getTypeOfWork()).isNull(); + assertThat(risRecord.getMiscellaneous3()).isNull(); assertThat(risRecord.getNotes()).isNull(); assertThat(risRecord.getAbstr2()).isNull(); assertThat(risRecord.getNumberOfVolumes()).isNull(); @@ -276,4 +276,24 @@ public void givenRisRecordWithNumber_providesNumberButNotMisc1() { assertThat(risRecord.getMiscellaneous1()).isNull(); assertThat(risRecord.getNumber()).isEqualTo(1234L); } + + @SuppressWarnings("deprecation") + @Test + public void givenRisRecordWithMisc3_providesMisc3ButNotTypeOfWork() { + RisRecord risRecord = new RisRecord.Builder() + .miscellaneous3("misc3") + .build(); + assertThat(risRecord.getMiscellaneous3()).isEqualTo("misc3"); + assertThat(risRecord.getTypeOfWork()).isNull(); + } + + @SuppressWarnings("deprecation") + @Test + public void givenRisRecordWithTypeOfWork_providesTypeOfWorkButNotMisc3() { + RisRecord risRecord = new RisRecord.Builder() + .typeOfWork("misc3") + .build(); + assertThat(risRecord.getMiscellaneous3()).isNull(); + assertThat(risRecord.getTypeOfWork()).isEqualTo("misc3"); + } } diff --git a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/KRisProcessFromListTest.kt b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/KRisProcessFromListTest.kt index d99556c0..72562e14 100644 --- a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/KRisProcessFromListTest.kt +++ b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/KRisProcessFromListTest.kt @@ -58,7 +58,7 @@ class KRisProcessFromListTest { websiteLink = "websiteLink", miscellaneous1 = "number", miscellaneous2 = "miscellaneous2", - typeOfWork = "typeOfWork", + miscellaneous3 = "typeOfWork", notes = "notes", abstr2 = "abstr2", numberOfVolumes = "numberOfVolumes", diff --git a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisRecordSpec.kt b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisRecordSpec.kt index 30012f9a..49211c2e 100644 --- a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisRecordSpec.kt +++ b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisRecordSpec.kt @@ -74,7 +74,7 @@ object RisRecordSpec : DescribeSpec({ websiteLink = null, miscellaneous1 = null, miscellaneous2 = null, - typeOfWork = null, + miscellaneous3 = null, notes = null, abstr2 = null, numberOfVolumes = null, @@ -161,7 +161,7 @@ object RisRecordSpec : DescribeSpec({ websiteLink = "websiteLink", miscellaneous1 = "number", miscellaneous2 = "miscellaneous2", - typeOfWork = "typeOfWork", + miscellaneous3 = "typeOfWork", notes = "notes", abstr2 = "abstr2", numberOfVolumes = "numberOfVolumes", @@ -246,7 +246,7 @@ object RisRecordSpec : DescribeSpec({ .websiteLink("websiteLink") .miscellaneous1("number") .miscellaneous2("miscellaneous2") - .typeOfWork("typeOfWork") + .miscellaneous3("typeOfWork") .notes("notes") .abstr2("abstr2") .numberOfVolumes("numberOfVolumes") @@ -285,22 +285,34 @@ object RisRecordSpec : DescribeSpec({ @Suppress("DEPRECATION") describe("Deprecated fields") { describe("with RisRecord constructed with new properties") { - val record = RisRecord(miscellaneous1 = "1234") + val record = RisRecord(miscellaneous1 = "1234", miscellaneous3 = "foo") it("should return null as Number") { record.number.shouldBeNull() } + it("should return null as typeOfWork") { + record.typeOfWork.shouldBeNull() + } it("should return '1234' as miscellaneous1") { record.miscellaneous1 shouldBeEqualTo "1234" } + it("should return 'foo'' as miscellaneous3") { + record.miscellaneous3 shouldBeEqualTo "foo" + } } describe("with RisRecord constructed with deprecated properties") { - val record = RisRecord(number = 1234L) + val record = RisRecord(number = 1234L, typeOfWork = "foo") it("should return 1234 as Number") { record.number shouldBeEqualTo 1234L } + it("should return 'foo' as typeOfWork") { + record.typeOfWork shouldBeEqualTo "foo" + } it("should return null as miscellaneous1") { record.miscellaneous1.shouldBeNull() } + it("should return null as miscellaneous3") { + record.miscellaneous3.shouldBeNull() + } } } }) @@ -346,7 +358,7 @@ private suspend fun DescribeSpecContainerScope.assertDefaultValues(record: RisRe "websiteLink" to record.websiteLink, "number" to record.miscellaneous1, "miscellaneous2" to record.miscellaneous2, - "typeOfWork" to record.typeOfWork, + "typeOfWork" to record.miscellaneous3, "notes" to record.notes, "abstr2" to record.abstr2, "numberOfVolumes" to record.numberOfVolumes, @@ -442,7 +454,7 @@ private suspend fun DescribeSpecContainerScope.assertSpecifiedValues(record: Ris "websiteLink" to record.websiteLink, "number" to record.miscellaneous1, "miscellaneous2" to record.miscellaneous2, - "typeOfWork" to record.typeOfWork, + "typeOfWork" to record.miscellaneous3, "notes" to record.notes, "abstr2" to record.abstr2, "numberOfVolumes" to record.numberOfVolumes, diff --git a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisTagTest.kt b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisTagTest.kt index fe0a2a38..5869e732 100644 --- a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisTagTest.kt +++ b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/domain/RisTagTest.kt @@ -59,7 +59,7 @@ internal class RisTagTest { "Website Link", "Miscellaneous 1 (often Number)", "Miscellaneous 2.", - "Type of Work", + "Miscellaneous 3 (often Type of Work)", "Notes", "Abstract.", "Number of Volumes", diff --git a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/usage/KRisUsageSpec.kt b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/usage/KRisUsageSpec.kt index f25725b5..e0e041ca 100644 --- a/subprojects/kris-core/src/test/kotlin/ch/difty/kris/usage/KRisUsageSpec.kt +++ b/subprojects/kris-core/src/test/kotlin/ch/difty/kris/usage/KRisUsageSpec.kt @@ -199,20 +199,42 @@ object KRisUsageSpec : DescribeSpec({ risRecords.first().number.shouldBeNull() } } + describe("given M3") { + val risLines: List = listOf( + "M3 - typeOfWork", + "ER - " + ) + it("can be processed") { + val risRecords = risLines.toRisRecords() + risRecords.shouldHaveSize(1) + } + it("can retrieve it with new property miscellaneous3") { + val risRecords = risLines.toRisRecords() + risRecords.first().miscellaneous3 shouldBeEqualTo "typeOfWork" + } + it("can retrieve it with deprecated property typeOfWork") { + val risRecords = risLines.toRisRecords() + risRecords.first().typeOfWork shouldBeEqualTo "typeOfWork" + } + } } describe("exporting to RIS") { - describe("using new properties miscellaneous1") { + describe("using new properties miscellaneous1 and miscellaneous 3") { val risRecord1 = RisRecord( miscellaneous1 = "1234-5678", + miscellaneous3 = "typeOfWork", ) val risRecord2 = RisRecord( number = 4567L, + typeOfWork = "tow", ) - it("should export to M1") { + it("should export both to M1 and M3") { listOf(risRecord1, risRecord2).toRisLines().joinToString(separator = "") shouldBeEqualTo """M1 - 1234-5678 + |M3 - typeOfWork |ER - | |M1 - 4567 + |M3 - tow |ER - |""".trimMargin() } diff --git a/subprojects/kris-io/src/integrationTest/kotlin/ch/difty/kris/usage/KRisIoUsageSpec.kt b/subprojects/kris-io/src/integrationTest/kotlin/ch/difty/kris/usage/KRisIoUsageSpec.kt index 2010e272..939e1f84 100644 --- a/subprojects/kris-io/src/integrationTest/kotlin/ch/difty/kris/usage/KRisIoUsageSpec.kt +++ b/subprojects/kris-io/src/integrationTest/kotlin/ch/difty/kris/usage/KRisIoUsageSpec.kt @@ -63,7 +63,7 @@ object KRisIoUsageSpec : DescribeSpec({ val records = listOf( RisRecord( type = RisType.ABST, - typeOfWork = "tow", + miscellaneous3 = "tow", abstr = "abstr", language = "lang", databaseProvider = "dp"