From 23399d154f969b175d7ae6ef8c93b1df8ec0ac1f Mon Sep 17 00:00:00 2001 From: Peter Weber Date: Wed, 6 Sep 2023 11:26:23 +0200 Subject: [PATCH] entities: add temporal Co-Authored-by: Peter Weber --- rero_ils/config.py | 3 +- .../modules/entities/remote_entities/proxy.py | 31 +++++++++++++++++-- .../entities/remote_entities/replace.py | 8 +---- .../modules/entities/remote_entities/sync.py | 6 +--- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/rero_ils/config.py b/rero_ils/config.py index 6fe9bb5053..266b423ec1 100644 --- a/rero_ils/config.py +++ b/rero_ils/config.py @@ -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 diff --git a/rero_ils/modules/entities/remote_entities/proxy.py b/rero_ils/modules/entities/remote_entities/proxy.py index fe1327913c..5517157da9 100644 --- a/rero_ils/modules/entities/remote_entities/proxy.py +++ b/rero_ils/modules/entities/remote_entities/proxy.py @@ -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,) @@ -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): @@ -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 + """ + 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. @@ -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) diff --git a/rero_ils/modules/entities/remote_entities/replace.py b/rero_ils/modules/entities/remote_entities/replace.py index 419ad3ad93..d4f92934fd 100644 --- a/rero_ils/modules/entities/remote_entities/replace.py +++ b/rero_ils/modules/entities/remote_entities/replace.py @@ -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 {} diff --git a/rero_ils/modules/entities/remote_entities/sync.py b/rero_ils/modules/entities/remote_entities/sync.py index 2be3f64dfa..caf8a9c4dc 100644 --- a/rero_ils/modules/entities/remote_entities/sync.py +++ b/rero_ils/modules/entities/remote_entities/sync.py @@ -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 {}