Skip to content

Commit

Permalink
agent: remove bf:Agent
Browse files Browse the repository at this point in the history
Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Feb 12, 2024
1 parent 42c43c2 commit 2650e5c
Show file tree
Hide file tree
Showing 27 changed files with 8,179 additions and 16,085 deletions.
3,663 changes: 0 additions & 3,663 deletions data/aggnd.json

Large diffs are not rendered by default.

7,326 changes: 3,663 additions & 3,663 deletions data/aggnd_metadata.csv

Large diffs are not rendered by default.

1,771 changes: 0 additions & 1,771 deletions data/agrero.json

Large diffs are not rendered by default.

3,542 changes: 1,771 additions & 1,771 deletions data/agrero_metadata.csv

Large diffs are not rendered by default.

2,495 changes: 0 additions & 2,495 deletions data/aidref.json

Large diffs are not rendered by default.

4,990 changes: 2,495 additions & 2,495 deletions data/aidref_metadata.csv

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"pid": {
"type": "keyword"
},
"bf:Agent": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"pid": {
"type": "keyword"
},
"bf:Agent": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
Expand Down
6 changes: 0 additions & 6 deletions rero_mef/agents/mef/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ def get_latest(cls, pid_type, pid):
if search.count() > 0:
new_data = next(search.scan()).to_dict()
new_pid = new_data.get('idref', {}).get('pid')
for agent in cls.entities:
if agent_data := data.get(agent):
if not agent_data.get('type'):
data[agent]['type'] = agent_data['bf:Agent']
if not data.get('type'):
data['type'] = agent_data['bf:Agent']
return cls.get_latest(pid_type=pid_type, pid=new_pid) \
if new_pid else data
return {}
Expand Down
9 changes: 0 additions & 9 deletions rero_mef/agents/mef/mappings/v7/mef/mef-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
"pid": {
"type": "keyword"
},
"bf:Agent": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
Expand Down Expand Up @@ -164,9 +161,6 @@
"pid": {
"type": "keyword"
},
"bf:Agent": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
Expand Down Expand Up @@ -272,9 +266,6 @@
"pid": {
"type": "keyword"
},
"bf:Agent": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"pid": {
"type": "keyword"
},
"bf:Agent": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
Expand Down
4 changes: 0 additions & 4 deletions rero_mef/agents/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ def serialize(self, pid, record, links_factory=None, **kwargs):
:param record: Record instance.
:param links_factory: Factory function for record links.
"""
# TODO: could be deleted in the future
if not record.get('type'):
record['type'] = record['bf:Agent']

return super(ReroMefSerializer, self).serialize(
pid=pid, record=record, links_factory=add_links, **kwargs)

Expand Down
115 changes: 115 additions & 0 deletions rero_mef/alembic/28982ef7ce63_delete_bf_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2018 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""delete bf:Agent"""

import click
from invenio_db import db

from rero_mef.agents import AgentMefIndexer, AgentMefRecord
from rero_mef.utils import get_entity_class, get_entity_indexer_class, \
progressbar

# revision identifiers, used by Alembic.
revision = '28982ef7ce63'
down_revision = '0d0b3009dbe0'
branch_labels = ()
depends_on = None

COMMIT_COUNT = 1000

agents = {
'aggnd': 'GND',
'aidref': 'IDREF',
'agrero': 'RERO'
}


def commit_changes(indexer, ids):
db.session.commit()
indexer.bulk_index(ids)
indexer.process_bulk_queue()


def upgrade():
"""Upgrade database."""
for agent, name in agents.items():
agent_class = get_entity_class(agent)
indexer = get_entity_indexer_class(agent)()
click.echo(
f'Delete bf:Agent from {agent}: {agent_class.count()}')
progress_bar = progressbar(
items=agent_class.get_all_records(),
length=agent_class.count(),
verbose=True
)
ids = []
for idx, rec in enumerate(progress_bar, 1):
rec.pop('bf:Agent', None)
ids.append(rec.id)
rec.update(data=rec, dbcommit=False, reindex=False)
if idx % COMMIT_COUNT == 0:
commit_changes(indexer, ids)
ids = []
commit_changes(indexer, ids)

click.echo(f'Delete bf:Agent from mef: {AgentMefRecord.count()}')
progress_bar = progressbar(
items=AgentMefRecord.get_all_records(),
length=AgentMefRecord.count(),
verbose=True
)
ids = []
indexer = AgentMefIndexer()
for idx, rec in enumerate(progress_bar, 1):
rec.pop('bf:Agent', None)
ids.append(rec.id)
rec.update(data=rec, dbcommit=False, reindex=False)
if idx % COMMIT_COUNT == 0:
commit_changes(indexer, ids)
ids = []
commit_changes(indexer, ids)


def downgrade():
"""Downgrade database."""
for agent, name in agents.items():
agent_class = get_entity_class(agent)
indexer = get_entity_indexer_class(agent)()
click.echo(
f'Add bf:Agent to {agent}: {agent_class.count()}')
progress_bar = progressbar(
items=agent_class.get_all_records(),
length=agent_class.count(),
verbose=True
)
ids = []
for idx, rec in enumerate(progress_bar, 1):
rec['bf:Agent'] = rec['type']
ids.append(rec.id)
rec.update(data=rec, dbcommit=False, reindex=False)
if idx % COMMIT_COUNT == 0:
commit_changes(indexer, ids)
ids = []
commit_changes(indexer, ids)

click.echo(f'Add bf:Agent to mef: {AgentMefRecord.count()}')
progress_bar = progressbar(
items=AgentMefRecord.get_all_records(),
length=AgentMefRecord.count(),
verbose=True
)
ids = []
indexer = AgentMefIndexer()
for idx, rec in enumerate(progress_bar, 1):
rec['bf:Agent'] = rec['type']
ids.append(rec.id)
rec.update(data=rec, dbcommit=False, reindex=False)
if idx % COMMIT_COUNT == 0:
commit_changes(indexer, ids)
ids = []
commit_changes(indexer, ids)
2 changes: 1 addition & 1 deletion rero_mef/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def create_or_update(cls, data, id_=None, delete_pid=True, dbcommit=False,
data = add_schema(data, agent_record.provider.pid_type)
# save the records old data if the new one is empty
copy_fields = ['pid', '$schema', 'identifier', 'identifiedBy',
'authorized_access_point', 'type', 'bf:Agent',
'authorized_access_point', 'type',
'relation_pid', 'deleted']
original_data = {
k: v for k, v in agent_record.items() if k in copy_fields}
Expand Down
8 changes: 0 additions & 8 deletions rero_mef/jsonschemas/common/agent-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@
"type": "string",
"minLength": 1
},
"bf:Agent": {
"title": "Type",
"type": "string",
"enum": [
"bf:Person",
"bf:Organisation"
]
},
"type": {
"title": "Type",
"type": "string",
Expand Down
1 change: 0 additions & 1 deletion rero_mef/marctojson/do_gnd_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ def trans_gnd_authorized_access_point(self):
subfields=subfields
)
for authorized_access_point in authorized_access_points:
self.json_dict['bf:Agent'] = agent
self.json_dict['type'] = agent
if self.json_dict.get('authorized_access_point'):
variant_access_points.append(authorized_access_point)
Expand Down
1 change: 0 additions & 1 deletion rero_mef/marctojson/do_idref_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ def trans_idref_authorized_access_point(self):
tag_grouping=tag_grouping
)
for authorized_access_point in authorized_access_points:
self.json_dict['bf:Agent'] = agent
self.json_dict['type'] = agent
if self.json_dict.get('authorized_access_point'):
variant_access_points.append(authorized_access_point)
Expand Down
1 change: 0 additions & 1 deletion rero_mef/marctojson/do_rero_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def trans_rero_authorized_access_point(self):
if self.logger and self.verbose:
self.logger.info(
'Call Function', 'trans_rero_authorized_access_point')
self.json_dict['bf:Agent'] = agent
self.json_dict['type'] = agent
authorized_access_points = build_string_list_from_fields(
record=self.marc,
Expand Down
Loading

0 comments on commit 2650e5c

Please sign in to comment.