adiwg-mdtranslator 2.0.0rc11 → 2.0.0rc13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Rakefile +1 -0
- data/adiwg-mdtranslator.gemspec +2 -0
- data/lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb +32 -18
- data/lib/adiwg/mdtranslator/readers/mdJson/mdJson_reader.rb +96 -96
- data/lib/adiwg/mdtranslator/readers/mdJson/mdJson_validator.rb +35 -35
- data/lib/adiwg/mdtranslator/readers/mdJson/modules/module_mdJson.rb +102 -105
- data/lib/adiwg/mdtranslator/readers/mdReaders.rb +49 -49
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_additionalDocumentation.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_boundingBox.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_browseGraphic.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_citation.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_contacts.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_dateTime.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_distributionInfo.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_extent.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_geoCoordSystem.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_geoProperties.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_geographicElement.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_metadata.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_metadataInfo.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_onlineResource.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_resourceIdentifier.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_resourceInfo.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_responsibleParty.rb +0 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_body.rb +41 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_citation.rb +32 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_id.rb +35 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_identifier.rb +46 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_provenance.rb +59 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_purpose.rb +32 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_rights.rb +43 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_sbJson.rb +106 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/modules/module_titles.rb +42 -0
- data/lib/adiwg/mdtranslator/readers/sbJson/sbJson_reader.rb +56 -198
- data/lib/adiwg/mdtranslator/readers/sbJson/version.rb +14 -0
- data/lib/adiwg/mdtranslator/version.rb +3 -1
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_codelist.rb +38 -38
- data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_date.rb +1 -1
- data/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dateTime.rb +1 -1
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_abstract.rb +27 -0
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_citation.rb +6 -6
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_codelists.rb +90 -12
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb +12 -4
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_date.rb +4 -4
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_id.rb +16 -17
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_materialRequest.rb +6 -2
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_provenance.rb +2 -18
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_rights.rb +13 -0
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_sbJson.rb +3 -2
- data/lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_webLink.rb +23 -2
- metadata +59 -22
- data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/module_sbJson.rb +0 -52
- data/lib/adiwg/mdtranslator/readers/sbJson/modules_v0/version.rb +0 -12
@@ -1,69 +1,69 @@
|
|
1
1
|
# MdTranslator - controller for evaluating and directing readers
|
2
2
|
|
3
3
|
# History:
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
4
|
+
# Stan Smith 2016-11-12 refactored for mdTranslator 2.0
|
5
|
+
# Stan Smith 2015-07-14 refactored to remove global namespace constants
|
6
|
+
# Stan Smith 2015-06-22 replace global ($response) with passed in object (hResponseObj)
|
7
|
+
# Stan Smith 2015-03-04 changed method of setting $WriterNS
|
8
|
+
# Stan Smith 2012-12-16 generalized handleReader to use :readerRequested
|
9
9
|
# Stan Smith 2014-12-11 original script
|
10
10
|
|
11
11
|
module ADIWG
|
12
|
-
|
13
|
-
|
12
|
+
module Mdtranslator
|
13
|
+
module Readers
|
14
14
|
|
15
|
-
|
15
|
+
def self.handleReader(file, hResponseObj)
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
# use ':readerRequested' from hResponseObj to build directory path to reader
|
18
|
+
# reader's high level folder must be placed in 'lib/adiwg/mdtranslator/readers/'
|
19
|
+
# reader's code must must be in folder named '{reader}'
|
20
|
+
# '{reader}' must contain a module named '{reader}_reader.rb'
|
21
|
+
# '{reader}_reader.rb' must have a method named 'readFile()'
|
22
|
+
# 'readFile()' must pass two parameters (file, hResponseObj)
|
23
|
+
# all reader modules and classes must remain in their private namespace
|
24
|
+
# reader namespace is 'ADIWG::Mdtranslator::Readers::{reader}'
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
# reader high-level folder
|
27
|
+
thisDir = File.dirname(File.expand_path(__FILE__))
|
28
|
+
readerDir = File.join(thisDir, hResponseObj[:readerRequested])
|
29
|
+
if File.directory?(readerDir)
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# reader folder
|
32
|
+
readerModule = File.join(readerDir, hResponseObj[:readerRequested] + '_reader')
|
33
|
+
require readerModule
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# reader namespace
|
36
|
+
readerNS = hResponseObj[:readerRequested].dup
|
37
|
+
readerNS[0] = readerNS[0].upcase
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
else
|
43
|
-
hResponseObj[:readerValidationMessages] << "Requested reader '#{hResponseObj[:readerRequested]}' cannot be found."
|
44
|
-
hResponseObj[:readerValidationPass] = false
|
45
|
-
return {}
|
46
|
-
end
|
39
|
+
# reader will return intObj and updated hResponseObj
|
40
|
+
return ADIWG::Mdtranslator::Readers.const_get(readerNS).readFile(file, hResponseObj)
|
47
41
|
|
42
|
+
else
|
43
|
+
hResponseObj[:readerValidationMessages] << "Requested reader '#{hResponseObj[:readerRequested]}' cannot be found."
|
44
|
+
hResponseObj[:readerValidationPass] = false
|
45
|
+
return {}
|
48
46
|
end
|
49
47
|
|
50
|
-
|
51
|
-
# this is called from the Rails API
|
52
|
-
def self.get_reader_readme(reader)
|
48
|
+
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
file = File.open(path, 'r')
|
58
|
-
readmeText = file.read
|
59
|
-
file.close
|
60
|
-
return readmeText
|
61
|
-
else
|
62
|
-
return 'Readme file not found'
|
63
|
-
end
|
50
|
+
# return reader readme text
|
51
|
+
# this is called from the Rails API
|
52
|
+
def self.get_reader_readme(reader)
|
64
53
|
|
54
|
+
thisDir = File.dirname(File.expand_path(__FILE__))
|
55
|
+
path = File.join(thisDir, reader, 'readme.md')
|
56
|
+
if File.exist?(path)
|
57
|
+
file = File.open(path, 'r')
|
58
|
+
readmeText = file.read
|
59
|
+
file.close
|
60
|
+
return readmeText
|
61
|
+
else
|
62
|
+
return 'Readme file not found'
|
65
63
|
end
|
66
64
|
|
67
|
-
|
68
|
-
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
69
|
end
|
File without changes
|
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_browseGraphic.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_distributionInfo.rb
RENAMED
File without changes
|
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_geoCoordSystem.rb
RENAMED
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_geoProperties.rb
RENAMED
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_geographicElement.rb
RENAMED
File without changes
|
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_metadataInfo.rb
RENAMED
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_onlineResource.rb
RENAMED
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_resourceIdentifier.rb
RENAMED
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_resourceInfo.rb
RENAMED
File without changes
|
data/lib/adiwg/mdtranslator/readers/sbJson/{modules_v0 → modules/Old}/module_responsibleParty.rb
RENAMED
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# unpack body / summary
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-19 original script
|
6
|
+
|
7
|
+
module ADIWG
|
8
|
+
module Mdtranslator
|
9
|
+
module Readers
|
10
|
+
module SbJson
|
11
|
+
|
12
|
+
module Body
|
13
|
+
|
14
|
+
def self.unpack(hSbJson, hResourceInfo, hResponseObj)
|
15
|
+
|
16
|
+
# body
|
17
|
+
if hSbJson.has_key?('body')
|
18
|
+
sbAbstract = hSbJson['body']
|
19
|
+
unless sbAbstract.nil? || sbAbstract == ''
|
20
|
+
hResourceInfo[:abstract] = sbAbstract
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# summary
|
25
|
+
if hSbJson.has_key?('summary')
|
26
|
+
sbShort = hSbJson['summary']
|
27
|
+
unless sbShort.nil? || sbShort == ''
|
28
|
+
hResourceInfo[:shortAbstract] = sbShort
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
return hResourceInfo
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# unpack citation
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-19 original script
|
6
|
+
|
7
|
+
module ADIWG
|
8
|
+
module Mdtranslator
|
9
|
+
module Readers
|
10
|
+
module SbJson
|
11
|
+
|
12
|
+
module Citation
|
13
|
+
|
14
|
+
def self.unpack(hSbJson, hCitation, hResponseObj)
|
15
|
+
|
16
|
+
if hSbJson.has_key?('citation')
|
17
|
+
sbCitation = hSbJson['citation']
|
18
|
+
unless sbCitation.nil? || sbCitation == ''
|
19
|
+
hCitation[:otherDetails][0] = sbCitation
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
return hCitation
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# unpack id
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-14 original script
|
6
|
+
|
7
|
+
module ADIWG
|
8
|
+
module Mdtranslator
|
9
|
+
module Readers
|
10
|
+
module SbJson
|
11
|
+
|
12
|
+
module Id
|
13
|
+
|
14
|
+
def self.unpack(hSbJson, hIdentifier, hResponseObj)
|
15
|
+
|
16
|
+
# title
|
17
|
+
if hSbJson.has_key?('id')
|
18
|
+
sbId = hSbJson['id']
|
19
|
+
unless sbId.nil? || sbId == ''
|
20
|
+
hIdentifier[:identifier] = sbId
|
21
|
+
hIdentifier[:namespace] = 'gov.sciencebase.catalog'
|
22
|
+
hIdentifier[:description] = 'USGS ScienceBase Identifier'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
return hIdentifier
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# unpack identifier
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-19 original script
|
6
|
+
|
7
|
+
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
8
|
+
|
9
|
+
module ADIWG
|
10
|
+
module Mdtranslator
|
11
|
+
module Readers
|
12
|
+
module SbJson
|
13
|
+
|
14
|
+
module Identifier
|
15
|
+
|
16
|
+
# instance classes needed in script
|
17
|
+
@intMetadataClass = InternalMetadata.new
|
18
|
+
|
19
|
+
def self.unpack(hSbJson, hCitation, hResponseObj)
|
20
|
+
|
21
|
+
hSbJson['identifiers'].each_with_index do |hSbIdentifier, i|
|
22
|
+
hIdentifier = @intMetadataClass.newIdentifier
|
23
|
+
|
24
|
+
unless hSbIdentifier['type'].nil? || hSbIdentifier['type'] == ''
|
25
|
+
hIdentifier[:description] = hSbIdentifier['type']
|
26
|
+
end
|
27
|
+
unless hSbIdentifier['scheme'].nil? || hSbIdentifier['scheme'] == ''
|
28
|
+
hIdentifier[:namespace] = hSbIdentifier['scheme']
|
29
|
+
end
|
30
|
+
unless hSbIdentifier['key'].nil? || hSbIdentifier['key'] == ''
|
31
|
+
hIdentifier[:identifier] = hSbIdentifier['key']
|
32
|
+
end
|
33
|
+
|
34
|
+
hCitation[:identifiers] << hIdentifier
|
35
|
+
end
|
36
|
+
|
37
|
+
return hCitation
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# unpack provenance
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-20 original script
|
6
|
+
|
7
|
+
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
8
|
+
require 'adiwg/mdtranslator/internal/module_dateTimeFun'
|
9
|
+
|
10
|
+
module ADIWG
|
11
|
+
module Mdtranslator
|
12
|
+
module Readers
|
13
|
+
module SbJson
|
14
|
+
|
15
|
+
module Provenance
|
16
|
+
|
17
|
+
def self.unpack(hSbJson, hCitation, hResponseObj)
|
18
|
+
|
19
|
+
# instance classes needed in script
|
20
|
+
intMetadataClass = InternalMetadata.new
|
21
|
+
|
22
|
+
# title
|
23
|
+
if hSbJson.has_key?('provenance')
|
24
|
+
hSbProv = hSbJson['provenance']
|
25
|
+
|
26
|
+
if hSbProv.has_key?('dateCreated')
|
27
|
+
unless hSbProv['dateCreated'].nil? || hSbProv['dateCreated'] == ''
|
28
|
+
hDate = intMetadataClass.newDate
|
29
|
+
hReturn = AdiwgDateTimeFun.dateTimeFromString(hSbProv['dateCreated'])
|
30
|
+
hDate[:date] = hReturn[0]
|
31
|
+
hDate[:dateResolution] = hReturn[1]
|
32
|
+
hDate[:dateType] = 'creation'
|
33
|
+
hCitation[:dates] << hDate
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if hSbProv.has_key?('lastUpdated')
|
38
|
+
unless hSbProv['lastUpdated'].nil? || hSbProv['lastUpdated'] == ''
|
39
|
+
hDate = intMetadataClass.newDate
|
40
|
+
hReturn = AdiwgDateTimeFun.dateTimeFromString(hSbProv['lastUpdated'])
|
41
|
+
hDate[:date] = hReturn[0]
|
42
|
+
hDate[:dateResolution] = hReturn[1]
|
43
|
+
hDate[:dateType] = 'lastUpdate'
|
44
|
+
hCitation[:dates] << hDate
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
return hCitation
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# unpack purpose
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-19 original script
|
6
|
+
|
7
|
+
module ADIWG
|
8
|
+
module Mdtranslator
|
9
|
+
module Readers
|
10
|
+
module SbJson
|
11
|
+
|
12
|
+
module Purpose
|
13
|
+
|
14
|
+
def self.unpack(hSbJson, hResourceInfo, hResponseObj)
|
15
|
+
|
16
|
+
if hSbJson.has_key?('purpose')
|
17
|
+
sbPurpose = hSbJson['purpose']
|
18
|
+
unless sbPurpose.nil? || sbPurpose == ''
|
19
|
+
hResourceInfo[:purpose] = sbPurpose
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
return hResourceInfo
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# unpack rights
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-19 original script
|
6
|
+
|
7
|
+
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
8
|
+
|
9
|
+
module ADIWG
|
10
|
+
module Mdtranslator
|
11
|
+
module Readers
|
12
|
+
module SbJson
|
13
|
+
|
14
|
+
module Rights
|
15
|
+
|
16
|
+
def self.unpack(hSbJson, hResponseObj)
|
17
|
+
|
18
|
+
# instance classes needed in script
|
19
|
+
intMetadataClass = InternalMetadata.new
|
20
|
+
|
21
|
+
hConstraint = intMetadataClass.newConstraint
|
22
|
+
hLegal = intMetadataClass.newLegalConstraint
|
23
|
+
|
24
|
+
if hSbJson.has_key?('rights')
|
25
|
+
sbRights = hSbJson['rights']
|
26
|
+
unless sbRights.nil? || sbRights == ''
|
27
|
+
hConstraint[:type] = 'legal'
|
28
|
+
hLegal[:otherCons][0] = sbRights
|
29
|
+
hConstraint[:legalConstraint] = hLegal
|
30
|
+
return hConstraint
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
return nil
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# unpack sbJson
|
2
|
+
# Reader - sbJson to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2017-06-12 refactor for mdTranslator 2.0
|
6
|
+
# Josh Bradley original script
|
7
|
+
|
8
|
+
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
|
9
|
+
require_relative 'module_titles'
|
10
|
+
require_relative 'module_id'
|
11
|
+
require_relative 'module_body'
|
12
|
+
require_relative 'module_citation'
|
13
|
+
require_relative 'module_identifier'
|
14
|
+
require_relative 'module_purpose'
|
15
|
+
require_relative 'module_rights'
|
16
|
+
require_relative 'module_provenance'
|
17
|
+
|
18
|
+
module ADIWG
|
19
|
+
module Mdtranslator
|
20
|
+
module Readers
|
21
|
+
module SbJson
|
22
|
+
|
23
|
+
module SbJson
|
24
|
+
|
25
|
+
def self.unpack(hSbJson, hResponseObj)
|
26
|
+
|
27
|
+
# instance classes needed in script
|
28
|
+
intMetadataClass = InternalMetadata.new
|
29
|
+
|
30
|
+
intObj = intMetadataClass.newBase
|
31
|
+
|
32
|
+
# build basic mdTranslator internal object
|
33
|
+
hMetadata = intMetadataClass.newMetadata
|
34
|
+
hMetadataInfo = intMetadataClass.newMetadataInfo
|
35
|
+
hResourceInfo = intMetadataClass.newResourceInfo
|
36
|
+
hCitation = intMetadataClass.newCitation
|
37
|
+
|
38
|
+
hResourceInfo[:citation] = hCitation
|
39
|
+
hMetadata[:metadataInfo] = hMetadataInfo
|
40
|
+
hMetadata[:resourceInfo] = hResourceInfo
|
41
|
+
intObj[:metadata] = hMetadata
|
42
|
+
|
43
|
+
# titles / alternateTitles
|
44
|
+
Title.unpack(hSbJson, hCitation, hResponseObj)
|
45
|
+
|
46
|
+
# id
|
47
|
+
Id.unpack(hSbJson, hMetadataInfo[:metadataIdentifier], hResponseObj)
|
48
|
+
|
49
|
+
# body / summary
|
50
|
+
Body.unpack(hSbJson, hResourceInfo, hResponseObj)
|
51
|
+
|
52
|
+
# citation
|
53
|
+
Citation.unpack(hSbJson, hCitation, hResponseObj)
|
54
|
+
|
55
|
+
# identifier
|
56
|
+
Identifier.unpack(hSbJson, hCitation, hResponseObj)
|
57
|
+
|
58
|
+
# purpose
|
59
|
+
Purpose.unpack(hSbJson, hResourceInfo, hResponseObj)
|
60
|
+
|
61
|
+
# rights
|
62
|
+
hReturn = Rights.unpack(hSbJson, hResponseObj)
|
63
|
+
hResourceInfo[:constraints] << hReturn unless hReturn.nil?
|
64
|
+
|
65
|
+
# provenance
|
66
|
+
Provenance.unpack(hSbJson, hCitation, hResponseObj)
|
67
|
+
|
68
|
+
# materialRequestInstructions
|
69
|
+
|
70
|
+
# something goes here
|
71
|
+
@contacts = []
|
72
|
+
|
73
|
+
return intObj
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
# find the array pointer and type for a contact
|
78
|
+
def self.findContact(contactId)
|
79
|
+
|
80
|
+
contactIndex = nil
|
81
|
+
contactType = nil
|
82
|
+
@contacts.each_with_index do |contact, i|
|
83
|
+
if contact[:contactId] == contactId
|
84
|
+
contactIndex = i
|
85
|
+
if contact[:isOrganization]
|
86
|
+
contactType = 'organization'
|
87
|
+
else
|
88
|
+
contactType = 'individual'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
return contactIndex, contactType
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
# set contacts array for reader test modules
|
97
|
+
def self.setContacts(contacts)
|
98
|
+
@contacts = contacts
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# unpack titles
|
2
|
+
# Reader - ScienceBase JSON to internal data structure
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2016-06-13 original script
|
6
|
+
|
7
|
+
module ADIWG
|
8
|
+
module Mdtranslator
|
9
|
+
module Readers
|
10
|
+
module SbJson
|
11
|
+
|
12
|
+
module Title
|
13
|
+
|
14
|
+
def self.unpack(hSbJson, hCitation, hResponseObj)
|
15
|
+
|
16
|
+
# title
|
17
|
+
if hSbJson.has_key?('title')
|
18
|
+
title = hSbJson['title']
|
19
|
+
unless title.nil? || title == ''
|
20
|
+
hCitation[:title] = title
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# alternate titles []
|
25
|
+
if hSbJson.has_key?('alternateTitles')
|
26
|
+
hSbJson['alternateTitles'].each do |item|
|
27
|
+
unless item.nil? || item == ''
|
28
|
+
hCitation[:alternateTitles] << item
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
return hCitation
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|