lib/adiwg/mdtranslator/writers/iso19110/iso19110_writer.rb in adiwg-mdtranslator-2.0.0rc8 vs lib/adiwg/mdtranslator/writers/iso19110/iso19110_writer.rb in adiwg-mdtranslator-2.0.0rc9
- old
+ new
@@ -1,68 +1,79 @@
# Writer - internal data structure to ISO 19110:2003
# History:
-# Stan Smith 2017-01-20 refactor for mdJson/mdTranslator 2.0
+# Stan Smith 2017-05-26 allow choice of which dictionary to translate
+# ... fix bug when no dictionary is provided in mdJson
+# Stan Smith 2017-01-20 refactor for mdJson/mdTranslator 2.0
+# Stan Smith 2015-07-14 refactored to eliminate namespace globals $WriterNS and $IsoNS
+# Stan Smith 2015-07-14 refactored to make iso19110 independent of iso19115_2 classes
+# Stan Smith 2015-06-22 replace global ($response) with passed in object (responseObj)
+# Stan Smith 2015-03-02 added test and return for missing data dictionary
+# Stan Smith 2014-12-12 refactored to handle namespacing readers and writers
# Stan Smith 2014-12-01 original script
-# Stan Smith 2014-12-12 refactored to handle namespacing readers and writers
-# Stan Smith 2015-03-02 added test and return for missing data dictionary
-# Stan Smith 2015-06-22 replace global ($response) with passed in object (responseObj)
-# Stan Smith 2015-07-14 refactored to make iso19110 independent of iso19115_2 classes
-# Stan Smith 2015-07-14 refactored to eliminate namespace globals $WriterNS and $IsoNS
require 'builder'
require_relative 'classes/class_fcFeatureCatalogue'
module ADIWG
- module Mdtranslator
- module Writers
- module Iso19110
+ module Mdtranslator
+ module Writers
+ module Iso19110
- def self.startWriter(intObj, responseObj)
+ def self.startWriter(intObj, responseObj, whichDict: 0)
- # make contacts and domains available to the instance
- @contacts = intObj[:contacts]
- @domains = intObj[:dataDictionaries][0][:domains]
+ # Iso19110 can only output one dictionary at a time
+ # test if requested dictionary is in input file
+ if intObj[:dataDictionaries][whichDict].nil?
+ responseObj[:writerMessages] << 'Dictionary is missing'
+ responseObj[:writerPass] = false
+ return nil
+ end
- # set the format of the output file based on the writer specified
- responseObj[:writerFormat] = 'xml'
+ # make contacts and domains available to the instance
+ @contacts = intObj[:contacts]
+ dictionary = intObj[:dataDictionaries][whichDict]
+ @domains = dictionary[:domains]
- # create new XML document
- xml = Builder::XmlMarkup.new(indent: 3)
+ # set the format of the output file based on the writer specified
+ responseObj[:writerFormat] = 'xml'
- # start writing the ISO 19110 XML record
- metadataWriter = FC_FeatureCatalogue.new(xml, responseObj)
- metadata = metadataWriter.writeXML(intObj)
+ # create new XML document
+ xml = Builder::XmlMarkup.new(indent: 3)
- return metadata
+ # start writing the ISO 19110 XML record
+ metadataWriter = FC_FeatureCatalogue.new(xml, responseObj)
+ metadata = metadataWriter.writeXML(intObj)
- end
+ return metadata
- # find contact in contact array and return the contact hash
- def self.getContact(contactId)
+ end
- @contacts.each do |contact|
- if contact[:contactId] == contactId
- return contact
- end
- end
- return {}
+ # find contact in contact array and return the contact hash
+ def self.getContact(contactId)
- end
+ @contacts.each do |contact|
+ if contact[:contactId] == contactId
+ return contact
+ end
+ end
+ return {}
- # find domain in domain array and return the domain hash
- def self.getDomain(domainId)
+ end
- @domains.each do |domain|
- if domain[:domainId] == domainId
- return domain
- end
- end
- return {}
+ # find domain in domain array and return the domain hash
+ def self.getDomain(domainId)
- end
+ @domains.each do |domain|
+ if domain[:domainId] == domainId
+ return domain
+ end
+ end
+ return {}
end
- end
- end
+
+ end
+ end
+ end
end