Skip to content

Commit

Permalink
fix nil handling within instrument and revision classes in mdJson rea…
Browse files Browse the repository at this point in the history
…der. Updated test for iso-3 acquisition to fix errors.
  • Loading branch information
J-Oliveros committed Jul 1, 2024
1 parent 289791f commit 0f002f5
Show file tree
Hide file tree
Showing 6 changed files with 755 additions and 688 deletions.
20 changes: 16 additions & 4 deletions lib/adiwg/mdtranslator/readers/mdJson/modules/module_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ def self.unpack(hInstrument, responseObj, inContext = nil)
end

if hInstrument.has_key?('citation')
intInstrument[:citation] = Citation.unpack(hInstrument['citation'], responseObj, outContext)
hReturn = Citation.unpack(hInstrument['citation'], responseObj, outContext)
unless hReturn.nil?
intInstrument[:citation] = hReturn
end
end

if hInstrument.has_key?('identifier')
intInstrument[:identifier] = Identifier.unpack(hInstrument['identifier'], responseObj, outContext)
hReturn = Identifier.unpack(hInstrument['identifier'], responseObj, outContext)
unless hReturn.nil?
intInstrument[:identifier] = hReturn
end
else
@MessagePath.issueWarning(40, responseObj, outContext)
end
Expand All @@ -46,7 +52,10 @@ def self.unpack(hInstrument, responseObj, inContext = nil)
end

if hInstrument.has_key?('mountedOn')
intInstrument[:mountedOn] = Platform.unpack(hInstrument['mountedOn'], responseObj, outContext)
hReturn = Platform.unpack(hInstrument['mountedOn'], responseObj, outContext)
unless hReturn.nil?
intInstrument[:mountedOn] = hReturn
end
end

if hInstrument.has_key?('history')
Expand All @@ -59,7 +68,10 @@ def self.unpack(hInstrument, responseObj, inContext = nil)
end

if hInstrument.has_key?('hostId')
intInstrument[:hostId] = Identifier.unpack(hInstrument['hostId'], responseObj, outContext)
hReturn = Identifier.unpack(hInstrument['hostId'], responseObj, outContext)
unless hReturn.nil?
intInstrument[:hostId] = hReturn
end
end

intInstrument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def self.unpack(hRevision, responseObj, inContext = nil)
end

if hRevision.has_key?('responsibleParty')
intRevision[:responsibleParty] = ResponsibleParty.unpack(hRevision['responsibleParty'], responseObj, outContext)
hReturn = ResponsibleParty.unpack(hRevision['responsibleParty'], responseObj, outContext)
unless hReturn.nil?
intRevision[:responsibleParty] = hReturn
end
else
@MessagePath.issueWarning(41, responseObj, outContext)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@ def writeXML(hAcquisition)
end
end

unless hAcquisition[:requirements].empty?
hAcquisition[:requirements].each do |hRequirement|
@xml.tag!('mac:acquisitionRequirement') do
requirementClass.writeXML(hRequirement)
unless hAcquisition[:instruments].empty?
hAcquisition[:instruments].each do |hInstrument|
@xml.tag!('mac:instrument') do
instrumentClass.writeXML(hInstrument)
end
end
end

unless hAcquisition[:environment].empty?
@xml.tag!('mac:environmentalConditions') do
environmentClass.writeXML(hAcquisition[:environment])
unless hAcquisition[:operations].empty?
hAcquisition[:operations].each do |hOperation|
@xml.tag!('mac:operation') do
operationClass.writeXML(hOperation)
end
end
end

unless hAcquisition[:instruments].empty?
hAcquisition[:instruments].each do |hInstrument|
@xml.tag!('mac:instrument') do
instrumentClass.writeXML(hInstrument)
unless hAcquisition[:platforms].empty?
hAcquisition[:platforms].each do |hPlatform|
@xml.tag!('mac:platform') do
platformClass.writeXML(hPlatform)
end
end
end
Expand All @@ -75,22 +77,20 @@ def writeXML(hAcquisition)
end
end

unless hAcquisition[:operations].empty?
hAcquisition[:operations].each do |hOperation|
@xml.tag!('mac:operation') do
operationClass.writeXML(hOperation)
unless hAcquisition[:requirements].empty?
hAcquisition[:requirements].each do |hRequirement|
@xml.tag!('mac:acquisitionRequirement') do
requirementClass.writeXML(hRequirement)
end
end
end

unless hAcquisition[:platforms].empty?
hAcquisition[:platforms].each do |hPlatform|
@xml.tag!('mac:platform') do
platformClass.writeXML(hPlatform)
end
unless hAcquisition[:environment].empty?
@xml.tag!('mac:environmentalConditions') do
environmentClass.writeXML(hAcquisition[:environment])
end
end

end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require_relative 'class_responsibility'
require_relative 'class_gcoDateTime'

module ADIWG
module Mdtranslator
Expand All @@ -15,7 +14,6 @@ def initialize(xml, hResponseObj)
def writeXML(hRevision)

responsibilityClass = CI_Responsibility.new(@xml, @hResponseObj)
gcoDateTimeClass = GcoDateTime.new(@xml, @hResponseObj)

@xml.tag!('mac:MI_Revision') do
unless hRevision[:description].nil?
Expand Down
Loading

0 comments on commit 0f002f5

Please sign in to comment.