rsmart_toolbox 0.10 → 0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +7 -0
- data/bin/transform_CSV_to_HR_XML +2 -28
- data/bin/validate_HR_XML +32 -0
- data/lib/rsmart_toolbox/etl/grm.rb +37 -0
- data/lib/rsmart_toolbox/version.rb +1 -1
- metadata +4 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ab463e0fe4efdc8c8264b52d9eb1de6b6f2c9cf
|
4
|
+
data.tar.gz: 441a7cc41c768e9f0cb906b9b4b14805e8f953e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 289a7548aabe2f24752affb7f3d36e2b2e46b305a38e76a7ca4c94a8a82e2753bec731a03845d6d9281a2221393709c9fa95db6792522eaef160d7dce23e5f0f
|
7
|
+
data.tar.gz: 956180913c4683d73c68caf9bd8f72015936f8bac666f290ed24201c01fb87e56a8064ad7e04633221829fb9cb24991e145d9c5172a24e1ba6485066211aac53
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -40,6 +40,13 @@ Usage: transform_CSV_to_HR_XML [options] csv_file
|
|
40
40
|
-h, --help Display this screen
|
41
41
|
```
|
42
42
|
|
43
|
+
### validate_HR_XML
|
44
|
+
|
45
|
+
```
|
46
|
+
Usage: validate_HR_XML xml_file
|
47
|
+
-h, --help Display this screen
|
48
|
+
```
|
49
|
+
|
43
50
|
## Contributing
|
44
51
|
|
45
52
|
1. Fork it: https://github.com/rSmart/rsmart_toolbox/fork
|
data/bin/transform_CSV_to_HR_XML
CHANGED
@@ -5,11 +5,8 @@ require 'bundler/setup'
|
|
5
5
|
|
6
6
|
require 'builder'
|
7
7
|
require 'csv'
|
8
|
-
require 'net/http'
|
9
|
-
require 'nokogiri'
|
10
8
|
require 'optparse'
|
11
9
|
require 'rest_client'
|
12
|
-
require 'tempfile'
|
13
10
|
require 'time'
|
14
11
|
require 'rsmart_toolbox/etl/grm'
|
15
12
|
|
@@ -302,33 +299,10 @@ CSV.open(opt[:csv_filename], opt[:csv_options]) do |csv|
|
|
302
299
|
end # hrmanifest
|
303
300
|
end # xml_file
|
304
301
|
end # csv
|
302
|
+
|
305
303
|
puts "\nXML file written to #{opt[:xml_filename]}\n\n"
|
306
304
|
|
307
|
-
|
308
|
-
uri = URI 'https://raw.githubusercontent.com/rSmart/ce-tech-docs/master/hrmanifest.xsd'
|
309
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
310
|
-
Tempfile.open "hrmanifest.xsd" do |file|
|
311
|
-
request = Net::HTTP::Get.new uri
|
312
|
-
http.request request do |response|
|
313
|
-
response.read_body do |segment|
|
314
|
-
file.write(segment)
|
315
|
-
end
|
316
|
-
end
|
317
|
-
file.rewind
|
318
|
-
xsd = Nokogiri::XML::Schema file
|
319
|
-
doc = Nokogiri::XML File.read opt[:xml_filename]
|
320
|
-
xml_errors = xsd.validate doc
|
321
|
-
if xml_errors.empty?
|
322
|
-
puts "Congratulations! The XML file passes XSD schema validation! w00t!\n\n"
|
323
|
-
else
|
324
|
-
puts "Sorry, the XML file does NOT pass XSD schema validation!:"
|
325
|
-
xml_errors.each do |error|
|
326
|
-
puts error.message
|
327
|
-
end
|
328
|
-
exit 1
|
329
|
-
end
|
330
|
-
end # file
|
331
|
-
end
|
305
|
+
exit 1 unless GRM.validate_hr_xml opt[:xml_filename]
|
332
306
|
|
333
307
|
# POST the XML file to the server if opt[:url]
|
334
308
|
if opt[:url]
|
data/bin/validate_HR_XML
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'rsmart_toolbox/etl/grm'
|
8
|
+
|
9
|
+
GRM = Rsmart::ETL::GRM
|
10
|
+
|
11
|
+
def self.parse_command_line_options( executable, args, opt={} )
|
12
|
+
optparse = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: #{executable} xml_file"
|
14
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
15
|
+
puts opts
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
opt[:xml_filename] = args[0] unless opt[:xml_filename]
|
20
|
+
if opt[:xml_filename].nil? || opt[:xml_filename].empty?
|
21
|
+
puts opts
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
optparse.parse!
|
26
|
+
|
27
|
+
return opt
|
28
|
+
end
|
29
|
+
|
30
|
+
opt = parse_command_line_options (File.basename $0), ARGF.argv
|
31
|
+
|
32
|
+
exit 1 unless GRM.validate_hr_xml opt[:xml_filename]
|
@@ -14,6 +14,9 @@
|
|
14
14
|
# You should have received a copy of the GNU Affero General Public License
|
15
15
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
|
17
|
+
require 'net/http'
|
18
|
+
require 'nokogiri'
|
19
|
+
require 'tempfile'
|
17
20
|
require "rsmart_toolbox/etl"
|
18
21
|
|
19
22
|
# rSmart Grant and Research Management methods.
|
@@ -354,4 +357,38 @@ module Rsmart::ETL::GRM
|
|
354
357
|
Rsmart::ETL::mutate_sql_stmt! insert_str, opt[:name], values_str, actv_ind
|
355
358
|
end
|
356
359
|
|
360
|
+
# Performs an XML XSD schema validation using the published schema.
|
361
|
+
# @note Any schema validation errors are output to STDOUT via puts.
|
362
|
+
# @param xml_filename [String] A path to the XML file to be validated.
|
363
|
+
# @return [Boolean] true if no validation errors are found; otherwise false.
|
364
|
+
def self.validate_hr_xml(xml_filename)
|
365
|
+
ret_val = false
|
366
|
+
# validate the resulting XML file against the official XSD schema
|
367
|
+
uri = URI 'https://raw.githubusercontent.com/rSmart/ce-tech-docs/master/hrmanifest.xsd'
|
368
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
369
|
+
Tempfile.open "hrmanifest.xsd" do |schema|
|
370
|
+
request = Net::HTTP::Get.new uri
|
371
|
+
http.request request do |response|
|
372
|
+
response.read_body do |segment|
|
373
|
+
schema.write(segment)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
schema.rewind
|
377
|
+
xsd = Nokogiri::XML::Schema schema
|
378
|
+
doc = Nokogiri::XML File.read xml_filename
|
379
|
+
xml_errors = xsd.validate doc
|
380
|
+
if xml_errors.empty?
|
381
|
+
puts "Congratulations! The XML file passes XSD schema validation! w00t!\n\n"
|
382
|
+
ret_val = true
|
383
|
+
else
|
384
|
+
puts "Sorry, the XML file does NOT pass XSD schema validation!:"
|
385
|
+
xml_errors.each do |error|
|
386
|
+
puts error.message
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end # schema
|
390
|
+
end
|
391
|
+
return ret_val
|
392
|
+
end
|
393
|
+
|
357
394
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsmart_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.11'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lance Speelmon
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
sKRWzEtHFamxQaIspOja5O4oQKiCbWa90fEuIoCtwyy1rQtL9VKoDTs4vZASXNuc
|
31
31
|
F/lEyekXSjN36uTtlt4LkKLn/k7k5gRbt4+C9Q==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2014-09-
|
33
|
+
date: 2014-09-17 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: builder
|
@@ -135,6 +135,7 @@ email:
|
|
135
135
|
- lspeelmon@rsmart.com
|
136
136
|
executables:
|
137
137
|
- transform_CSV_to_HR_XML
|
138
|
+
- validate_HR_XML
|
138
139
|
extensions: []
|
139
140
|
extra_rdoc_files: []
|
140
141
|
files:
|
@@ -145,6 +146,7 @@ files:
|
|
145
146
|
- README.md
|
146
147
|
- Rakefile
|
147
148
|
- bin/transform_CSV_to_HR_XML
|
149
|
+
- bin/validate_HR_XML
|
148
150
|
- lib/rsmart_toolbox.rb
|
149
151
|
- lib/rsmart_toolbox/etl.rb
|
150
152
|
- lib/rsmart_toolbox/etl/grm.rb
|
metadata.gz.sig
CHANGED
Binary file
|