Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marketplace: enabling iiif #185

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions geo_rdm_records/modules/iiif/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,36 @@
from invenio_rdm_records.proxies import current_rdm_records_service
from invenio_rdm_records.services.services import IIIFService as BaseIIIFService

from geo_rdm_records.proxies import current_geo_packages_service
from geo_rdm_records.proxies import (
current_geo_packages_service,
current_marketplace_service,
)


class IIIFService(BaseIIIFService):
"""IIIF service."""

modes = {"record": ["record", "draft"], "package": ["package", "package-draft"]}
modes = {
"record": ["record", "draft"],
"package": ["package", "package-draft"],
"marketplace": ["marketplace-item", "marketplace-item-draft"],
}
"""Service operation mode."""

modes_service = {
"record": current_rdm_records_service,
"package": current_geo_packages_service,
"marketplace": current_marketplace_service,
}
"""Service per mode."""

modes_type = {
"record": {"record": ["record"], "draft": ["draft"]},
"package": {"record": ["package"], "draft": ["package-draft"]},
"marketplace": {
"record": ["marketplace-item"],
"draft": ["marketplace-item-draft"],
},
}
"""Types handled in each operation mode."""

Expand Down
100 changes: 88 additions & 12 deletions geo_rdm_records/modules/marketplace/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
PIDsComponent,
ReviewComponent,
)
from invenio_rdm_records.services.config import is_draft, is_draft_and_has_review
from invenio_rdm_records.services.config import (
is_draft,
is_draft_and_has_review,
is_iiif_compatible,
)
from invenio_records_resources.services import ConditionalLink
from invenio_records_resources.services.base.config import FromConfig
from invenio_records_resources.services.files.links import FileLink

from geo_rdm_records.base.services.config import BaseGEOServiceConfig
from geo_rdm_records.base.services.links import LinksRegistryType
Expand Down Expand Up @@ -92,17 +97,18 @@ class GEOMarketplaceServiceConfig(BaseGEOServiceConfig):
else_=RecordLink("{+ui}/uploads/marketplace/items/{id}"),
),
# IIIF
# ToDo: Review
# "self_iiif_manifest": ConditionalLink(
# cond=is_record,
# if_=RecordLink("{+api}/iiif/marketplace/items:{id}/manifest"),
# else_=RecordLink("{+api}/iiif/package-draft:{id}/manifest"),
# ),
# "self_iiif_sequence": ConditionalLink(
# cond=is_record,
# if_=RecordLink("{+api}/iiif/package:{id}/sequence/default"),
# else_=RecordLink("{+api}/iiif/package-draft:{id}/sequence/default"),
# ),
"self_iiif_manifest": ConditionalLink(
cond=is_record,
if_=RecordLink("{+api}/iiif/marketplace-item:{id}/manifest"),
else_=RecordLink("{+api}/iiif/marketplace-item-draft:{id}/manifest"),
),
"self_iiif_sequence": ConditionalLink(
cond=is_record,
if_=RecordLink("{+api}/iiif/marketplace-item:{id}/sequence/default"),
else_=RecordLink(
"{+api}/iiif/marketplace-item-draft:{id}/sequence/default"
),
),
# Files
"files": ConditionalLink(
cond=is_record,
Expand Down Expand Up @@ -143,10 +149,80 @@ class GEOMarketplaceServiceConfig(BaseGEOServiceConfig):
class GEOMarketplaceItemFileServiceConfig(rdm_config.RDMFileRecordServiceConfig):
"""GEO Marketplace Item file service config."""

# Configurations
service_id = "files_marketplace"

# Record class
record_cls = GEOMarketplaceItem

# Permission policy
permission_policy_cls = FromConfig(
"GEO_MARKETPLACE_ITEMS_PERMISSION_POLICY",
default=BaseGEOPermissionPolicy, # ToDo: Review permissions for Marketplace
import_string=True,
)

file_links_item = {
"self": FileLink("{+api}/marketplace/items/{id}/files/{key}"),
"content": FileLink("{+api}/marketplace/items/{id}/files/{key}/content"),
# FIXME: filename instead
"iiif_canvas": FileLink(
"{+api}/iiif/marketplace-item:{id}/canvas/{key}", when=is_iiif_compatible
),
"iiif_base": FileLink(
"{+api}/iiif/marketplace-item:{id}:{key}", when=is_iiif_compatible
),
"iiif_info": FileLink(
"{+api}/iiif/marketplace-item:{id}:{key}/info.json", when=is_iiif_compatible
),
"iiif_api": FileLink(
"{+api}/iiif/marketplace-item:{id}:{key}/{region=full}"
"/{size=full}/{rotation=0}/{quality=default}.{format=png}",
when=is_iiif_compatible,
),
}


class GEOMarketplaceItemDraftFileServiceConfig(rdm_config.RDMFileDraftServiceConfig):
"""GEO Marketplace Item (Draft) file service config."""

# Configurations
service_id = "files_marketplace_draft"

# Record class
record_cls = GEOMarketplaceItemDraft

# Permission policy
permission_action_prefix = "draft_"
permission_policy_cls = FromConfig(
"GEO_MARKETPLACE_ITEMS_PERMISSION_POLICY",
default=BaseGEOPermissionPolicy, # ToDo: Review permissions for Marketplace
import_string=True,
)

file_links_list = {
"self": RecordLink("{+api}/marketplace/items/{id}/draft/files"),
}

file_links_item = {
"self": FileLink("{+api}/marketplace/items/{id}/draft/files/{key}"),
"content": FileLink("{+api}/marketplace/items/{id}/draft/files/{key}/content"),
"commit": FileLink("{+api}/marketplace/items/{id}/draft/files/{key}/commit"),
# FIXME: filename instead
"iiif_canvas": FileLink(
"{+api}/iiif/marketplace-item-draft:{id}/canvas/{key}",
when=is_iiif_compatible,
),
"iiif_base": FileLink(
"{+api}/iiif/marketplace-item-draft:{id}:{key}", when=is_iiif_compatible
),
"iiif_info": FileLink(
"{+api}/iiif/marketplace-item-draft:{id}:{key}/info.json",
when=is_iiif_compatible,
),
"iiif_api": FileLink(
"{+api}/iiif/marketplace-item-draft:{id}:{key}/{region=full}"
"/{size=full}/{rotation=0}/{quality=default}.{format=png}",
when=is_iiif_compatible,
),
}
4 changes: 4 additions & 0 deletions geo_rdm_records/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
lambda: current_app.extensions["geo-rdm-records"].service_requests_notification
)
"""Helper proxy to get the current Requests notification service."""

current_marketplace_service = LocalProxy(
lambda: current_app.extensions["geo-rdm-records"].service_marketplace
)
Loading