adiwg-mdtranslator 1.0.0rc1 → 1.0.0rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c323c30414ec1eba70403136085ae2eeba8f288f
4
- data.tar.gz: 5b0f79036a8d2513e5b73a2c9eb29b651d8a4603
3
+ metadata.gz: aef130968578631bf49c4bdc764b4a207ddf6faa
4
+ data.tar.gz: 7b7a30dfe0bc5fa1c924d414be8520b5bd327974
5
5
  SHA512:
6
- metadata.gz: 278f8307994c6faa5995139f61041721e91c1baca1fb2fceb3a92ef228597c9425e51c981a33abe22e6b512d4516c6cde9095fff1660f0115809a0f285c12a26
7
- data.tar.gz: 7bcc1201a25fdbb735a00d71c68f412df564068ebcd0daacdc6ef7c537f3d763d588aaf62de1475ed439d614fee556ddb2e10885d4607f70e096c3add9b7873d
6
+ metadata.gz: 1014723327cf4bf6e2cfbbef689a7c9b4eb493dc0c478e86a3deaadb19018b1f9c057f61f4f2b8f32802e4dbc97593c7d754c41ebc25d12838df0b4d47a7bac4
7
+ data.tar.gz: 5a8ad6128813a53648d7f3ad263dd9f7b72fa251f39cf26133a1aaa736208df9bdab3ab9e203c5826c89b5d15b851c0af2445a1963116892854fa989eec7cc6d
@@ -17,6 +17,7 @@
17
17
  # Stan Smith 2014-12-02 organized shared class/code/units folders for 19115-2, 19110
18
18
  # Stan Smith 2014-12-11 refactored to handle namespacing readers and writers
19
19
  # Stan Smith 2015-01-15 changed translate() to keyword parameter list
20
+ # Stan Smith 2015-03-04 moved addFinalMessages into this module from rails app
20
21
 
21
22
  # add main directories to load_path
22
23
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'mdtranslator/internal'))
@@ -32,6 +33,24 @@ require 'adiwg/mdtranslator/writers/mdWriters'
32
33
  module ADIWG
33
34
  module Mdtranslator
34
35
 
36
+ def self.addFinalMessages
37
+ if $response[:readerStructurePass].nil?
38
+ $response[:readerStructureMessages].insert(0, 'Input file structure was not checked \n')
39
+ end
40
+
41
+ if $response[:readerValidationPass].nil?
42
+ $response[:readerValidationMessages].insert(0, 'Validator was not called \n')
43
+ end
44
+
45
+ if $response[:readerExecutionPass].nil?
46
+ $response[:readerExecutionMessages].insert(0, 'Reader was not called \n')
47
+ end
48
+
49
+ if $response[:writerPass].nil?
50
+ $response[:writerMessages].insert(0, 'Writer not called \n')
51
+ end
52
+ end
53
+
35
54
  def self.translate(file:, reader:, validate: 'normal', writer: nil, showAllTags: false)
36
55
 
37
56
  $showAllTags = showAllTags
@@ -60,10 +79,11 @@ module ADIWG
60
79
 
61
80
  # handle readers
62
81
  if reader.nil? || reader == ''
63
- $response[:readerValidationPass] = false
82
+ $response[:readerStructureMessages] << 'Reader name is missing.'
64
83
  $response[:readerValidationMessages] << 'Reader name is missing.'
65
- $response[:readerExecutionPass] = false
66
- $response[:readerExecutionMessages] << 'Reader failed to complete.'
84
+ $response[:readerExecutionMessages] << 'Reader name is missing.'
85
+ $response[:writerMessages] << 'Input file was not read.'
86
+ addFinalMessages()
67
87
  return $response
68
88
  else
69
89
  require File.join(File.dirname(__FILE__), 'mdtranslator/readers/mdReaders')
@@ -72,20 +92,19 @@ module ADIWG
72
92
  if intObj
73
93
  $response[:readerExecutionPass] = true
74
94
  else
75
- $response[:readerExecutionPass] = false
76
- $response[:readerExecutionMessages] << 'Reader failed to complete.'
95
+ addFinalMessages()
77
96
  return $response
78
97
  end
79
98
  end
80
99
 
81
100
  # handle writers
82
101
  if writer.nil? || writer == ''
83
- $response[:writerPass] = false
84
- $response[:writerMessages] << 'Writer name is missing.'
102
+ $response[:writerMessages] << 'Writer name was not provided.'
85
103
  else
86
104
  require File.join(File.dirname(__FILE__), 'mdtranslator/writers/mdWriters')
87
105
  ADIWG::Mdtranslator::Writers.handleWriter(intObj)
88
106
  end
107
+ addFinalMessages()
89
108
  return $response
90
109
 
91
110
  end
@@ -20,9 +20,6 @@ module ADIWG
20
20
  module Readers
21
21
  module MdJson
22
22
 
23
- # set reader namespace
24
- $ReaderNS = ADIWG::Mdtranslator::Readers::MdJson
25
-
26
23
  def self.readFile(file)
27
24
  # set anticipated format of file in $response
28
25
  $response[:readerFormat] = 'json'
@@ -52,7 +49,7 @@ module ADIWG
52
49
  return false
53
50
  end
54
51
 
55
- # unpack mdJson file
52
+ # load mdJson file into internal object
56
53
  require readerModule('module_mdJson')
57
54
  intObj = $ReaderNS.unpack(@hMdJson)
58
55
  return intObj
@@ -67,8 +64,8 @@ module ADIWG
67
64
  $response[:readerStructurePass] = true
68
65
  rescue JSON::JSONError => err
69
66
  $response[:readerStructurePass] = false
70
- $response[:readerStructureMessages] << err
71
- return
67
+ $response[:readerStructureMessages] << 'JSON Parsing Failed - see following message(s):\n'
68
+ $response[:readerStructureMessages] << err.to_s.slice(0,300)
72
69
  end
73
70
  end
74
71
 
@@ -78,6 +75,7 @@ module ADIWG
78
75
  hVersion = @hMdJson['version']
79
76
  else
80
77
  $response[:readerStructurePass] = false
78
+ $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n'
81
79
  $response[:readerStructureMessages] << 'The input file is missing the version:{} block.'
82
80
  return
83
81
  end
@@ -89,21 +87,23 @@ module ADIWG
89
87
  $response[:readerFound] = s
90
88
  else
91
89
  $response[:readerStructurePass] = false
92
- $response[:readerStructureMessages] << 'The input file version name is missing.'
90
+ $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n'
91
+ $response[:readerStructureMessages] << 'The input file version: => name: is missing.'
93
92
  return
94
93
  end
95
94
  else
96
95
  $response[:readerStructurePass] = false
97
- $response[:readerStructureMessages] << "The input file version:{} block is missing the 'name' attribute."
96
+ $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n'
97
+ $response[:readerStructureMessages] << "The input file version:{} block is missing the 'name:' attribute."
98
98
  return
99
99
  end
100
100
 
101
101
  # check the version name is 'mdJson'
102
102
  if s != 'mdJson'
103
103
  $response[:readerStructurePass] = false
104
- $response[:readerStructureMessages] << "The mdTranslator reader expected the input file version name to be 'mdJson'."
104
+ $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n'
105
+ $response[:readerStructureMessages] << "The mdTranslator reader expected the input file version: name: to be 'mdJson'."
105
106
  $response[:readerStructureMessages] << "Version name found was: '#{s}'."
106
- return
107
107
  end
108
108
  end
109
109
 
@@ -117,7 +117,8 @@ module ADIWG
117
117
  end
118
118
  else
119
119
  $response[:readerStructurePass] = false
120
- $response[:readerStructureMessages] << "The input file version:{} block is missing the 'version' number attribute."
120
+ $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n'
121
+ $response[:readerStructureMessages] << "The input file version:{} block is missing the 'version:' number attribute."
121
122
  return
122
123
  end
123
124
 
@@ -131,6 +132,7 @@ module ADIWG
131
132
  dir = File.join(File.dirname(__FILE__), 'modules_' + readerVersion)
132
133
  if !File.directory?(dir)
133
134
  $response[:readerStructurePass] = false
135
+ $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n'
134
136
  $response[:readerStructureMessages] << 'The input file version is not supported.'
135
137
  $response[:readerStructureMessages] << "mdJson version requested was '#{s}'"
136
138
  return
@@ -138,9 +140,9 @@ module ADIWG
138
140
  $response[:readerVersionUsed] = readerVersion
139
141
  else
140
142
  $response[:readerStructurePass] = false
143
+ $response[:readerStructureMessages] << 'Invalid input file schema declaration - see following message(s):\n'
141
144
  $response[:readerStructureMessages] << 'The input file version number must be in the form MAJOR.MINOR.PATCH, e.g. 1.2.3'
142
145
  $response[:readerStructureMessages] << 'Note the PATCH number is optional.'
143
- return
144
146
  end
145
147
  end
146
148
 
@@ -36,11 +36,13 @@ module ADIWG
36
36
 
37
37
  if aValErrs.length > 0
38
38
  $response[:readerValidationPass] = false
39
+ $response[:readerValidationMessages] << 'mdJson schema validation Failed - see following message(s):\n'
39
40
  $response[:readerValidationMessages] = aValErrs
40
41
  return
41
42
  end
42
43
  rescue JSON::Schema::ValidationError
43
44
  $response[:readerValidationPass] = false
45
+ $response[:readerValidationMessages] << 'mdJson schema validation Failed - see following message(s):\n'
44
46
  $response[:readerValidationMessages] << $!.message
45
47
  return
46
48
  end
@@ -3,6 +3,7 @@
3
3
  # History:
4
4
  # Stan Smith 2014-12-11 original script
5
5
  # Stan Smith 2012-12-16 generalized handleReader to use :readerRequested
6
+ # Stan Smith 2015-03-04 changed method of setting $WriterNS
6
7
 
7
8
  module ADIWG
8
9
  module Mdtranslator
@@ -18,16 +19,20 @@ module ADIWG
18
19
  # if directory path exists, build reader file name and require it
19
20
  readerFile = File.join(readerDir, $response[:readerRequested] + '_reader')
20
21
  require readerFile
22
+ readerClassName = $response[:readerRequested].clone
23
+ readerClassName[0] = readerClassName[0].upcase
24
+ $ReaderNS = ADIWG::Mdtranslator::Readers.const_get(readerClassName)
25
+
21
26
 
22
27
  # pass file to requested reader and return internal object
23
28
  # $ReaderNS is the reader namespace constant set in
24
29
  # ... readerRequested_reader.rb and initialized when the file is required
25
- intObj = $ReaderNS.readFile(file)
26
- return intObj
30
+ return $ReaderNS.readFile(file)
27
31
  else
28
32
  # directory path was not found
29
33
  $response[:readerValidationPass] = false
30
- $response[:readerValidationMessages] << "Reader name '#{$response[:readerRequested]}' is not supported."
34
+ $response[:readerValidationMessages] << "Validation Failed - see following message(s):\n"
35
+ $response[:readerValidationMessages] << "Reader '#{$response[:readerRequested]}' is not supported."
31
36
  return false
32
37
  end
33
38
 
@@ -41,7 +41,7 @@
41
41
  module ADIWG
42
42
  module Mdtranslator
43
43
  # current mdtranslator version
44
- VERSION = "1.0.0rc1"
44
+ VERSION = "1.0.0rc2"
45
45
  end
46
46
  end
47
47
 
@@ -13,9 +13,6 @@ module ADIWG
13
13
  module Writers
14
14
  module Html
15
15
 
16
- # set writer namespace
17
- $WriterNS = ADIWG::Mdtranslator::Writers::Html
18
-
19
16
  def self.startWriter(intObj)
20
17
 
21
18
  # set the format of the output file based on the writer specified
@@ -3,6 +3,7 @@
3
3
  # History:
4
4
  # Stan Smith 2014-12-01 original script
5
5
  # Stan Smith 2014-12-12 refactored to handle namespacing readers and writers
6
+ # Stan Smith 2015-03-02 added test and return for missing data dictionary
6
7
 
7
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../iso/units'))
8
9
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../iso/codelists'))
@@ -18,9 +19,6 @@ module ADIWG
18
19
  module Writers
19
20
  module Iso19110
20
21
 
21
- # set writer namespace
22
- $WriterNS = ADIWG::Mdtranslator::Writers::Iso19110
23
-
24
22
  def self.startWriter(intObj)
25
23
 
26
24
  # reset ISO id='' counter
@@ -30,14 +28,24 @@ module ADIWG
30
28
  $response[:writerFormat] = 'xml'
31
29
  $response[:writerVersion] = ADIWG::Mdtranslator::VERSION
32
30
 
31
+ # test for a valid dataDictionary object in the internal object
32
+ aDictionaries = intObj[:dataDictionary]
33
+ if aDictionaries.length == 0
34
+ $response[:writerMessages] << 'Writer Failed - see following message(s):\n'
35
+ $response[:writerMessages] << 'No data dictionary was loaded from the input file'
36
+ $response[:writerPass] = false
37
+ return
38
+ end
39
+
33
40
  # create new XML document
34
41
  xml = Builder::XmlMarkup.new(indent: 3)
35
42
  metadataWriter = $WriterNS::FC_FeatureCatalogue.new(xml)
36
43
  metadata = metadataWriter.writeXML(intObj)
37
44
 
38
- # set writer pass to true if no messages
45
+ # set writer pass to true if no writer modules set it to false
39
46
  # false or warning will be set by code that places the message
40
- if $response[:writerMessages].length == 0
47
+ # load metadata into $response
48
+ if $response[:writerPass].nil?
41
49
  $response[:writerPass] = true
42
50
  end
43
51
 
@@ -20,9 +20,6 @@ module ADIWG
20
20
  module Writers
21
21
  module Iso19115_2
22
22
 
23
- # set writer namespace
24
- $WriterNS = ADIWG::Mdtranslator::Writers::Iso19115_2
25
-
26
23
  def self.startWriter(internalObj)
27
24
 
28
25
  # reset ISO id='' counter
@@ -42,9 +39,10 @@ module ADIWG
42
39
  metadataWriter = $WriterNS::MI_Metadata.new(xml)
43
40
  metadata = metadataWriter.writeXML(internalObj)
44
41
 
45
- # set writer pass to true if no messages
42
+ # set writer pass to true if no writer modules set it to false
46
43
  # false or warning will be set by code that places the message
47
- if $response[:writerMessages].length == 0
44
+ # load metadata into $response
45
+ if $response[:writerPass].nil?
48
46
  $response[:writerPass] = true
49
47
  end
50
48
 
@@ -3,6 +3,7 @@
3
3
  # History:
4
4
  # Stan Smith 2014-12-11 original script
5
5
  # Stan Smith 2012-12-16 generalized handleWriter to use :writerName
6
+ # Stan Smith 2015-03-04 changed method of setting $WriterNS
6
7
 
7
8
  module ADIWG
8
9
  module Mdtranslator
@@ -10,21 +11,34 @@ module ADIWG
10
11
 
11
12
  def self.handleWriter(intObj)
12
13
 
14
+ # this is a temp fix until the directory structure is changed
15
+ if $response[:writerName] == 'iso'
16
+ $response[:writerPass] = false
17
+ $response[:writerMessages] << 'Writer not called - see following message(s):\n'
18
+ $response[:writerMessages] << "Writer name 'iso' is not supported."
19
+ return false
20
+ end
21
+
13
22
  # use writer name to load and initiate requested writer
14
23
  # build directory path for writer from writerName
15
24
  writerDir = File.join(path_to_resources, $response[:writerName])
16
25
  if File.directory?(writerDir)
26
+
17
27
  # if directory path exists, build writer file name and then require it
18
28
  writerFile = File.join(writerDir, $response[:writerName] + '_writer')
19
29
  require writerFile
30
+ writerClassName = $response[:writerName].clone
31
+ writerClassName[0] = writerClassName[0].upcase
32
+ $WriterNS = ADIWG::Mdtranslator::Writers.const_get(writerClassName)
20
33
 
21
34
  # pass internal object to requested writer
22
35
  $response[:writerOutput] = $WriterNS.startWriter(intObj)
23
- return $response
36
+
24
37
  else
25
38
  # directory path was not found
26
- $response[:writerValidationPass] = false
27
- $response[:readerValidationMessages] << "Writer name '#{$response[:writerName]}' is not supported."
39
+ $response[:writerPass] = false
40
+ $response[:writerMessages] << 'Writer not called - see following message(s):\n'
41
+ $response[:writerMessages] << "Writer name '#{$response[:writerName]}' is not supported."
28
42
  return false
29
43
  end
30
44
 
@@ -14,6 +14,7 @@ require 'minitest/autorun'
14
14
  require 'json'
15
15
  require 'adiwg/mdtranslator/internal/internal_metadata_obj'
16
16
  require 'adiwg/mdtranslator/readers/mdJson/mdJson_reader'
17
+ $ReaderNS = ADIWG::Mdtranslator::Readers::MdJson
17
18
  require 'adiwg/mdtranslator/readers/mdJson/modules_1.0/module_additionalDocumentation'
18
19
 
19
20
  class TestReaderMdJsonAdditionalDocumentation_v1_0 < MiniTest::Test
@@ -14,6 +14,7 @@ require 'minitest/autorun'
14
14
  require 'json'
15
15
  require 'adiwg/mdtranslator/internal/internal_metadata_obj'
16
16
  require 'adiwg/mdtranslator/readers/mdJson/mdJson_reader'
17
+ $ReaderNS = ADIWG::Mdtranslator::Readers::MdJson
17
18
  require 'adiwg/mdtranslator/readers/mdJson/modules_1.0/module_associatedResource'
18
19
 
19
20
  class TestReaderMdJsonAssociatedResource_v1_0 < MiniTest::Test
@@ -17,6 +17,7 @@ require 'json'
17
17
  require 'adiwg/mdtranslator/internal/internal_metadata_obj'
18
18
  require 'adiwg/mdtranslator/internal/module_dateTimeFun'
19
19
  require 'adiwg/mdtranslator/readers/mdJson/mdJson_reader'
20
+ $ReaderNS = ADIWG::Mdtranslator::Readers::MdJson
20
21
  require 'adiwg/mdtranslator/readers/mdJson/modules_1.0/module_citation'
21
22
 
22
23
  class TestReaderMdJsonCitation_v1_0 < MiniTest::Test
@@ -16,6 +16,7 @@ require 'minitest/autorun'
16
16
  require 'json'
17
17
  require 'adiwg/mdtranslator/internal/internal_metadata_obj'
18
18
  require 'adiwg/mdtranslator/readers/mdJson/mdJson_reader'
19
+ $ReaderNS = ADIWG::Mdtranslator::Readers::MdJson
19
20
  require 'adiwg/mdtranslator/readers/mdJson/modules_1.0/module_contacts'
20
21
 
21
22
  class TestReaderMdJsonContact_v1_0 < MiniTest::Test
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: 1.0.0rc1
4
+ version: 1.0.0rc2
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: 2015-02-28 00:00:00.000000000 Z
12
+ date: 2015-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler