Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Relax the ODL requirement to have an OA acquisition link to just an a…
Browse files Browse the repository at this point in the history
…cquisition link.
  • Loading branch information
jonathangreen committed Jul 31, 2024
1 parent 264cac7 commit f031560
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/webpub_manifest_parser/odl/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def _format_message(
message="ODL feed '{0}' contains redundant 'navigation' subcollection",
)

ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_OA_ACQUISITION_LINK_ERROR = partial(
ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_ACQUISITION_LINK_ERROR = partial(
ODLPublicationSemanticError,
message="ODL publication '{0}' contains neither 'licenses' subcollection nor "
"an Open-Access Acquisition Link (http://opds-spec.org/acquisition/open-access)",
"an Acquisition Link (http://opds-spec.org/acquisition)",
)

ODL_LICENSE_MUST_CONTAIN_SELF_LINK_TO_LICENSE_INFO_DOCUMENT_ERROR = partial(
Expand Down Expand Up @@ -195,12 +195,19 @@ def visit(self, node):
"""
self._logger.debug(f"Started processing {encode(node)}")

links = node.links or []
acquisition_uri = OPDS2LinkRelationsRegistry.ACQUISITION.key
acquisition_links = [
l
for l in links
if any([rel.startswith(acquisition_uri) for rel in l.rels or []])
]

if (not node.licenses or len(node.licenses) == 0) and (
(not node.links or len(node.links) == 0)
or not node.links.get_by_rel(OPDS2LinkRelationsRegistry.OPEN_ACCESS.key)
(not node.links or len(node.links) == 0) or (len(acquisition_links) == 0)
):
with self._record_errors():
raise ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_OA_ACQUISITION_LINK_ERROR(
raise ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_ACQUISITION_LINK_ERROR(
node=node, node_property=None
)
elif node.licenses:
Expand Down
78 changes: 73 additions & 5 deletions tests/webpub_manifest_parser/odl/test_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ODL_FEED_MISSING_PUBLICATIONS_SUBCOLLECTION_ERROR,
ODL_LICENSE_MUST_CONTAIN_CHECKOUT_LINK_TO_LICENSE_STATUS_DOCUMENT_ERROR,
ODL_LICENSE_MUST_CONTAIN_SELF_LINK_TO_LICENSE_INFO_DOCUMENT_ERROR,
ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_OA_ACQUISITION_LINK_ERROR,
ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_ACQUISITION_LINK_ERROR,
ODLSemanticAnalyzer,
)
from webpub_manifest_parser.opds2 import (
Expand Down Expand Up @@ -123,7 +123,7 @@ class ODLSemanticAnalyzerTest(AnalyzerTest):
],
),
(
"when_publication_does_not_contain_neither_licenses_nor_oa_link",
"when_publication_does_not_contain_licenses_nor_acquisition_link",
ODLFeed(
metadata=OPDS2FeedMetadata(title="test"),
links=LinkList(
Expand All @@ -146,7 +146,7 @@ class ODLSemanticAnalyzerTest(AnalyzerTest):
),
),
[
ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_OA_ACQUISITION_LINK_ERROR(
ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_ACQUISITION_LINK_ERROR(
node=ODLPublication(
metadata=OPDS2PublicationMetadata(title="Publication 1")
),
Expand All @@ -155,7 +155,7 @@ class ODLSemanticAnalyzerTest(AnalyzerTest):
],
),
(
"when_publication_does_not_contain_neither_licenses_nor_oa_link",
"when_publication_does_not_contain_licenses_nor_acquisition_link",
ODLFeed(
metadata=OPDS2FeedMetadata(title="test"),
links=LinkList(
Expand All @@ -178,7 +178,7 @@ class ODLSemanticAnalyzerTest(AnalyzerTest):
),
),
[
ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_OA_ACQUISITION_LINK_ERROR(
ODL_PUBLICATION_MUST_CONTAIN_EITHER_LICENSES_OR_ACQUISITION_LINK_ERROR(
node=ODLPublication(
metadata=OPDS2PublicationMetadata(title="Publication 1")
),
Expand Down Expand Up @@ -220,6 +220,74 @@ class ODLSemanticAnalyzerTest(AnalyzerTest):
),
[],
),
(
"when_publication_does_not_contain_licenses_and_has_an_acquisition_link",
ODLFeed(
metadata=OPDS2FeedMetadata(title="test"),
links=LinkList(
[
Link(
href="http://example.com",
rels=[LinkRelationsRegistry.SELF.key],
)
]
),
publications=CollectionList(
[
ODLPublication(
metadata=OPDS2PublicationMetadata(
title="Publication 1"
),
links=LinkList(
[
Link(
href="http://example.com",
rels=[
OPDS2LinkRelationsRegistry.ACQUISITION.key
],
)
]
),
)
]
),
),
[],
),
(
"when_publication_does_not_contain_licenses_and_has_an_acquisition_link",
ODLFeed(
metadata=OPDS2FeedMetadata(title="test"),
links=LinkList(
[
Link(
href="http://example.com",
rels=[LinkRelationsRegistry.SELF.key],
)
]
),
publications=CollectionList(
[
ODLPublication(
metadata=OPDS2PublicationMetadata(
title="Publication 1"
),
links=LinkList(
[
Link(
href="http://example.com",
rels=[
OPDS2LinkRelationsRegistry.ACQUISITION.key
],
)
]
),
)
]
),
),
[],
),
(
"when_license_does_not_contain_self_link_and_borrow_link",
ODLFeed(
Expand Down

0 comments on commit f031560

Please sign in to comment.