From 68c151ed85c6800f94c2ba6ac540d1badb4ce5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Tue, 4 Aug 2020 16:37:22 +0200 Subject: [PATCH 1/2] Fix Publication.type when parsing a RWPM --- .../r2/shared/publication/Publication.kt | 17 ++++++++++--- .../r2/shared/publication/PublicationTest.kt | 25 ++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/publication/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/publication/Publication.kt index 19fb543b..7e131c47 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/publication/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/publication/Publication.kt @@ -243,7 +243,7 @@ data class Publication( * Returns whether all the resources in the reading order are bitmaps. */ internal val allReadingOrderIsBitmap: Boolean get() = - readingOrder.all { + allReadingOrderMatches { it.mediaType?.isBitmap == true } @@ -251,7 +251,7 @@ data class Publication( * Returns whether all the resources in the reading order are audio clips. */ internal val allReadingOrderIsAudio: Boolean get() = - readingOrder.all { + allReadingOrderMatches { it.mediaType?.isAudio == true } @@ -259,10 +259,13 @@ data class Publication( * Returns whether all the resources in the reading order are contained in any of the given media types. */ internal fun allReadingOrderMatchesAnyOf(vararg mediaTypes: MediaType): Boolean = - readingOrder.all { link -> + allReadingOrderMatches { link -> mediaTypes.any { link.mediaType?.matches(it) == true } } + private fun allReadingOrderMatches(predicate: (Link) -> Boolean): Boolean = + readingOrder.isNotEmpty() && readingOrder.all(predicate) + companion object { fun fromJSON(json: JSONObject?, normalizeHref: LinkHrefNormalizer = LinkHrefNormalizerIdentity): Publication? = @@ -313,7 +316,13 @@ data class Publication( resources = resources, tableOfContents = tableOfContents, otherCollections = otherCollections - ) + ).apply { + type = when { + metadata.type == "http://schema.org/Audiobook" || allReadingOrderIsAudio -> TYPE.AUDIO + allReadingOrderIsBitmap -> TYPE.DiViNa + else -> TYPE.WEBPUB + } + } } /** diff --git a/r2-shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt b/r2-shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt index bb631d3b..36c2bffa 100644 --- a/r2-shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt +++ b/r2-shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt @@ -14,7 +14,9 @@ import org.json.JSONObject import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Test +import org.readium.r2.shared.Fixtures import org.readium.r2.shared.assertJSONEquals +import org.readium.r2.shared.publication.Publication.TYPE.WEBPUB import org.readium.r2.shared.publication.services.positions import org.readium.r2.shared.publication.services.positionsByReadingOrder import java.net.URL @@ -47,7 +49,7 @@ class PublicationTest { metadata = Metadata(localizedTitle = LocalizedString("Title")), links = emptyList(), readingOrder = emptyList() - ), + ).apply { type = WEBPUB }, Publication.fromJSON(JSONObject("""{ "metadata": {"title": "Title"}, "links": [], @@ -66,7 +68,7 @@ class PublicationTest { resources = listOf(Link(href = "/image.png", type = "image/png")), tableOfContents = listOf(Link(href = "/cover.html"), Link(href = "/chap1.html")), otherCollections = listOf(PublicationCollection(role = "sub", links = listOf(Link(href = "/sublink")))) - ), + ).apply { type = WEBPUB }, Publication.fromJSON(JSONObject("""{ "@context": "https://readium.org/webpub-manifest/context.jsonld", "metadata": {"title": "Title"}, @@ -99,7 +101,7 @@ class PublicationTest { metadata = Metadata(localizedTitle = LocalizedString("Title")), links = listOf(Link(href = "/manifest.json", rels = setOf("self"))), readingOrder = listOf(Link(href = "/chap1.html", type = "text/html")) - ), + ).apply { type = WEBPUB }, Publication.fromJSON(JSONObject("""{ "@context": ["context1", "context2"], "metadata": {"title": "Title"}, @@ -131,7 +133,7 @@ class PublicationTest { metadata = Metadata(localizedTitle = LocalizedString("Title")), links = listOf(Link(href = "/manifest.json", rels = setOf("self"))), readingOrder = listOf(Link(href = "/chap1.html", type = "text/html")) - ), + ).apply { type = WEBPUB }, Publication.fromJSON(JSONObject("""{ "metadata": {"title": "Title"}, "links": [ @@ -150,7 +152,7 @@ class PublicationTest { metadata = Metadata(localizedTitle = LocalizedString("Title")), links = listOf(Link(href = "/manifest.json", rels = setOf("self"))), readingOrder = listOf(Link(href = "/chap1.html", type = "text/html")) - ), + ).apply { type = WEBPUB }, Publication.fromJSON(JSONObject("""{ "metadata": {"title": "Title"}, "links": [ @@ -171,7 +173,7 @@ class PublicationTest { links = listOf(Link(href = "/manifest.json", rels = setOf("self"))), readingOrder = listOf(Link(href = "/chap1.html", type = "text/html")), resources = listOf(Link(href = "/withtype", type = "text/html")) - ), + ).apply { type = WEBPUB }, Publication.fromJSON(JSONObject("""{ "metadata": {"title": "Title"}, "links": [ @@ -188,6 +190,17 @@ class PublicationTest { ) } + @Test fun `parse JSON computes the Publication {type} from the manifest content`() { + val fixtures = Fixtures("format") + fun parseAt(path: String): Publication = + Publication.fromJSON(JSONObject(fixtures.fileAt(path).readText()))!! + + assertEquals(Publication.TYPE.AUDIO, parseAt("audiobook.json").type) + assertEquals(Publication.TYPE.DiViNa, parseAt("divina.json").type) + assertEquals(WEBPUB, parseAt("webpub.json").type) + assertEquals(WEBPUB, parseAt("opds2-publication.json").type) + } + @Test fun `get minimal JSON`() { assertJSONEquals( JSONObject("""{ From f0620471b5608137512fe7ed2d8c1d08e5584a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Tue, 11 Aug 2020 15:38:07 +0200 Subject: [PATCH 2/2] Release 2.0.0-alpha.1 --- .github/CODEOWNERS | 1 - CHANGELOG.md | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index d9ce658a..00000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @aferditamuriqi diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d92cbcb..1267c3db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,9 @@ All notable changes to this project will be documented in this file. **Warning:** Features marked as *experimental* may change or be removed in a future release without notice. Use with caution. -[unreleased]: https://github.com/readium/r2-shared-kotlin/compare/master...HEAD -[1.2.0]: https://github.com/readium/r2-shared-kotlin/compare/1.1.6...1.2.0 - ## [Unreleased] -## [1.2.0] +## [2.0.0-alpha.1] ### Added @@ -42,3 +39,7 @@ All notable changes to this project will be documented in this file. * [The local HTTP server was broken](https://github.com/readium/r2-testapp-kotlin/pull/306) when provided with publication filenames containing invalid characters. * XML namespace prefixes are now properly supported when an author chooses unusual ones (contributed by [@qnga](https://github.com/readium/r2-shared-kotlin/pull/85)). * The `AndroidManifest.xml` is not forcing anymore `allowBackup` and `supportsRtl`, to let reading apps manage these features themselves (contributed by [@twaddington](https://github.com/readium/r2-shared-kotlin/pull/93)). + + +[unreleased]: https://github.com/readium/r2-shared-kotlin/compare/master...HEAD +[2.0.0-alpha.1]: https://github.com/readium/r2-shared-kotlin/compare/1.1.6...2.0.0-alpha.1