adiwg-mdtranslator 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/adiwg-mdtranslator.gemspec +2 -2
- data/lib/adiwg/mdtranslator/readers/fgcd/version.rb +14 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_browseCategory.rb +2 -4
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_codelists.rb +196 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_date.rb +4 -5
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_extent.rb +2 -2
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_project.rb +2 -4
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_publication.rb +3 -5
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_relatedItem.rb +178 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_sbJson.rb +6 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_tag.rb +0 -2
- data/lib/adiwg/mdtranslator/version.rb +2 -1
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_browseCategory.rb +1 -1
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_citation.rb +2 -2
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_codelists.rb +160 -212
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb +1 -1
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_date.rb +1 -1
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_materialRequest.rb +1 -1
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_project.rb +1 -1
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_sbJson.rb +2 -4
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_tag.rb +20 -3
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_webLink.rb +9 -2
- metadata +8 -6
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_metadataRepository.rb +0 -45
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 424da312bdcfc7617f563857a6e8767ebb3b3c4c
|
|
4
|
+
data.tar.gz: f35fdf24c6a34dd418bab443b39d4050a748cdbc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fb9075e39f5f0406ca5196353a7dd75a19735b0a72870f0d7a7814a3361a0390feec8080a6fa6fbf458fb7d46dd382f816e42db3fe955d1462e2248b0d51b38
|
|
7
|
+
data.tar.gz: 8db4fd7f94bac35cf98473c353dde6513e9dfc56347ca71218bf719d5919e28c533a47e532620d19ae52305c71c424a18e6d9055f1b8eb520cad16e016c24aad
|
data/adiwg-mdtranslator.gemspec
CHANGED
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.test_files = spec.files.grep(%r{^(tc|test|spec|features)/})
|
|
23
23
|
spec.require_paths = ["lib"]
|
|
24
24
|
|
|
25
|
-
spec.required_ruby_version = '>= 2.
|
|
25
|
+
spec.required_ruby_version = '>= 2.2'
|
|
26
26
|
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1"
|
|
28
28
|
spec.add_development_dependency "rake", "~> 10"
|
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
spec.add_runtime_dependency "uuidtools", "~> 2.1"
|
|
35
35
|
spec.add_runtime_dependency "json-schema", "~> 2.7"
|
|
36
36
|
spec.add_runtime_dependency "adiwg-mdjson_schemas", ">= 2.2"
|
|
37
|
-
spec.add_runtime_dependency "adiwg-mdcodes", "~> 2.
|
|
37
|
+
spec.add_runtime_dependency "adiwg-mdcodes", "~> 2.3"
|
|
38
38
|
spec.add_runtime_dependency "jbuilder", "~> 2.5"
|
|
39
39
|
spec.add_runtime_dependency "kramdown", "~> 1.13"
|
|
40
40
|
spec.add_runtime_dependency "coderay", "~> 1.1"
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Stan Smith 2016-06-22 original script
|
|
6
6
|
|
|
7
7
|
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
|
8
|
-
|
|
8
|
+
require_relative 'module_codelists'
|
|
9
9
|
|
|
10
10
|
module ADIWG
|
|
11
11
|
module Mdtranslator
|
|
@@ -14,8 +14,6 @@ module ADIWG
|
|
|
14
14
|
|
|
15
15
|
module BrowseCategory
|
|
16
16
|
|
|
17
|
-
@Namespace = ADIWG::Mdtranslator::Writers::SbJson
|
|
18
|
-
|
|
19
17
|
def self.unpack(hSbJson, hResourceInfo, hResponseObj)
|
|
20
18
|
|
|
21
19
|
# instance classes needed in script
|
|
@@ -24,7 +22,7 @@ module ADIWG
|
|
|
24
22
|
if hSbJson.has_key?('browseCategories')
|
|
25
23
|
hSbJson['browseCategories'].each do |category|
|
|
26
24
|
hResType = intMetadataClass.newResourceType
|
|
27
|
-
scope =
|
|
25
|
+
scope = Codelists.codelist_sb2adiwg('scope_sb2adiwg', category)
|
|
28
26
|
if scope.nil?
|
|
29
27
|
hResType[:type] = 'dataset'
|
|
30
28
|
hResType[:name] = category
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# sbJson 1.0 reader
|
|
2
|
+
|
|
3
|
+
# History:
|
|
4
|
+
# Stan Smith 2017-08-03 refactored - separated forward and reverse translations
|
|
5
|
+
# Stan Smith 2017-05-26 original script
|
|
6
|
+
|
|
7
|
+
require 'adiwg-mdcodes'
|
|
8
|
+
|
|
9
|
+
module ADIWG
|
|
10
|
+
module Mdtranslator
|
|
11
|
+
module Readers
|
|
12
|
+
module SbJson
|
|
13
|
+
|
|
14
|
+
module Codelists
|
|
15
|
+
|
|
16
|
+
@role_sb2adiwg = [
|
|
17
|
+
{sb: 'administrator', adiwg: 'administrator'},
|
|
18
|
+
{sb: 'Associate Project Chief', adiwg: nil},
|
|
19
|
+
{sb: 'Author', adiwg: 'author'},
|
|
20
|
+
{sb: 'client', adiwg: 'client'},
|
|
21
|
+
{sb: 'Co-Investigator', adiwg: 'coPrincipalInvestigator'},
|
|
22
|
+
{sb: 'Contact', adiwg: 'pointOfContact'},
|
|
23
|
+
{sb: 'Cooperator/Partner', adiwg: 'collaborator'},
|
|
24
|
+
{sb: 'Custodian', adiwg: 'custodian'},
|
|
25
|
+
{sb: 'Data Owner', adiwg: 'owner'},
|
|
26
|
+
{sb: 'Data Provider', adiwg: nil},
|
|
27
|
+
{sb: 'Distributor', adiwg: 'distributor'},
|
|
28
|
+
{sb: 'Editor', adiwg: 'editor'},
|
|
29
|
+
{sb: 'funder', adiwg: 'funder'},
|
|
30
|
+
{sb: 'Funding Agency', adiwg: nil},
|
|
31
|
+
{sb: 'Lead Organization', adiwg: nil},
|
|
32
|
+
{sb: 'logistics', adiwg: 'logistics'},
|
|
33
|
+
{sb: 'Material Request Contact', adiwg: nil},
|
|
34
|
+
{sb: 'mediator', adiwg: 'mediator'},
|
|
35
|
+
{sb: 'Metadata Contact', adiwg: nil},
|
|
36
|
+
{sb: 'Originator', adiwg: 'originator'},
|
|
37
|
+
{sb: 'Participant', adiwg: nil},
|
|
38
|
+
{sb: 'Photographer', adiwg: nil},
|
|
39
|
+
{sb: 'Point of Contact', adiwg: 'pointOfContact'},
|
|
40
|
+
{sb: 'Principal Investigator', adiwg: 'principalInvestigator'},
|
|
41
|
+
{sb: 'Process Contact', adiwg: nil},
|
|
42
|
+
{sb: 'Processor', adiwg: 'processor'},
|
|
43
|
+
{sb: 'Project Chief', adiwg: nil},
|
|
44
|
+
{sb: 'Project Team', adiwg: nil},
|
|
45
|
+
{sb: 'publisher', adiwg: 'publisher'},
|
|
46
|
+
{sb: 'Referred By', adiwg: nil},
|
|
47
|
+
{sb: 'Report Prepared By', adiwg: nil},
|
|
48
|
+
{sb: 'Resource Provider', adiwg: 'resourceProvider'},
|
|
49
|
+
{sb: 'SoftwareEngineer', adiwg: nil},
|
|
50
|
+
{sb: 'sponsor', adiwg: 'sponsor'},
|
|
51
|
+
{sb: 'stakeholder', adiwg: 'stakeholder'},
|
|
52
|
+
{sb: 'Subtask Leader', adiwg: nil},
|
|
53
|
+
{sb: 'Supporter', adiwg: nil},
|
|
54
|
+
{sb: 'Task Leader', adiwg: nil},
|
|
55
|
+
{sb: 'Transmitted', adiwg: nil},
|
|
56
|
+
{sb: 'User', adiwg: 'use'},
|
|
57
|
+
{sb: 'USGS Mission Area', adiwg: nil},
|
|
58
|
+
{sb: 'USGS Program', adiwg: nil},
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
@onlineFunction_sb2adiwg = [
|
|
62
|
+
{sb: 'arcgis', adiwg: nil},
|
|
63
|
+
{sb: 'browseImage', adiwg: 'browseGraphic'},
|
|
64
|
+
{sb: 'browsing', adiwg: 'browsing'},
|
|
65
|
+
{sb: 'citation', adiwg: nil},
|
|
66
|
+
{sb: 'configFile', adiwg: nil},
|
|
67
|
+
{sb: 'download',adiwg: 'download' },
|
|
68
|
+
{sb: 'emailService', adiwg: 'emailService'},
|
|
69
|
+
{sb: 'fileAccess', adiwg: 'fileAccess'},
|
|
70
|
+
{sb: 'kml', adiwg: nil},
|
|
71
|
+
{sb: 'mapapp', adiwg: nil},
|
|
72
|
+
{sb: 'method', adiwg: nil},
|
|
73
|
+
{sb: 'oai-pmh', adiwg: nil},
|
|
74
|
+
{sb: 'offlineAccess', adiwg: 'offlineAccess'},
|
|
75
|
+
{sb: 'order', adiwg: 'order'},
|
|
76
|
+
{sb: 'originalMetadata', adiwg: 'completeMetadata'},
|
|
77
|
+
{sb: 'pdf', adiwg: nil},
|
|
78
|
+
{sb: 'publicationReferenceSource', adiwg: nil},
|
|
79
|
+
{sb: 'repo', adiwg: nil},
|
|
80
|
+
{sb: 'search', adiwg: 'search'},
|
|
81
|
+
{sb: 'serviceCapabilitiesUrl', adiwg: nil},
|
|
82
|
+
{sb: 'serviceFeatureInfoUrl', adiwg: nil},
|
|
83
|
+
{sb: 'serviceLegendUrl', adiwg: nil},
|
|
84
|
+
{sb: 'serviceLink', adiwg: nil},
|
|
85
|
+
{sb: 'serviceMapUrl', adiwg: nil},
|
|
86
|
+
{sb: 'serviceWfsBackingUrl', adiwg: nil},
|
|
87
|
+
{sb: 'sitemap', adiwg: nil},
|
|
88
|
+
{sb: 'sourceCode', adiwg: nil},
|
|
89
|
+
{sb: 'txt', adiwg: nil},
|
|
90
|
+
{sb: 'upload', adiwg: 'upload'},
|
|
91
|
+
{sb: 'WAF', adiwg: nil},
|
|
92
|
+
{sb: 'webapp', adiwg: 'webApplication'},
|
|
93
|
+
{sb: 'webLink', adiwg: 'information'},
|
|
94
|
+
{sb: 'xls', adiwg: nil},
|
|
95
|
+
{sb: 'zip', adiwg: nil}
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
@scope_sb2adiwg = [
|
|
99
|
+
{sb: 'Collection', adiwg: 'collection'},
|
|
100
|
+
{sb: 'Data', adiwg: 'dataset'},
|
|
101
|
+
{sb: 'Data Release - In Progress', adiwg: nil},
|
|
102
|
+
{sb: 'Image', adiwg: 'photographicImage'},
|
|
103
|
+
{sb: 'Map', adiwg: 'map'},
|
|
104
|
+
{sb: 'Physical Item', adiwg: 'sample'},
|
|
105
|
+
{sb: 'Project', adiwg: 'project'},
|
|
106
|
+
{sb: 'Publication', adiwg: 'publication'},
|
|
107
|
+
{sb: 'Software', adiwg: 'software'},
|
|
108
|
+
{sb: 'Web Site', adiwg: 'website'}
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
@date_sb2adiwg = [
|
|
112
|
+
{sb: 'Acquisition', adiwg: 'acquisition'},
|
|
113
|
+
{sb: 'adopted', adiwg: 'adopted'},
|
|
114
|
+
{sb: 'AssessmentDate', adiwg: 'assessment'},
|
|
115
|
+
{sb: 'Award', adiwg: 'award'},
|
|
116
|
+
{sb: 'beginPosition', adiwg: nil},
|
|
117
|
+
{sb: 'Collected', adiwg: 'collected'},
|
|
118
|
+
{sb: 'creation', adiwg: 'creation'},
|
|
119
|
+
{sb: 'deprecated', adiwg: 'deprecated'},
|
|
120
|
+
{sb: 'distribution', adiwg: 'distribution'},
|
|
121
|
+
{sb: 'Due', adiwg: 'due'},
|
|
122
|
+
{sb: 'End', adiwg: 'end'},
|
|
123
|
+
{sb: 'endPosition', adiwg: nil},
|
|
124
|
+
{sb: 'firstProcessed', adiwg: nil},
|
|
125
|
+
{sb: 'info', adiwg: nil},
|
|
126
|
+
{sb: 'inForce', adiwg: 'inForce'},
|
|
127
|
+
{sb: 'lastProcessed', adiwg: nil},
|
|
128
|
+
{sb: 'lastRevision', adiwg: 'lastRevision'},
|
|
129
|
+
{sb: 'lastUpdate', adiwg: 'lastUpdate'},
|
|
130
|
+
{sb: 'nextUpdate', adiwg: 'nextUpdate'},
|
|
131
|
+
{sb: 'Publication', adiwg: 'publication'},
|
|
132
|
+
{sb: 'Received', adiwg: 'received'},
|
|
133
|
+
{sb: 'Release', adiwg: 'released'},
|
|
134
|
+
{sb: 'Reported', adiwg: 'reported'},
|
|
135
|
+
{sb: 'Repository Created', adiwg: nil},
|
|
136
|
+
{sb: 'Repository Updated', adiwg: nil},
|
|
137
|
+
{sb: 'revision', adiwg: 'revision'},
|
|
138
|
+
{sb: 'Start', adiwg: 'start'},
|
|
139
|
+
{sb: 'suspended', adiwg: 'suspended'},
|
|
140
|
+
{sb: 'Transmitted', adiwg: 'transmitted'},
|
|
141
|
+
{sb: 'unavailable', adiwg: 'unavailable'},
|
|
142
|
+
{sb: 'validityBegins', adiwg: 'validityBegins'},
|
|
143
|
+
{sb: 'validityExpires', adiwg: 'validityExpires'}
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
@progress_sb2adiwg = [
|
|
147
|
+
{sb: 'Active', adiwg: 'onGoing'},
|
|
148
|
+
{sb: 'Approved', adiwg: 'accepted'},
|
|
149
|
+
{sb: 'Completed', adiwg: 'completed'},
|
|
150
|
+
{sb: 'In Progress', adiwg: 'onGoing'},
|
|
151
|
+
{sb: 'Proposed', adiwg: 'proposed'}
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
@association_sb2adiwg = [
|
|
155
|
+
{sb: 'alternate', adiwg: 'alternate', reverse: 'alternate'},
|
|
156
|
+
{sb: 'constituentOf', adiwg: 'isComposedOf', reverse: 'constituent'},
|
|
157
|
+
{sb: 'copiedFrom', adiwg: nil, reverse: 'copiedInto'},
|
|
158
|
+
{sb: 'derivativeOf', adiwg: 'derivativeProduct', reverse: 'derived'},
|
|
159
|
+
{sb: 'precededBy', adiwg: nil, reverse: 'succeededBy'},
|
|
160
|
+
{sb: 'productOf', adiwg: 'parentProject', reverse: 'produced'},
|
|
161
|
+
{sb: 'related', adiwg: 'crossReference', reverse: 'related'},
|
|
162
|
+
{sb: 'subprojectOf', adiwg: 'subProject', reverse: 'mainprojectOf'}
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
# translate iso/adiwg code to sb
|
|
166
|
+
def self.codelist_sb2adiwg(codelist, sbCode)
|
|
167
|
+
codeList = instance_variable_get("@#{codelist}")
|
|
168
|
+
unless sbCode.nil?
|
|
169
|
+
codeList.each do |obj|
|
|
170
|
+
if obj[:sb] == sbCode
|
|
171
|
+
return obj[:adiwg]
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
return nil
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# test if provided code is a valid sb code
|
|
179
|
+
def self.is_sb_code(codelist, sbCode)
|
|
180
|
+
codeList = instance_variable_get("@#{codelist}")
|
|
181
|
+
unless sbCode.nil?
|
|
182
|
+
codeList.each do |obj|
|
|
183
|
+
if obj[:sb] == sbCode
|
|
184
|
+
return true
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
return false
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Stan Smith 2016-06-25 original script
|
|
6
6
|
|
|
7
7
|
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
|
8
|
-
|
|
8
|
+
require_relative 'module_codelists'
|
|
9
9
|
|
|
10
10
|
module ADIWG
|
|
11
11
|
module Mdtranslator
|
|
@@ -14,8 +14,6 @@ module ADIWG
|
|
|
14
14
|
|
|
15
15
|
module Date
|
|
16
16
|
|
|
17
|
-
@Namespace = ADIWG::Mdtranslator::Writers::SbJson
|
|
18
|
-
|
|
19
17
|
def self.unpack(hSbJson, hCitation, hResponseObj)
|
|
20
18
|
|
|
21
19
|
# instance classes needed in script
|
|
@@ -29,8 +27,9 @@ module ADIWG
|
|
|
29
27
|
hDate[:date] = aReturn[0]
|
|
30
28
|
hDate[:dateResolution] = aReturn[1]
|
|
31
29
|
hDate[:description] = hSbDate['label']
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
sbType = hSbDate['type']
|
|
31
|
+
adiwgType = Codelists.codelist_sb2adiwg('date_sb2adiwg', sbType)
|
|
32
|
+
type = adiwgType.nil? ? sbType : adiwgType
|
|
34
33
|
hDate[:dateType] = type
|
|
35
34
|
hCitation[:dates] << hDate
|
|
36
35
|
end
|
|
@@ -21,7 +21,7 @@ module ADIWG
|
|
|
21
21
|
extentAdd = "http://www.sciencebase.gov/catalog/extent/#{extentId}?format=geojson"
|
|
22
22
|
web_contents = open(extentAdd, :read_timeout => 30) { |f| f.read }
|
|
23
23
|
rescue => readErr
|
|
24
|
-
hResponseObj[:readerExecutionMessages] << 'ScienceBase
|
|
24
|
+
hResponseObj[:readerExecutionMessages] << 'Failed reading ScienceBase extent - see following message(s):\n'
|
|
25
25
|
hResponseObj[:readerExecutionMessages] << readErr.to_s.slice(0, 300)
|
|
26
26
|
return {}
|
|
27
27
|
else
|
|
@@ -29,7 +29,7 @@ module ADIWG
|
|
|
29
29
|
begin
|
|
30
30
|
hGeoJson = JSON.parse(web_contents)
|
|
31
31
|
rescue JSON::JSONError => parseErr
|
|
32
|
-
hResponseObj[:readerExecutionMessages] << 'Parsing
|
|
32
|
+
hResponseObj[:readerExecutionMessages] << 'Parsing extent failed - see following message(s):\n'
|
|
33
33
|
hResponseObj[:readerExecutionMessages] << parseErr.to_s.slice(0, 300)
|
|
34
34
|
return {}
|
|
35
35
|
end
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# History:
|
|
5
5
|
# Stan Smith 2016-06-27 original script
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
require_relative 'module_codelists'
|
|
8
8
|
|
|
9
9
|
module ADIWG
|
|
10
10
|
module Mdtranslator
|
|
@@ -13,15 +13,13 @@ module ADIWG
|
|
|
13
13
|
|
|
14
14
|
module Project
|
|
15
15
|
|
|
16
|
-
@Namespace = ADIWG::Mdtranslator::Writers::SbJson
|
|
17
|
-
|
|
18
16
|
def self.unpack(hFacet, hResourceInfo, hResponseObj)
|
|
19
17
|
|
|
20
18
|
# project status
|
|
21
19
|
if hFacet.has_key?('projectStatus')
|
|
22
20
|
unless hFacet['projectStatus'].nil? || ['projectStatus'] == ''
|
|
23
21
|
sbStatus = hFacet['projectStatus']
|
|
24
|
-
status =
|
|
22
|
+
status = Codelists.codelist_sb2adiwg('progress_sb2adiwg', sbStatus)
|
|
25
23
|
status = status.nil? ? sbStatus : status
|
|
26
24
|
hResourceInfo[:status] << status
|
|
27
25
|
end
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Stan Smith 2016-06-25 original script
|
|
6
6
|
|
|
7
7
|
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
|
8
|
-
|
|
8
|
+
require_relative 'module_codelists'
|
|
9
9
|
|
|
10
10
|
module ADIWG
|
|
11
11
|
module Mdtranslator
|
|
@@ -16,8 +16,6 @@ module ADIWG
|
|
|
16
16
|
|
|
17
17
|
def self.unpack(hFacet, hResourceInfo, hCitation, hResponseObj)
|
|
18
18
|
|
|
19
|
-
@Namespace = ADIWG::Mdtranslator::Writers::SbJson
|
|
20
|
-
|
|
21
19
|
# instance classes needed in script
|
|
22
20
|
intMetadataClass = InternalMetadata.new
|
|
23
21
|
|
|
@@ -26,8 +24,8 @@ module ADIWG
|
|
|
26
24
|
unless hFacet['citationType'].nil? || hFacet['citationType'] == ''
|
|
27
25
|
hResType = intMetadataClass.newResourceType
|
|
28
26
|
sbType = hFacet['citationType']
|
|
29
|
-
|
|
30
|
-
type =
|
|
27
|
+
adiwgType = Codelists.codelist_sb2adiwg('scope_sb2adiwg', sbType)
|
|
28
|
+
type = adiwgType.nil? ? sbType : adiwgType
|
|
31
29
|
hResType[:type] = type
|
|
32
30
|
hResType[:name] = sbType
|
|
33
31
|
hResourceInfo[:resourceTypes] << hResType
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# unpack related items
|
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2016-08-03 original script
|
|
6
|
+
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'open-uri'
|
|
9
|
+
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
|
10
|
+
require_relative 'module_codelists'
|
|
11
|
+
|
|
12
|
+
module ADIWG
|
|
13
|
+
module Mdtranslator
|
|
14
|
+
module Readers
|
|
15
|
+
module SbJson
|
|
16
|
+
|
|
17
|
+
module RelatedItem
|
|
18
|
+
|
|
19
|
+
def self.unpack(hSbJson, hMetadata, hResponseObj)
|
|
20
|
+
|
|
21
|
+
# instance classes needed in script
|
|
22
|
+
intMetadataClass = InternalMetadata.new
|
|
23
|
+
|
|
24
|
+
# relationship direction of related items depends on the main record id
|
|
25
|
+
sbId = nil
|
|
26
|
+
if hSbJson.has_key?('id')
|
|
27
|
+
sbId = hSbJson['id']
|
|
28
|
+
end
|
|
29
|
+
if sbId.nil? || sbId == ''
|
|
30
|
+
hResponseObj[:readerExecutionMessages] << 'ScienceBase id missing'
|
|
31
|
+
return hMetadata
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# get the link to the related items array
|
|
35
|
+
hRelatedItems = hSbJson['relatedItems']
|
|
36
|
+
itemsLink = nil
|
|
37
|
+
if hRelatedItems.has_key?('link')
|
|
38
|
+
hLink = hRelatedItems['link']
|
|
39
|
+
unless hLink.empty?
|
|
40
|
+
itemsLink = hLink['url']
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
return hMetadata if itemsLink.nil?
|
|
44
|
+
|
|
45
|
+
# fetch the related items array in json format
|
|
46
|
+
itemsLink = itemsLink + '&format=json'
|
|
47
|
+
begin
|
|
48
|
+
web_contents = open(itemsLink, :read_timeout => 30) { |f| f.read }
|
|
49
|
+
rescue => readErr
|
|
50
|
+
hResponseObj[:readerExecutionMessages] << "Failed reading ScienceBase relatedItems #{itemsLink} - see following message(s):\n"
|
|
51
|
+
hResponseObj[:readerExecutionMessages] << readErr.to_s.slice(0, 300)
|
|
52
|
+
return hMetadata
|
|
53
|
+
else
|
|
54
|
+
# parse related items array
|
|
55
|
+
aItems = []
|
|
56
|
+
begin
|
|
57
|
+
aItems = JSON.parse(web_contents)
|
|
58
|
+
rescue JSON::JSONError => parseErr
|
|
59
|
+
hResponseObj[:readerExecutionMessages] << 'Parsing related links failed - see following message(s):\n'
|
|
60
|
+
hResponseObj[:readerExecutionMessages] << parseErr.to_s.slice(0, 300)
|
|
61
|
+
return hMetadata
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# process each returned related item as a separate associated resource
|
|
65
|
+
aItems.each do |hItem|
|
|
66
|
+
unless hItem.empty?
|
|
67
|
+
|
|
68
|
+
# determine relationship direction
|
|
69
|
+
forward = nil
|
|
70
|
+
if hItem.has_key?('itemId')
|
|
71
|
+
forward = true if sbId == hItem['itemId']
|
|
72
|
+
end
|
|
73
|
+
if hItem.has_key?('relatedItemId')
|
|
74
|
+
forward = false if sbId == hItem['relatedItemId']
|
|
75
|
+
end
|
|
76
|
+
if forward.nil?
|
|
77
|
+
hResponseObj[:readerExecutionMessages] << 'Main ScienceBase id was not referenced in related item'
|
|
78
|
+
return hMetadata
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# fetch resourceTypes from related item
|
|
82
|
+
if forward
|
|
83
|
+
resourceId = hItem['relatedItemId']
|
|
84
|
+
else
|
|
85
|
+
resourceId = hItem['itemId']
|
|
86
|
+
end
|
|
87
|
+
resourceLink = "https://www.sciencebase.gov/catalog/item/#{resourceId}?format=json"
|
|
88
|
+
begin
|
|
89
|
+
web_contents = open(resourceLink, :read_timeout => 30) { |f| f.read }
|
|
90
|
+
rescue => readErr
|
|
91
|
+
hResponseObj[:readerExecutionMessages] << "Failed reading ScienceBase relatedItem #{resourceId} - see following message(s)"
|
|
92
|
+
hResponseObj[:readerExecutionMessages] << readErr.to_s.slice(0, 300)
|
|
93
|
+
hResponseObj[:readerExecutionMessages] << 'Either the item does not exist or the item is secured and requires authentication to access.'
|
|
94
|
+
break
|
|
95
|
+
else
|
|
96
|
+
# parse related item
|
|
97
|
+
begin
|
|
98
|
+
hRelatedItem = JSON.parse(web_contents)
|
|
99
|
+
rescue JSON::JSONError => parseErr
|
|
100
|
+
hResponseObj[:readerExecutionMessages] << 'Parsing related item failed - see following message(s):\n'
|
|
101
|
+
hResponseObj[:readerExecutionMessages] << parseErr.to_s.slice(0, 300)
|
|
102
|
+
break
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# create mew associated resource
|
|
106
|
+
hResource = intMetadataClass.newAssociatedResource
|
|
107
|
+
|
|
108
|
+
if hRelatedItem.has_key?('browseCategories')
|
|
109
|
+
aBrowse = hRelatedItem['browseCategories']
|
|
110
|
+
aBrowse.each do |category|
|
|
111
|
+
resourceType = Codelists.codelist_sb2adiwg('scope_sb2adiwg', category)
|
|
112
|
+
resourceType = resourceType.nil? ? category : resourceType
|
|
113
|
+
hResource[:resourceTypes] << resourceType
|
|
114
|
+
end
|
|
115
|
+
else
|
|
116
|
+
hResponseObj[:readerExecutionMessages] << "Related item #{resourceId} did not have browseCategories"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# fill in associated resource citation
|
|
120
|
+
hCitation = intMetadataClass.newCitation
|
|
121
|
+
citationTitle = nil
|
|
122
|
+
if hItem.has_key?('relatedItemTitle')
|
|
123
|
+
citationTitle = hItem['relatedItemTitle'] if forward
|
|
124
|
+
end
|
|
125
|
+
if hItem.has_key?('title')
|
|
126
|
+
citationTitle = hItem['title'] unless forward
|
|
127
|
+
end
|
|
128
|
+
hCitation[:title] = citationTitle
|
|
129
|
+
|
|
130
|
+
# create an identifier for each related item id
|
|
131
|
+
if hItem.has_key?('id')
|
|
132
|
+
hIdentifier = intMetadataClass.newIdentifier
|
|
133
|
+
hIdentifier[:identifier] = hItem['id']
|
|
134
|
+
hIdentifier[:namespace] = 'gov.sciencebase.catalog'
|
|
135
|
+
hIdentifier[:description] = 'id'
|
|
136
|
+
hCitation[:identifiers] << hIdentifier
|
|
137
|
+
end
|
|
138
|
+
if hItem.has_key?('itemId')
|
|
139
|
+
hIdentifier = intMetadataClass.newIdentifier
|
|
140
|
+
hIdentifier[:identifier] = hItem['itemId']
|
|
141
|
+
hIdentifier[:namespace] = 'gov.sciencebase.catalog'
|
|
142
|
+
hIdentifier[:description] = 'itemId'
|
|
143
|
+
hCitation[:identifiers] << hIdentifier
|
|
144
|
+
end
|
|
145
|
+
if hItem.has_key?('relatedItemId')
|
|
146
|
+
hIdentifier = intMetadataClass.newIdentifier
|
|
147
|
+
hIdentifier[:identifier] = hItem['relatedItemId']
|
|
148
|
+
hIdentifier[:namespace] = 'gov.sciencebase.catalog'
|
|
149
|
+
hIdentifier[:description] = 'relatedItemId'
|
|
150
|
+
hCitation[:identifiers] << hIdentifier
|
|
151
|
+
end
|
|
152
|
+
if hItem.has_key?('itemLinkTypeId')
|
|
153
|
+
hIdentifier = intMetadataClass.newIdentifier
|
|
154
|
+
hIdentifier[:identifier] = hItem['itemLinkTypeId']
|
|
155
|
+
hIdentifier[:namespace] = 'gov.sciencebase.catalog'
|
|
156
|
+
hIdentifier[:description] = 'itemLinkTypeId'
|
|
157
|
+
hCitation[:identifiers] << hIdentifier
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
hResource[:resourceCitation] = hCitation
|
|
161
|
+
hMetadata[:associatedResources] << hResource
|
|
162
|
+
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
return hMetadata
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
@@ -27,6 +27,7 @@ require_relative 'module_budget'
|
|
|
27
27
|
require_relative 'module_publication'
|
|
28
28
|
require_relative 'module_project'
|
|
29
29
|
require_relative 'module_extent'
|
|
30
|
+
require_relative 'module_relatedItem'
|
|
30
31
|
|
|
31
32
|
module ADIWG
|
|
32
33
|
module Mdtranslator
|
|
@@ -146,6 +147,11 @@ module ADIWG
|
|
|
146
147
|
end
|
|
147
148
|
end
|
|
148
149
|
|
|
150
|
+
# related items
|
|
151
|
+
if hSbJson.has_key?('relatedItems')
|
|
152
|
+
RelatedItem.unpack(hSbJson, hMetadata, hResponseObj)
|
|
153
|
+
end
|
|
154
|
+
|
|
149
155
|
hResourceInfo[:citation] = hCitation
|
|
150
156
|
hMetadata[:metadataInfo] = hMetadataInfo
|
|
151
157
|
hMetadata[:resourceInfo] = hResourceInfo
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# adiwg mdTranslator
|
|
2
2
|
|
|
3
3
|
# version 2 history
|
|
4
|
+
# 2.1.0 2017-08-10 revisions to sbJson reader
|
|
4
5
|
# 2.0.0 2017-06-28 added sbJson reader
|
|
5
6
|
# 2.0.0rc13 2017-06-16 apply changes to sbJson writer after fourth review session
|
|
6
7
|
# 2.0.0rc12 2017-06-14 apply changes to sbJson writer after third review session
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
module ADIWG
|
|
22
23
|
module Mdtranslator
|
|
23
24
|
# current mdtranslator version
|
|
24
|
-
VERSION = "2.
|
|
25
|
+
VERSION = "2.1.0"
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -44,7 +44,7 @@ module ADIWG
|
|
|
44
44
|
hContact = ADIWG::Mdtranslator::Writers::SbJson.get_contact_by_index(hIndex[:index])
|
|
45
45
|
unless hContact.empty?
|
|
46
46
|
unless hContact[:name].nil?
|
|
47
|
-
sbRole = Codelists.
|
|
47
|
+
sbRole = Codelists.codelist_adiwg2sb('role_adiwg2sb', hIndex[:role])
|
|
48
48
|
sbRole = sbRole.nil? ? hIndex[:role] : sbRole
|
|
49
49
|
citation += hContact[:name] + '(' + sbRole + '), '
|
|
50
50
|
end
|
|
@@ -54,7 +54,7 @@ module ADIWG
|
|
|
54
54
|
# dates
|
|
55
55
|
hCitation[:dates].each do |hDate|
|
|
56
56
|
dateStr = AdiwgDateTimeFun.stringDateFromDateObject(hDate)
|
|
57
|
-
dateType = Codelists.
|
|
57
|
+
dateType = Codelists.codelist_adiwg2sb('date_adiwg2sb', hDate[:dateType])
|
|
58
58
|
unless dateType.nil?
|
|
59
59
|
citation += dateStr + '(' + dateType + '), '
|
|
60
60
|
end
|