Skip to content

Commit

Permalink
Merge pull request #185 from M3nin0/marketplace
Browse files Browse the repository at this point in the history
marketplace: enabling iiif
  • Loading branch information
M3nin0 authored Feb 13, 2024
2 parents 3b9ecb6 + 4c2acc2 commit 7c19911
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 14 deletions.
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
)

0 comments on commit 7c19911

Please sign in to comment.