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`.
* Adds `--port` parameter to `server` script.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep and rerowep committed Feb 17, 2022
1 parent 1738b7a commit 97a2f2f
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 175 deletions.
239 changes: 103 additions & 136 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ invenio-pidstore = ">=1.2.1,<1.3.0"
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"
invenio-stats = "^1.0.0a18"
# 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 All @@ -37,7 +37,7 @@ pycountry = "*"
flask-wiki = {git = "https://github.com/rero/flask-wiki.git"}
markdown-captions = "*"
bleach = ">3.11"
wand = ">=0.5.0,<0.6.0"
wand = ">=0.6.6,<0.7.0"
python-dotenv = "*"
flask-cors = ">3.0.8"
cryptography = ">=3.2"
Expand All @@ -58,6 +58,8 @@ wtforms = "<3.0.0"
flask-wtf = "<1.0.0"
zipp = "*"
pycparser = "*"
sqlalchemy_continuum = "<2.0.0"
psycopg2-binary = "<3.0.0"

[tool.poetry.dev-dependencies]
Flask-Debugtoolbar = ">=0.10.1"
Expand Down
22 changes: 21 additions & 1 deletion scripts/server
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,31 @@
source $(dirname "$0")/functions

set -e
PORT=5000

# Poetry is a mandatory condition to launch this program!
if [[ -z "${VIRTUAL_ENV}" ]]; then
message "Launch this script via poetry command: poetry run ${PROGRAM}" "error"
exit 1
fi

if ! options=$(getopt -o p: port: -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
fi

while [ $# -gt 0 ]
do
case $1 in
-p|--port) PORT=$2; shift;;
(--) shift; break;;
(-*) error_msg+exit "$0: Unrecognized option $1";;
esac
shift
done


title "Start web server and celery"

script_path=$(dirname "$0")
Expand All @@ -41,7 +59,9 @@ message "Done" "success"
section "Start web server" "info"
invenio run \
--cert "$script_path"/../docker/nginx/test.crt \
--key "$script_path"/../docker/nginx/test.key & pid_server=$!
--key "$script_path"/../docker/nginx/test.key \
-p $PORT & pid_server=$!

message "Done" "success"

trap 'kill $pid_celery $pid_server &>/dev/null' EXIT
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 @@ -42,6 +42,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 @@ -175,7 +177,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 @@ -211,7 +213,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
17 changes: 9 additions & 8 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 @@ -35,13 +36,13 @@ class RecordResourceConfig(BaseRecordResourceConfig):
item_route = f'{list_route}/<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')
}


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)
5 changes: 0 additions & 5 deletions sonar/resources/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@
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."""
Expand Down

0 comments on commit 97a2f2f

Please # to comment.