pkm_level2_converter 0.1.2
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 +10 -0
- data/.rspec +3 -0
- data/.rspec_status +5 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +21 -0
- data/README.md +27 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/pkmlevel2 +22 -0
- data/lib/conv_PV_KM.rb +75 -0
- data/lib/conv_RN_TM.rb +73 -0
- data/lib/pkm_level2_converter.rb +107 -0
- data/lib/pkm_level2_converter/ka/pkm/1/XML-Schema_PKM.xsd +2847 -0
- data/lib/pkm_level2_converter/ka/pkm/1/XML-Schema_PKM_TX.xsd +221 -0
- data/lib/pkm_level2_converter/ka/pkm/2/XML-Schema_PKM.xsd +4082 -0
- data/lib/pkm_level2_converter/ka/pkm/2/XML-Schema_PKM.xsd.MD5 +1 -0
- data/lib/pkm_level2_converter/ka/pkm/2/XML-Schema_PKM_TX.xsd +178 -0
- data/lib/pkm_level2_converter/ka/pkm/2/XML-Schema_PKM_TX.xsd.MD5 +1 -0
- data/lib/pkm_level2_converter/version.rb +5 -0
- data/pkm_level2_converter.gemspec +39 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff4b2395882a262593bc5f25148d8cca36e9a6bfca27cd98d59090501d76e04c
|
4
|
+
data.tar.gz: bd2be0b4c5ce218d418a6724c5b3c069f65418c895fc344ce11df9314b3cae93
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de8cb77e36efc2939edc0cf83488ce780a5a868358e4dd5352bceaf4612e93094727e98b4f34408690ff9a25d3111439f6f70b0de788faf8f8cf8219e980a175
|
7
|
+
data.tar.gz: a36b0392d7aa30791240e2710bff4efc55dac23edefc6d7dfac11d8767ae0851b23a09fe7d131c5a14b5197f469eb0956bfac5ac1c6a73332eb86413ad0e5c7f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rspec_status
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------------------ | ------ | --------------- |
|
3
|
+
./spec/pkm_level2_converter_spec.rb[1:1] | passed | 0.00408 seconds |
|
4
|
+
./spec/pkm_level2_converter_spec.rb[1:2:1] | passed | 0.00323 seconds |
|
5
|
+
./spec/pkm_level2_converter_spec.rb[1:3:1] | passed | 0.0001 seconds |
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pkm_level2_converter (0.1.1)
|
5
|
+
nokogiri (~> 1.10.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
mini_portile2 (2.4.0)
|
12
|
+
nokogiri (1.10.10-x64-mingw32)
|
13
|
+
mini_portile2 (~> 2.4.0)
|
14
|
+
rake (13.0.3)
|
15
|
+
rspec (3.10.0)
|
16
|
+
rspec-core (~> 3.10.0)
|
17
|
+
rspec-expectations (~> 3.10.0)
|
18
|
+
rspec-mocks (~> 3.10.0)
|
19
|
+
rspec-core (3.10.1)
|
20
|
+
rspec-support (~> 3.10.0)
|
21
|
+
rspec-expectations (3.10.1)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-mocks (3.10.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-support (3.10.2)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
x64-mingw32
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
pkm_level2_converter!
|
34
|
+
rake (~> 13.0)
|
35
|
+
rspec (~> 3.2)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
2.2.20
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Francis Doege
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# PkmLevel2Converter
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Install it yourself as:
|
6
|
+
```bash
|
7
|
+
$ gem install pkm_level2_converter
|
8
|
+
```
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
```bash
|
12
|
+
$ pkmlevel2 DLKM_1234_G210801_0000_E1_1_1.3_SuperVU.xml
|
13
|
+
```
|
14
|
+
|
15
|
+
## Development
|
16
|
+
|
17
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
18
|
+
|
19
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/justusjonas74/pkm_level2_converter.
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "pkm_level2_converter"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/pkmlevel2
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pkm_level2_converter'
|
4
|
+
|
5
|
+
if ARGV.first
|
6
|
+
orig_file_name = ARGV.first
|
7
|
+
converter = PkmLevel2Converter::Converter.new(orig_file_name)
|
8
|
+
converter.convert_pkm()
|
9
|
+
else
|
10
|
+
arr_of_local_xml = Dir["*.xml"]
|
11
|
+
if arr_of_local_xml.empty?
|
12
|
+
puts "Error: No .xml file found."
|
13
|
+
puts "Usage \"pkmlevel2 filename.xml\""
|
14
|
+
else
|
15
|
+
arr_of_local_xml.each do |xml_file|
|
16
|
+
converter = PkmLevel2Converter::Converter.new(orig_file_name)
|
17
|
+
converter.convert_pkm()
|
18
|
+
end
|
19
|
+
end
|
20
|
+
puts "Press ENTER to close."
|
21
|
+
gets
|
22
|
+
end
|
data/lib/conv_PV_KM.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
#require 'pry'
|
3
|
+
require_relative 'check_xsd'
|
4
|
+
|
5
|
+
def convertFileName(file_name)
|
6
|
+
f = file_name.split('_')
|
7
|
+
org_id_l3 = f[1].to_i
|
8
|
+
org_id_l2 = org_id_l3 + 0x8000
|
9
|
+
f[1] = org_id_l2.to_s
|
10
|
+
return f.join("_")
|
11
|
+
end
|
12
|
+
|
13
|
+
def safe_file(file, new_file_name)
|
14
|
+
#SAVE FILE with NEW name
|
15
|
+
output = File.open( new_file_name, "w" )
|
16
|
+
output << file.to_xml(:indent_text => "", :indent => 0).gsub(/>\n/,">")
|
17
|
+
output.close
|
18
|
+
puts "File saved as: #{new_file_name}"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def convert_pkm(orig_file_name)
|
23
|
+
if File.file?(orig_file_name)
|
24
|
+
new_file_name = convertFileName(orig_file_name)
|
25
|
+
@xml_doc = File.open(orig_file_name) { |f| Nokogiri::XML(f) }
|
26
|
+
convert_ids
|
27
|
+
if xml_is_valid_pkm(@xml_doc)
|
28
|
+
safe_file(@xml_doc, new_file_name)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
puts "File ('#{orig_file_name}') not found."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def xml_is_valid_pkm(xml)
|
36
|
+
#xsd = File.read("./ka/pkm/1/XML-Schema_PKM.xsd")
|
37
|
+
file_path = File.join(File.dirname(__FILE__), './ka/pkm/1/XML-Schema_PKM.xsd')
|
38
|
+
xsd = File.read(file_path)
|
39
|
+
return check_xsd(xsd,xml)
|
40
|
+
end
|
41
|
+
|
42
|
+
def convert_xpath_l3_id(node, x_path)
|
43
|
+
map = node.at_xpath x_path
|
44
|
+
id = map.content.to_i
|
45
|
+
map.content = (id + 0x8000).to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def convert_ids
|
49
|
+
#Organisations-ID des DL:
|
50
|
+
#dl-km/organisation/id
|
51
|
+
# convert_xpath_l3_id(@xml_doc, 'xmlns:dl-km/xmlns:organisation/xmlns:id')
|
52
|
+
# puts "Converted following IDs:"
|
53
|
+
# puts "/dl-km/organisation/id = " + @xml_doc.xpath('/xmlns:dl-km/xmlns:organisation/xmlns:id').text
|
54
|
+
|
55
|
+
# @xml_doc.xpath('/xmlns:dl-km/xmlns:kontrollmodul-pool/xmlns:item').each do |node|
|
56
|
+
node = @xml_doc.xpath('/xmlns:pv-km')
|
57
|
+
#Organisations-ID des PV:
|
58
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/organisation/id
|
59
|
+
# convert_xpath_l3_id(node, '/xmlns:pv-km/xmlns:organisation/xmlns:id')
|
60
|
+
convert_xpath_l3_id(node, 'xmlns:organisation/xmlns:id')
|
61
|
+
puts "# pv-km/organisation/id = " + node.xpath('xmlns:organisation/xmlns:id').text
|
62
|
+
#Für PVKM zulässige Organisations-IDs der DL:
|
63
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/organisation-pool/item/id
|
64
|
+
node.xpath('xmlns:organisation-pool/xmlns:item').each do |child|
|
65
|
+
convert_xpath_l3_id(child, 'xmlns:id')
|
66
|
+
puts "## pv-km/organisation-pool/item/id = " + child.xpath('xmlns:id').text
|
67
|
+
end
|
68
|
+
# end
|
69
|
+
#Für Anzeige von KVP als Klartext:
|
70
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/nummerninterpretation-pool/item[nr=2]/nummerntext-pool/item/nr
|
71
|
+
end
|
72
|
+
|
73
|
+
orig_file_name = ARGV.first
|
74
|
+
convert_pkm(orig_file_name)
|
75
|
+
|
data/lib/conv_RN_TM.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
#require 'pry'
|
3
|
+
require_relative 'check_xsd'
|
4
|
+
|
5
|
+
def convertFileName(file_name)
|
6
|
+
f = file_name.split('_')
|
7
|
+
org_id_l3 = f[1].to_i
|
8
|
+
org_id_l2 = org_id_l3 + 0x8000
|
9
|
+
f[1] = org_id_l2.to_s
|
10
|
+
return f.join("_")
|
11
|
+
end
|
12
|
+
|
13
|
+
def safe_file(file, new_file_name)
|
14
|
+
#SAVE FILE with NEW name
|
15
|
+
output = File.open( new_file_name, "w" )
|
16
|
+
output << file.to_xml(:indent_text => "", :indent => 0).gsub(/>\n/,">")
|
17
|
+
output.close
|
18
|
+
puts "File saved as: #{new_file_name}"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def convert_pkm(orig_file_name)
|
23
|
+
if File.file?(orig_file_name)
|
24
|
+
new_file_name = convertFileName(orig_file_name)
|
25
|
+
@xml_doc = File.open(orig_file_name) { |f| Nokogiri::XML(f) }
|
26
|
+
convert_ids
|
27
|
+
if xml_is_valid_pkm(@xml_doc)
|
28
|
+
safe_file(@xml_doc, new_file_name)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
puts "File ('#{orig_file_name}') not found."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def xml_is_valid_pkm(xml)
|
36
|
+
xsd = File.read("ka/pkm/2/XML-Schema_PKM.xsd")
|
37
|
+
return check_xsd(xsd,xml)
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert_xpath_l3_id(node, x_path)
|
41
|
+
map = node.at_xpath x_path
|
42
|
+
id = map.content.to_i
|
43
|
+
map.content = (id + 0x8000).to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def convert_ids
|
47
|
+
#Organisations-ID des RN:
|
48
|
+
#rntm/herausgeber/nr
|
49
|
+
convert_xpath_l3_id(@xml_doc, 'xmlns:rntm/xmlns:herausgeber/xmlns:nr')
|
50
|
+
puts "Converted following IDs:"
|
51
|
+
puts "rntm/herausgeber/nr = " + @xml_doc.xpath('xmlns:rntm/xmlns:herausgeber/xmlns:nr').text
|
52
|
+
|
53
|
+
@xml_doc.xpath('/xmlns:rntm/xmlns:tarifmodul-pool/xmlns:item').each do |node|
|
54
|
+
|
55
|
+
#Organisations-ID des PV:
|
56
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/organisation/id
|
57
|
+
|
58
|
+
convert_xpath_l3_id(node, 'xmlns:tarifmodul/xmlns:herausgeber/xmlns:nr')
|
59
|
+
puts "# /rntm/tarifmodul-pool/item/tarifmodul/herausgeber/nr/ = " + node.xpath('xmlns:tarifmodul/xmlns:herausgeber/xmlns:nr').text
|
60
|
+
#Für PVKM zulässige Organisations-IDs der DL:
|
61
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/organisation-pool/item/id
|
62
|
+
node.xpath('xmlns:tarifmodul/xmlns:organisation-pool/xmlns:item').each do |child|
|
63
|
+
convert_xpath_l3_id(child, 'xmlns:nr')
|
64
|
+
puts "## /rntm/tarifmodul-pool/item/tarifmodul/organisation-pool/item/nr = " + child.xpath('xmlns:nr').text
|
65
|
+
end
|
66
|
+
end
|
67
|
+
#Für Anzeige von KVP als Klartext:
|
68
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/nummerninterpretation-pool/item[nr=2]/nummerntext-pool/item/nr
|
69
|
+
end
|
70
|
+
|
71
|
+
orig_file_name = ARGV.first
|
72
|
+
convert_pkm(orig_file_name)
|
73
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'nokogiri'
|
3
|
+
require_relative "pkm_level2_converter/version"
|
4
|
+
|
5
|
+
module PkmLevel2Converter
|
6
|
+
class Error < StandardError; end
|
7
|
+
class Converter
|
8
|
+
def initialize(file_name)
|
9
|
+
@filename = file_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def filename
|
13
|
+
@filename
|
14
|
+
end
|
15
|
+
|
16
|
+
def convertFileName()
|
17
|
+
file_name = @filename
|
18
|
+
#puts file_name
|
19
|
+
f = file_name.split('_')
|
20
|
+
#puts f
|
21
|
+
org_id_l3 = f[1].to_i
|
22
|
+
#puts org_id_l3
|
23
|
+
org_id_l2 = org_id_l3 + 0x8000
|
24
|
+
#puts org_id_l2
|
25
|
+
f[1] = org_id_l2.to_s
|
26
|
+
#puts f.join("_")
|
27
|
+
return f.join("_")
|
28
|
+
end
|
29
|
+
|
30
|
+
def save_file(file)
|
31
|
+
#SAVE FILE with NEW name
|
32
|
+
new_file_name = self.convertFileName()
|
33
|
+
output = File.open( new_file_name, "w" )
|
34
|
+
output << file.to_xml(:indent_text => "", :indent => 0).gsub(/>\n/,">")
|
35
|
+
output.close
|
36
|
+
puts "File saved as: #{new_file_name}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_xsd(xsd, xml)
|
40
|
+
puts "Check XML-Schema..."
|
41
|
+
xsd = Nokogiri::XML::Schema(xsd)
|
42
|
+
error = xsd.validate(xml)
|
43
|
+
if error.empty?
|
44
|
+
puts "XML-Schema is valid."
|
45
|
+
return true
|
46
|
+
else
|
47
|
+
puts "XML-Schema is invalid."
|
48
|
+
error.each do |e|
|
49
|
+
puts e.message
|
50
|
+
end
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def convert_pkm()
|
56
|
+
orig_file_name = @filename
|
57
|
+
if File.file?(orig_file_name)
|
58
|
+
@xml_doc = File.open(orig_file_name) { |f| Nokogiri::XML(f) }
|
59
|
+
convert_ids
|
60
|
+
if xml_is_valid_pkm(@xml_doc)
|
61
|
+
save_file(@xml_doc)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
puts "File ('#{orig_file_name}') not found."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def xml_is_valid_pkm(xml)
|
69
|
+
#xsd = File.read("./ka/pkm/1/XML-Schema_PKM.xsd")
|
70
|
+
file_path = File.join(File.dirname(__FILE__), './pkm_level2_converter/ka/pkm/1/XML-Schema_PKM.xsd')
|
71
|
+
xsd = File.read(file_path)
|
72
|
+
return self.check_xsd(xsd,xml)
|
73
|
+
end
|
74
|
+
|
75
|
+
def convert_xpath_l3_id(node, x_path)
|
76
|
+
map = node.at_xpath x_path
|
77
|
+
id = map.content.to_i
|
78
|
+
map.content = (id + 0x8000).to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
def convert_ids
|
82
|
+
#Organisations-ID des DL:
|
83
|
+
#dl-km/organisation/id
|
84
|
+
convert_xpath_l3_id(@xml_doc, 'xmlns:dl-km/xmlns:organisation/xmlns:id')
|
85
|
+
puts "Converted following IDs:"
|
86
|
+
puts "/dl-km/organisation/id = " + @xml_doc.xpath('/xmlns:dl-km/xmlns:organisation/xmlns:id').text
|
87
|
+
|
88
|
+
@xml_doc.xpath('/xmlns:dl-km/xmlns:kontrollmodul-pool/xmlns:item').each do |node|
|
89
|
+
|
90
|
+
#Organisations-ID des PV:
|
91
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/organisation/id
|
92
|
+
convert_xpath_l3_id(node, 'xmlns:moduldaten/xmlns:organisation/xmlns:id')
|
93
|
+
puts "# dl-km/kontrollmodul-pool/item/moduldaten/organisation/id = " + node.xpath('xmlns:moduldaten/xmlns:organisation/xmlns:id').text
|
94
|
+
#Für PVKM zulässige Organisations-IDs der DL:
|
95
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/organisation-pool/item/id
|
96
|
+
node.xpath('xmlns:moduldaten/xmlns:organisation-pool/xmlns:item').each do |child|
|
97
|
+
convert_xpath_l3_id(child, 'xmlns:id')
|
98
|
+
puts "## dl-km/kontrollmodul-pool/item/moduldaten/organisation-pool/item/id = " + child.xpath('xmlns:id').text
|
99
|
+
end
|
100
|
+
end
|
101
|
+
#Für Anzeige von KVP als Klartext:
|
102
|
+
#dl-km/kontrollmodul-pool/item/moduldaten/nummerninterpretation-pool/item[nr=2]/nummerntext-pool/item/nr
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|