adiwg-mdtranslator 0.8.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 +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +31 -0
- data/Rakefile +13 -0
- data/adiwg-mdtranslator.gemspec +31 -0
- data/bin/mdtranslator +164 -0
- data/lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb +499 -0
- data/lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb +98 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/adiwgJson_reader.rb +80 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/adiwgJson_validator.rb +115 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_address.rb +71 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_associatedResource.rb +57 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_boundingBox.rb +51 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_browseGraphic.rb +52 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_citation.rb +104 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_contacts.rb +121 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_coordinates.rb +52 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_dataQuality.rb +40 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_dateTime.rb +27 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_descriptiveKeyword.rb +49 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_distributionInfo.rb +150 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_extent.rb +62 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_geoCoordSystem.rb +46 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_geoProperties.rb +89 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_geographicElement.rb +168 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_legalConstraint.rb +45 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_lineString.rb +25 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_lineage.rb +50 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_metadata.rb +76 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_metadataExtension.rb +40 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_metadataInfo.rb +119 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_onlineResource.rb +62 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_phone.rb +59 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_point.rb +25 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_polygon.rb +55 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_processStep.rb +64 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resolution.rb +42 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceFormat.rb +35 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceIdentifier.rb +49 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceInfo.rb +298 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceMaintenance.rb +50 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceSpecificUsage.rb +50 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_responsibleParty.rb +37 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_securityConstraint.rb +52 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_source.rb +48 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_spatialReference.rb +48 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_taxonClass.rb +43 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_taxonomy.rb +83 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_temporalElement.rb +71 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_timeInstant.rb +45 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_timePeriod.rb +53 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_verticalElement.rb +53 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_voucher.rb +38 -0
- data/lib/adiwg/mdtranslator/validator.rb +43 -0
- data/lib/adiwg/mdtranslator/version.rb +7 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_address.rb +91 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_aggregateInformation.rb +68 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_boundingPolygon.rb +75 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_browseGraphic.rb +51 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_citation.rb +157 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_contact.rb +85 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_dataIdentification.rb +338 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_dataQuality.rb +55 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_date.rb +60 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_digitalTransferOptions.rb +51 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_distribution.rb +36 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_distributor.rb +80 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_extent.rb +94 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_format.rb +40 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_genericMetaData.rb +65 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_geographicBoundingBox.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_geographicDescription.rb +29 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_geographicElement.rb +36 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_identifier.rb +51 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_keyword.rb +63 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_legalConstraints.rb +63 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_lineString.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_lineage.rb +63 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_maintenanceInformation.rb +64 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_medium.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadata.rb +277 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadataExtension.rb +156 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_multiGeometry.rb +140 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_onlineResource.rb +78 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_point.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_polygon.rb +94 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_processStep.rb +81 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_referenceIdentifier.rb +42 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_referenceSystem.rb +29 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_resolution.rb +46 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_responsibleParty.rb +90 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_securityConstraints.rb +68 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_source.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_standardOrderProcess.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_taxonClassification.rb +65 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_taxonSystem.rb +100 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_telephone.rb +77 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_temporalExtent.rb +58 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_timeInstant.rb +47 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_timePeriod.rb +54 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_usage.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_useConstraints.rb +30 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_verticalExtent.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_vouchers.rb +48 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_associationType.rb +35 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_characterSet.rb +58 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_classification.rb +35 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_datatype.rb +45 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_dateType.rb +29 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_initiativeType.rb +35 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_keywordType.rb +33 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_maintenanceFrequency.rb +42 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_mediumFormat.rb +32 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_mediumName.rb +44 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_obligation.rb +32 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_onlineFunction.rb +31 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_presentationForm.rb +44 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_progress.rb +33 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_restriction.rb +38 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_role.rb +37 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_scope.rb +46 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_spatialRepresentationType.rb +36 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_topicCategory.rb +50 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/iso19115_2_writer.rb +131 -0
- data/lib/adiwg/mdtranslator.rb +97 -0
- data/lib/adiwg-mdtranslator.rb +1 -0
- data/mdtranslator.rb +178 -0
- data/test/adiwgJson_full_test_example.json +1717 -0
- data/test/adiwgJson_template.json +977 -0
- data/test/dev.rb +32 -0
- data/test/tc_translation.rb +31 -0
- metadata +317 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Get minor version of ADIwg JSON V1
|
|
2
|
+
|
|
3
|
+
# History:
|
|
4
|
+
# Stan Smith 2014-07-09 original script
|
|
5
|
+
# Stan Smith 2014-07-21 added json structure validation method
|
|
6
|
+
# Stan Smith 2014-08-21 parsed json-schema validation message to readable text
|
|
7
|
+
# Stan Smith 2014-09-26 added processing of minor release numbers
|
|
8
|
+
|
|
9
|
+
require 'json'
|
|
10
|
+
require 'json-schema'
|
|
11
|
+
require 'adiwg-json_schemas'
|
|
12
|
+
#json-schema patch
|
|
13
|
+
require 'validator.rb'
|
|
14
|
+
|
|
15
|
+
module AdiwgJsonValidation
|
|
16
|
+
|
|
17
|
+
def self.validate(file)
|
|
18
|
+
|
|
19
|
+
# set the anticipated format of the input file based on the reader specified
|
|
20
|
+
$response[:readerFormat] = 'json'
|
|
21
|
+
|
|
22
|
+
# validate the input file structure
|
|
23
|
+
# test for valid json syntax by attempting to parse the file
|
|
24
|
+
begin
|
|
25
|
+
hashObj = JSON.parse(file)
|
|
26
|
+
$response[:readerStructurePass] = true
|
|
27
|
+
rescue JSON::JSONError => err
|
|
28
|
+
$response[:readerStructurePass] = false
|
|
29
|
+
$response[:readerStructureMessages] << err
|
|
30
|
+
return
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# find name and version of input json file
|
|
34
|
+
if hashObj.has_key?('version')
|
|
35
|
+
hVersion = hashObj['version']
|
|
36
|
+
else
|
|
37
|
+
$response[:readerStructurePass] = false
|
|
38
|
+
$response[:readerStructureMessages] << 'input file is missing the version:{} block'
|
|
39
|
+
return
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# get the version name
|
|
43
|
+
if hVersion.has_key?('name')
|
|
44
|
+
s = hVersion['name']
|
|
45
|
+
if !s.nil?
|
|
46
|
+
$response[:readerNameFound] = s
|
|
47
|
+
if s != 'adiwgJson'
|
|
48
|
+
$response[:readerStructurePass] = false
|
|
49
|
+
$response[:readerStructureMessages] << "input file version name must be 'adiwgJson'"
|
|
50
|
+
$response[:readerStructureMessages] << "found version name '#{s}'"
|
|
51
|
+
return
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
else
|
|
55
|
+
$response[:readerStructurePass] = false
|
|
56
|
+
$response[:readerStructureMessages] << "input file version:{} block is missing the 'name' attribute"
|
|
57
|
+
return
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# get version number
|
|
61
|
+
if hVersion.has_key?('version')
|
|
62
|
+
requestReaderVersion = hVersion['version']
|
|
63
|
+
$response[:readerVersionFound] = requestReaderVersion
|
|
64
|
+
# test if reader version is supported
|
|
65
|
+
# remove minor release number
|
|
66
|
+
# ...and look for a module folder name ending with the requested version
|
|
67
|
+
# ...example: 'modules_1.2.0'
|
|
68
|
+
if !requestReaderVersion.nil?
|
|
69
|
+
aVersionParts = requestReaderVersion.split('.')
|
|
70
|
+
readerVersion = aVersionParts[0] +'.' + aVersionParts[1] + '.0'
|
|
71
|
+
dir = File.join(File.dirname(__FILE__),'modules_' + readerVersion)
|
|
72
|
+
if !File.directory?(dir)
|
|
73
|
+
$response[:readerStructurePass] = false
|
|
74
|
+
$response[:readerStructureMessages] << 'input file version is not supported'
|
|
75
|
+
$response[:readerStructureMessages] << "adiwgJson version requested was '#{requestReaderVersion}'"
|
|
76
|
+
return
|
|
77
|
+
end
|
|
78
|
+
$response[:readerVersionUsed] = readerVersion
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
$response[:readerStructurePass] = false
|
|
82
|
+
$response[:readerStructureMessages] << "input file version:{} block is missing the 'version' attribute"
|
|
83
|
+
return
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# validate json against the adiwg-json_schemas
|
|
87
|
+
# only one schema version is supported at this time
|
|
88
|
+
begin
|
|
89
|
+
|
|
90
|
+
schema = ADIWG::JsonSchemas::Utils.schema_path
|
|
91
|
+
aValErrs = Array.new
|
|
92
|
+
if $response[:readerValidationLevel] == 'strict'
|
|
93
|
+
aValErrs = JSON::Validator.fully_validate(schema, file, :strict => true, :errors_as_objects => true)
|
|
94
|
+
elsif $response[:readerValidationLevel] == 'normal'
|
|
95
|
+
aValErrs = JSON::Validator.fully_validate(schema, file, :errors_as_objects => true)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if aValErrs.length > 0
|
|
99
|
+
$response[:readerValidationPass] = false
|
|
100
|
+
$response[:readerValidationMessages] = aValErrs
|
|
101
|
+
return
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
rescue JSON::Schema::ValidationError
|
|
105
|
+
$response[:readerValidationPass] = false
|
|
106
|
+
$response[:readerValidationMessages] << $!.message
|
|
107
|
+
return
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
$response[:readerValidationPass] = true
|
|
111
|
+
return
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# unpack address
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-10-21 original script
|
|
6
|
+
|
|
7
|
+
module Adiwg_Address
|
|
8
|
+
|
|
9
|
+
def self.unpack(hConAddress)
|
|
10
|
+
|
|
11
|
+
# instance classes needed in script
|
|
12
|
+
intMetadataClass = InternalMetadata.new
|
|
13
|
+
intAdd = nil
|
|
14
|
+
|
|
15
|
+
unless hConAddress.empty?
|
|
16
|
+
intAdd = intMetadataClass.newAddress
|
|
17
|
+
|
|
18
|
+
# address - delivery point
|
|
19
|
+
if hConAddress.has_key?('deliveryPoint')
|
|
20
|
+
dPoint = hConAddress['deliveryPoint']
|
|
21
|
+
dPoint.each do |addLine|
|
|
22
|
+
intAdd[:deliveryPoints] << addLine
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# address - city
|
|
27
|
+
if hConAddress.has_key?('city')
|
|
28
|
+
s = hConAddress['city']
|
|
29
|
+
if s != ''
|
|
30
|
+
intAdd[:city] = s
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# address - admin area
|
|
35
|
+
if hConAddress.has_key?('administrativeArea')
|
|
36
|
+
s = hConAddress['administrativeArea']
|
|
37
|
+
if s != ''
|
|
38
|
+
intAdd[:adminArea] = s
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# address - postal code
|
|
43
|
+
if hConAddress.has_key?('postalCode')
|
|
44
|
+
s = hConAddress['postalCode']
|
|
45
|
+
if s != ''
|
|
46
|
+
intAdd[:postalCode] = s
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# address - country
|
|
51
|
+
if hConAddress.has_key?('country')
|
|
52
|
+
s = hConAddress['country']
|
|
53
|
+
if s != ''
|
|
54
|
+
intAdd[:country] = s
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# address - email
|
|
59
|
+
if hConAddress.has_key?('electronicMailAddress')
|
|
60
|
+
eMailList = hConAddress['electronicMailAddress']
|
|
61
|
+
eMailList.each do |email|
|
|
62
|
+
intAdd[:eMailList] << email
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
return intAdd
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# unpack associated resource
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2014-05-02 original script
|
|
6
|
+
# Stan Smith 2014-05-28 added resource identifier section
|
|
7
|
+
# Stan Smith 2014-06-02 added resource metadata citation section
|
|
8
|
+
# Stan Smith 2014-07-08 resolve require statements using Mdtranslator.reader_module
|
|
9
|
+
# Stan Smith 2014-08-18 moved resourceIdentifier to citation module schema 0.6.0
|
|
10
|
+
|
|
11
|
+
require ADIWG::Mdtranslator.reader_module('module_citation', $response[:readerVersionUsed])
|
|
12
|
+
require ADIWG::Mdtranslator.reader_module('module_resourceIdentifier', $response[:readerVersionUsed])
|
|
13
|
+
|
|
14
|
+
module Adiwg_AssociatedResource
|
|
15
|
+
|
|
16
|
+
def self.unpack(hAssocRes)
|
|
17
|
+
|
|
18
|
+
# instance classes needed in script
|
|
19
|
+
intMetadataClass = InternalMetadata.new
|
|
20
|
+
intAssocRes = intMetadataClass.newAssociatedResource
|
|
21
|
+
|
|
22
|
+
# associated resource - resource type - initiativeTypeCode
|
|
23
|
+
if hAssocRes.has_key?('associationType')
|
|
24
|
+
s = hAssocRes['associationType']
|
|
25
|
+
if s != ''
|
|
26
|
+
intAssocRes[:associationType] = s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# associated resource - association type - associationTypeCode
|
|
31
|
+
if hAssocRes.has_key?('resourceType')
|
|
32
|
+
s = hAssocRes['resourceType']
|
|
33
|
+
if s != ''
|
|
34
|
+
intAssocRes[:resourceType] = s
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# associated resource - resource citation
|
|
39
|
+
if hAssocRes.has_key?('resourceCitation')
|
|
40
|
+
hCitation = hAssocRes['resourceCitation']
|
|
41
|
+
unless hCitation.empty?
|
|
42
|
+
intAssocRes[:resourceCitation] = Adiwg_Citation.unpack(hCitation)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# associated resource - metadata citation
|
|
47
|
+
if hAssocRes.has_key?('metadataCitation')
|
|
48
|
+
hCitation = hAssocRes['metadataCitation']
|
|
49
|
+
unless hCitation.empty?
|
|
50
|
+
intAssocRes[:metadataCitation] = Adiwg_Citation.unpack(hCitation)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return intAssocRes
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# unpack bounding box
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-11-07 original script
|
|
6
|
+
# Stan Smith 2014-04-28 reorganized for json schema 0.3.0
|
|
7
|
+
|
|
8
|
+
module Adiwg_BoundingBox
|
|
9
|
+
|
|
10
|
+
def self.unpack(aBBox)
|
|
11
|
+
|
|
12
|
+
# instance classes needed in script
|
|
13
|
+
intMetadataClass = InternalMetadata.new
|
|
14
|
+
intGeometry = intMetadataClass.newGeometry
|
|
15
|
+
intGeometry[:geoType] = 'BoundingBox'
|
|
16
|
+
|
|
17
|
+
# unpack GeoJSON bounding box elements
|
|
18
|
+
intBBox = intMetadataClass.newBoundingBox
|
|
19
|
+
west = aBBox[0]
|
|
20
|
+
south = aBBox[1]
|
|
21
|
+
east = aBBox[2]
|
|
22
|
+
north = aBBox[3]
|
|
23
|
+
|
|
24
|
+
# validate coordinates if easting +/-180 and northing +/-90
|
|
25
|
+
valid = false
|
|
26
|
+
if (180 >= west) && (west >= -180)
|
|
27
|
+
if (90 >= south) && (south >= -90)
|
|
28
|
+
if (180 >= east) && (east >= -180)
|
|
29
|
+
if (90 >= north) &&(north >= -90)
|
|
30
|
+
valid = true
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# build internal geo element if valid
|
|
37
|
+
if valid
|
|
38
|
+
intBBox[:westLong] = west
|
|
39
|
+
intBBox[:eastLong] = east
|
|
40
|
+
intBBox[:southLat] = south
|
|
41
|
+
intBBox[:northLat] = north
|
|
42
|
+
intGeometry[:geometry] = intBBox
|
|
43
|
+
|
|
44
|
+
return intGeometry
|
|
45
|
+
else
|
|
46
|
+
return nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# unpack browse graphic
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-10-17 original script
|
|
6
|
+
# Stan Smith 2013-11-27 modified to process single browse graphic rather than array
|
|
7
|
+
# Stan Smith 2014-04-28 modified attribute names to match json schema 0.3.0
|
|
8
|
+
|
|
9
|
+
module Adiwg_BrowseGraphic
|
|
10
|
+
|
|
11
|
+
def self.unpack(hBgraphic)
|
|
12
|
+
|
|
13
|
+
# instance classes needed in script
|
|
14
|
+
intMetadataClass = InternalMetadata.new
|
|
15
|
+
intBGraphic = intMetadataClass.newBrowseGraphic
|
|
16
|
+
|
|
17
|
+
# graphic - file name
|
|
18
|
+
if hBgraphic.has_key?('fileName')
|
|
19
|
+
s = hBgraphic['fileName']
|
|
20
|
+
if s != ''
|
|
21
|
+
intBGraphic[:bGName] = s
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# graphic - file description
|
|
26
|
+
if hBgraphic.has_key?('fileDescription')
|
|
27
|
+
s = hBgraphic['fileDescription']
|
|
28
|
+
if s != ''
|
|
29
|
+
intBGraphic[:bGDescription] = s
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# graphic - file type
|
|
34
|
+
if hBgraphic.has_key?('fileType')
|
|
35
|
+
s = hBgraphic['fileType']
|
|
36
|
+
if s != ''
|
|
37
|
+
intBGraphic[:bGType] = s
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# graphic - web link
|
|
42
|
+
if hBgraphic.has_key?('fileUri')
|
|
43
|
+
s = hBgraphic['fileUri']
|
|
44
|
+
if s != ''
|
|
45
|
+
intBGraphic[:bGURI] = s
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
return intBGraphic
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# unpack citation
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-08-26 original script
|
|
6
|
+
# Stan Smith 2014-04-25 modified to support json schema 0.3.0
|
|
7
|
+
# Stan Smith 2014-07-03 resolve require statements using Mdtranslator.reader_module
|
|
8
|
+
# Stan Smith 2014-08-18 changed additionalIdentifier section to identifier schema 0.6.0
|
|
9
|
+
|
|
10
|
+
require ADIWG::Mdtranslator.reader_module('module_dateTime', $response[:readerVersionUsed])
|
|
11
|
+
require ADIWG::Mdtranslator.reader_module('module_responsibleParty', $response[:readerVersionUsed])
|
|
12
|
+
require ADIWG::Mdtranslator.reader_module('module_onlineResource', $response[:readerVersionUsed])
|
|
13
|
+
require ADIWG::Mdtranslator.reader_module('module_resourceIdentifier', $response[:readerVersionUsed])
|
|
14
|
+
|
|
15
|
+
module Adiwg_Citation
|
|
16
|
+
|
|
17
|
+
def self.unpack(hCitation)
|
|
18
|
+
|
|
19
|
+
# instance classes needed in script
|
|
20
|
+
intMetadataClass = InternalMetadata.new
|
|
21
|
+
intCitation = intMetadataClass.newCitation
|
|
22
|
+
|
|
23
|
+
# citation - title
|
|
24
|
+
if hCitation.has_key?('title')
|
|
25
|
+
s = hCitation['title']
|
|
26
|
+
if s != ''
|
|
27
|
+
intCitation[:citTitle] = s
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# citation - date
|
|
32
|
+
if hCitation.has_key?('date')
|
|
33
|
+
aCitDates = hCitation['date']
|
|
34
|
+
unless aCitDates.empty?
|
|
35
|
+
aCitDates.each do |hCitDate|
|
|
36
|
+
if hCitDate.has_key?('date')
|
|
37
|
+
s = hCitDate['date']
|
|
38
|
+
if s != ''
|
|
39
|
+
intDateTime = Adiwg_DateTime.unpack(s)
|
|
40
|
+
if hCitDate.has_key?('dateType')
|
|
41
|
+
s = hCitDate['dateType']
|
|
42
|
+
if s != ''
|
|
43
|
+
intDateTime[:dateType] = s
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
intCitation[:citDate] << intDateTime
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# citation - edition
|
|
54
|
+
if hCitation.has_key?('edition')
|
|
55
|
+
s = hCitation['edition']
|
|
56
|
+
if s != ''
|
|
57
|
+
intCitation[:citEdition] = s
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# citation - responsible party
|
|
62
|
+
if hCitation.has_key?('responsibleParty')
|
|
63
|
+
aRParty = hCitation['responsibleParty']
|
|
64
|
+
unless aRParty.empty?
|
|
65
|
+
aRParty.each do |hRParty|
|
|
66
|
+
intCitation[:citResponsibleParty] << Adiwg_ResponsibleParty.unpack(hRParty)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# citation - presentation form
|
|
72
|
+
if hCitation.has_key?('presentationForm')
|
|
73
|
+
aPForms = hCitation['presentationForm']
|
|
74
|
+
unless aPForms.empty?
|
|
75
|
+
aPForms.each do |pForm|
|
|
76
|
+
intCitation[:citResourceForms] << pForm
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# citation - resource identifiers
|
|
82
|
+
if hCitation.has_key?('identifier')
|
|
83
|
+
aResIds = hCitation['identifier']
|
|
84
|
+
aResIds.each do |hIdentifier|
|
|
85
|
+
unless hIdentifier.empty?
|
|
86
|
+
intCitation[:citResourceIDs] << Adiwg_ResourceIdentifier.unpack(hIdentifier)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# citation - online resources
|
|
92
|
+
if hCitation.has_key?('onlineResource')
|
|
93
|
+
aOlRes = hCitation['onlineResource']
|
|
94
|
+
aOlRes.each do |hOlRes|
|
|
95
|
+
unless hOlRes.empty?
|
|
96
|
+
intCitation[:citOlResources] << Adiwg_OnlineResource.unpack(hOlRes)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
return intCitation
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# unpack contacts
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-08-20 original script
|
|
6
|
+
# Stan Smith 2013-09-25 moved onlineResource to new module
|
|
7
|
+
# Stan Smith 2013-10-21 moved address to new module
|
|
8
|
+
# Stan Smith 2014-04-23 modify for json schema version 0.3.0
|
|
9
|
+
# Stan Smith 2014-04-24 split default contacts to a separate method
|
|
10
|
+
# Stan Smith 2014-05-14 combine phone service types
|
|
11
|
+
# Stan Smith 2014-07-03 added module_path method to support versioning
|
|
12
|
+
|
|
13
|
+
require ADIWG::Mdtranslator.reader_module('module_address', $response[:readerVersionUsed])
|
|
14
|
+
require ADIWG::Mdtranslator.reader_module('module_onlineResource', $response[:readerVersionUsed])
|
|
15
|
+
require ADIWG::Mdtranslator.reader_module('module_phone', $response[:readerVersionUsed])
|
|
16
|
+
|
|
17
|
+
module Adiwg_Contact
|
|
18
|
+
|
|
19
|
+
def self.unpack(hContact)
|
|
20
|
+
|
|
21
|
+
# instance classes needed in script
|
|
22
|
+
intMetadataClass = InternalMetadata.new
|
|
23
|
+
intCont = intMetadataClass.newContact
|
|
24
|
+
|
|
25
|
+
# contact ID
|
|
26
|
+
if hContact.has_key?('contactId')
|
|
27
|
+
s = hContact['contactId']
|
|
28
|
+
if s != ''
|
|
29
|
+
intCont[:contactID] = s
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# individual name
|
|
34
|
+
if hContact.has_key?('individualName')
|
|
35
|
+
s = hContact['individualName']
|
|
36
|
+
if s != ''
|
|
37
|
+
intCont[:indName] = s
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# organization name
|
|
42
|
+
if hContact.has_key?('organizationName')
|
|
43
|
+
s = hContact['organizationName']
|
|
44
|
+
if s != ''
|
|
45
|
+
intCont[:orgName] = s
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# position name
|
|
50
|
+
if hContact.has_key?('positionName')
|
|
51
|
+
s = hContact['positionName']
|
|
52
|
+
if s != ''
|
|
53
|
+
intCont[:position] = s
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# online resources
|
|
58
|
+
if hContact.has_key?('onlineResource')
|
|
59
|
+
aOlRes = hContact['onlineResource']
|
|
60
|
+
aOlRes.each do |hOlRes|
|
|
61
|
+
unless hOlRes.empty?
|
|
62
|
+
intCont[:onlineRes] << Adiwg_OnlineResource.unpack(hOlRes)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# contact instructions
|
|
68
|
+
if hContact.has_key?('contactInstructions')
|
|
69
|
+
s = hContact['contactInstructions']
|
|
70
|
+
if s != ''
|
|
71
|
+
intCont[:contactInstructions] = s
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# phones - all service types
|
|
76
|
+
if hContact.has_key?('phoneBook')
|
|
77
|
+
aPhones = hContact['phoneBook']
|
|
78
|
+
aPhones.each do |hPhone|
|
|
79
|
+
intCont[:phones].concat(Adiwg_Phone.unpack(hPhone))
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# address
|
|
84
|
+
if hContact.has_key?('address')
|
|
85
|
+
conAddress = hContact['address']
|
|
86
|
+
intCont[:address] = Adiwg_Address.unpack(conAddress)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
return intCont
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def self.setDefaultContacts()
|
|
94
|
+
|
|
95
|
+
# add default contacts
|
|
96
|
+
intMetadataClass = InternalMetadata.new
|
|
97
|
+
aDefContacts = Array.new
|
|
98
|
+
|
|
99
|
+
# contact to support biological extensions
|
|
100
|
+
intCont = intMetadataClass.newContact
|
|
101
|
+
intCont[:contactID] = 'ADIwgBio'
|
|
102
|
+
intCont[:orgName] = 'National Biological Information Infrastructure (NBII)'
|
|
103
|
+
aDefContacts << intCont
|
|
104
|
+
|
|
105
|
+
# contact to support doi (digital object identifier)
|
|
106
|
+
intCont = intMetadataClass.newContact
|
|
107
|
+
intCont[:contactID] = 'ADIwgDOI'
|
|
108
|
+
intCont[:orgName] = 'International DOI Foundation (IDF)'
|
|
109
|
+
|
|
110
|
+
intOlRes = intMetadataClass.newOnlineResource
|
|
111
|
+
intOlRes[:olResURI] = 'http://www.doi.org'
|
|
112
|
+
intCont[:onlineRes] << intOlRes
|
|
113
|
+
|
|
114
|
+
aDefContacts << intCont
|
|
115
|
+
|
|
116
|
+
return aDefContacts
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# repack coordinates
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-11-07 original script
|
|
6
|
+
# Stan Smith 2013-11-13 added getDimension
|
|
7
|
+
# Stan Smith 2014-05-23 added getLevels
|
|
8
|
+
|
|
9
|
+
module Adiwg_Coordinates
|
|
10
|
+
|
|
11
|
+
# repack coordinate array into single string for ISO
|
|
12
|
+
def self.unpack(aCoords)
|
|
13
|
+
s = ''
|
|
14
|
+
i = 0
|
|
15
|
+
coordCount = aCoords.length
|
|
16
|
+
aCoords.each do |coord|
|
|
17
|
+
if coord.kind_of?(Array)
|
|
18
|
+
s = s + unpack(coord)
|
|
19
|
+
else
|
|
20
|
+
i += 1
|
|
21
|
+
s = s + coord.to_s
|
|
22
|
+
if i < coordCount
|
|
23
|
+
s = s + ','
|
|
24
|
+
end
|
|
25
|
+
s = s + ' '
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
return s
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# get the number of dimensions in a coordinate array
|
|
33
|
+
def self.getDimension(aCoords)
|
|
34
|
+
if aCoords[0].kind_of?(Array)
|
|
35
|
+
coordDim = getDimension(aCoords[0])
|
|
36
|
+
else
|
|
37
|
+
coordDim = aCoords.length
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
return coordDim
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# get the number of levels in the coordinate array
|
|
44
|
+
def self.getLevels(aCoords)
|
|
45
|
+
i = 1
|
|
46
|
+
if aCoords[0].kind_of?(Array)
|
|
47
|
+
i = i + getLevels(aCoords[0])
|
|
48
|
+
end
|
|
49
|
+
return i
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# unpack data quality
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-11-26 original script
|
|
6
|
+
# Stan Smith 2014-07-03 resolve require statements using Mdtranslator.reader_module
|
|
7
|
+
|
|
8
|
+
require ADIWG::Mdtranslator.reader_module('module_lineage', $response[:readerVersionUsed])
|
|
9
|
+
|
|
10
|
+
module Adiwg_DataQuality
|
|
11
|
+
|
|
12
|
+
def self.unpack(hDataQual)
|
|
13
|
+
|
|
14
|
+
# instance classes needed in script
|
|
15
|
+
intMetadataClass = InternalMetadata.new
|
|
16
|
+
intDataQual = intMetadataClass.newDataQuality
|
|
17
|
+
|
|
18
|
+
# data quality - scope
|
|
19
|
+
if hDataQual.has_key?('scope')
|
|
20
|
+
s = hDataQual['scope']
|
|
21
|
+
if s != ''
|
|
22
|
+
intDataQual[:dataScope] = s
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# data quality - report
|
|
27
|
+
# on hold
|
|
28
|
+
|
|
29
|
+
# data quality - lineage
|
|
30
|
+
if hDataQual.has_key?('lineage')
|
|
31
|
+
hLineage = hDataQual['lineage']
|
|
32
|
+
unless hLineage.empty?
|
|
33
|
+
intDataQual[:dataLineage] = Adiwg_Lineage.unpack(hLineage)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
return intDataQual
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# unpack dateTime
|
|
2
|
+
# Reader - ADIwg JSON V1 to internal data structure
|
|
3
|
+
|
|
4
|
+
# History:
|
|
5
|
+
# Stan Smith 2013-12-11 original script
|
|
6
|
+
|
|
7
|
+
require 'module_dateTimeFun'
|
|
8
|
+
|
|
9
|
+
module Adiwg_DateTime
|
|
10
|
+
|
|
11
|
+
def self.unpack(sDateTime)
|
|
12
|
+
|
|
13
|
+
# instance classes needed in script
|
|
14
|
+
intMetadataClass = InternalMetadata.new
|
|
15
|
+
|
|
16
|
+
# dateTime
|
|
17
|
+
intDateTime = intMetadataClass.newDateTime
|
|
18
|
+
|
|
19
|
+
aDateTimeReturn = AdiwgDateTimeFun.dateTimeFromString(sDateTime)
|
|
20
|
+
intDateTime[:dateTime] = aDateTimeReturn[0]
|
|
21
|
+
intDateTime[:dateResolution] = aDateTimeReturn[1]
|
|
22
|
+
|
|
23
|
+
return intDateTime
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|