adiwg-mdtranslator 0.8.2 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/bin/mdtranslator +1 -1
  5. data/lib/adiwg/mdtranslator/readers/adiwgJson/readme.md +19 -0
  6. data/lib/adiwg/mdtranslator/version.rb +6 -1
  7. data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadata.rb +101 -56
  8. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_associationType.rb +2 -2
  9. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_characterSet.rb +2 -2
  10. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_classification.rb +2 -2
  11. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_datatype.rb +2 -2
  12. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_dateType.rb +2 -2
  13. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_initiativeType.rb +2 -2
  14. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_keywordType.rb +2 -2
  15. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_maintenanceFrequency.rb +2 -2
  16. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_mediumFormat.rb +2 -2
  17. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_mediumName.rb +2 -2
  18. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_onlineFunction.rb +2 -2
  19. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_presentationForm.rb +2 -2
  20. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_progress.rb +2 -2
  21. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_restriction.rb +2 -2
  22. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_role.rb +2 -2
  23. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_scope.rb +2 -2
  24. data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_spatialRepresentationType.rb +2 -2
  25. data/lib/adiwg/mdtranslator/writers/iso19115_2/readme.md +15 -0
  26. data/lib/adiwg/mdtranslator.rb +31 -0
  27. data/mdtranslator.rb +1 -1
  28. data/test/adiwgJson_min_test_example.json +28 -0
  29. data/test/dev.rb +8 -3
  30. data/test/tc_translation.rb +46 -21
  31. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a21e023a3df66e70b5dcbf88200bf0a31ccd870b
4
- data.tar.gz: 1f5fdf7561ba3996fc6d078a02322128975d1c35
3
+ metadata.gz: 743d6fa5ca6424c64685a27c08da9923ed2a1594
4
+ data.tar.gz: c5035035e07dd6f57a404915cb5cacb135fe061f
5
5
  SHA512:
6
- metadata.gz: 42039c21df08fc136684a03e9f11d7277d730244629128d64142bdb21858cd526a6c5e0c7ef995eb9bcc4f402234aafb178e1ef6b4b70801e33f4bb84e8b636d
7
- data.tar.gz: ee607ee29405df707a0df243969fd58347b1989a2f839e0f6ebace00425e699d64a190537fcdd5a3a16d822488eb548fb0230bf9441f800372f1a2f2ca2f352e
6
+ metadata.gz: 621006a98dbbe19d6bb2b5e6669ca7c5968016a55e63a21ddc4ab1e6b3aa6f972456cbbe5d2617fe42194d39d6fffd30b1bbb2f6d6b3e5fced7011a766e3a364
7
+ data.tar.gz: 957ba7ca86c82aebf87a02c5291b46fd7824507a2c2597c13edf44063158c32307b165708511456cd4b9fe41fa9af3d46341ebc0f3ef3de5a36073de5b350016
data/.gitignore CHANGED
@@ -15,9 +15,13 @@ rdoc
15
15
  spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
+ test/adiwgJson_full_test_example.json
19
+ test/adiwgJson_min_test_example.json
20
+ test/dev.rb
18
21
  tmp
19
22
  *.bundle
20
23
  *.so
21
24
  *.o
22
25
  *.a
23
26
  mkmf.log
27
+
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "test/schemas/v0_8"]
2
+ path = test/schemas/v0_8
3
+ url = https://github.com/adiwg/adiwg-json-schemas.git
data/bin/mdtranslator CHANGED
@@ -31,7 +31,7 @@ class Mdtranslator < Thor
31
31
  method_option :validate, :aliases => '-v', :desc => 'Specify level of validation to be performed', :enum => %w{none normal strict}, :default => 'normal'
32
32
  method_option :showAllTags, :aliases => '-s', :desc => 'Include tags for unused attributes', :type => :boolean, :default => false
33
33
  method_option :messages, :aliases => '-m', :desc => 'On error return messages as formatted text or json object', :enum => %w{json text}, :default => 'text'
34
- method_option :returnObject, :aliases => '-o', :desc => 'Return full JSON object generated by translator', :type => :boolean, :default => false
34
+ # method_option :returnObject, :aliases => '-o', :desc => 'Return full JSON object generated by translator', :type => :boolean, :default => false
35
35
 
36
36
  # accept command and options
37
37
  def translate(file)
@@ -0,0 +1,19 @@
1
+
2
+ ## adiwgJson
3
+
4
+ ### Supported versions
5
+
6
+ > 0.8.0
7
+
8
+ ### Reader for ADIwg JSON metadata format
9
+
10
+ The adiwgJson format is a simple JSON format for documenting and exchanging information
11
+ about scientific projects and data. The Alaska Data Integration working group (ADIwg) wrote the
12
+ standard to support translation to complex standards such as the ISO 19115-2 Geographic Metadata standard
13
+ and FGDC's Content Standard for Digital Geospatial Metadata. The adiwgJson standard
14
+ remains independent of any published standards while comprehensive enough to support translation
15
+ to many. The adiwgJson standard is also a convenient format to exchange directly with other organizations as
16
+ the JSON structure is easier read and ingest by many programming languages.
17
+
18
+ The adiwg format is fully documented on the interactive
19
+ [adiwgJson Viewer](http://jlblcc.github.io/json-schema-viewer/) website.
@@ -8,11 +8,16 @@
8
8
  # ... removed resourceURI from resourceInfo section of adiwgJson
9
9
  # 0.8.2 2014-10-09 added the 'version' command to the CLI for returning the
10
10
  # ... mdTranslator version number
11
+ # 0.8.3 2014-10-10 added readme files in kramdown format for each reader and writer
12
+ # 0.8.4 2014-10-10 modified writers to pass minimum metadata input test
13
+ # ... test were added to handle a missing metadata > metadataInfo
14
+ # ... block in the input.
15
+ # 0.8.5 2014-10-11 added methods to pass content of readme files
11
16
 
12
17
  module ADIWG
13
18
  module Mdtranslator
14
19
  # current mdtranslator version
15
- VERSION = "0.8.2"
20
+ VERSION = "0.8.5"
16
21
  end
17
22
  end
18
23
 
@@ -19,6 +19,8 @@
19
19
  # ... an MD_Identifier class. To support version 0.8.0 json.
20
20
  # Stan Smith 2014-10-07 changed source of dataSetURI to
21
21
  # ... metadata: {resourceInfo: {citation: {citOlResources[0]: {olResURI:}}}}
22
+ # Stan Smith 2014-10-10 modified to pass minimum metadata input test
23
+ # ... test were added to handle a missing metadata > metadataInfo block in the input
22
24
 
23
25
  require 'code_characterSet'
24
26
  require 'code_scope'
@@ -75,14 +77,22 @@ class MI_Metadata
75
77
 
76
78
  # metadata information - file identifier - default
77
79
  # the internal object stores the file identifier as a MD_Identifier to support 19115-1
80
+ # hMetaInfo => metadata > metadataInfo
81
+ # hMetaInfo[:metadataId] => MD_Identifier
78
82
  # ISO 19115-2 only support the file identifier as a character string
79
83
  @xml.tag!('gmd:fileIdentifier') do
80
- hMetadataId = hMetaInfo[:metadataId]
81
- if hMetadataId[:identifier].nil?
84
+ s = nil
85
+ if hMetaInfo
86
+ if hMetaInfo[:metadataId]
87
+ s = hMetaInfo[:metadataId][:identifier]
88
+ unless s.nil?
89
+ @xml.tag!('gco:CharacterString',s)
90
+ end
91
+ end
92
+ end
93
+ if s.nil?
82
94
  # generate fileIdentifier if one not provided
83
95
  @xml.tag!('gco:CharacterString',UUIDTools::UUID.random_create.to_s)
84
- else
85
- @xml.tag!('gco:CharacterString',hMetadataId[:identifier])
86
96
  end
87
97
  end
88
98
 
@@ -100,67 +110,88 @@ class MI_Metadata
100
110
 
101
111
  # metadata information - parent identifier
102
112
  # the internal object stores the parent identifier as a CI_Citation to support 19115-1
113
+ # hMetaInfo => metadata > metadataInfo
114
+ # hMetaInfo[:parentMetadata] => hParent => CI_Citation
103
115
  # ISO 19115-2 only support the parent identifier as a character string
104
- hParent = hMetaInfo[:parentMetadata]
105
- if !hParent.empty?
106
- @xml.tag!('gmd:parentIdentifier') do
107
- s = hParent[:citTitle]
108
- aResIds = hParent[:citResourceIDs]
109
- if aResIds.length > 0
110
- s += ' ids: | '
111
- aResIds.each do |resource|
112
- s += resource[:identifierType] + ': ' + resource[:identifier] + ' | '
116
+ s = nil
117
+ if hMetaInfo
118
+ if hMetaInfo[:parentMetadata]
119
+ hParent = hMetaInfo[:parentMetadata]
120
+ if !hParent.empty?
121
+ s = hParent[:citTitle]
122
+ aResIds = hParent[:citResourceIDs]
123
+ if aResIds.length > 0
124
+ s += ' ids: | '
125
+ aResIds.each do |resource|
126
+ s += resource[:identifierType] + ': ' + resource[:identifier] + ' | '
127
+ end
113
128
  end
114
129
  end
130
+ end
131
+ end
132
+ if !s.nil?
133
+ @xml.tag!('gmd:parentIdentifier') do
115
134
  @xml.tag!('gco:CharacterString',s)
116
135
  end
117
136
  elsif $showAllTags
118
137
  @xml.tag!('gmd:parentIdentifier')
119
138
  end
120
139
 
121
- # metadata information - file hierarchy - default dataset
122
- aHierarchy = hMetaInfo[:metadataScope]
123
- if aHierarchy.empty?
140
+ # metadata information - file hierarchy - defaults to 'dataset'
141
+ fileHierarchy = false
142
+ if hMetaInfo
143
+ if hMetaInfo[:metadataScope]
144
+ aHierarchy = hMetaInfo[:metadataScope]
145
+ unless aHierarchy.empty?
146
+ fileHierarchy = true
147
+ aHierarchy.each do |hierarchy|
148
+ @xml.tag!('gmd:hierarchyLevel') do
149
+ scopeCode.writeXML(hierarchy)
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ if !fileHierarchy
124
156
  @xml.tag!('gmd:hierarchyLevel') do
125
157
  scopeCode.writeXML('dataset')
126
158
  end
127
- else
128
- aHierarchy.each do |hierarchy|
129
- @xml.tag!('gmd:hierarchyLevel') do
130
- scopeCode.writeXML(hierarchy)
131
- end
132
- end
133
159
  end
134
160
 
135
161
  # metadata information - metadata custodian - required
136
- aCustodians = hMetaInfo[:metadataCustodians]
137
- if aCustodians.empty?
138
- @xml.tag!('gmd:contact', {'gco:nilReason' => 'missing'})
139
- else
140
- aCustodians.each do |hCustodian|
141
- @xml.tag!('gmd:contact') do
142
- rPartyClass.writeXML(hCustodian)
162
+ custodians = false
163
+ if hMetaInfo
164
+ if hMetaInfo[:metadataCustodians]
165
+ aCustodians = hMetaInfo[:metadataCustodians]
166
+ unless aCustodians.empty?
167
+ custodians = true
168
+ aCustodians.each do |hCustodian|
169
+ @xml.tag!('gmd:contact') do
170
+ rPartyClass.writeXML(hCustodian)
171
+ end
172
+ end
143
173
  end
144
174
  end
145
175
  end
176
+ if !custodians
177
+ @xml.tag!('gmd:contact', {'gco:nilReason' => 'missing'})
178
+ end
146
179
 
147
180
  # metadata information - date stamp - required - default to now()
148
- @xml.tag!('gmd:dateStamp') do
149
-
150
- # if date not supplied, fill with today's date
151
- hDate = hMetaInfo[:metadataCreateDate]
152
- if hDate.empty?
153
- mDate = AdiwgDateTimeFun.stringDateFromDateTime(DateTime.now, 'YMD')
154
- else
155
- mDateTime = hDate[:dateTime]
156
- mDateRes = hDate[:dateResolution]
157
- if mDateTime.nil?
158
- mDate = AdiwgDateTimeFun.stringDateFromDateTime(DateTime.now, 'YMD')
159
- else
160
- mDate = AdiwgDateTimeFun.stringDateFromDateTime(mDateTime, mDateRes)
181
+ mDate = AdiwgDateTimeFun.stringDateFromDateTime(DateTime.now, 'YMD')
182
+ if hMetaInfo
183
+ if hMetaInfo[:metadataCreateDate]
184
+ hDate = hMetaInfo[:metadataCreateDate]
185
+ unless hDate.empty?
186
+ mDateTime = hDate[:dateTime]
187
+ mDateRes = hDate[:dateResolution]
188
+ if mDateTime.nil?
189
+ mDate = AdiwgDateTimeFun.stringDateFromDateTime(mDateTime, mDateRes)
190
+ end
161
191
  end
162
192
  end
163
-
193
+ end
194
+ @xml.tag!('gmd:dateStamp') do
164
195
  @xml.tag!('gco:Date',mDate)
165
196
  end
166
197
 
@@ -230,14 +261,21 @@ class MI_Metadata
230
261
  end
231
262
 
232
263
  # metadata information - metadata extension info
233
- aExtensions = hMetaInfo[:extensions]
234
- if !aExtensions.empty?
235
- aExtensions.each do |hExtension|
236
- @xml.tag!('gmd:metadataExtensionInfo') do
237
- mdExtClass.writeXML(hExtension)
264
+ extensions = false
265
+ if hMetaInfo
266
+ if hMetaInfo[:extensions]
267
+ aExtensions = hMetaInfo[:extensions]
268
+ if !aExtensions.empty?
269
+ extensions = true
270
+ aExtensions.each do |hExtension|
271
+ @xml.tag!('gmd:metadataExtensionInfo') do
272
+ mdExtClass.writeXML(hExtension)
273
+ end
274
+ end
238
275
  end
239
276
  end
240
- elsif $showAllTags
277
+ end
278
+ if !extensions && $showAllTags
241
279
  @xml.tag!('gmd:metadataExtensionInfo')
242
280
  end
243
281
 
@@ -273,17 +311,24 @@ class MI_Metadata
273
311
  end
274
312
  end
275
313
  elsif $showAllTags
276
- xml.tag!('gmd:dataQualityInfo')
314
+ @xml.tag!('gmd:dataQualityInfo')
277
315
  end
278
316
 
279
317
  # metadata information - metadata maintenance
280
- hMetaMaint = hMetaInfo[:maintInfo]
281
- if !hMetaMaint.empty?
282
- @xml.tag!('gmd:metadataMaintenance') do
283
- metaMaintClass.writeXML(hMetaMaint)
318
+ maintInfo = false
319
+ if hMetaInfo
320
+ if hMetaInfo[:maintInfo]
321
+ hMetaMaint = hMetaInfo[:maintInfo]
322
+ if !hMetaMaint.empty?
323
+ maintInfo = true
324
+ @xml.tag!('gmd:metadataMaintenance') do
325
+ metaMaintClass.writeXML(hMetaMaint)
326
+ end
327
+ end
284
328
  end
285
- elsif $showAllTags
286
- xml.tag!('gmd:metadataMaintenance')
329
+ end
330
+ if !maintInfo && $showAllTags
331
+ @xml.tag!('gmd:metadataMaintenance')
287
332
  end
288
333
 
289
334
  end
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-10-21 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class DS_AssociationTypeCode
8
9
  def initialize(xml)
@@ -17,8 +18,7 @@ class DS_AssociationTypeCode
17
18
  when 'source' then codeID = '004'
18
19
  when 'stereoMate' then codeID = '005'
19
20
  else
20
- codeName = 'INVALID ASSOCIATION TYPE CODE'
21
- codeID = '999'
21
+ codeID = 'non-ISO codeName'
22
22
  end
23
23
 
24
24
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-08-09 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_CharacterSetCode
8
9
  def initialize(xml)
@@ -40,8 +41,7 @@ class MD_CharacterSetCode
40
41
  when 'big5' then codeID = '028'
41
42
  when 'GB2312' then codeID = '029'
42
43
  else
43
- codeName = 'INVALID CHARACTER SET'
44
- codeID = '999'
44
+ codeID = 'non-ISO codeName'
45
45
  end
46
46
 
47
47
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-10-21 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_ClassificationCode
8
9
  def initialize(xml)
@@ -17,8 +18,7 @@ class MD_ClassificationCode
17
18
  when 'secret' then codeID = '004'
18
19
  when 'topSecret' then codeID = '005'
19
20
  else
20
- codeName = 'INVALID CLASSIFICATION CODE'
21
- codeID = '999'
21
+ codeID = 'non-ISO codeName'
22
22
  end
23
23
 
24
24
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-10-21 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_DatatypeCode
8
9
  def initialize(xml)
@@ -27,8 +28,7 @@ class MD_DatatypeCode
27
28
  when 'integer' then codeID = '014'
28
29
  when 'association' then codeID = '015'
29
30
  else
30
- codeName = 'INVALID DATATYPE'
31
- codeID = '999'
31
+ codeID = 'non-ISO codeName'
32
32
  end
33
33
 
34
34
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-08-09 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class CI_DateTypeCode
8
9
 
@@ -16,8 +17,7 @@ class CI_DateTypeCode
16
17
  when 'publication' then codeID = '002'
17
18
  when 'revision' then codeID = '003'
18
19
  else
19
- codeName = 'INVALID DATE TYPE'
20
- codeID = '999'
20
+ codeID = 'non-ISO codeName'
21
21
  end
22
22
 
23
23
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2014-05-21 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class DS_InitiativeTypeCode
8
9
  def initialize(xml)
@@ -17,8 +18,7 @@ class DS_InitiativeTypeCode
17
18
  when 'experiment' then codeID = '004'
18
19
  when 'investigation' then codeID = '005'
19
20
  else
20
- codeName = 'INVALID CLASSIFICATION CODE'
21
- codeID = '999'
21
+ codeID = 'non-ISO codeName'
22
22
  end
23
23
 
24
24
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-09-18 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_KeywordTypeCode
8
9
 
@@ -20,8 +21,7 @@ class MD_KeywordTypeCode
20
21
  when 'taxon' then codeID = '006'
21
22
  when 'instrument' then codeID = 'ADIwg-001'
22
23
  else
23
- codeName = 'INVALID KEYWORD TYPE'
24
- codeID = '999'
24
+ codeID = 'non-ISO codeName'
25
25
  end
26
26
 
27
27
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-10-21 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_MaintenanceFrequencyCode
8
9
  def initialize(xml)
@@ -24,8 +25,7 @@ class MD_MaintenanceFrequencyCode
24
25
  when 'notPlanned' then codeID = '011'
25
26
  when 'unknown' then codeID = '012'
26
27
  else
27
- codeName = 'INVALID MAINTENANCE FREQUENCY'
28
- codeID = '999'
28
+ codeID = 'non-ISO codeName'
29
29
  end
30
30
 
31
31
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-09-24 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_MediumFormatCode
8
9
 
@@ -19,8 +20,7 @@ class MD_MediumFormatCode
19
20
  when 'iso9660RockRidge' then codeID = '005'
20
21
  when 'iso9660AppleHFS' then codeID = '006'
21
22
  else
22
- codeName = 'INVALID MEDIUM FORMAT TYPE'
23
- codeID = '999'
23
+ codeID = 'non-ISO codeName'
24
24
  end
25
25
 
26
26
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-09-24 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_MediumNameCode
8
9
 
@@ -31,8 +32,7 @@ class MD_MediumNameCode
31
32
  when 'telephoneLink' then codeID = '017'
32
33
  when 'hardcopy' then codeID = '018'
33
34
  else
34
- codeName = 'INVALID MEDIUM NAME'
35
- codeID = '999'
35
+ codeID = 'non-ISO codeName'
36
36
  end
37
37
 
38
38
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-09-26 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class CI_OnLineFunctionCode
8
9
 
@@ -18,8 +19,7 @@ class CI_OnLineFunctionCode
18
19
  when 'order' then codeID = '004'
19
20
  when 'search' then codeID = '005'
20
21
  else
21
- codeName = 'INVALID ONLINE FUNCTION CODE'
22
- codeID = '999'
22
+ codeID = 'non-ISO codeName'
23
23
  end
24
24
 
25
25
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-11-20 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class CI_PresentationFormCode
8
9
  def initialize(xml)
@@ -26,8 +27,7 @@ class CI_PresentationFormCode
26
27
  when 'videoDigital' then codeID = '013'
27
28
  when 'videoHardcopy' then codeID = '014'
28
29
  else
29
- codeName = 'INVALID PRESENTATION FORM SET'
30
- codeID = '999'
30
+ codeID = 'non-ISO codeName'
31
31
  end
32
32
 
33
33
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-08-26 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_ProgressCode
8
9
  def initialize(xml)
@@ -20,8 +21,7 @@ class MD_ProgressCode
20
21
  when 'required' then codeID = '006'
21
22
  when 'underDevelopment' then codeID = '007'
22
23
  else
23
- codeName = 'INVALID ROLE CODE'
24
- codeID = '999'
24
+ codeID = 'non-ISO codeName'
25
25
  end
26
26
 
27
27
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-10-21 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_RestrictionCode
8
9
  def initialize(xml)
@@ -20,8 +21,7 @@ class MD_RestrictionCode
20
21
  when 'restricted' then codeID = '007'
21
22
  when 'otherRestrictions' then codeID = '008'
22
23
  else
23
- codeName = 'INVALID RESTRICTION'
24
- codeID = '999'
24
+ codeID = 'non-ISO codeName'
25
25
  end
26
26
 
27
27
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-08-09 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class CI_RoleCode
8
9
  def initialize(xml)
@@ -24,8 +25,7 @@ class CI_RoleCode
24
25
  when 'publisher' then codeID = '010'
25
26
  when 'author' then codeID = '011'
26
27
  else
27
- codeName = 'INVALID ROLE CODE'
28
- codeID = '999'
28
+ codeID = 'non-ISO codeName'
29
29
  end
30
30
 
31
31
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-08-09 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_ScopeCode
8
9
  def initialize(xml)
@@ -28,8 +29,7 @@ class MD_ScopeCode
28
29
  when 'model' then codeID = '015'
29
30
  when 'tile' then codeID = '016'
30
31
  else
31
- codeName = 'INVALID SCOPE CODE'
32
- codeID = '999'
32
+ codeID = 'non-ISO codeName'
33
33
  end
34
34
 
35
35
  # write xml
@@ -3,6 +3,7 @@
3
3
  # from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
4
4
  # History:
5
5
  # Stan Smith 2013-10-21 original script
6
+ # Stan Smith 2014-10-15 allow non-ISO codesNames to be rendered
6
7
 
7
8
  class MD_SpatialRepresentationTypeCode
8
9
  def initialize(xml)
@@ -18,8 +19,7 @@ class MD_SpatialRepresentationTypeCode
18
19
  when 'stereoModel' then codeID = '005'
19
20
  when 'video' then codeID = '006'
20
21
  else
21
- codeName = 'INVALID SPATIAL REPRESENTATION TYPE'
22
- codeID = '999'
22
+ codeID = 'non-ISO codeName'
23
23
  end
24
24
 
25
25
  # write xml
@@ -0,0 +1,15 @@
1
+
2
+ ## iso19115_2
3
+
4
+ ### Writer for ISO 19115-2:2009 Geographic Metadata
5
+
6
+ The mdTranslator iso19115_2 writer implements about 65% of the for ISO 19115-2 standard.
7
+ Efforts were made to include all elements of the ISO standard that support general data
8
+ descriptions to ensure health and robust project and data metadata records can be created.
9
+ The two significant sections not supported by the writer are the Feature Catalogue and
10
+ 'quantitative' Data Quality sections.
11
+
12
+ The Feature Catalogue section (which contains entity and attribute
13
+ information) is saved as separate file in 19115-2. This inconvenient implementation was
14
+ corrected in the ISO 19115-1:2014 revision and will be supported in the
15
+ iso19115_1 writer.
@@ -9,6 +9,8 @@
9
9
  # Stan Smith 2014-07-23 moved all validations to readers/adiwg/adiwg_validator.rb
10
10
  # ... each reader will have it's own validator
11
11
  # Stan Smith 2014-09-26 added processing of minor release numbers
12
+ # Stan Smith 2014-10-10 added method to return path to readers and writers
13
+ # Stan Smith 2014-10-11 added methods to return content of readme files
12
14
 
13
15
  # add main directories to load_path
14
16
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'mdtranslator'))
@@ -92,6 +94,35 @@ module ADIWG
92
94
  return file
93
95
  end
94
96
 
97
+ # return path to readers and writers
98
+ def self.path_to_resources
99
+ File.join(File.dirname(File.expand_path(__FILE__)),'mdtranslator')
100
+ end
101
+
102
+ # return reader readme text
103
+ def self.get_reader_readme(reader)
104
+ readmeText = 'No text found'
105
+ path = File.join(path_to_resources, 'readers', reader, 'readme.md')
106
+ if File.exist?(path)
107
+ file = File.open(path, 'r')
108
+ readmeText = file.read
109
+ file.close
110
+ end
111
+ return readmeText
112
+ end
113
+
114
+ # return writer readme text
115
+ def self.get_writer_readme(writer)
116
+ readmeText = 'No text found'
117
+ path = File.join(path_to_resources, 'writers', writer, 'readme.md')
118
+ if File.exist?(path)
119
+ file = File.open(path, 'r')
120
+ readmeText = file.read
121
+ file.close
122
+ end
123
+ return readmeText
124
+ end
125
+
95
126
  end
96
127
 
97
128
  end
data/mdtranslator.rb CHANGED
@@ -35,7 +35,7 @@ class Mdtranslator < Thor
35
35
  method_option :validate, :aliases => '-v', :desc => 'Specify level of validation to be performed', :enum => %w{none normal strict}, :default => 'normal'
36
36
  method_option :showAllTags, :aliases => '-s', :desc => 'Include tags for unused attributes', :type => :boolean, :default => false
37
37
  method_option :messages, :aliases => '-m', :desc => 'On error return messages as formatted text or json object', :enum => %w{json text}, :default => 'text'
38
- method_option :returnObject, :aliases => '-o', :desc => 'Return full JSON object generated by translator', :type => :boolean, :default => false
38
+ # method_option :returnObject, :aliases => '-o', :desc => 'Return full JSON object generated by translator', :type => :boolean, :default => false
39
39
 
40
40
  # accept command and options
41
41
  def translate(file)
@@ -0,0 +1,28 @@
1
+ {
2
+ "version": {
3
+ "name": "adiwgJson",
4
+ "version": "0.8.1"
5
+ },
6
+ "contact": [
7
+ {
8
+ "contactId": "1",
9
+ "organizationName": "US Geological Survey - Alaska Science Center"
10
+ }
11
+ ],
12
+ "metadata": {
13
+ "resourceInfo": {
14
+ "citation": {
15
+ "title": "Real-Time Permafrost and Climate Monitoring Network - Arctic Alaska",
16
+ "date": [
17
+ {
18
+ "date": "2012-12-21",
19
+ "dateType": "revision"
20
+ }
21
+ ]
22
+ },
23
+ "abstract": "DOI is developing a long-term permafrost monitoring network.",
24
+ "status": "onGoing",
25
+ "language": ["eng; USA","esp; MEX"]
26
+ }
27
+ }
28
+ }
data/test/dev.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # MdTranslator - code to test mdtranslator from Ruby Terminal during development
2
2
 
3
- # History:
4
- # Stan Smith 2014-07-02 original script
5
-
6
3
  # uncomment next 2 lines to run code (not gem) ....
7
4
  lib = File.expand_path('lib')
8
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -29,4 +26,12 @@ puts writerOut.to_s
29
26
  # pp writerOut
30
27
  puts '---------------------========================END==========================---------------------------'
31
28
 
29
+ # # test for resource path
30
+ # puts ADIWG::Mdtranslator.path_to_resources
31
+
32
+ # # test reader readme
33
+ # puts ADIWG::Mdtranslator.get_reader_readme('adiwgJson')
34
+ # puts '================================================='
35
+ # puts ADIWG::Mdtranslator.get_writer_readme('iso19115_2')
36
+
32
37
  puts 'test script has completed'
@@ -5,27 +5,52 @@
5
5
  # Josh Bradley 2014-09-28 updated to use test/unit
6
6
 
7
7
  require 'minitest/autorun'
8
+ require 'json'
8
9
  require File.join(File.expand_path('..', __FILE__),'..','lib', 'adiwg-mdtranslator.rb')
9
10
 
10
- class TestTranslation < MiniTest::Unit::TestCase
11
- def test_ouput_success
12
- # read test adiwg full json test
13
- file = File.open(File.join(File.dirname(__FILE__),'adiwgJson_full_test_example.json'), 'r')
14
- jsonObj = file.read
15
- file.close
16
-
17
- # call opening module in mdTranslator
18
- reader = 'adiwgJson'
19
- writer = 'iso19115_2'
20
- metadata = ADIWG::Mdtranslator.translate(jsonObj,reader,writer,'normal','true')
21
-
22
- assert_equal('json',metadata[:readerFormat])
23
- assert metadata[:readerStructurePass]
24
- assert_equal(reader,metadata[:readerName])
25
- #assert_equal(ADIWG::Mdtranslator::VERSION,metadata[:readerVersionUsed])
26
- assert metadata[:readerValidationPass]
27
- assert_equal(writer,metadata[:writerName])
28
- assert metadata[:writerPass]
29
- refute_nil metadata[:writerOutput]
30
- end
11
+ class TestTranslation_v0_8 < MiniTest::Unit::TestCase
12
+ @@reader = 'adiwgJson'
13
+ @@writer = 'iso19115_2'
14
+
15
+ def test_ouput_success
16
+ # read test adiwg full json test
17
+ file = File.open(File.join(File.dirname(__FILE__),'schemas','v0_8','examples','full_example.json'), 'r')
18
+ jsonObj = file.read
19
+ file.close
20
+
21
+ # call opening module in mdTranslator
22
+
23
+ metadata = ADIWG::Mdtranslator.translate(jsonObj,@@reader,@@writer,'normal','true')
24
+ version = JSON.parse(jsonObj)['version']['version'].split('.')
25
+
26
+ assert_equal('json',metadata[:readerFormat])
27
+ assert metadata[:readerStructurePass]
28
+ assert_equal(@@reader,metadata[:readerName])
29
+ #major version
30
+ assert_equal(version[0],metadata[:readerVersionUsed].split('.')[0])
31
+ #minor version
32
+ assert_equal(version[1],metadata[:readerVersionUsed].split('.')[1])
33
+ assert metadata[:readerValidationPass]
34
+ assert_equal(@@writer,metadata[:writerName])
35
+ assert metadata[:writerPass]
36
+ refute_nil metadata[:writerOutput]
37
+ end
38
+
39
+ def test_minimum
40
+ # read test adiwg minimum json test
41
+ file = File.open(File.join(File.dirname(__FILE__),'schemas','v0_8','examples','minimum_example.json'), 'r')
42
+ jsonObj = file.read
43
+ file.close
44
+
45
+ # call opening module in mdTranslator
46
+ metadata = ADIWG::Mdtranslator.translate(jsonObj,@@reader,@@writer,'normal','true')
47
+
48
+ assert_equal('json',metadata[:readerFormat])
49
+ assert metadata[:readerStructurePass]
50
+ assert_equal(@@reader,metadata[:readerName])
51
+ assert metadata[:readerValidationPass]
52
+ assert_equal(@@writer,metadata[:writerName])
53
+ assert metadata[:writerPass]
54
+ refute_nil metadata[:writerOutput]
55
+ end
31
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adiwg-mdtranslator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stan Smith
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-10 00:00:00.000000000 Z
12
+ date: 2014-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -151,6 +151,7 @@ extensions: []
151
151
  extra_rdoc_files: []
152
152
  files:
153
153
  - .gitignore
154
+ - .gitmodules
154
155
  - .travis.yml
155
156
  - Gemfile
156
157
  - LICENSE.txt
@@ -207,6 +208,7 @@ files:
207
208
  - lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_timePeriod.rb
208
209
  - lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_verticalElement.rb
209
210
  - lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_voucher.rb
211
+ - lib/adiwg/mdtranslator/readers/adiwgJson/readme.md
210
212
  - lib/adiwg/mdtranslator/validator.rb
211
213
  - lib/adiwg/mdtranslator/version.rb
212
214
  - lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_address.rb
@@ -278,8 +280,10 @@ files:
278
280
  - lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_spatialRepresentationType.rb
279
281
  - lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_topicCategory.rb
280
282
  - lib/adiwg/mdtranslator/writers/iso19115_2/iso19115_2_writer.rb
283
+ - lib/adiwg/mdtranslator/writers/iso19115_2/readme.md
281
284
  - mdtranslator.rb
282
285
  - test/adiwgJson_full_test_example.json
286
+ - test/adiwgJson_min_test_example.json
283
287
  - test/adiwgJson_template.json
284
288
  - test/dev.rb
285
289
  - test/tc_translation.rb
@@ -311,6 +315,7 @@ summary: The mdtranslator (metadata translator) is a toolkit for translating met
311
315
  Integration Working Group (ADIwg).
312
316
  test_files:
313
317
  - test/adiwgJson_full_test_example.json
318
+ - test/adiwgJson_min_test_example.json
314
319
  - test/adiwgJson_template.json
315
320
  - test/dev.rb
316
321
  - test/tc_translation.rb