mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
parent
0c089d73c1
commit
2012f8be98
5 changed files with 164 additions and 10 deletions
|
|
@ -65,8 +65,19 @@ class ComicInfoProvider(
|
||||||
}
|
}
|
||||||
|
|
||||||
comicInfo.storyArc?.let { value ->
|
comicInfo.storyArc?.let { value ->
|
||||||
val arcs = value.split(",").mapNotNull { it.trim().ifBlank { null } }
|
// get list of arcs and corresponding number, split by `,`
|
||||||
readLists.addAll(arcs.map { BookMetadataPatch.ReadListEntry(it) })
|
val arcs = value.split(",").map { it.trim().ifBlank { null } }
|
||||||
|
val numbers = comicInfo.storyArcNumber?.split(",")?.map { it.trim().toIntOrNull() }
|
||||||
|
|
||||||
|
if (!numbers.isNullOrEmpty()) {
|
||||||
|
// if there is associated numbers, add each valid association as a read list entry
|
||||||
|
(arcs zip numbers).forEach { (arc, number) ->
|
||||||
|
if (arc != null && number != null) readLists.add(BookMetadataPatch.ReadListEntry(arc, number))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if there is no numbers, only use the arcs name
|
||||||
|
readLists.addAll(arcs.filterNotNull().map { BookMetadataPatch.ReadListEntry(it) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BookMetadataPatch(
|
return BookMetadataPatch(
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,9 @@ class ComicInfo {
|
||||||
@JsonProperty(value = "StoryArc")
|
@JsonProperty(value = "StoryArc")
|
||||||
var storyArc: String? = null
|
var storyArc: String? = null
|
||||||
|
|
||||||
|
@JsonProperty(value = "StoryArcNumber")
|
||||||
|
var storyArcNumber: String? = null
|
||||||
|
|
||||||
@JsonProperty(value = "SeriesGroup")
|
@JsonProperty(value = "SeriesGroup")
|
||||||
var seriesGroup: String? = null
|
var seriesGroup: String? = null
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.gotson.komga.domain.model.BookMetadataPatch
|
||||||
import org.gotson.komga.domain.model.BookWithMedia
|
import org.gotson.komga.domain.model.BookWithMedia
|
||||||
import org.gotson.komga.domain.model.Media
|
import org.gotson.komga.domain.model.Media
|
||||||
import org.gotson.komga.domain.model.SeriesMetadata
|
import org.gotson.komga.domain.model.SeriesMetadata
|
||||||
|
|
@ -62,14 +63,137 @@ class ComicInfoProviderTest {
|
||||||
assertThat(number).isEqualTo("010")
|
assertThat(number).isEqualTo("010")
|
||||||
assertThat(numberSort).isEqualTo(10F)
|
assertThat(numberSort).isEqualTo(10F)
|
||||||
assertThat(releaseDate).isEqualTo(LocalDate.of(2020, 2, 1))
|
assertThat(releaseDate).isEqualTo(LocalDate.of(2020, 2, 1))
|
||||||
with(readLists) {
|
|
||||||
assertThat(this).hasSize(4)
|
assertThat(readLists).hasSize(4)
|
||||||
assertThat(this.map { it.name }).containsExactly("story arc", "one", "two", "three")
|
assertThat(readLists).containsExactlyInAnyOrder(
|
||||||
this.first { it.number != null }.let {
|
BookMetadataPatch.ReadListEntry("story arc", 5),
|
||||||
assertThat(it.name).isEqualTo("story arc")
|
BookMetadataPatch.ReadListEntry("one"),
|
||||||
assertThat(it.number).isEqualTo(5)
|
BookMetadataPatch.ReadListEntry("two"),
|
||||||
}
|
BookMetadataPatch.ReadListEntry("three"),
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given comicInfo with StoryArcNumber when getting book metadata then metadata patch is valid`() {
|
||||||
|
val comicInfo = ComicInfo().apply {
|
||||||
|
storyArc = "one"
|
||||||
|
storyArcNumber = "6"
|
||||||
|
}
|
||||||
|
|
||||||
|
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
|
||||||
|
|
||||||
|
val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))
|
||||||
|
|
||||||
|
with(patch!!) {
|
||||||
|
assertThat(readLists).hasSize(1)
|
||||||
|
assertThat(readLists).containsExactlyInAnyOrder(
|
||||||
|
BookMetadataPatch.ReadListEntry("one", 6)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given comicInfo with multiple StoryArcNumber when getting book metadata then metadata patch is valid`() {
|
||||||
|
val comicInfo = ComicInfo().apply {
|
||||||
|
alternateSeries = "story arc"
|
||||||
|
alternateNumber = "5"
|
||||||
|
storyArc = "one, two, three"
|
||||||
|
storyArcNumber = "6, 7, 8"
|
||||||
|
}
|
||||||
|
|
||||||
|
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
|
||||||
|
|
||||||
|
val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))
|
||||||
|
|
||||||
|
with(patch!!) {
|
||||||
|
assertThat(readLists).hasSize(4)
|
||||||
|
assertThat(readLists).containsExactlyInAnyOrder(
|
||||||
|
BookMetadataPatch.ReadListEntry("story arc", 5),
|
||||||
|
BookMetadataPatch.ReadListEntry("one", 6),
|
||||||
|
BookMetadataPatch.ReadListEntry("two", 7),
|
||||||
|
BookMetadataPatch.ReadListEntry("three", 8),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given comicInfo with uneven StoryArcNumber when getting book metadata then metadata patch is valid`() {
|
||||||
|
val comicInfo = ComicInfo().apply {
|
||||||
|
storyArc = "one, two"
|
||||||
|
storyArcNumber = "6, 7, 8"
|
||||||
|
}
|
||||||
|
|
||||||
|
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
|
||||||
|
|
||||||
|
val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))
|
||||||
|
|
||||||
|
with(patch!!) {
|
||||||
|
assertThat(readLists).hasSize(2)
|
||||||
|
assertThat(readLists).containsExactlyInAnyOrder(
|
||||||
|
BookMetadataPatch.ReadListEntry("one", 6),
|
||||||
|
BookMetadataPatch.ReadListEntry("two", 7),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given another comicInfo with uneven StoryArcNumber when getting book metadata then metadata patch is valid`() {
|
||||||
|
val comicInfo = ComicInfo().apply {
|
||||||
|
storyArc = "one, two, three"
|
||||||
|
storyArcNumber = "6, 7"
|
||||||
|
}
|
||||||
|
|
||||||
|
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
|
||||||
|
|
||||||
|
val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))
|
||||||
|
|
||||||
|
with(patch!!) {
|
||||||
|
assertThat(readLists).hasSize(2)
|
||||||
|
assertThat(readLists).containsExactlyInAnyOrder(
|
||||||
|
BookMetadataPatch.ReadListEntry("one", 6),
|
||||||
|
BookMetadataPatch.ReadListEntry("two", 7),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given comicInfo with invalid StoryArcNumber when getting book metadata then invalid pairs are omitted`() {
|
||||||
|
val comicInfo = ComicInfo().apply {
|
||||||
|
storyArc = "one, two, three"
|
||||||
|
storyArcNumber = "6, x, 8"
|
||||||
|
}
|
||||||
|
|
||||||
|
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
|
||||||
|
|
||||||
|
val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))
|
||||||
|
|
||||||
|
with(patch!!) {
|
||||||
|
assertThat(readLists).hasSize(2)
|
||||||
|
assertThat(readLists).containsExactlyInAnyOrder(
|
||||||
|
BookMetadataPatch.ReadListEntry("one", 6),
|
||||||
|
BookMetadataPatch.ReadListEntry("three", 8),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given comicInfo with invalid StoryArc when getting book metadata then invalid pairs are omitted`() {
|
||||||
|
val comicInfo = ComicInfo().apply {
|
||||||
|
storyArc = "one, , three"
|
||||||
|
storyArcNumber = "6, 7, 8"
|
||||||
|
}
|
||||||
|
|
||||||
|
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
|
||||||
|
|
||||||
|
val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))
|
||||||
|
|
||||||
|
with(patch!!) {
|
||||||
|
assertThat(readLists).hasSize(2)
|
||||||
|
assertThat(readLists).containsExactlyInAnyOrder(
|
||||||
|
BookMetadataPatch.ReadListEntry("one", 6),
|
||||||
|
BookMetadataPatch.ReadListEntry("three", 8),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,4 +72,15 @@ class ComicInfoTest {
|
||||||
assertThat(manga).isNull()
|
assertThat(manga).isNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given valid xml file with StoryArc fields when deserializing then properties are available`() {
|
||||||
|
val file = ClassPathResource("comicrack/ComicInfo_StoryArc.xml")
|
||||||
|
val comicInfo = mapper.readValue<ComicInfo>(file.url)
|
||||||
|
|
||||||
|
with(comicInfo) {
|
||||||
|
assertThat(storyArc).isEqualTo("Arc")
|
||||||
|
assertThat(storyArcNumber).isEqualTo("2")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<ComicInfo>
|
||||||
|
<StoryArc>Arc</StoryArc>
|
||||||
|
<StoryArcNumber>2</StoryArcNumber>
|
||||||
|
</ComicInfo>
|
||||||
Loading…
Reference in a new issue