Skip to content

Commit

Permalink
entities: add temporal
Browse files Browse the repository at this point in the history
Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Sep 7, 2023
1 parent 770dc5e commit 23399d1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
3 changes: 2 additions & 1 deletion rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,8 @@ def _(x):
RERO_ILS_ENTITY_TYPES = {
'bf:Person': 'agents',
'bf:Organisation': 'agents',
'bf:Topic': 'concepts'
'bf:Topic': 'concepts',
'bf:Temporal': 'concepts'
}

# The absolute path to put the agent synchronization logs, default is the
Expand Down
31 changes: 29 additions & 2 deletions rero_ils/modules/entities/remote_entities/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,17 @@ def create_proxy(category):
'entities': (EntityType.ORGANISATION,)
},
'concepts': {
'class': MefConceptsProxy,
'entities': (EntityType.TOPIC, EntityType.TEMPORAL)
},
'topics': {
'class': MefConceptsProxy,
'entities': (EntityType.TOPIC,)
},
'temporals': {
'class': MefConceptsProxy,
'entities': (EntityType.TEMPORAL, )
},
'concepts-genreForm': {
'class': MefConceptsGenreFormProxy,
'entities': (EntityType.TOPIC,)
Expand All @@ -80,7 +88,8 @@ def create_proxy(category):
# Create proxy configuration aliases
proxy_config[EntityType.PERSON] = proxy_config['person']
proxy_config[EntityType.ORGANISATION] = proxy_config['organisation']
proxy_config[EntityType.TOPIC] = proxy_config['concepts']
proxy_config[EntityType.TOPIC] = proxy_config['topics']
proxy_config[EntityType.TEMPORAL] = proxy_config['temporals']

# Try to create the proxy, otherwise raise a ValueError
if data := proxy_config.get(category):
Expand Down Expand Up @@ -276,6 +285,25 @@ class MefConceptsProxy(MEFProxyMixin):

mef_entrypoint = 'concepts'

def _get_query_params(self, term):
"""Get all parameters to use to build the MEF query.
:param term: the searched term
:type term: str
:returns: a list of query parameters to build the `q` parameter to send
to the remote MEF server to filter the response. All these params
will be joined by 'AND' condition.
:rtype: list<str>
"""
params = super()._get_query_params(term)
if self.entity_types:
ent_types = []
for _type in self.entity_types:
_type = _type.replace(":", "\\:")
ent_types.append(f'type:{_type}')
params += [f'({" OR ".join(ent_types)})']
return params

def _post_process_result_hit(self, hit):
"""Modify a MEF hit response to return a standardized hit.
Expand All @@ -287,7 +315,6 @@ def _post_process_result_hit(self, hit):
"""
if not (metadata := hit.get('metadata', {})):
return
metadata['type'] = EntityType.TOPIC
super()._post_process_result_hit(hit)


Expand Down
8 changes: 1 addition & 7 deletions rero_ils/modules/entities/remote_entities/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@ def _get_latest(self, entity_type, source, pid):
url = f'{self._get_base_url(entity_type)}/mef/latest/{source}:{pid}'
res = requests_retry_session().get(url)
if res.status_code == requests.codes.ok:
# TODO: could be deleted if MEF is updated.
if data := res.json():
if data_type := data.get('bf:Agent', data.get('type')):
data['type'] = data_type
elif entity_type == 'concepts':
data['type'] = 'bf:Topic'
return data
return res.json()
self.logger.warning(f'Problem get {url}: {res.status_code}')
return {}

Expand Down
6 changes: 1 addition & 5 deletions rero_ils/modules/entities/remote_entities/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ def _get_latest(self, entity_type, source, pid):
url = f'{base_url}/mef/latest/{source}:{pid}'
res = requests_retry_session().get(url)
if res.status_code == requests.codes.ok:
data = res.json()
if entity_type == 'concepts' and not data.get('type'):
# TODO: delete for MEF v0.12.0
data['type'] = 'bf:Topic'
return data
return res.json()
self.logger.debug(f'Problem get {url}: {res.status_code}')
return {}

Expand Down

0 comments on commit 23399d1

Please sign in to comment.