Skip to content

Commit

Permalink
migrator: records files and communities fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Sep 18, 2023
1 parent 644126b commit bc3755b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
10 changes: 8 additions & 2 deletions migrator/zenodo_rdm_migrator/transform/entries/parents.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ def __init__(self, partial=False):
self.partial = partial

def _communities(self, entry):
result = {}
communities = entry["json"].get("communities")
if communities:
slugs = [slug for slug in communities]
return {"ids": slugs, "default": slugs[0]}
return {}
result["ids"] = slugs
# If there's only one community, we set it as the default also
if len(slugs) == 1:
result["default"] = slugs[0]
else:
result["default"] = None
return result

def _pids(self, entry):
pids = {}
Expand Down
18 changes: 0 additions & 18 deletions migrator/zenodo_rdm_migrator/transform/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from invenio_rdm_migrator.streams.records import RDMRecordTransform

from .entries.parents import ParentRecordEntry
from .entries.records.record_files import ZenodoRDMRecordFileEntry
from .entries.records.records import ZenodoDraftEntry, ZenodoRecordEntry


Expand All @@ -29,21 +28,6 @@ def _draft(self, entry):
"""Extract a draft."""
return ZenodoDraftEntry().transform(entry)

def _file_records(self, entry):
"""Transform file records for an entry."""
files = entry["json"].get("_files", [])
return list(map(ZenodoRDMRecordFileEntry(context=entry).transform, files))

def _draft_files(self, entry):
"""Transform file records of a record."""
# draft files are migrated as post load since new versions/new drafts
# do not have _files until they are saved so we cannot rely on it
return {}

def _record_files(self, entry):
"""Transform file records of a record."""
return self._file_records(entry)

def _transform(self, entry):
"""Transform a single entry."""
is_draft = "deposits" in entry["json"]["$schema"]
Expand All @@ -60,11 +44,9 @@ def _transform(self, entry):
return {
"draft": draft,
"parent": parent,
"draft_files": self._draft_files(entry),
}

return {
"record": self._record(entry),
"parent": self._parent(entry),
"record_files": self._record_files(entry),
}

0 comments on commit bc3755b

Please sign in to comment.