Skip to content

Commit

Permalink
feat: Add metadata extension section for taxonomy info.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaspin committed Jun 25, 2024
1 parent 2abd84d commit 346f0c4
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ISO <<CodeLists>> Enumerations
# 19115-2 writer output in XML

# History:
# Stan Smith 2016-12-12 refactored for mdTranslator/mdJson 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-06-12 refactored to use mdCodes gem for codelist contents
# Stan Smith 2014-12-15 replaced NOAA CT_CodelistCatalogue with mdTranslator CT_CodelistCatalogue
# Stan Smith 2014-12-12 refactored to handle namespacing readers and writers
# Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
# Stan Smith 2013-08-09 original script

require 'adiwg-mdcodes'

module ADIWG
module Mdtranslator
module Writers
module Iso19115_3

class MD_EnumerationList

def initialize(xml, responseObj)
@xml = xml
@hResponseObj = responseObj
end

def writeXML(codeList, codeName)

# get requested codelist from the adiwg-mdcodes gem
mdCodelist = ADIWG::Mdcodes.getCodelistDetail(codeList)

sourceName = mdCodelist['sourceName']
codelist = mdCodelist['codelist']

# search the codelist for a matching codeName
# only valid enumeration values can be written in ISO
codelist.each do |code|
if code['codeName'] == codeName
@xml.tag!('gmd:' + "#{sourceName}", codeName)
break
end
end

end # writeXML
end # MD_EnumerationList class

end
end
end
end
208 changes: 208 additions & 0 deletions lib/adiwg/mdtranslator/writers/iso19115_3/classes/class_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# ISO <<Class>> MD_MetadataExtensionInformation
# 19115-2 writer output in XML

# History:
# Stan Smith 2019-03-22 replaced Enumeration class with method
# Stan Smith 2018-04-09 add error and warning messaging
# 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 (hResponseObj)
# Stan Smith 2015-06-11 change all codelists to use 'class_codelist' method
# Stan Smith 2014-12-12 refactored to handle namespacing readers and writers
# Stan Smith 2014-07-08 modify require statements to function in RubyGem structure
# Stan Smith 2013-11-22 original script.

require 'adiwg/mdtranslator/internal/module_codelistFun'
require_relative '../iso19115_3_writer'
require_relative 'class_codelist'
require_relative 'class_enumerationList'
require_relative 'class_onlineResource'

module ADIWG
module Mdtranslator
module Writers
module Iso19115_3

class MD_MetadataExtensionInformation

def initialize(xml, hResponseObj)
@xml = xml
@hResponseObj = hResponseObj
@NameSpace = ADIWG::Mdtranslator::Writers::Iso19115_3
end

def writeXML(hExtension)

# classes used
codelistClass = MD_Codelist.new(@xml, @hResponseObj)
olResClass = CI_OnlineResource.new(@xml, @hResponseObj)

outContext = 'extension information'
outContext = 'extension name ' + hExtension[:name] unless hExtension[:name].nil?

@xml.tag!('gmd:MD_MetadataExtensionInformation') do

# metadata extension - online resource {CI_OnLineResource}
hOLResource = hExtension[:onLineResource]
unless hOLResource.empty?
@xml.tag!('gmd:extensionOnLineResource') do
olResClass.writeXML(hOLResource, outContext)
end
end
if hOLResource.empty? && @hResponseObj[:writerShowTags]
@xml.tag!('gmd:extensionOnLineResource')
end

# metadata extension = extended element information
@xml.tag!('gmd:extendedElementInformation') do
@xml.tag!('gmd:MD_ExtendedElementInformation') do

# extended element info - name (required)
s = hExtension[:name]
unless s.nil?
@xml.tag!('gmd:name') do
@xml.tag!('gco:CharacterString', s)
end
end
if s.nil?
@NameSpace.issueWarning(100, 'gmd:name')
end

# extended element info - short name
s = hExtension[:shortName]
unless s.nil?
@xml.tag!('gmd:shortName') do
@xml.tag!('gco:CharacterString', s)
end
end
if s.nil? && @hResponseObj[:writerShowTags]
@xml.tag!('gmd:shortName')
end

# extended element info - definition (required)
s = hExtension[:definition]
unless s.nil?
@xml.tag!('gmd:definition') do
@xml.tag!('gco:CharacterString', s)
end
end
if s.nil?
@NameSpace.issueWarning(101, 'gmd:definition', outContext)
end

# extended element info - obligation {MD_ObligationCode}
obligation = hExtension[:obligation]
unless obligation.nil?
if CodelistFun.validateItem('iso_obligation', obligation)
@xml.tag!('gmd:obligation') do
@xml.tag!('gmd:MD_ObligationCode', obligation)
end
else
@NameSpace.issueWarning(380, 'gmd:obligation', "#{obligation}")
end
end
if obligation.nil? && @hResponseObj[:writerShowTags]
@xml.tag!('gmd:obligation')
end

# extended element info - data type (required)
s = hExtension[:dataType]
unless s.nil?
@xml.tag!('gmd:dataType') do
codelistClass.writeXML('gmd', 'iso_entityClass', s)
end
end
if s.nil?
@NameSpace.issueWarning(102, 'gmd:dataType', outContext)
end

# extended element info - maximum occurrence
s = hExtension[:maxOccurrence]
unless s.nil?
@xml.tag!('gmd:maximumOccurrence') do
@xml.tag!('gco:CharacterString', s)
end
end
if s.nil? && @hResponseObj[:writerShowTags]
@xml.tag!('gmd:maximumOccurrence')
end

# extended element info - parent entity [] (required)
aParents = hExtension[:parentEntities]
aParents.each do |parent|
@xml.tag!('gmd:parentEntity') do
@xml.tag!('gco:CharacterString', parent)
end
end
if aParents.empty?
@NameSpace.issueWarning(103, 'gmd:parentEntity', outContext)
end

# extended element info - rule
s = hExtension[:rule]
unless s.nil?
@xml.tag!('gmd:rule') do
@xml.tag!('gco:CharacterString', s)
end
end
if s.nil?
@NameSpace.issueWarning(104, 'gmd:rule', outContext)
end

# extended element info - rationale []
aRations = hExtension[:rationales]
aRations.each do |ration|
@xml.tag!('gmd:rationale') do
@xml.tag!('gco:CharacterString', ration)
end
end
if aRations.empty? && @hResponseObj[:writerShowTags]
@xml.tag!('gmd:rationale')
end

# extended element info - source [] (required)
# only allowing 1 for now
role = hExtension[:sourceRole]
unless role.nil?
@xml.tag!('gmd:source') do
@xml.tag!('gmd:CI_ResponsibleParty') do
orgName = hExtension[:sourceOrganization]
unless orgName.nil?
@xml.tag!('gmd:organisationName') do
@xml.tag!('gco:CharacterString', orgName)
end
end
uri = hExtension[:sourceURI]
unless uri.nil?
@xml.tag!('gmd:contactInfo') do
@xml.tag!('gmd:CI_Contact') do
@xml.tag!('gmd:onlineResource') do
@xml.tag!('gmd:CI_OnlineResource') do
@xml.tag!('gmd:linkage') do
@xml.tag!('gmd:URL', uri)
end
end
end
end
end
end
@xml.tag!('gmd:role') do
codelistClass.writeXML('gmd', 'iso_role', role)
end
end
end
end
if role.nil?
@NameSpace.issueWarning(105, 'gmd:source', outContext)
end

end # gmd:MD_ExtendedElementInformation tag
end # gmd:extendedElementInformation
end # gmd:MD_MetadataExtensionInformation
end # writeXML
end # MD_MetadataExtensionInformation class

end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
require_relative 'class_spatialRepresentation'
require_relative 'class_referenceSystem'
require_relative 'class_featureCatalog'
require_relative 'class_extension'

module ADIWG
module Mdtranslator
Expand Down Expand Up @@ -62,6 +63,7 @@ def writeXML(intObj)
representationClass = SpatialRepresentation.new(@xml, @hResponseObj)
referenceSystemClass = MD_ReferenceSystem.new(@xml, @hResponseObj)
mdCatalogClass = MD_FeatureCatalogue.new(@xml, @hResponseObj)
extensionClass = MD_MetadataExtensionInformation.new(@xml, @hResponseObj)

# create shortcuts to sections of internal object
hMetadata = intObj[:metadata]
Expand Down Expand Up @@ -291,6 +293,28 @@ def writeXML(intObj)
@xml.tag!('mdb:referenceSystemInfo')
end

# metadata information - metadata extension info
# add biological profile to all metadata records
intBio = intMetadataClass.newMetadataExtension
intBio[:name] = 'Taxonomy System'
intBio[:shortName] = 'TaxonSys'
intBio[:definition] = 'Documentation of taxonomic sources, procedures, and treatments'
intBio[:obligation] = 'optional'
intBio[:dataType] = 'class'
intBio[:maxOccurrence] = '1'
intBio[:parentEntities] << 'MD_Identification'
intBio[:rule] = 'New Metadata section as a class to MD_Identification'
intBio[:rationales] << 'The set of data elements contained within this class element ' +
'represents an attempt to provide better documentation of ' +
'taxonomic sources, procedures, and treatments.'
intBio[:sourceOrganization] = 'National Biological Information Infrastructure'
intBio[:sourceURI] = 'https://www2.usgs.gov/core_science_systems/Access/p1111-1.html'
intBio[:sourceRole] = 'author'

@xml.tag!('gmd:metadataExtensionInfo') do
extensionClass.writeXML(intBio)
end

# ###################### Begin Data Identification #####################

# metadata information - data identification info - required
Expand Down
57 changes: 57 additions & 0 deletions test/writers/iso19115-3/testData/19115_3_mdMetadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,63 @@
<mdb:metadataLinkage/>
<mdb:spatialRepresentationInfo/>
<mdb:referenceSystemInfo/>
<gmd:metadataExtensionInfo>
<gmd:MD_MetadataExtensionInformation>
<gmd:extensionOnLineResource/>
<gmd:extendedElementInformation>
<gmd:MD_ExtendedElementInformation>
<gmd:name>
<gco:CharacterString>Taxonomy System</gco:CharacterString>
</gmd:name>
<gmd:shortName>
<gco:CharacterString>TaxonSys</gco:CharacterString>
</gmd:shortName>
<gmd:definition>
<gco:CharacterString>Documentation of taxonomic sources, procedures, and treatments</gco:CharacterString>
</gmd:definition>
<gmd:obligation>
<gmd:MD_ObligationCode>optional</gmd:MD_ObligationCode>
</gmd:obligation>
<gmd:dataType>
<gmd:MD_DatatypeCode codeList="http://mdtranslator.adiwg.org/api/codelists?format=xml#MD_DatatypeCode" codeListValue="class" codeSpace="001"/>
</gmd:dataType>
<gmd:maximumOccurrence>
<gco:CharacterString>1</gco:CharacterString>
</gmd:maximumOccurrence>
<gmd:parentEntity>
<gco:CharacterString>MD_Identification</gco:CharacterString>
</gmd:parentEntity>
<gmd:rule>
<gco:CharacterString>New Metadata section as a class to MD_Identification</gco:CharacterString>
</gmd:rule>
<gmd:rationale>
<gco:CharacterString>The set of data elements contained within this class element represents an attempt to provide better documentation of taxonomic sources, procedures, and treatments.</gco:CharacterString>
</gmd:rationale>
<gmd:source>
<gmd:CI_ResponsibleParty>
<gmd:organisationName>
<gco:CharacterString>National Biological Information Infrastructure</gco:CharacterString>
</gmd:organisationName>
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:onlineResource>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>https://www2.usgs.gov/core_science_systems/Access/p1111-1.html</gmd:URL>
</gmd:linkage>
</gmd:CI_OnlineResource>
</gmd:onlineResource>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://mdtranslator.adiwg.org/api/codelists?format=xml#CI_RoleCode" codeListValue="author" codeSpace="011"/>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:source>
</gmd:MD_ExtendedElementInformation>
</gmd:extendedElementInformation>
</gmd:MD_MetadataExtensionInformation>
</gmd:metadataExtensionInfo>
<mdb:identificationInfo>
<mri:MD_DataIdentification>
<mri:citation>
Expand Down

0 comments on commit 346f0c4

Please sign in to comment.