Skip to content
Open
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
24 changes: 16 additions & 8 deletions iroko/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from invenio_records.api import Record
from invenio_records_files.api import Record
from sqlalchemy.exc import NoResultFound
import json

from iroko.pidstore import pids
from iroko.pidstore.minters import identifiers_minter, iroko_uuid_minter
Expand Down Expand Up @@ -68,6 +69,7 @@ def resolve_and_update(cls, iroko_uuid=None, data={}, **kwargs):
persistent_identifier, rec = resolver.resolve(str(iroko_uuid))
if rec:
print("{0}={1} found".format(pid_type, iroko_uuid))
print('REC',rec)
rec.update(data)
# .update(data, dbcommit=dbcommit, reindex=reindex)
return rec, 'updated'
Expand All @@ -85,16 +87,20 @@ def resolve_and_update(cls, iroko_uuid=None, data={}, **kwargs):
str(identifier[IDENTIFIERS_FIELD_VALUE])
)
print('<<<<<<<<<<<<<<<<<<')
print('rec= ', rec)
print('rec= ', json.dumps(rec, indent=3))
if rec:
print(
"{0}={1} found".format(
schema, str(
identifier[IDENTIFIERS_FIELD_VALUE]
)
)
)
# print(
# "{0}={1} found".format(
# schema, str(
# identifier[IDENTIFIERS_FIELD_VALUE]
# )
# )
# )
# print("===================", data)
print(json.dumps(data, indent=3))
rec.update(data)
print('========================================')

print('>>>>>>>>>>>>>>>>>>>>')
print('rec updated: ', rec)
return rec, 'updated'
Expand Down Expand Up @@ -182,6 +188,8 @@ def update(self, data=None, dbcommit=True, reindex=True, override_pids=True):
""" Update data for record.
override_pids, if True
"""
print(json.dumps(data, indent=3), type(data))

print('begin update')

self['_save_info_updated'] = str(date.today())
Expand Down
80 changes: 79 additions & 1 deletion iroko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
from iroko.organizations.api import OrganizationRecord
from iroko.organizations.permissions import can_edit_organization_factory
from iroko.organizations.search import OrganizationSearch
from iroko.patents.api import PatentRecord
from iroko.patents.search import PatentsSearch
from iroko.patents.permissions import can_edit_patent_factory
from iroko.persons.api import PersonRecord
from iroko.persons.permissions import can_edit_person_factory
from iroko.persons.search import PersonsSearch
from iroko.pidstore import pids as pids
from iroko.pidstore.pids import (
ORGANIZATION_PID_FETCHER, ORGANIZATION_PID_MINTER,
ORGANIZATION_PID_TYPE, PERSON_PID_FETCHER, PERSON_PID_MINTER, PERSON_PID_TYPE,
ORGANIZATION_PID_TYPE, PATENT_PID_FETCHER, PATENT_PID_MINTER, PATENT_PID_TYPE,
PERSON_PID_FETCHER, PERSON_PID_MINTER, PERSON_PID_TYPE,
)
from iroko.records.api import IrokoRecord
from iroko.records.search import IrokoRecordSearch
Expand Down Expand Up @@ -122,6 +126,10 @@ def _(x):
_ORG_CONVERTER = (
'pid(orgid, record_class="iroko.organizations.api.OrganizationRecord")'
)
_PATENT_CONVERTER = (
'pid(patid, record_class="iroko.patents.api.PatentRecord")'
)

_PERSON_CONVERTER = (
'pid(perid, record_class="iroko.persons.api.PersonRecord")'
)
Expand Down Expand Up @@ -224,6 +232,37 @@ def _(x):
'delete_permission_factory_imp': can_edit_organization_factory,
'list_permission_factory_imp': allow_all
},
'patid': {
'pid_type': PATENT_PID_TYPE,
'pid_minter': PATENT_PID_MINTER,
'pid_fetcher': PATENT_PID_FETCHER,
'default_endpoint_prefix': True,
'record_class': PatentRecord,
'search_class': PatentsSearch,
'indexer_class': RecordIndexer,
'record_serializers': {
'application/json': ('iroko.patents.serializers'
':json_v1_response'),
},
'search_serializers': {
'application/json': ('iroko.patents.serializers'
':json_v1_search'),
},
'record_loaders': {
'application/json': ('iroko.patents.loaders'
':json_v1'),
},
'list_route': '/search/patents/',
'item_route': '/pid/patent/<{0}:pid_value>'.format(_PATENT_CONVERTER),
'default_media_type': 'application/json',
'max_result_window': 10000,
'error_handlers': {},
'create_permission_factory_imp': can_edit_patent_factory,
'read_permission_factory_imp': check_elasticsearch,
'update_permission_factory_imp': can_edit_patent_factory,
'delete_permission_factory_imp': can_edit_patent_factory,
'list_permission_factory_imp': allow_all
},
'perid': {
'pid_type': PERSON_PID_TYPE,
'pid_minter': PERSON_PID_MINTER,
Expand Down Expand Up @@ -359,6 +398,26 @@ def _(x):
}
}
},
'patents': {
'filters': {
'country': terms_filter('country.name'),
'language': terms_filter('language')
},
'aggs': {
'country': {
'terms': {
'field': 'country.name',
'size': 5
}
},
'language': {
'terms': {
'field': 'language',
'size': 5
}
}
}
},
'persons': {
'filters': {
'gender': terms_filter('gender'),
Expand Down Expand Up @@ -432,6 +491,20 @@ def _(x):
'order': 2
}
},
'patents': {
'bestmatch': {
'title': _('Best match'),
'fields': ['_score'],
'default_order': 'desc',
'order': 1
},
'mostrecent': {
'title': _('Most recent'),
'fields': ['-_created'],
'default_order': 'asc',
'order': 2
}
},
'persons': {
'bestmatch': {
'title': _('Best match'),
Expand All @@ -447,6 +520,7 @@ def _(x):
}
}
}

"""Setup sorting options."""

RECORDS_REST_DEFAULT_SORT: {
Expand All @@ -462,6 +536,10 @@ def _(x):
'query': 'bestmatch',
'noquery': 'bestmatch',
},
'patents': {
'query': 'bestmatch',
'noquery': 'bestmatch',
},
'persons': {
'query': 'bestmatch',
'noquery': 'bestmatch',
Expand Down
16 changes: 16 additions & 0 deletions iroko/patents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2022. Universidad de Pinar del Rio
# This file is part of SCEIBA (sceiba.cu).
# SCEIBA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
#


"""iroko."""

from __future__ import absolute_import, print_function

from .ext import IrokoPatents

__all__ = ('IrokoPatents', )
Loading