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 Apr 24, 2024
1 parent 71ac03d commit 85158d1
Show file tree
Hide file tree
Showing 28 changed files with 8,150 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
78 changes: 78 additions & 0 deletions rero_mef/alembic/28982ef7ce63_delete_bf_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# 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 sqlalchemy import func

from rero_mef.utils import get_entity_class

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


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


def commit_changes(indexer, ids):
"""Commit changes and reindex."""
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)

count = agent_class.model_cls.query.filter(
agent_class.model_cls.json.op('->')('bf:Agent') is not None
).update(
{
agent_class.model_cls.json:
agent_class.model_cls.json - "bf:Agent"
},
synchronize_session=False
)
click.echo(
f'Delete bf:Agent from {agent}: {count}')
db.session.commit()
# For ES: update mapping must be done.


def downgrade():
"""Downgrade database."""
for agent, name in agents.items():
agent_class = get_entity_class(agent)

count = agent_class.model_cls.query.filter(
agent_class.model_cls.json.op('->')('type') is not None
).update(
{
"json": func.jsonb_set(
agent_class.model_cls.json,
'{bf:Agent}',
agent_class.model_cls.json.op('->')('type')
)
},
synchronize_session=False
)
click.echo(
f'Add bf:Agent to {agent}: {count}')
db.session.commit()
# For ES: update mapping must be done
# and all agents and MEF have to be reindexed
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
8 changes: 8 additions & 0 deletions rero_mef/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,11 @@ def oai_save_records_from_dates(name, file_name, sickle, oai_item_iterator,
rec.leader = f'{rec.leader[:9]}a{rec.leader[10:]}'
output_file.write(rec.as_marc())
except NoRecordsMatch:
<<<<<<< HEAD
from_date = until_date
=======
from_date = from_date + timedelta(days=days_span)
>>>>>>> f902a45 (agent: remove bf:Agent)
continue
except Exception as err:
current_app.logger.error(err)
Expand All @@ -475,7 +479,11 @@ def oai_save_records_from_dates(name, file_name, sickle, oai_item_iterator,
f'{from_date.strftime(TIME_FORMAT)} .. '
f'{until_date.strftime(TIME_FORMAT)}'
)
<<<<<<< HEAD
from_date = until_date
=======
from_date = from_date + timedelta(days=days_span)
>>>>>>> f902a45 (agent: remove bf:Agent)
if verbose:
click.echo(f'OAI {name}: {count}')
return count
Expand Down
Loading

0 comments on commit 85158d1

Please sign in to comment.