Skip to content

Commit

Permalink
feat(metadata): support multiple values in Web field from ComicInfo.xml
Browse files Browse the repository at this point in the history
Closes: #1639
  • Loading branch information
gotson committed Sep 11, 2024
1 parent f07be06 commit d12f3b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,18 @@ class ComicInfoProvider(
}
}

val link =
comicInfo.web?.let {
try {
val uri = URI(it)
listOf(WebLink(uri.host, uri))
} catch (e: Exception) {
logger.error(e) { "Could not parse Web element as valid URI: $it" }
null
val links =
comicInfo.web
?.split(" ")
?.filter { it.isNotBlank() }
?.mapNotNull {
try {
URI(it.trim()).let { uri -> WebLink(uri.host, uri) }
} catch (e: Exception) {
logger.error(e) { "Could not parse Web element as valid URI: $it" }
null
}
}
}

val tags = comicInfo.tags?.split(',')?.mapNotNull { it.trim().lowercase().ifBlank { null } }

Expand All @@ -112,7 +114,7 @@ class ComicInfoProvider(
releaseDate = releaseDate,
authors = authors.ifEmpty { null },
readLists = readLists,
links = link,
links = links?.ifEmpty { null },
tags = if (!tags.isNullOrEmpty()) tags.toSet() else null,
isbn = isbn,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ComicInfoProviderTest {
alternateSeries = "story arc"
alternateNumber = "5"
storyArc = "one, two, three"
web = "https://www.comixology.com/Sandman/digital-comic/727888"
web = " https://www.comixology.com/Sandman/digital-comic/727888 https://www.comics.com/Sandman/digital-comic/727889 "
tags = "dark, Occult"
gtin = "9783440077894"
}
Expand All @@ -84,9 +84,9 @@ class ComicInfoProviderTest {
)

assertThat(links)
.hasSize(1)
.containsExactlyInAnyOrder(
WebLink("www.comixology.com", URI("https://www.comixology.com/Sandman/digital-comic/727888")),
WebLink("www.comics.com", URI("https://www.comics.com/Sandman/digital-comic/727889")),
)

assertThat(tags as Iterable<String>)
Expand All @@ -95,6 +95,25 @@ class ComicInfoProviderTest {
}
}

@Test
fun `given comicInfo with single link when getting book metadata then metadata patch is valid`() {
val comicInfo =
ComicInfo().apply {
web = "https://www.comixology.com/Sandman/digital-comic/727888"
}

every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo

val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))

with(patch!!) {
assertThat(links)
.containsExactlyInAnyOrder(
WebLink("www.comixology.com", URI("https://www.comixology.com/Sandman/digital-comic/727888")),
)
}
}

@Test
fun `given comicInfo with StoryArcNumber when getting book metadata then metadata patch is valid`() {
val comicInfo =
Expand Down Expand Up @@ -236,6 +255,7 @@ class ComicInfoProviderTest {
storyArc = ""
penciller = ""
gtin = ""
web = ""
}

every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
Expand All @@ -250,6 +270,7 @@ class ComicInfoProviderTest {
assertThat(authors).isNull()
assertThat(readLists).isEmpty()
assertThat(isbn).isNull()
assertThat(links).isNull()
}
}

Expand Down

0 comments on commit d12f3b3

Please sign in to comment.