Class: ADIWG::Mdtranslator::Writers::Iso19115_2::MD_DataIdentification

Inherits:
Object
  • Object
show all
Defined in:
lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_dataIdentification.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml, hResponseObj) ⇒ MD_DataIdentification

Returns a new instance of MD_DataIdentification.



60
61
62
63
64
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_dataIdentification.rb', line 60

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

Instance Method Details

#writeXML(hMetadata) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_dataIdentification.rb', line 66

def writeXML()

   # classes used
   intMetadataClass = InternalMetadata.new
   codelistClass = MD_Codelist.new(@xml, @hResponseObj)
   citationClass = CI_Citation.new(@xml, @hResponseObj)
   rPartyClass = CI_ResponsibleParty.new(@xml, @hResponseObj)
   mInfoClass = MD_MaintenanceInformation.new(@xml, @hResponseObj)
   bGraphicClass = MD_BrowseGraphic.new(@xml, @hResponseObj)
   rFormatClass = MD_Format.new(@xml, @hResponseObj)
   keywordClass = MD_Keywords.new(@xml, @hResponseObj)
   useClass = MD_Usage.new(@xml, @hResponseObj)
   uConClass = MD_Constraints.new(@xml, @hResponseObj)
   lConClass = MD_LegalConstraints.new(@xml, @hResponseObj)
   sConClass = MD_SecurityConstraints.new(@xml, @hResponseObj)
   aggInfoClass = MD_AggregateInformation.new(@xml, @hResponseObj)
   taxClass = MD_TaxonSys.new(@xml, @hResponseObj)
   resolutionClass = MD_Resolution.new(@xml, @hResponseObj)
   extentClass = EX_Extent.new(@xml, @hResponseObj)

   # create shortcuts to sections of internal object
   hResource = [:resourceInfo]
   aAssocRes = [:associatedResources]
   aDistInfo = [:distributorInfo]

   # data identification
   @xml.tag!('gmd:MD_DataIdentification') do

      # data identification - citation {CI_Citation} (required)
      hCitation = hResource[:citation]
      unless hCitation.empty?
         @xml.tag!('gmd:citation') do
            citationClass.writeXML(hCitation, 'main resource')
         end
      end
      if hCitation.empty?
         @NameSpace.issueWarning(50, 'gmd:citation')
      end

      # data identification - abstract (required)
      s = hResource[:abstract]
      unless s.nil?
         @xml.tag!('gmd:abstract') do
            @xml.tag!('gco:CharacterString', s)
         end
      end
      if s.nil?
         @NameSpace.issueWarning(51, 'gmd:abstract')
      end

      # data identification - purpose
      s = hResource[:purpose]
      unless s.nil?
         @xml.tag!('gmd:purpose') do
            @xml.tag!('gco:CharacterString', s)
         end
      end
      if s.nil? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:purpose')
      end

      # data identification - time period {timePeriod}
      # package as a temporal extent
      unless hResource[:timePeriod].empty?
         hExtent = intMetadataClass.newExtent
         hTempExtent = intMetadataClass.newTemporalExtent
         hTempExtent[:timePeriod] = hResource[:timePeriod]
         hExtent[:temporalExtents] << hTempExtent
         hResource[:extents] << hExtent
      end

      # data identification - credit []
      aCredits = hResource[:credits]
      aCredits.each do |credit|
         @xml.tag!('gmd:credit') do
            @xml.tag!('gco:CharacterString', credit)
         end
      end
      if aCredits.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:credit')
      end

      # data identification - status []
      aStatus = hResource[:status]
      aStatus.each do |code|
         @xml.tag!('gmd:status') do
            codelistClass.writeXML('gmd', 'iso_progress', code)
         end
      end
      if aStatus.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:status')
      end

      # data identification - point of contact
      aRParties = hResource[:pointOfContacts]
      aRParties.each do |hRParty|
         role = hRParty[:roleName]
         aParties = hRParty[:parties]
         aParties.each do |hParty|
            @xml.tag!('gmd:pointOfContact') do
               rPartyClass.writeXML(role, hParty, 'resource point of contact')
            end
         end
      end
      if aRParties.empty? && @hResponseObj[:writerShowTags]
         @NameSpace.issueWarning(52, 'gmd:pointOfContact')
      end

      # data identification - resource maintenance []
      aMaint = hResource[:resourceMaintenance]
      aMaint.each do |hMaint|
         @xml.tag!('gmd:resourceMaintenance') do
            mInfoClass.writeXML(hMaint, 'main resource')
         end
      end
      if aMaint.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:resourceMaintenance')
      end

      # data identification - graphic overview []
      aGraphics = hResource[:graphicOverviews]
      aGraphics.each do |hGraphic|
         @xml.tag!('gmd:graphicOverview') do
            bGraphicClass.writeXML(hGraphic, 'main resource')
         end
      end
      if aGraphics.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:graphicOverview')
      end

      # data identification - resource format []
      aFormats = hResource[:resourceFormats]
      aFormats.each do |hResFormat|
         @xml.tag!('gmd:resourceFormat') do
            rFormatClass.writeXML(hResFormat)
         end
      end
      if aFormats.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:resourceFormat')
      end

      # data identification - descriptive keywords []
      aKeywords = hResource[:keywords]
      aKeywords.each do |hKeyword|
         @xml.tag!('gmd:descriptiveKeywords') do
            keywordClass.writeXML(hKeyword)
         end
      end
      if aKeywords.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:descriptiveKeywords')
      end

      # data identification - resource specific usage []
      aUses = hResource[:resourceUsages]
      aUses.each do |hResUse|
         @xml.tag!('gmd:resourceSpecificUsage') do
            useClass.writeXML(hResUse)
         end
      end
      if aUses.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:resourceSpecificUsage')
      end

      # data identification - resource constraints {}
      haveCon = false
      aCons = hResource[:constraints]
      aCons.each do |hCon|
         @xml.tag!('gmd:resourceConstraints') do
            type = hCon[:type]
            if type == 'use'
               uConClass.writeXML(hCon)
            end
            if type == 'legal'
               lConClass.writeXML(hCon)
            end
            if type == 'security'
               sConClass.writeXML(hCon)
            end
            haveCon = true
         end
      end

      # data identification - resource constraints {}  from distribution liability statement
      aDistInfo.each do |hDistribution|
         unless hDistribution.empty?
            unless hDistribution[:liabilityStatement].nil?
               @xml.tag!('gmd:resourceConstraints') do
                  @xml.tag!('gmd:MD_LegalConstraints') do
                     @xml.tag!('gmd:otherConstraints') do
                        @xml.tag!('gco:CharacterString', hDistribution[:liabilityStatement])
                     end
                  end
               end
               haveCon = true
            end
         end
      end

      if !haveCon && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:resourceConstraints')
      end

      # data identification - aggregate information []
      aAssocRes.each do |hAssocRes|
         @xml.tag!('gmd:aggregationInfo') do
            aggInfoClass.writeXML(hAssocRes)
         end
      end
      if aAssocRes.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:aggregationInfo')
      end

      # data identification - taxonomy (first)
      unless hResource[:taxonomy].empty?
         hTaxonomy = hResource[:taxonomy][0]
         unless hTaxonomy.empty?
            @xml.tag!('gmd:taxonomy') do
               taxClass.writeXML(hTaxonomy)
            end
         end
         if hResource[:taxonomy].length > 1
            @NameSpace.issueNotice(53, 'main resource')
            @NameSpace.issueNotice(54, 'main resource')
         end
      end
      if hResource[:taxonomy].empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:taxonomy')
      end

      # data identification - spatial representation type []
      aSpatialType = hResource[:spatialRepresentationTypes]
      aSpatialType.each do |spType|
         @xml.tag!('gmd:spatialRepresentationType') do
            codelistClass.writeXML('gmd', 'iso_spatialRepresentation', spType)
         end
      end
      if aSpatialType.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:spatialRepresentationType')
      end

      # data identification - spatial resolution []
      aSpatialRes = hResource[:spatialResolutions]
      aSpatialRes.each do |hSpRes|
         @xml.tag!('gmd:spatialResolution') do
            resolutionClass.writeXML(hSpRes)
         end
      end
      if aSpatialRes.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:spatialResolution')
      end

      # data identification - language [] (required)
      aLocale = hResource[:otherResourceLocales]
      aLocale.insert(0, hResource[:defaultResourceLocale])
      aLocale.each do |hLocale|
         s = hLocale[:languageCode]
         unless hLocale[:countryCode].nil?
            s += '; ' + hLocale[:countryCode]
         end
         @xml.tag!('gmd:language') do
            @xml.tag!('gco:CharacterString', s)
         end
      end
      if aLocale.empty?
         @xml.tag!('gmd:language') do
            @xml.tag!('gco:CharacterString', 'eng; USA')
         end
      end

      # data identification - characterSet [] (default 'utf8')
      charSets = 0
      aLocale.each do |hLocale|
         s = hLocale[:characterEncoding]
         unless s.nil?
            @xml.tag!('gmd:characterSet') do
               codelistClass.writeXML('gmd', 'iso_characterSet', s)
               charSets += 1
            end
         end
      end
      if charSets == 0
         @xml.tag!('gmd:language') do
            @xml.tag!('gco:CharacterString', 'eng; USA')
         end
      end

      # data identification - topic category [] {MD_TopicCategoryCode}
      # get from hData.keywords where keywordType='isoTopicCategory'
      aTopics = []
      aKeywords = hResource[:keywords]
      aKeywords.each do |hKeyword|
         if hKeyword[:keywordType] == 'isoTopicCategory'
            hKeyword[:keywords].each do |hKeyObj|
               aTopics << hKeyObj[:keyword]
            end
         end
      end
      # only allow valid ISO 19115-2 topic categories to be written
      aTopics.each do |topic|
         if CodelistFun.validateItem('iso_topicCategory', topic)
            @xml.tag!('gmd:topicCategory') do
               @xml.tag!('gmd:MD_TopicCategoryCode', topic)
            end
         else
            @NameSpace.issueWarning(380, 'gmd:topicCategory', "#{topic}")
         end
      end
      if aTopics.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:topicCategory')
      end

      # data identification - environment description
      s = hResource[:environmentDescription]
      unless s.nil?
         @xml.tag!('gmd:environmentDescription') do
            @xml.tag!('gco:CharacterString', s)
         end
      end
      if s.nil? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:environmentDescription')
      end

      # data identification - extent []
      aExtents = hResource[:extents]
      aExtents.each do |hExtent|
         @xml.tag!('gmd:extent') do
            extentClass.writeXML(hExtent)
         end
      end
      if aExtents.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:extent')
      end

      # data identification - supplemental info
      s = hResource[:supplementalInfo]
      unless s.nil?
         @xml.tag!('gmd:supplementalInformation') do
            @xml.tag!('gco:CharacterString', s)
         end
      end
      if s.nil? && @hResponseObj[:writerShowTags]
         @xml.tag!('gmd:supplementalInformation')
      end

   end # gmd:MD_DataIdentification tag
end