Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions addons/weko/schema/ro_crate.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def _flatten_json_ld_root(object, counts=None):
clone[i]['name'] = final_values[i]
i += 1

# keywords 特殊対応: 公的の Person, 未病の PropertyValue で利用
if '@id' in item and item.get('@type') in ('Person', 'PropertyValue'):
if 'keywords' in item:
parent_raw_id = item['@id']
parent_base_id = normalize_base_id(parent_raw_id)
Expand Down Expand Up @@ -314,33 +316,35 @@ def _flatten_json_ld_root(object, counts=None):
final_values.append(new_entry)
root_data['rdm:keywords'] = final_values

if 'subitem_filename' in item:
try:
subitems = json.loads(item['subitem_filename'])
except (TypeError, ValueError) as exc:
logger.warning('Could not parse subitem_filename: %s', exc)
else:
if isinstance(subitems, list) and subitems:
new_entries = []
for i, sub in enumerate(subitems, start=1):
new_entry = {
'@id': f'{root_base_id}{i}',
'@type': item.get('@type', 'PropertyValue'),
'value': sub.get('filename', '')
}
new_entries.append(new_entry)
root_data[key] = new_entries
# subitem 特殊対応: 公的の Person, 未病の externalMetadataFiles で利用
if 'subitem_filename' in item:
raw_id = item.get('@id', '')
root_base_id = normalize_base_id(raw_id)
try:
subitems = json.loads(item['subitem_filename'])
except (TypeError, ValueError) as exc:
logger.warning('Could not parse subitem_filename: %s', exc)
else:
if isinstance(subitems, list) and subitems:
new_entries = []
for i, sub in enumerate(subitems, start=1):
new_entry = {
'@id': f'{root_base_id}{i}',
'@type': item.get('@type', 'PropertyValue'),
'value': sub.get('filename', '')
}
new_entries.append(new_entry)
root_data[key] = new_entries

# analysisType 特殊対応
if key == 'ams:analysisType' and len(values) == 1:
parent_raw_id = values[0]['@id']
parent_base_id = normalize_base_id(parent_raw_id)
final_values = []
iCnt = 0

for iCnt, value_str in enumerate(values[0]['value'], start=1):
for i, value_str in enumerate(values[0]['value'], start=1):
new_entry = {
'@id': f'{parent_base_id}{iCnt}',
'@id': f'{parent_base_id}{i}',
'@type': values[0].get('@type', 'PropertyValue'),
'value': value_str
}
Expand Down Expand Up @@ -594,6 +598,7 @@ def _prepare_file_metadata_entries(file_metadatas, download_file_names, schema_i
})
return entries


def write_ro_crate_json(user, f, target_index, download_file_names, schema_id, file_metadatas, project_metadatas, node_id, flatten=True, base_host=None):
from ..models import RegistrationMetadataMapping

Expand Down
Loading
Loading