Description
Summary
When uploading a BagIt-formatted ZIP file containing metadata/converter.json, the metadata is not automatically extracted. The BagIt detection logic exists in process_source but its return value is ignored by the caller process_zip_file, causing the detection result to be lost.
Expected Behavior
- Upload a BagIt ZIP file with
metadata/converter.json
- System detects BagIt format via
bagit_metadata_file?
handle_bagit_result is called, setting con_state to CONVERTED
Converter.metadata extracts data from converter.json
- Metadata is populated in the Dataset
Actual Behavior
- Upload a BagIt ZIP file
process_source detects BagIt and returns { is_bagit: true, metadata: nil }
- Return value is ignored by
process_zip_file
- Since BagIt files don't contain
acqus/procs files, final_parameters remains empty
process_zip_file returns nil
NmrMapper.process_ds returns NONE
con_state remains 0, no metadata processing occurs
Environment
- LabIMotion version: 2.0.0
- Chemotion ELN version: 2.2.0
Root Cause
File: lib/labimotion/utils/mapper_utils.rb
The process_source method correctly detects BagIt files and returns { is_bagit: true, metadata: nil }, but process_zip_file discards this return value:
def process_zip_file(zip_file_url, source_map)
final_parameters = {}
Zip::File.open(zip_file_url) do |zip_file|
source_map['sourceSelector'].each do |source_name|
process_source(zip_file, source_map[source_name], final_parameters)
# ↑ Return value is discarded
end
end
return { is_bagit: false, metadata: final_parameters } if final_parameters.present?
nil # BagIt files end up here because final_parameters is empty
end
Steps to Reproduce
-
Create a BagIt-formatted ZIP file containing:
data/sample.jdx
metadata/converter.json
bagit.txt
manifest-sha256.txt
-
The converter.json should contain valid metadata, e.g.:
{
"ols": "CHMO:0000593",
"matches": [
{
"identifier": { "outputLayer": "set", "outputKey": "temperature" },
"result": { "value": 298.0 }
}
]
}
-
Upload the ZIP file to a Sample's Analysis in Chemotion ELN
-
Check the Attachment's con_state in Rails console:
att = Attachment.where("filename LIKE '%.zip'").order(created_at: :desc).first
att.con_state # => 0 (NONE) - should be 6 (COMPLETED)
Workaround
Manually trigger metadata processing after upload:
att = Attachment.find(ID)
att.update_column(:con_state, 3) # CONVERTED
Labimotion::Converter.process_ds(att.id, User.first)
This confirms that downstream processing works correctly when properly invoked.
Suggested Fix
One possible fix is to check the return value of process_source and return early when BagIt is detected:
def process_zip_file(zip_file_url, source_map)
final_parameters = {}
Zip::File.open(zip_file_url) do |zip_file|
source_map['sourceSelector'].each do |source_name|
- process_source(zip_file, source_map[source_name], final_parameters)
+ result = process_source(zip_file, source_map[source_name], final_parameters)
+ return result if result.is_a?(Hash) && result[:is_bagit]
end
end
return { is_bagit: false, metadata: final_parameters } if final_parameters.present?
nil
end
Additional Context
- The
bagit_metadata_file? method exists and correctly identifies BagIt files
- The
handle_bagit_result method in nmr_mapper.rb is implemented and functional
- The
Converter.collect_metadata method correctly parses converter.json
- BagIt support was added in commit 078e1f5 (2024-01-15)
Description
Summary
When uploading a BagIt-formatted ZIP file containing
metadata/converter.json, the metadata is not automatically extracted. The BagIt detection logic exists inprocess_sourcebut its return value is ignored by the callerprocess_zip_file, causing the detection result to be lost.Expected Behavior
metadata/converter.jsonbagit_metadata_file?handle_bagit_resultis called, settingcon_statetoCONVERTEDConverter.metadataextracts data fromconverter.jsonActual Behavior
process_sourcedetects BagIt and returns{ is_bagit: true, metadata: nil }process_zip_fileacqus/procsfiles,final_parametersremains emptyprocess_zip_filereturnsnilNmrMapper.process_dsreturnsNONEcon_stateremains0, no metadata processing occursEnvironment
Root Cause
File:
lib/labimotion/utils/mapper_utils.rbThe
process_sourcemethod correctly detects BagIt files and returns{ is_bagit: true, metadata: nil }, butprocess_zip_filediscards this return value:Steps to Reproduce
Create a BagIt-formatted ZIP file containing:
The
converter.jsonshould contain valid metadata, e.g.:{ "ols": "CHMO:0000593", "matches": [ { "identifier": { "outputLayer": "set", "outputKey": "temperature" }, "result": { "value": 298.0 } } ] }Upload the ZIP file to a Sample's Analysis in Chemotion ELN
Check the Attachment's
con_statein Rails console:Workaround
Manually trigger metadata processing after upload:
This confirms that downstream processing works correctly when properly invoked.
Suggested Fix
One possible fix is to check the return value of
process_sourceand return early when BagIt is detected:def process_zip_file(zip_file_url, source_map) final_parameters = {} Zip::File.open(zip_file_url) do |zip_file| source_map['sourceSelector'].each do |source_name| - process_source(zip_file, source_map[source_name], final_parameters) + result = process_source(zip_file, source_map[source_name], final_parameters) + return result if result.is_a?(Hash) && result[:is_bagit] end end return { is_bagit: false, metadata: final_parameters } if final_parameters.present? nil endAdditional Context
bagit_metadata_file?method exists and correctly identifies BagIt fileshandle_bagit_resultmethod innmr_mapper.rbis implemented and functionalConverter.collect_metadatamethod correctly parsesconverter.json