Skip to content

Commit

Permalink
WIP on #561.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Feb 22, 2023
1 parent e54722a commit 5128e8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
22 changes: 12 additions & 10 deletions workbench
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,18 @@ def create():
# Therefore, only tasks whose names are registered there should populate
# their objects' 'field_member_of'.
secondary_task_data = read_node_ids_tsv(config)
if os.path.abspath(args.config) in json.loads(os.environ["ISLANDORA_WORKBENCH_SECONDARY_TASKS"]):
if len(secondary_task_data) > 0:
if 'field_member_of' in row and 'parent_id' in row and row['parent_id'] in secondary_task_data.keys():
row['field_member_of'] = secondary_task_data[row['parent_id']]
else:
# If there is no parent ID/nid pair in the secondary_task_data mapping,
# either because it wasn't in the primary CSV or it failed to be created
# in the primary task, skip creating the current secondary node and move on.
logging.warning('Node for row with ID %s in secondary task CSV not created because its parent was not present or not created in the primary task.', id_field)
continue

if os.environ.get('ISLANDORA_WORKBENCH_SECONDARY_TASKS') is not None:
if os.path.abspath(args.config) in json.loads(os.environ["ISLANDORA_WORKBENCH_SECONDARY_TASKS"]):
if len(secondary_task_data) > 0:
if 'field_member_of' in row and 'parent_id' in row and row['parent_id'] in secondary_task_data.keys():
row['field_member_of'] = secondary_task_data[row['parent_id']]
else:
# If there is no parent ID/nid pair in the secondary_task_data mapping,
# either because it wasn't in the primary CSV or it failed to be created
# in the primary task, skip creating the current secondary node and move on.
logging.warning('Node for row with ID %s in secondary task CSV not created because its parent was not present or not created in the primary task.', id_field)
continue

# Add custom (non-required) CSV fields.
entity_fields = get_entity_fields(config, 'node', config['content_type'])
Expand Down
15 changes: 12 additions & 3 deletions workbench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6096,7 +6096,10 @@ def prep_node_ids_tsv(config):
populate their objects' 'field_member_of'. We write the parent ID->nid map to this file
as well, in write_to_node_ids_tsv().
"""
path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file'])
if os.environ.get('ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR') is not None:
path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file'])
else:
path_to_tsv_file = os.path.join(config['temp_dir'], config['secondary_tasks_data_file'])
if os.path.exists(path_to_tsv_file):
os.remove(path_to_tsv_file)
if len(config['secondary_tasks']) > 0:
Expand All @@ -6110,15 +6113,21 @@ def prep_node_ids_tsv(config):


def write_to_node_ids_tsv(config, row_id, node_id):
path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file'])
if os.environ.get('ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR') is not None:
path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file'])
else:
path_to_tsv_file = os.path.join(config['temp_dir'], config['secondary_tasks_data_file'])
tsv_file = open(path_to_tsv_file, "a+", encoding='utf-8')
tsv_file.write(str(row_id) + "\t" + str(node_id) + "\n")
tsv_file.close()


def read_node_ids_tsv(config):
map = dict()
path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file'])
if os.environ.get('ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR') is not None:
path_to_tsv_file = os.path.join(os.environ["ISLANDORA_WORKBENCH_PRIMARY_TASK_TEMP_DIR"], config['secondary_tasks_data_file'])
else:
path_to_tsv_file = os.path.join(config['temp_dir'], config['secondary_tasks_data_file'])
if config['secondary_tasks'] is not None:
if not os.path.exists(path_to_tsv_file):
message = 'Secondary task data file ' + path_to_tsv_file + ' not found.'
Expand Down

0 comments on commit 5128e8c

Please sign in to comment.