Skip to content

Commit

Permalink
module: invenio-record-resources
Browse files Browse the repository at this point in the history
* Updates `invenio-record-resources` from version v.0.12.5 to v0.16.14.
  Versions greater then 17 are not working for `invenio 3.4`.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep and rerowep committed Mar 10, 2022
1 parent 547d5ee commit 6164215
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 368 deletions.
616 changes: 292 additions & 324 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ invenio-records-rest = ">=1.8.0,<1.9.0"
invenio-records-ui= ">=1.2.0,<1.3.0"
invenio-records = "<=1.6.0"
invenio-stats = "^1.0.0-alpha.18"
# TODO: update invenio-records-resources
invenio-records-resources = "==0.12.5"
invenio-records-resources = "<0.17.0"
invenio = {version = ">=3.4.0,<3.5.0", extras = ["base", "files", "postgresql", "auth", "elasticsearch7", "docs", "tests"]}

uwsgi = ">=2.0"
Expand Down
37 changes: 19 additions & 18 deletions sonar/dedicated/hepvs/projects/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

"""HEP Valais Projects resource."""

from flask_resources import ResponseHandler
from flask_resources.serializers import JSONSerializer
from invenio_records_resources.resources import \
RecordResourceConfig as BaseRecordResourceConfig
from invenio_records_resources.resources.records.response import RecordResponse
from invenio_records_resources.resources.records.headers import etag_headers

from sonar.dedicated.hepvs.projects.serializers.csv import CSVSerializer
from sonar.resources.projects.resource import \
Expand All @@ -32,21 +33,21 @@ class RecordResourceConfig(BaseRecordResourceConfig):
"""HEP Valais Projects resource configuration."""

response_handlers = {
'application/json':
RecordResponse(JSONSerializer()),
'text/csv':
StreamResponse(CSVSerializer(csv_included_fields=[
'pid', 'name', 'approvalDate', 'projectSponsor', 'statusHep',
'mainTeam', 'innerSearcher', 'secondaryTeam', 'externalPartners',
'status', 'startDate', 'endDate', 'description', 'keywords',
'realizationFramework', 'funding_funder_type',
'funding_funder_name', 'funding_funder_number',
'funding_fundingReceived', 'actorsInvolved', 'benefits',
'impactOnFormation', 'impactOnProfessionalEnvironment',
'impactOnPublicAction', 'promoteInnovation',
'relatedToMandate_mandate', 'relatedToMandate_name',
'relatedToMandate_briefDescription', 'educationalDocument',
'searchResultsValorised'
]),
filename='projects.csv')
'application/json': ResponseHandler(
JSONSerializer(), headers=etag_headers),
'text/csv': StreamResponse(
CSVSerializer(csv_included_fields=[
'pid', 'name', 'approvalDate', 'projectSponsor', 'statusHep',
'mainTeam', 'innerSearcher', 'secondaryTeam',
'externalPartners', 'status', 'startDate', 'endDate',
'description', 'keywords', 'realizationFramework',
'funding_funder_type', 'funding_funder_name',
'funding_funder_number', 'funding_fundingReceived',
'actorsInvolved', 'benefits', 'impactOnFormation',
'impactOnProfessionalEnvironment', 'impactOnPublicAction',
'promoteInnovation', 'relatedToMandate_mandate',
'relatedToMandate_name', 'relatedToMandate_briefDescription',
'educationalDocument', 'searchResultsValorised'
]),
filename='projects.csv')
}
6 changes: 4 additions & 2 deletions sonar/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
RecordResource as ProjectRecordResource
from sonar.resources.projects.service import \
RecordService as ProjectRecordService
from sonar.resources.projects.service import \
RecordServiceConfig as ProjectRecordServiceConfig

from . import config_sonar
from .route_converters import OrganisationCodeConverter
Expand Down Expand Up @@ -202,7 +204,7 @@ def create_resources(self):
"""Create resources."""
# Initialize the project resource with the corresponding service.
projects_resource = ProjectRecordResource(
service=ProjectRecordService())
service=ProjectRecordService(config=ProjectRecordServiceConfig))
self.resources['projects'] = projects_resource

def get_endpoints(self):
Expand Down Expand Up @@ -238,7 +240,7 @@ def register_blueprints(self, app):
"""Register the blueprints."""
# Register REST endpoint for projects resource.
app.register_blueprint(
self.resources['projects'].as_blueprint('projects'))
self.resources['projects'].as_blueprint())

@app.before_request
def set_accept_mimetype():
Expand Down
51 changes: 40 additions & 11 deletions sonar/resources/projects/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

"""Projects resource."""

from flask_resources import ResponseHandler
from flask_resources.serializers import JSONSerializer
from invenio_records_resources.resources import \
RecordResourceConfig as BaseRecordResourceConfig
from invenio_records_resources.resources.records.response import RecordResponse
from invenio_records_resources.resources.records.headers import etag_headers

from sonar.resources.projects.serializers.csv import CSVSerializer
from sonar.resources.resource import RecordResource as BaseRecordResource
Expand All @@ -30,19 +31,47 @@
class RecordResourceConfig(BaseRecordResourceConfig):
"""Projects resource configuration."""

resource_name = 'projects'
list_route = '/projects/'
item_route = f'{list_route}/<pid_value>'
blueprint_name = 'projects'
url_prefix = "/projects"
routes = {
'list': '/projects_list',
'item': '/<pid_value>',
}

response_handlers = {
'application/json':
RecordResponse(JSONSerializer()),
'text/csv':
StreamResponse(CSVSerializer(csv_included_fields=[
'pid', 'name', 'description', 'startDate', 'endDate'
]),
filename='projects.csv')
'application/json': ResponseHandler(
JSONSerializer(), headers=etag_headers),
'text/csv': StreamResponse(
CSVSerializer(csv_included_fields=[
'pid', 'name', 'description', 'startDate', 'endDate'
]),
filename='projects.csv')
}
# TODO: check configuratuin
# # Blueprint configuration
# blueprint_name = None
# url_prefix = "/records"
# routes = {
# "list": "",
# "item": "/<pid_value>",
# }

# # Request parsing
# request_read_args = {}
# request_view_args = {"pid_value": ma.fields.Str()}
# request_search_args = SearchRequestArgsSchema
# request_headers = {"if_match": ma.fields.Int()}
# request_body_parsers = {
# "application/json": RequestBodyParser(JSONDeserializer())
# }
# default_content_type = "application/json"

# # Response handling
# response_handlers = {
# "application/json": ResponseHandler(
# JSONSerializer(), headers=etag_headers)
# }
# default_accept_mimetype = "application/json"


class RecordResource(BaseRecordResource):
Expand Down
4 changes: 2 additions & 2 deletions sonar/resources/projects/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""Projects service."""

from invenio_records_resources.services.records.schema import \
MarshmallowServiceSchema
ServiceSchemaWrapper
from invenio_records_rest.utils import obj_or_import_string

from sonar.config import DEFAULT_AGGREGATION_SIZE
Expand Down Expand Up @@ -101,4 +101,4 @@ def schema(self):

schema = obj_or_import_string(schema_path)

return MarshmallowServiceSchema(self, schema=schema)
return ServiceSchemaWrapper(self, schema=schema)
9 changes: 2 additions & 7 deletions sonar/resources/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@
from invenio_records_resources.services.records import \
RecordService as BaseRecordService

from .params import FilterParams


class RecordServiceConfig(BaseRecordServiceConfig):
"""Service factory configuration."""

search_params_interpreters_cls = \
[FilterParams] + BaseRecordServiceConfig.search_params_interpreters_cls


class RecordService(BaseRecordService):
"""SONAR resources base service class."""

def create(self, identity, data, links_config=None):
def create(self, identity, data):
"""Create a record.
:param identity: Identity of user creating the record.
Expand All @@ -48,7 +43,7 @@ def create(self, identity, data, links_config=None):
identity.provides.add(UserNeed(1))
identity.provides.add(Need(method='system_role', value='any_user'))

return super().create(identity, data, links_config)
return super().create(identity, data)

def bulk_reindex(self):
"""Send all records to the index queue and process indexing."""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/resources/test_resources_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def test_config(app, client, make_user, admin):
assert isinstance(app.extensions['sonar'].resources['projects'].config(),
HEPVSRecordResourceConfig)

# No `resource_name` attribute
# No `blueprint_name` attribute
delattr(app.extensions['sonar'].resources['projects'].default_config,
'resource_name')
'blueprint_name')
assert isinstance(app.extensions['sonar'].resources['projects'].config(),
RecordResourceConfig)

0 comments on commit 6164215

Please # to comment.