Module: ADIWG::Mdtranslator::Readers::MdJson::ResourceInfo

Defined in:
lib/adiwg/mdtranslator/readers/mdJson/modules/module_resourceInfo.rb

Class Method Summary collapse

Class Method Details

.unpack(hResInfo, responseObj) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_resourceInfo.rb', line 38

def self.unpack(hResInfo, responseObj)

   @MessagePath = ADIWG::Mdtranslator::Readers::MdJson::MdJson

   # return nil object if input is empty
   if hResInfo.empty?
      @MessagePath.issueError(680, responseObj)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intResInfo = intMetadataClass.newResourceInfo

   outContext = 'resource information'

   # resource information - resource type [] (required) {resourceType}
   if hResInfo.has_key?('resourceType')
      hResInfo['resourceType'].each do |item|
         unless item.empty?
            hReturn = ResourceType.unpack(item, responseObj, outContext)
            unless hReturn.nil?
               intResInfo[:resourceTypes] << hReturn
            end
         end
      end
   end
   if intResInfo[:resourceTypes].empty?
      @MessagePath.issueError(681, responseObj, outContext)
   end

   # resource information - citation {citation} (required)
   if hResInfo.has_key?('citation')
      hObject = hResInfo['citation']
      unless hObject.empty?
         hReturn = Citation.unpack(hObject, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:citation] = hReturn
         end
      end
   end
   if intResInfo[:citation].empty?
      @MessagePath.issueError(682, responseObj, outContext)
   end

   # resource information - abstract (required)
   if hResInfo.has_key?('abstract')
      intResInfo[:abstract] = hResInfo['abstract']
   end
   if intResInfo[:abstract].nil? || intResInfo[:abstract] == ''
      @MessagePath.issueError(683, responseObj, outContext)
   end

   # resource information - short abstract
   if hResInfo.has_key?('shortAbstract')
      unless hResInfo['shortAbstract'] == ''
         intResInfo[:shortAbstract] = hResInfo['shortAbstract']
      end
   end

   # resource information - purpose
   if hResInfo.has_key?('purpose')
      unless hResInfo['purpose'] == ''
         intResInfo[:purpose] = hResInfo['purpose']
      end
   end

   # resource information - resource time period {timePeriod}
   if hResInfo.has_key?('timePeriod')
      hObject = hResInfo['timePeriod']
      unless hObject.empty?
         hObject[:description] = 'resource time period' if hObject[:description].nil?
         hReturn = TimePeriod.unpack(hObject, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:timePeriod] = hReturn
         end
      end
   end

   # resource information - credits []
   if hResInfo.has_key?('credit')
      hResInfo['credit'].each do |item|
         unless item == ''
            intResInfo[:credits] << item
         end
      end
   end

   # resource information - status [] (required)
   if hResInfo.has_key?('status')
      hResInfo['status'].each do |item|
         unless item == ''
            intResInfo[:status] << item
         end
      end
   end
   if intResInfo[:status].empty?
      @MessagePath.issueError(684, responseObj, outContext)
   end

   # resource information - topic category (deprecated)
   if hResInfo.has_key?('topicCategory')
      unless hResInfo['topicCategory'].empty?
         # move topicCategories to keywordObject
         hKeyword = {}
         hKeyword['keyword'] = []
         hKeyword['keywordType'] = 'isoTopicCategory'
         hResInfo['topicCategory'].each do |keyword|
            hKeywordObj = {}
            hKeywordObj['keyword'] = keyword
            hKeyword['keyword'] << hKeywordObj
         end
         hReturn = Keyword.unpack(hKeyword, responseObj)
         unless hReturn.nil?
            intResInfo[:keywords] << hReturn
         end
         @MessagePath.issueNotice(685, responseObj, outContext)
      end
   end

   # resource information - point of contact [] {responsibleParty} (required)
   if hResInfo.has_key?('pointOfContact')
      aItems = hResInfo['pointOfContact']
      aItems.each do |item|
         hReturn = ResponsibleParty.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:pointOfContacts] << hReturn
         end
      end
   end
   if intResInfo[:pointOfContacts].empty?
      @MessagePath.issueError(686, responseObj, outContext)
   end

   # resource information - spatial reference system [] {spatialReference}
   if hResInfo.has_key?('spatialReferenceSystem')
      aItems = hResInfo['spatialReferenceSystem']
      aItems.each do |item|
         hReturn = SpatialReferenceSystem.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:spatialReferenceSystems] << hReturn
         end
      end
   end

   # resource information - spatial representation type []
   if hResInfo.has_key?('spatialRepresentationType')
      hResInfo['spatialRepresentationType'].each do |item|
         unless item == ''
            intResInfo[:spatialRepresentationTypes] << item
         end
      end
   end

   # resource information - spatial representation [] {spatialRepresentation}
   if hResInfo.has_key?('spatialRepresentation')
      aItems = hResInfo['spatialRepresentation']
      aItems.each do |item|
         hReturn = SpatialRepresentation.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:spatialRepresentations] << hReturn
         end
      end
   end

   # resource information - spatial resolution [] {spatialResolution}
   if hResInfo.has_key?('spatialResolution')
      aItems = hResInfo['spatialResolution']
      aItems.each do |item|
         hReturn = SpatialResolution.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:spatialResolutions] << hReturn
         end
      end
   end

   # resource information - temporal resolution [] {duration}
   if hResInfo.has_key?('temporalResolution')
      aItems = hResInfo['temporalResolution']
      aItems.each do |item|
         hReturn = Duration.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:temporalResolutions] << hReturn
         end
      end
   end

   # resource information - extent [] {extent}
   if hResInfo.has_key?('extent')
      aItems = hResInfo['extent']
      aItems.each do |item|
         hReturn = Extent.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:extents] << hReturn
         end
      end
   end

   # resource information - content information [] {contentInformation}
   if hResInfo.has_key?('coverageDescription')
      aItems = hResInfo['coverageDescription']
      aItems.each do |item|
         hReturn = CoverageDescription.unpack(item, responseObj)
         unless hReturn.nil?
            intResInfo[:coverageDescriptions] << hReturn
         end
      end
   end

   # resource information - taxonomy [] {taxonomy}
   # support deprecated taxonomy{}
   if hResInfo.has_key?('taxonomy')
      aTaxonomy = hResInfo['taxonomy']
      if aTaxonomy.is_a?(Array)
         aTaxonomy.each do |hTaxonomy|
            hReturn = Taxonomy.unpack(hTaxonomy, responseObj)
            unless hReturn.nil?
               intResInfo[:taxonomy] << hReturn
            end
         end
      else
         hReturn = Taxonomy.unpack(aTaxonomy, responseObj)
         unless hReturn.nil?
            intResInfo[:taxonomy] << hReturn
         end
         @MessagePath.issueNotice(687, responseObj, outContext)
      end
   end

   # resource information - graphic overview [] {graphicOverview}
   if hResInfo.has_key?('graphicOverview')
      aItems = hResInfo['graphicOverview']
      aItems.each do |item|
         hReturn = Graphic.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:graphicOverviews] << hReturn
         end
      end
   end

   # resource information - resource format [] {format}
   if hResInfo.has_key?('resourceFormat')
      aItems = hResInfo['resourceFormat']
      aItems.each do |item|
         hReturn = Format.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:resourceFormats] << hReturn
         end
      end
   end

   # resource information - keyword [] {keyword}
   if hResInfo.has_key?('keyword')
      aItems = hResInfo['keyword']
      aItems.each do |item|
         hReturn = Keyword.unpack(item, responseObj)
         unless hReturn.nil?
            intResInfo[:keywords] << hReturn
         end
      end
   end

   # resource information - resource usage [] {resourceUsage}
   if hResInfo.has_key?('resourceUsage')
      aItems = hResInfo['resourceUsage']
      aItems.each do |item|
         hReturn = ResourceUsage.unpack(item, responseObj)
         unless hReturn.nil?
            intResInfo[:resourceUsages] << hReturn
         end
      end
   end

   # resource information - constraint [] {constraint}
   if hResInfo.has_key?('constraint')
      aCons = hResInfo['constraint']
      aCons.each do |hItem|
         hReturn = Constraint.unpack(hItem, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:constraints] << hReturn
         end
      end
   end

   # resource information - default resource locale {locale} (required)
   if hResInfo.has_key?('defaultResourceLocale')
      hObject = hResInfo['defaultResourceLocale']
      unless hObject.empty?
         hReturn = Locale.unpack(hObject, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:defaultResourceLocale] = hReturn
         end
      end
   end
   if intResInfo[:defaultResourceLocale].empty?
      @MessagePath.issueError(688, responseObj, outContext)
   end

   # resource information - other resource locale [] {locale}
   if hResInfo.has_key?('otherResourceLocale')
      aItems = hResInfo['otherResourceLocale']
      aItems.each do |item|
         hReturn = Locale.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:otherResourceLocales] << hReturn
         end
      end
   end

   # resource information - resource maintenance [] {maintenance}
   if hResInfo.has_key?('resourceMaintenance')
      aItems = hResInfo['resourceMaintenance']
      aItems.each do |item|
         hReturn = Maintenance.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intResInfo[:resourceMaintenance] << hReturn
         end
      end
   end

   # resource information - environment description
   if hResInfo.has_key?('environmentDescription')
      unless hResInfo['environmentDescription'] == ''
         intResInfo[:environmentDescription] = hResInfo['environmentDescription']
      end
   end

   # resource information - supplemental information
   if hResInfo.has_key?('supplementalInfo')
      unless hResInfo['supplementalInfo'] == ''
         intResInfo[:supplementalInfo] = hResInfo['supplementalInfo']
      end
   end

   return intResInfo

end