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

All vocabularies endpoint and Admin interface #310

Merged
merged 28 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
37b5401
register new route
karkraeg May 13, 2024
e75df2d
Implemented first Admin view based on mock API
karkraeg May 14, 2024
ee02370
add copyright
karkraeg May 14, 2024
b5b3a28
remove WIP import
karkraeg May 14, 2024
9608045
remove more imports
karkraeg May 14, 2024
ec5f278
provide API endpoint with aggregated counts for all types of vocabula…
karkraeg May 16, 2024
2935b1a
add missing invenio-administration dependency
karkraeg May 17, 2024
f9e7eae
Add and update docstrings
SarahW91 May 17, 2024
9853d63
dirty commit, added resources
karkraeg May 22, 2024
5c6a166
fix imports and cleanup
karkraeg May 22, 2024
bf655be
cleanup
karkraeg May 23, 2024
4fe5dd3
overwrite api endpoint
karkraeg May 23, 2024
7c96f6c
Fixes after review. Take out additional list view for now until it is…
SarahW91 May 24, 2024
5bc8d9d
Fixed formatting and doc strings.
SarahW91 May 24, 2024
1acc37f
Fixed formatting
SarahW91 May 24, 2024
b7f83d2
vocabulary types: Implement query functionality
SarahW91 May 28, 2024
e2065d6
vocabulary types: Show count in list view
SarahW91 May 28, 2024
365c00d
vocabulary types: Implement sorting
SarahW91 May 28, 2024
cc8d455
vocabulary type endpoint: fix formatting
SarahW91 Jun 13, 2024
474b4e8
vocabulary types endpoint: split implementation for service, config a…
SarahW91 Jun 13, 2024
25c9810
services: fix service proxy
karkraeg Jun 14, 2024
2b9802c
vocabulary types administration: Fix sidebar menu name and remove cre…
SarahW91 Jun 17, 2024
7ea3d9a
vocabulary types administration: Add Uni Münster copyright notice.
SarahW91 Jun 17, 2024
9d66db2
vocabulary types administration tests: Use correct service for tests
SarahW91 Jun 17, 2024
e6ff95a
vocabulary types: cleanup
SarahW91 Jun 24, 2024
329f03f
vocabulary types: remove schema property from VocabularyTypeService
SarahW91 Jun 25, 2024
b5c5ae9
vocabulary types: remove unused read response handler from Vocabulari…
SarahW91 Jun 25, 2024
2a2885e
vocabulary types: rename route and response handler of VocabulariesAd…
SarahW91 Jun 25, 2024
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
10 changes: 10 additions & 0 deletions invenio_vocabularies/administration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
# Copyright (C) 2024 Uni Münster.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Invenio administration views module for vocabularies."""
10 changes: 10 additions & 0 deletions invenio_vocabularies/administration/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2021 CERN.
# Copyright (C) 2024 Uni Münster.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Invenio administration views module for Vocabularies."""
44 changes: 44 additions & 0 deletions invenio_vocabularies/administration/views/vocabularies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2021 CERN.
# Copyright (C) 2024 Uni Münster.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Vocabularies admin interface."""
from invenio_administration.views.base import (
AdminResourceEditView,
AdminResourceListView,
)


class VocabulariesListView(AdminResourceListView):
"""Configuration for vocabularies list view."""

api_endpoint = "/vocabularies/"
name = "vocabulary-types"
menu_label = "Vocabulary Types"
resource_config = "vocabulary_admin_resource"
search_request_headers = {"Accept": "application/json"}
title = "Vocabulary Types"
category = "Site management"

pid_path = "id"
icon = "exchange"
template = "invenio_administration/search.html"

display_search = True
display_delete = False
display_edit = False
display_create = False

item_field_list = {
"id": {"text": "Name", "order": 1},
"count": {"text": "Number of entries", "order": 2},
}

search_config_name = "VOCABULARIES_TYPES_SEARCH"
search_facets_config_name = "VOCABULARIES_TYPES_FACETS"
search_sort_config_name = "VOCABULARIES_TYPES_SORT_OPTIONS"
31 changes: 29 additions & 2 deletions invenio_vocabularies/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
)
from .datastreams.transformers import XMLTransformer
from .datastreams.writers import ServiceWriter, YamlWriter
from .resources.resource import VocabulariesResourceConfig
from .services.service import VocabulariesServiceConfig
from .resources import VocabulariesResourceConfig
from .services.config import VocabulariesServiceConfig

VOCABULARIES_RESOURCE_CONFIG = VocabulariesResourceConfig
"""Configure the resource."""
Expand Down Expand Up @@ -103,6 +103,15 @@
}
"""Names allowed identifier schemes."""

# configure CUSTOM_VOCABULARY_TYPES to differentiate output. Is used in VocabulariesServiceConfig
VOCABULARIES_CUSTOM_VOCABULARY_TYPES = [
"names",
"affiliations",
"awards",
"funders",
"subjects",
]
slint marked this conversation as resolved.
Show resolved Hide resolved

VOCABULARIES_DATASTREAM_READERS = {
"csv": CSVReader,
"json": JsonReader,
Expand All @@ -126,3 +135,21 @@
"yaml": YamlWriter,
}
"""Data Streams writers."""

VOCABULARIES_TYPES_SORT_OPTIONS = {
"name": dict(
title=_("Name"),
fields=["id"],
),
"count": dict(
title=_("Number of entries"),
fields=["count"],
),
}
"""Definitions of available Vocabulary types sort options. """

VOCABULARIES_TYPES_SEARCH = {
"facets": [],
"sort": ["name", "count"],
}
"""Vocabulary type search configuration."""
27 changes: 21 additions & 6 deletions invenio_vocabularies/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@
SubjectsService,
SubjectsServiceConfig,
)
from .resources.resource import VocabulariesResource
from .services.service import VocabulariesService
from .resources import (
VocabulariesAdminResource,
VocabulariesResource,
VocabulariesResourceConfig,
VocabularyTypeResourceConfig,
)
from .services.config import VocabularyTypesServiceConfig
from .services.service import VocabulariesService, VocabularyTypeService


class InvenioVocabularies(object):
Expand Down Expand Up @@ -76,6 +82,7 @@ class ServiceConfigs:
funders = FundersServiceConfig
names = NamesServiceConfig
subjects = SubjectsServiceConfig
vocabulary_types = VocabularyTypesServiceConfig

return ServiceConfigs

Expand All @@ -93,9 +100,12 @@ def init_services(self, app):
self.funders_service = FundersService(config=service_configs.funders)
self.names_service = NamesService(config=service_configs.names)
self.subjects_service = SubjectsService(config=service_configs.subjects)
self.service = VocabulariesService(
self.vocabularies_service = VocabulariesService(
config=app.config["VOCABULARIES_SERVICE_CONFIG"],
)
self.vocabulary_types_service = VocabularyTypeService(
config=service_configs.vocabulary_types
)

def init_resource(self, app):
"""Initialize vocabulary resources."""
Expand All @@ -121,9 +131,13 @@ def init_resource(self, app):
config=SubjectsResourceConfig,
)
self.resource = VocabulariesResource(
service=self.service,
service=self.vocabularies_service,
config=app.config["VOCABULARIES_RESOURCE_CONFIG"],
)
self.vocabulary_admin_resource = VocabulariesAdminResource(
service=self.vocabulary_types_service,
config=VocabularyTypeResourceConfig,
)


def finalize_app(app):
Expand Down Expand Up @@ -153,12 +167,13 @@ def init(app):
sregistry.register(ext.funders_service, service_id="funders")
sregistry.register(ext.names_service, service_id="names")
sregistry.register(ext.subjects_service, service_id="subjects")
sregistry.register(ext.service, service_id="vocabularies")
sregistry.register(ext.vocabularies_service, service_id="vocabularies")
sregistry.register(ext.vocabulary_types_service, service_id="vocabulary-types")
# Register indexers
iregistry = app.extensions["invenio-indexer"].registry
iregistry.register(ext.affiliations_service.indexer, indexer_id="affiliations")
iregistry.register(ext.awards_service.indexer, indexer_id="awards")
iregistry.register(ext.funders_service.indexer, indexer_id="funders")
iregistry.register(ext.names_service.indexer, indexer_id="names")
iregistry.register(ext.subjects_service.indexer, indexer_id="subjects")
iregistry.register(ext.service.indexer, indexer_id="vocabularies")
iregistry.register(ext.vocabularies_service.indexer, indexer_id="vocabularies")
2 changes: 1 addition & 1 deletion invenio_vocabularies/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _ext_proxy(attr):
)


current_service = _ext_proxy("service")
current_service = _ext_proxy("vocabularies_service")
"""Proxy to the instantiated vocabulary service."""


Expand Down
7 changes: 7 additions & 0 deletions invenio_vocabularies/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
"""Resources module."""
from invenio_vocabularies.resources.schema import L10NString, VocabularyL10Schema

from .config import VocabulariesResourceConfig, VocabularyTypeResourceConfig
from .resource import VocabulariesAdminResource, VocabulariesResource
SarahW91 marked this conversation as resolved.
Show resolved Hide resolved

__all__ = (
"VocabularyL10Schema",
"L10NString",
"VocabulariesResourceConfig",
"VocabularyTypeResourceConfig",
"VocabulariesAdminResource",
"VocabulariesResource",
)
105 changes: 105 additions & 0 deletions invenio_vocabularies/resources/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
# Copyright (C) 2024 University of Münster.
#
# Invenio-Vocabularies is free software; you can redistringibute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Resources config."""

import marshmallow as ma
from flask_resources import (
BaseListSchema,
HTTPJSONException,
JSONSerializer,
MarshmallowSerializer,
ResourceConfig,
ResponseHandler,
create_error_handler,
)
from invenio_records_resources.resources import (
RecordResource,
RecordResourceConfig,
SearchRequestArgsSchema,
)
from invenio_records_resources.resources.errors import ErrorHandlersMixin
from invenio_records_resources.resources.records.args import SearchRequestArgsSchema
from invenio_records_resources.resources.records.headers import etag_headers
from invenio_records_resources.services.base.config import ConfiguratorMixin

from .serializer import VocabularyL10NItemSchema


class VocabularySearchRequestArgsSchema(SearchRequestArgsSchema):
"""Vocabularies search request parameters."""

tags = ma.fields.Str()
active = ma.fields.Boolean()
status = ma.fields.Boolean()


class VocabulariesResourceConfig(RecordResourceConfig):
"""Vocabulary resource configuration."""

blueprint_name = "vocabularies"
url_prefix = "/vocabularies"
routes = {
"list": "/<type>",
"item": "/<type>/<pid_value>",
"tasks": "/tasks",
slint marked this conversation as resolved.
Show resolved Hide resolved
}

request_view_args = {
"pid_value": ma.fields.Str(),
"type": ma.fields.Str(required=True),
}

request_search_args = VocabularySearchRequestArgsSchema

response_handlers = {
"application/json": ResponseHandler(JSONSerializer(), headers=etag_headers),
"application/vnd.inveniordm.v1+json": ResponseHandler(
MarshmallowSerializer(
format_serializer_cls=JSONSerializer,
object_schema_cls=VocabularyL10NItemSchema,
list_schema_cls=BaseListSchema,
),
headers=etag_headers,
),
}


class VocabularyTypeResourceConfig(ResourceConfig, ConfiguratorMixin):
"""Vocabulary list resource config."""

# /vocabulary/vocabulary_id
# Blueprint configuration
blueprint_name = "vocabulary_types"
url_prefix = "/vocabularies"

routes = {"list": "/"}

# Request parsing
request_read_args = {}
request_view_args = {
"pid_value": ma.fields.String,
"type": ma.fields.String,
}
request_search_args = VocabularySearchRequestArgsSchema

error_handlers = {
**ErrorHandlersMixin.error_handlers,
# TODO: Add custom error handlers here
}
response_handlers = {
"application/json": ResponseHandler(JSONSerializer(), headers=etag_headers),
"application/vnd.inveniordm.v1+json": ResponseHandler(
MarshmallowSerializer(
format_serializer_cls=JSONSerializer,
object_schema_cls=VocabularyL10NItemSchema,
list_schema_cls=BaseListSchema,
),
headers=etag_headers,
),
}
Loading