adiwg-mdtranslator 1.3.0 → 1.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.jsbeautifyrc +8 -0
  3. data/Rakefile +1 -3
  4. data/adiwg-mdtranslator.gemspec +2 -0
  5. data/bin/mdtranslator +2 -2
  6. data/lib/adiwg/mdtranslator.rb +2 -0
  7. data/lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb +6 -3
  8. data/lib/adiwg/mdtranslator/internal/module_geoFormat.rb +183 -190
  9. data/lib/adiwg/mdtranslator/internal/module_lineString.rb +18 -0
  10. data/lib/adiwg/mdtranslator/internal/module_point.rb +18 -0
  11. data/lib/adiwg/mdtranslator/readers/mdJson/modules_v1/module_contacts.rb +3 -1
  12. data/lib/adiwg/mdtranslator/readers/mdJson/modules_v1/module_geographicElement.rb +18 -10
  13. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_additionalDocumentation.rb +52 -0
  14. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_boundingBox.rb +54 -0
  15. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_browseGraphic.rb +66 -0
  16. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_citation.rb +125 -0
  17. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_contacts.rb +144 -0
  18. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_dateTime.rb +31 -0
  19. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_distributionInfo.rb +64 -0
  20. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_extent.rb +61 -0
  21. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_geoCoordSystem.rb +50 -0
  22. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_geoProperties.rb +91 -0
  23. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_geographicElement.rb +161 -0
  24. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_metadata.rb +70 -0
  25. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_metadataInfo.rb +131 -0
  26. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_onlineResource.rb +71 -0
  27. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_resourceIdentifier.rb +73 -0
  28. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_resourceInfo.rb +437 -0
  29. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_responsibleParty.rb +53 -0
  30. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_sbJson.rb +52 -0
  31. data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/version.rb +12 -0
  32. data/lib/adiwg/mdtranslator/readers/sbJson/readme.md +12 -0
  33. data/lib/adiwg/mdtranslator/readers/sbJson/sbJson_reader.rb +205 -0
  34. data/lib/adiwg/mdtranslator/readers/sbJson/sbJson_validator.rb +44 -0
  35. data/lib/adiwg/mdtranslator/version.rb +1 -2
  36. data/lib/adiwg/mdtranslator/writers/html/sections/html_browseGraphic.rb +2 -1
  37. data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_multiGeometry.rb +5 -5
  38. data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_responsibleParty.rb +1 -1
  39. data/lib/adiwg/mdtranslator/writers/mdJson/mdJson_writer.rb +42 -0
  40. data/lib/adiwg/mdtranslator/writers/mdJson/readme.md +19 -0
  41. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_additionalDoc.rb +19 -0
  42. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_address.rb +22 -0
  43. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_associatedResource.rb +22 -0
  44. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_attribute.rb +27 -0
  45. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_base.rb +19 -0
  46. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_citation.rb +33 -0
  47. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_constraint.rb +28 -0
  48. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_contact.rb +31 -0
  49. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_coverageInfo.rb +30 -0
  50. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_coverageItem.rb +44 -0
  51. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dataQuality.rb +32 -0
  52. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dateTime.rb +18 -0
  53. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dictionary.rb +33 -0
  54. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_distributionInfo.rb +31 -0
  55. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_domain.rb +25 -0
  56. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_entity.rb +37 -0
  57. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_extent.rb +26 -0
  58. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_format.rb +19 -0
  59. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_geographicElement.rb +81 -0
  60. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_graphicOverview.rb +20 -0
  61. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_gridInfo.rb +27 -0
  62. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_imageInfo.rb +28 -0
  63. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_keyword.rb +20 -0
  64. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_locale.rb +19 -0
  65. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_metadata.rb +30 -0
  66. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_metadataInfo.rb +36 -0
  67. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_onlineResource.rb +21 -0
  68. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_phone.rb +19 -0
  69. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_processStep.rb +25 -0
  70. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_resourceIdentifier.rb +23 -0
  71. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_resourceInfo.rb +69 -0
  72. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_resourceMaintenance.rb +23 -0
  73. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_responsibleParty.rb +18 -0
  74. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_spatialreference.rb +19 -0
  75. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_taxon.rb +19 -0
  76. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_taxonomy.rb +32 -0
  77. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb +38 -0
  78. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_timePeriod.rb +20 -0
  79. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_transferOption.rb +33 -0
  80. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_usage.rb +23 -0
  81. data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_verticalElement.rb +20 -0
  82. data/lib/adiwg/mdtranslator/writers/mdJson/version.rb +13 -0
  83. data/lib/adiwg/mdtranslator/writers/sbJson/readme.md +12 -0
  84. data/lib/adiwg/mdtranslator/writers/sbJson/sbJson_writer.rb +126 -0
  85. data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_base.rb +19 -0
  86. data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb +42 -0
  87. data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_identifier.rb +22 -0
  88. data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_spatial.rb +49 -0
  89. data/lib/adiwg/mdtranslator/writers/sbJson/version.rb +13 -0
  90. data/test/readers/mdJson/v1/tc_reader_mdjson_translation.rb +83 -0
  91. data/test/readers/sbJson/v0/tc_reader_sbjson_translation.rb +79 -0
  92. data/test/readers/sbJson/v0/test.json +431 -0
  93. data/test/readers/sbJson/v0/test1.json +383 -0
  94. data/test/writers/mdJson/v1/tc_writer_mdJson.rb +60 -0
  95. data/test/writers/sbJson/v0/tc_writer_sbJson.rb +60 -0
  96. metadata +121 -7
  97. data/test/readers/mdJson/v1/tc_translation_19115_2.rb +0 -67
@@ -0,0 +1,70 @@
1
+ require 'uri'
2
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_metadataInfo')
3
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_resourceInfo')
4
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_distributionInfo')
5
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_associatedResource')
6
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_additionalDocumentation')
7
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_citation')
8
+
9
+ module ADIWG
10
+ module Mdtranslator
11
+ module Readers
12
+ module SbJson
13
+ module Metadata
14
+ def self.unpack(hMetadata, responseObj, intObj)
15
+ # instance classes needed in script
16
+ intMetadataClass = InternalMetadata.new
17
+ intMetadata = intMetadataClass.newMetadata
18
+
19
+ # metadata - metadataInfo
20
+ intMetadata[:metadataInfo] = MetadataInfo.unpack(hMetadata, responseObj, intObj)
21
+
22
+ # metadata - resource identification info
23
+ intMetadata[:resourceInfo] = ResourceInfo.unpack(hMetadata, responseObj, intObj)
24
+
25
+ # metadata - distribution info
26
+ if hMetadata.key?('webLinks')
27
+ intMetadata[:distributorInfo] << DistributionInfo.unpack(hMetadata, responseObj, intObj)
28
+ end
29
+
30
+ # metadata - associated resources
31
+ # if hMetadata.has_key?('associatedResource')
32
+ # aAssocRes = hMetadata['associatedResource']
33
+ # unless aAssocRes.empty?
34
+ # aAssocRes.each do |hAssocRes|
35
+ # intMetadata[:associatedResources] << AssociatedResource.unpack(hAssocRes, responseObj)
36
+ # end
37
+ # end
38
+ # end
39
+
40
+ # metadata - additional documents
41
+ if hMetadata.key?('webLinks')
42
+ aAddDocs = hMetadata['webLinks']
43
+ unless aAddDocs.empty?
44
+ aAddDocs.each do |hAddDoc|
45
+ doc = {
46
+ 'resourceType' => hAddDoc['type'],
47
+ 'citation' => {
48
+ 'title' => hAddDoc['title'],
49
+ 'onlineResource' => [
50
+ {
51
+ 'uri' => hAddDoc['uri'],
52
+ 'protocol' => URI.parse(hAddDoc['uri']).scheme,
53
+ 'name' => hAddDoc['title'],
54
+ 'function' => hAddDoc['type']
55
+ }
56
+ ]
57
+ }
58
+ }
59
+ intMetadata[:additionalDocuments] << AdditionalDocumentation.unpack(doc, responseObj)
60
+ end
61
+ end
62
+ end
63
+
64
+ intMetadata
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,131 @@
1
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_responsibleParty')
2
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_dateTime')
3
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_resourceMaintenance')
4
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_metadataExtension')
5
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_resourceIdentifier')
6
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_citation')
7
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_locale')
8
+
9
+ module ADIWG
10
+ module Mdtranslator
11
+ module Readers
12
+ module SbJson
13
+
14
+ module MetadataInfo
15
+
16
+ def self.unpack(hMetadata, responseObj, intObj)
17
+
18
+ # return nil object if input is empty
19
+ intMetadataInfo = nil
20
+ return if hMetadata.empty?
21
+
22
+ # instance classes needed in script
23
+ intMetadataClass = InternalMetadata.new
24
+ intMetadataInfo = intMetadataClass.newMetadataInfo
25
+ hMetadataInfo = hMetadata
26
+
27
+ # metadata - metadata identifier
28
+ if hMetadataInfo.has_key?('id')
29
+ hMetadataId = hMetadataInfo['id']
30
+ unless hMetadataId.empty?
31
+ rId = intMetadataClass.newResourceId
32
+ rId[:identifier] = hMetadataId
33
+ rId[:identifierType] = 'uuid'
34
+ rId[:identifierNamespace] = 'gov.sciencebase.catalog'
35
+ rId[:identifierDescription] = 'The unique ScienceBase id of the resource.'
36
+ intMetadataInfo[:metadataId] = rId
37
+ end
38
+ end
39
+
40
+ # metadata - parent metadata identifier
41
+ if hMetadataInfo.has_key?('parentId')
42
+ hParentId = hMetadataInfo['parentId']
43
+ hParent = intMetadataClass.newCitation
44
+ hParent[:citTitle] = 'Parent Metadata identifier'
45
+ pId = intMetadataClass.newResourceId
46
+ pId[:identifier] = hParentId
47
+ pId[:identifierType] = 'uuid'
48
+ pId[:identifierNamespace] = 'gov.sciencebase.catalog'
49
+ pId[:identifierDescription] = 'The unique ScienceBase id of the parent resource.'
50
+ hParent[:citResourceIds] << pId
51
+ pParty = intMetadataClass.newRespParty
52
+ pParty[:contactId] = 'SB'
53
+ pParty[:roleName] = 'originator'
54
+ hParent[:citResponsibleParty] << pParty
55
+
56
+ unless hParent.empty?
57
+ intMetadataInfo[:parentMetadata] = hParent
58
+ end
59
+ end
60
+
61
+ # metadata - metadata contacts, custodians
62
+ # We're just injecting the first sbJSON contact here
63
+ firstCont = intObj[:contacts][0]
64
+ aCust = {}
65
+ aCust['contactId'] = firstCont[:contactId]
66
+ aCust['role'] = firstCont[:sbType]
67
+ intMetadataInfo[:metadataCustodians] << ResponsibleParty.unpack(aCust, responseObj)
68
+
69
+ # metadata - creation date
70
+ if hMetadataInfo.has_key?('provenance')
71
+ s = hMetadataInfo['provenance']['dateCreated']
72
+ if s != ''
73
+ hDateTime = DateTime.unpack(s, responseObj)
74
+ hDateTime[:dateType] = 'creation'
75
+ intMetadataInfo[:metadataCreateDate] = hDateTime
76
+ end
77
+ end
78
+
79
+ # metadata - date of last metadata update
80
+ if hMetadataInfo.has_key?('provenance')
81
+ s = hMetadataInfo['provenance']['lastUpdated']
82
+ if s != ''
83
+ hDateTime = DateTime.unpack(s, responseObj)
84
+ hDateTime[:dateType] = 'lastUpdate'
85
+ intMetadataInfo[:metadataUpdateDate] = hDateTime
86
+ end
87
+ end
88
+
89
+ # metadata - characterSet - default 'utf8'
90
+ intMetadataInfo[:metadataCharacterSet] = 'utf8'
91
+
92
+ # metadata - locale
93
+ intLocale = intMetadataClass.newLocale
94
+ intLocale[:languageCode] = 'eng'
95
+ intLocale[:countryCode] = 'USA'
96
+ intLocale[:characterEncoding] = 'UTF-8'
97
+ intMetadataInfo[:metadataLocales] << intLocale
98
+
99
+
100
+ # metadata - metadata URI
101
+ intMetadataInfo[:metadataURI] = 'https://www.sciencebase.gov/catalog/item/' + hMetadataInfo['id']
102
+
103
+ # metadata - status
104
+ # if hMetadataInfo.has_key?('metadataStatus')
105
+ # s = hMetadataInfo['metadataStatus']
106
+ # if s != ''
107
+ # intMetadataInfo[:metadataStatus] = s
108
+ # end
109
+ # end
110
+
111
+ # metadata - metadata maintenance info
112
+ intResMaint = intMetadataClass.newResourceMaint
113
+
114
+ # resource maintenance - frequency code
115
+ intResMaint[:maintFreq] = 'asNeeded'
116
+
117
+ # resource maintenance - contact
118
+ intResMaint[:maintContacts] << intMetadataInfo[:metadataCustodians][0]
119
+
120
+ intMetadataInfo[:maintInfo] = intResMaint
121
+
122
+ return intMetadataInfo
123
+
124
+ end
125
+
126
+ end
127
+
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,71 @@
1
+ module ADIWG
2
+ module Mdtranslator
3
+ module Readers
4
+ module SbJson
5
+
6
+ module OnlineResource
7
+
8
+ def self.unpack(hOlResource, responseObj)
9
+
10
+ # return nil object if input is empty
11
+ intOLRes = nil
12
+ return if hOlResource.empty?
13
+
14
+ # instance classes needed in script
15
+ intMetadataClass = InternalMetadata.new
16
+ intOLRes = intMetadataClass.newOnlineResource
17
+
18
+ # unpack the online resource
19
+ # resource - web link
20
+ if hOlResource.has_key?('uri')
21
+ s = hOlResource['uri']
22
+ if s != ''
23
+ intOLRes[:olResURI] = s
24
+ else
25
+ responseObj[:readerExecutionMessages] << 'Online Resource URI is missing'
26
+ responseObj[:readerExecutionPass] = false
27
+ return nil
28
+ end
29
+ end
30
+
31
+ # resource - web link protocol
32
+ if hOlResource.has_key?('protocol')
33
+ s = hOlResource['protocol']
34
+ if s != ''
35
+ intOLRes[:olResProtocol] = s
36
+ end
37
+ end
38
+
39
+ # resource - web link name
40
+ if hOlResource.has_key?('name')
41
+ s = hOlResource['name']
42
+ if s != ''
43
+ intOLRes[:olResName] = s
44
+ end
45
+ end
46
+
47
+ # resource - web link description
48
+ if hOlResource.has_key?('description')
49
+ s = hOlResource['description']
50
+ if s != ''
51
+ intOLRes[:olResDesc] = s
52
+ end
53
+ end
54
+
55
+ # resource - web link function
56
+ if hOlResource.has_key?('function')
57
+ s = hOlResource['function']
58
+ if s != ''
59
+ intOLRes[:olResFunction] = s
60
+ end
61
+ end
62
+
63
+ return intOLRes
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,73 @@
1
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_citation')
2
+
3
+ module ADIWG
4
+ module Mdtranslator
5
+ module Readers
6
+ module SbJson
7
+
8
+ module ResourceIdentifier
9
+
10
+ def self.unpack(hResID, responseObj)
11
+
12
+ # instance classes needed in script
13
+ intMetadataClass = InternalMetadata.new
14
+ intResID = intMetadataClass.newResourceId
15
+
16
+ # resource identifier - identifier
17
+ if hResID.has_key?('identifier')
18
+ s = hResID['identifier']
19
+ if s != ''
20
+ intResID[:identifier] = s
21
+ end
22
+ end
23
+
24
+ # resource identifier - identifier type
25
+ if hResID.has_key?('type')
26
+ s = hResID['type']
27
+ if s != ''
28
+ intResID[:identifierType] = s
29
+ end
30
+ end
31
+
32
+ # resource identifier - namespace
33
+ if hResID.has_key?('namespace')
34
+ s = hResID['namespace']
35
+ if s != ''
36
+ intResID[:identifierNamespace] = s
37
+ end
38
+ end
39
+
40
+ # resource identifier - version
41
+ if hResID.has_key?('version')
42
+ s = hResID['version']
43
+ if s != ''
44
+ intResID[:identifierVersion] = s
45
+ end
46
+ end
47
+
48
+ # resource identifier - description
49
+ if hResID.has_key?('description')
50
+ s = hResID['description']
51
+ if s != ''
52
+ intResID[:identifierDescription] = s
53
+ end
54
+ end
55
+
56
+ # resource identifier - authority (expressed as a citation)
57
+ if hResID.has_key?('authority')
58
+ hCitation = hResID['authority']
59
+ unless hCitation.empty?
60
+ intResID[:identifierCitation] = Citation.unpack(hCitation, responseObj)
61
+ end
62
+ end
63
+
64
+ return intResID
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,437 @@
1
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_citation')
2
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_responsibleParty')
3
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_resourceFormat')
4
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_descriptiveKeyword')
5
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_resourceMaintenance')
6
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_resourceSpecificUsage')
7
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_browseGraphic')
8
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_legalConstraint')
9
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_securityConstraint')
10
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_taxonomy')
11
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_resolution')
12
+ require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_extent')
13
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_dataQuality')
14
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_spatialReference')
15
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_timePeriod')
16
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_locale')
17
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_gridInfo')
18
+ # require ADIWG::Mdtranslator::Readers::SbJson.readerModule('module_coverageInfo')
19
+ require 'uri'
20
+
21
+ module ADIWG
22
+ module Mdtranslator
23
+ module Readers
24
+ module SbJson
25
+ module ResourceInfo
26
+ def self.unpack(hResourceInfo, responseObj, intObj)
27
+ # instance classes needed in script
28
+ intMetadataClass = InternalMetadata.new
29
+ intResInfo = intMetadataClass.newResourceInfo
30
+
31
+ # resource information - resource type
32
+ # we can check for the project "facet",
33
+ # however there is no reliable way to determine
34
+ # other types so just default to "dataset"
35
+ if hResourceInfo.key?('facets')
36
+ projectFacet = hResourceInfo['facets'].find { |s| s['className'] == 'gov.sciencebase.catalog.item.facet.ProjectFacet' }
37
+ end
38
+ intResInfo[:resourceType] = projectFacet.nil? ? 'dataset' : 'project'
39
+
40
+ # resource information - citation
41
+ hCitation = intMetadataClass.newCitation
42
+ hCitation[:citTitle] = hResourceInfo['title']
43
+ if hResourceInfo.key?('alternateTitles')
44
+ hCitation[:citAltTitle] = hResourceInfo['alternateTitles'][0]
45
+ end
46
+
47
+ pId = intMetadataClass.newResourceId
48
+ pId[:identifier] = hResourceInfo['id']
49
+ pId[:identifierType] = 'uuid'
50
+ pId[:identifierNamespace] = 'gov.sciencebase.catalog'
51
+ pId[:identifierDescription] = 'The unique ScienceBase id of the parent resource.'
52
+ hCitation[:citResourceIds] << pId
53
+
54
+ if hResourceInfo.key?('identifiers')
55
+ hResourceInfo['identifiers'].each do |id|
56
+ pId = intMetadataClass.newResourceId
57
+ pId[:identifier] = id['key']
58
+ pId[:identifierType] = id['type']
59
+ pId[:identifierNamespace] = id['scheme']
60
+ hCitation[:citResourceIds] << pId
61
+ end
62
+ end
63
+
64
+ # citation - presentation form
65
+ if hResourceInfo.key?('browseTypes')
66
+ aPForms = hResourceInfo['browseTypes']
67
+ unless aPForms.empty?
68
+ aPForms.each do |pForm|
69
+ hCitation[:citResourceForms] << pForm
70
+ end
71
+ end
72
+ end
73
+
74
+ if hResourceInfo.key?('contacts')
75
+ hResourceInfo['contacts'].each do |contact|
76
+ aCont = {}
77
+ aCont[:contactId] = contact['contactId']
78
+ aCont[:roleName] = contact['type']
79
+ hCitation[:citResponsibleParty] << aCont
80
+ end
81
+ end
82
+
83
+ if hResourceInfo.key?('dates')
84
+ hResourceInfo['dates'].each do |date|
85
+ s = date['dateString']
86
+ next unless s != ''
87
+ hDateTime = DateTime.unpack(s, responseObj)
88
+ hDateTime[:dateType] = date['type']
89
+ hCitation[:citDate] << hDateTime
90
+ end
91
+ end
92
+
93
+ if hResourceInfo.key?('link')
94
+ link = hResourceInfo['link']
95
+ intOLRes = intMetadataClass.newOnlineResource
96
+ intOLRes[:olResURI] = link['url']
97
+ intOLRes[:olResProtocol] = 'http'
98
+ intOLRes[:olResName] = 'Resource Link'
99
+ intOLRes[:olResDesc] = 'ScienceBase URL of resource'
100
+ intOLRes[:olResFunction] = 'information'
101
+ hCitation[:citOlResources] << intOLRes
102
+ end
103
+
104
+ unless hCitation.empty?
105
+ intResInfo[:citation] = hCitation
106
+ end
107
+
108
+ # resource information - resource time period
109
+ # if hResourceInfo.has_key?('resourceTimePeriod')
110
+ # hResPeriod = hResourceInfo['resourceTimePeriod']
111
+ # unless hResPeriod.empty?
112
+ # intResInfo[:timePeriod] = TimePeriod.unpack(hResPeriod, responseObj)
113
+ # end
114
+ # end
115
+
116
+ # resource information - point of contact
117
+ # metadata - metadata contacts, custodians
118
+ # We're just injecting the first sbJSON contact here
119
+ firstCont = intObj[:contacts][0]
120
+ aCust = {}
121
+ aCust['contactId'] = firstCont[:contactId]
122
+ aCust['role'] = firstCont[:sbType]
123
+ intResInfo[:pointsOfContact] << ResponsibleParty.unpack(aCust, responseObj)
124
+
125
+ # resource information - abstract
126
+ if hResourceInfo.key?('body')
127
+ s = hResourceInfo['body']
128
+ intResInfo[:abstract] = s if s != ''
129
+ end
130
+
131
+ # resource information - short abstract
132
+ if hResourceInfo.key?('summary')
133
+ s = hResourceInfo['summary']
134
+ intResInfo[:shortAbstract] = s if s != ''
135
+ end
136
+
137
+ # resource information - status
138
+ # project status is sometimes available
139
+ # otherwise just defaults to "published"
140
+ if projectFacet.nil?
141
+
142
+ if hResourceInfo.key?('status')
143
+ s = hResourceInfo['status']
144
+ end
145
+ intResInfo[:status] = s.nil? ? 'published' : s
146
+ end
147
+
148
+ # resource information - has mappable location
149
+ intResInfo[:hasMapLocation?] = hResourceInfo.key?('spatial')
150
+
151
+ # resource information - has data available
152
+ intResInfo[:hasDataAvailable?] = hResourceInfo.key?('distributionLinks')
153
+
154
+ # resource information - language
155
+ intResInfo[:resourceLanguages] << 'eng'
156
+
157
+ # resource information - characterSet [] - default 'utf8'
158
+ intResInfo[:resourceCharacterSets] << 'UTF-8'
159
+
160
+ # resource - locale
161
+ intLocale = intMetadataClass.newLocale
162
+ intLocale[:languageCode] = 'eng'
163
+ intLocale[:countryCode] = 'USA'
164
+ intLocale[:characterEncoding] = 'UTF-8'
165
+ intResInfo[:resourceLocales] << intLocale
166
+
167
+ # resource information - purpose
168
+ if hResourceInfo.key?('purpose')
169
+ s = hResourceInfo['purpose']
170
+ intResInfo[:purpose] = s if s != ''
171
+ end
172
+
173
+ # resource information - credit
174
+ if hResourceInfo.key?('citation')
175
+ aCredits = hResourceInfo['citation']
176
+ intResInfo[:credits] << aCredits
177
+ end
178
+
179
+ # resource information - topic category
180
+ if hResourceInfo.key?('tags')
181
+ tags = hResourceInfo['tags'].group_by { |t| t['scheme'] || 'None' }
182
+ aTopics = tags['ISO 19115 Topic Categories']
183
+ unless aTopics.nil?
184
+ aTopics.each do |topic|
185
+ intResInfo[:topicCategories] << topic['name']
186
+ end
187
+ end
188
+ end
189
+
190
+ # resource information - environment description
191
+ # if hResourceInfo.has_key?('environmentDescription')
192
+ # s = hResourceInfo['environmentDescription']
193
+ # if s != ''
194
+ # intResInfo[:environmentDescription] = s
195
+ # end
196
+ # end
197
+
198
+ # resource information - resource format
199
+ # if hResourceInfo.has_key?('resourceNativeFormat')
200
+ # aResFormat = hResourceInfo['resourceNativeFormat']
201
+ # unless aResFormat.empty?
202
+ # aResFormat.each do |hResFormat|
203
+ # intResInfo[:resourceFormats] << ResourceFormat.unpack(hResFormat, responseObj)
204
+ # end
205
+ # end
206
+ # end
207
+
208
+ # resource information - descriptive keywords
209
+ unless tags.nil?
210
+ aDesKeywords = tags.select { |t| t != 'ISO 19115 Topic Categories' }
211
+ unless aDesKeywords.empty?
212
+ aDesKeywords.each do |k, kScheme|
213
+ kType = kScheme.group_by { |t| t['type'] || 'Theme' }
214
+
215
+ kType.each do |type, words|
216
+ intKw = intMetadataClass.newKeyword
217
+ intKw[:keywordType] = type
218
+ words.each do |kw|
219
+ intKw[:keyword] << kw['name']
220
+ end
221
+ kCitation = intMetadataClass.newCitation
222
+ kCitation[:citTitle] = 'ScienceBase Tags'
223
+ pParty = intMetadataClass.newRespParty
224
+ pParty[:contactId] = 'SB'
225
+ pParty[:roleName] = 'publisher'
226
+ kCitation[:citResponsibleParty] << pParty
227
+ if k =~ /\A#{URI.regexp(%w(http https))}\z/
228
+ intOLRes = intMetadataClass.newOnlineResource
229
+ intOLRes[:olResURI] = k
230
+ intOLRes[:olResProtocol] = 'http'
231
+ intOLRes[:olResName] = 'Link to ScienceBase scheme'
232
+ intOLRes[:olResDesc] = ' ScienceBase controlled vocabulary'
233
+ intOLRes[:olResFunction] = 'information'
234
+ kCitation[:citOlResources] << intOLRes
235
+ end
236
+ intKw[:keyTheCitation] = kCitation
237
+ intResInfo[:descriptiveKeywords] << intKw
238
+ end
239
+ end
240
+ end
241
+ end
242
+
243
+ # resource information - resource maintenance
244
+ # if hResourceInfo.has_key?('resourceMaintenance')
245
+ # aResMaint = hResourceInfo['resourceMaintenance']
246
+ # unless aResMaint.empty?
247
+ # aResMaint.each do |hResource|
248
+ # intResInfo[:resourceMaint] << ResourceMaintenance.unpack(hResource, responseObj)
249
+ # end
250
+ # end
251
+ # end
252
+
253
+ # resource information - resource specific usage
254
+ # if hResourceInfo.key?('resourceSpecificUsage')
255
+ # aResUses = hResourceInfo['resourceSpecificUsage']
256
+ # unless aResUses.empty?
257
+ # aResUses.each do |hUsage|
258
+ # intResInfo[:resourceUses] << ResourceSpecificUsage.unpack(hUsage, responseObj)
259
+ # end
260
+ # end
261
+ # end
262
+
263
+ # resource information - graphic overview
264
+ if hResourceInfo.key?('previewImage')
265
+ aBrowseGraph = hResourceInfo['previewImage']
266
+
267
+ unless aBrowseGraph.empty?
268
+ aBrowseGraph.each_pair do |name, bg|
269
+ next unless bg.is_a?(Hash)
270
+
271
+ hb = {
272
+ 'fileName' => name,
273
+ 'fileDescription' => 'Preview image.',
274
+ 'fileType' => 'image',
275
+ 'fileUri' => bg['uri']
276
+ }
277
+ intResInfo[:graphicOverview] << BrowseGraphic.unpack(hb, responseObj)
278
+ end
279
+ end
280
+ end
281
+
282
+ # resource information - use constraints
283
+ # if hResourceInfo.key?('constraint')
284
+ # hConstraint = hResourceInfo['constraint']
285
+
286
+ # resource information - resource constraints - use
287
+ # if hConstraint.key?('useLimitation')
288
+ # aUseLimits = hConstraint['useLimitation']
289
+ # unless aUseLimits.empty?
290
+ # aUseLimits.each do |useLimit|
291
+ # intResInfo[:useConstraints] << useLimit
292
+ # end
293
+ # end
294
+ # end
295
+
296
+ # resource information - resource constraints - legal
297
+ if hResourceInfo.key?('rights')
298
+ aLegalCons = hResourceInfo['rights']
299
+ unless aLegalCons.empty?
300
+ aCons = intMetadataClass.newLegalConstraint
301
+ aCons[:useCodes] << aLegalCons
302
+ intResInfo[:legalConstraints] << aCons
303
+ end
304
+ end
305
+
306
+ # resource information - resource constraints - security
307
+ # if hConstraint.key?('securityConstraint')
308
+ # aSecurityCons = hConstraint['securityConstraint']
309
+ # unless aSecurityCons.empty?
310
+ # aSecurityCons.each do |hSecurityCon|
311
+ # intResInfo[:securityConstraints] << SecurityConstraints.unpack(hSecurityCon, responseObj)
312
+ # end
313
+ # end
314
+ # end
315
+
316
+ # end
317
+
318
+ # # resource information - taxonomy
319
+ # if hResourceInfo.has_key?('taxonomy')
320
+ # hTaxonomy = hResourceInfo['taxonomy']
321
+ # unless hTaxonomy.empty?
322
+ # intResInfo[:taxonomy] = Taxonomy.unpack(hTaxonomy, responseObj)
323
+ # end
324
+ # end
325
+
326
+ # resource information - spatial reference systems
327
+ # if hResourceInfo.key?('spatialReferenceSystem')
328
+ # hSpatialRef = hResourceInfo['spatialReferenceSystem']
329
+ # unless hSpatialRef.empty?
330
+ # intResInfo[:spatialReferenceSystem] = SpatialReferenceSystem.unpack(hSpatialRef, responseObj)
331
+ # end
332
+ # end
333
+ #
334
+ # # resource information - spatial representation type
335
+ # if hResourceInfo.key?('spatialRepresentation')
336
+ # aSpatialType = hResourceInfo['spatialRepresentation']
337
+ # unless aSpatialType.empty?
338
+ # aSpatialType.each do |spType|
339
+ # intResInfo[:spatialRepresentationTypes] << spType
340
+ # end
341
+ # end
342
+ # end
343
+
344
+ # resource information - spatial resolution
345
+ # if hResourceInfo.has_key?('spatialResolution')
346
+ # aSpRes = hResourceInfo['spatialResolution']
347
+ # unless aSpRes.empty?
348
+ # aSpRes.each do |hResolution|
349
+ # intResInfo[:spatialResolutions] << Resolution.unpack(hResolution, responseObj)
350
+ # end
351
+ # end
352
+ # end
353
+
354
+ # resource information - extent
355
+ if hResourceInfo.key?('spatial')
356
+ aExtents = []
357
+ bbox = hResourceInfo['spatial']['boundingBox']
358
+ unless bbox.nil?
359
+ aExtents << {
360
+ 'description' => 'Spatial extent for Resource',
361
+ 'geographicElement' => [
362
+ {
363
+ 'type' => 'Feature',
364
+ 'id' => 'boundingBox',
365
+ 'bbox' => [
366
+ bbox['minX'],
367
+ bbox['minY'],
368
+ bbox['maxX'],
369
+ bbox['maxY']
370
+ ],
371
+ 'crs' => {
372
+ 'type' => 'name',
373
+ 'properties' => {
374
+ 'name' => 'EPSG:4326'
375
+ }
376
+ },
377
+ 'geometry' => nil,
378
+ 'properties' => {
379
+ 'featureName' => 'Bounding box',
380
+ 'description' => 'bounding box for resource'
381
+ }
382
+ }
383
+ ]
384
+ }
385
+ end
386
+ unless aExtents.empty?
387
+ aExtents.each do |hExtent|
388
+ intResInfo[:extents] << Extent.unpack(hExtent, responseObj)
389
+ end
390
+ end
391
+ end
392
+
393
+ # # resource information - grid information
394
+ # if hResourceInfo.has_key?('gridInfo')
395
+ # aGrids = hResourceInfo['gridInfo']
396
+ # unless aGrids.empty?
397
+ # aGrids.each do |hGrid|
398
+ # intResInfo[:gridInfo] << GridInfo.unpack(hGrid, responseObj)
399
+ # end
400
+ # end
401
+ # end
402
+ #
403
+ # # resource information - coverage information
404
+ # if hResourceInfo.has_key?('coverageInfo')
405
+ # aCoverage = hResourceInfo['coverageInfo']
406
+ # unless aCoverage.empty?
407
+ # aCoverage.each do |hCoverage|
408
+ # intResInfo[:coverageInfo] << CoverageInfo.unpack(hCoverage, responseObj)
409
+ # end
410
+ # end
411
+ # end
412
+ #
413
+ # # resource information - data quality information
414
+ # if hResourceInfo.has_key?('dataQualityInfo')
415
+ # aDataQual = hResourceInfo['dataQualityInfo']
416
+ # unless aDataQual.empty?
417
+ # aDataQual.each do |hDQ|
418
+ # intResInfo[:dataQualityInfo] << DataQuality.unpack(hDQ, responseObj)
419
+ # end
420
+ # end
421
+ # end
422
+
423
+ # # resource information - supplemental info
424
+ # if hResourceInfo.has_key?('supplementalInfo')
425
+ # s = hResourceInfo['supplementalInfo']
426
+ # if s != ''
427
+ # intResInfo[:supplementalInfo] = s
428
+ # end
429
+ # end
430
+
431
+ intResInfo
432
+ end
433
+ end
434
+ end
435
+ end
436
+ end
437
+ end