Skip to content

Commit

Permalink
concepts: add MEF
Browse files Browse the repository at this point in the history
* Adds MEF concepts class.
* Splits serialiazers.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Oct 11, 2021
1 parent 7934c3e commit abc87e8
Show file tree
Hide file tree
Showing 48 changed files with 1,718 additions and 466 deletions.
24 changes: 11 additions & 13 deletions rero_mef/agents/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ def replace_test_md5(self, data, dbcommit=False, reindex=False):

def create_or_update_mef_viaf_record(self, dbcommit=False, reindex=False,
online=False):
"""Create or update MEF and VIAF record."""
"""Create or update MEF and VIAF record.
:param dbcommit: Commit changes to DB.
:param reindex: Reindex record.
:param online: Try to get VIAF record online.
:returns: MEF record, MEF action, VIAF record, VIAF
"""
from .viaf.api import AgentViafRecord
AgentViafRecord.update_indexes()
viaf_record, got_online = AgentViafRecord.get_viaf_by_agent(
Expand All @@ -104,10 +110,7 @@ def create_or_update_mef_viaf_record(self, dbcommit=False, reindex=False,
agent_pid=self.pid
)
mef_data = {self.agent: {'$ref': ref_string}}
mef_record = AgentMefRecord.get_mef_by_agent_pid(
agent_pid=self.pid,
agent_name=self.name
)
mef_record = AgentMefRecord.get_mef_by_entity_pid(self.pid, self.name)
if viaf_record:
mef_data['viaf_pid'] = viaf_record.pid
if not mef_record:
Expand Down Expand Up @@ -142,10 +145,7 @@ def delete_from_mef(self, dbcommit=False, reindex=False, verbose=False):
from .mef.api import AgentMefRecord
mef_action = Action.DISCARD
old_mef_pid = 'None'
mef_record = AgentMefRecord.get_mef_by_agent_pid(
agent_pid=self.pid,
agent_name=self.name
)
mef_record = AgentMefRecord.get_mef_by_entity_pid(self.pid, self.name)
if mef_record:
old_mef_pid = mef_record.pid
if not mef_record.deleted:
Expand Down Expand Up @@ -225,10 +225,8 @@ def create_or_update_agent_mef_viaf(cls, data, id_=None, delete_pid=True,
online = False
else:
if action == Action.UPTODATE:
mef_record = AgentMefRecord.get_mef_by_agent_pid(
agent_pid=record.pid,
agent_name=record.name
)
mef_record = AgentMefRecord.get_mef_by_entity_pid(
record.pid, record.name)
mef_action = Action.UPTODATE
viaf_record, online = AgentViafRecord.get_viaf_by_agent(record)
else:
Expand Down
20 changes: 9 additions & 11 deletions rero_mef/agents/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import os

import click
from flask import current_app
from flask.cli import with_appcontext

from .mef.api import AgentMefRecord
from .tasks import create_from_viaf as task_mef_and_agents_from_viaf
from .tasks import create_mef as task_mef_from_agent
from .tasks import task_create_mef_for_agent, task_create_mef_from_viaf_agent
from .utils import create_mef_files, create_viaf_files
from .viaf.api import AgentViafRecord
from ..utils import get_entity_class, get_entity_classes, progressbar
Expand Down Expand Up @@ -77,7 +77,7 @@ def create_from_viaf(test_md5, enqueue, online, verbose, progress, wait,
)
for pid in progress_bar:
if enqueue:
task = task_mef_and_agents_from_viaf.delay(
task = task_create_mef_from_viaf_agent.delay(
pid=pid,
dbcommit=True,
reindex=True,
Expand All @@ -86,7 +86,7 @@ def create_from_viaf(test_md5, enqueue, online, verbose, progress, wait,
)
click.echo(f'viaf pid: {pid} task:{task}')
else:
task_mef_and_agents_from_viaf(
task_create_mef_from_viaf_agent(
pid=pid,
dbcommit=True,
reindex=True,
Expand Down Expand Up @@ -127,14 +127,12 @@ def create_from_viaf(test_md5, enqueue, online, verbose, progress, wait,
@with_appcontext
def create_mef(pid_type, enqueue, online, verbose, progress, wait, missing):
"""Create MEF from agents."""
AGENTS = current_app.config.get('AGENTS', [])
if missing:
missing_pids, to_much_pids = \
AgentMefRecord.get_all_missing_agents_pids(
agents=pid_type,
verbose=progress
)
AgentMefRecord.get_all_missing_pids(pid_type, verbose=progress)
for agent in pid_type:
if agent not in ['aidref', 'aggnd', 'agrero']:
if agent not in AGENTS:
click.secho(
f'Error create MEF from {agent}. Wrong agent!',
fg='red'
Expand Down Expand Up @@ -162,7 +160,7 @@ def create_mef(pid_type, enqueue, online, verbose, progress, wait, missing):
)
for pid in progress_bar:
if enqueue:
task = task_mef_from_agent.delay(
task = task_create_mef_for_agent.delay(
pid=pid,
agent=agent,
dbcommit=True,
Expand All @@ -172,7 +170,7 @@ def create_mef(pid_type, enqueue, online, verbose, progress, wait, missing):
if verbose:
click.echo(f'{agent} pid: {pid} task:{task}')
else:
msg = task_mef_from_agent(
msg = task_create_mef_for_agent(
pid=pid,
agent=agent,
dbcommit=True,
Expand Down
2 changes: 1 addition & 1 deletion rero_mef/agents/gnd/jsonresolvers/gnd_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ..api import AgentGndRecord


@jsonresolver.route('/api/gnd/<path:path>', host=get_host())
@jsonresolver.route('/api/agents/gnd/<path:path>', host=get_host())
def resolve_gnd(path):
"""Resolve GND records."""
return resolve_record(path, AgentGndRecord)
8 changes: 4 additions & 4 deletions rero_mef/agents/gnd/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@


@api_blueprint.route('')
def redirect_idref_list():
def redirect_gnd_list():
"""Redirect list to new address."""
return redirect(
url_for('invenio_records_rest.aidref_list', **request.args),
url_for('invenio_records_rest.aggnd_list', **request.args),
code=308
)


@api_blueprint.route('/<pid>')
def redirect_idref_item(pid):
def redirect_gnd_item(pid):
"""Redirect item to new address."""
return redirect(
url_for(
'invenio_records_rest.aidref_item', pid_value=pid, **request.args),
'invenio_records_rest.aggnd_item', pid_value=pid, **request.args),
code=308
)
2 changes: 1 addition & 1 deletion rero_mef/agents/idref/jsonresolvers/idref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ....utils import get_host, resolve_record


@jsonresolver.route('/api/idref/<path:path>', host=get_host())
@jsonresolver.route('/api/agents/idref/<path:path>', host=get_host())
def resolve_idref(path):
"""Resolve IDREF records."""
return resolve_record(path, AgentIdrefRecord)
4 changes: 2 additions & 2 deletions rero_mef/agents/idref/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def redirect_idref_list():
"""Redirect list to new address."""
return redirect(
url_for('invenio_records_rest.aggnd_list', **request.args),
url_for('invenio_records_rest.aidref_item', **request.args),
code=308
)

Expand All @@ -40,6 +40,6 @@ def redirect_idref_item(pid):
"""Redirect item to new address."""
return redirect(
url_for(
'invenio_records_rest.aggnd_item', pid_value=pid, **request.args),
'invenio_records_rest.aidref_item', pid_value=pid, **request.args),
code=308
)
Loading

0 comments on commit abc87e8

Please sign in to comment.