xmlconv 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/History.txt +8 -0
  4. data/README.txt +0 -4
  5. data/Rakefile +16 -32
  6. data/bin/migrate_xmlconv_to_utf_8 +235 -0
  7. data/bin/{admin → xmlconv_admin} +0 -0
  8. data/bin/xmlconvd +3 -1
  9. data/converter_scripts/convert.rb +23 -0
  10. data/{xmlconv_convert.rb → converter_scripts/xmlconv_convert.rb} +0 -0
  11. data/lib/xmlconv/config.rb +6 -0
  12. data/lib/xmlconv/custom/lookandfeel.rb +1 -1
  13. data/lib/xmlconv/i2/header.rb +5 -3
  14. data/lib/xmlconv/i2/position.rb +3 -2
  15. data/lib/xmlconv/util/application.rb +9 -6
  16. data/lib/xmlconv/util/destination.rb +11 -6
  17. data/lib/xmlconv/util/mail.rb +26 -14
  18. data/lib/xmlconv/util/transaction.rb +3 -1
  19. data/lib/xmlconv/version.rb +3 -0
  20. data/readme.md +46 -0
  21. data/test/data/polling.yaml +10 -0
  22. data/test/test_i2/address.rb +2 -2
  23. data/test/test_i2/date.rb +2 -2
  24. data/test/test_i2/document.rb +12 -22
  25. data/test/test_i2/header.rb +2 -2
  26. data/test/test_i2/order.rb +18 -32
  27. data/test/test_i2/parser.rb +4 -3
  28. data/test/test_i2/position.rb +9 -23
  29. data/test/test_model/address.rb +2 -2
  30. data/test/test_model/agreement.rb +2 -2
  31. data/test/test_model/bdd.rb +8 -9
  32. data/test/test_model/bsr.rb +6 -7
  33. data/test/test_model/delivery.rb +11 -15
  34. data/test/test_model/delivery_item.rb +5 -5
  35. data/test/test_model/freetext_container.rb +3 -3
  36. data/test/test_model/invoice.rb +8 -11
  37. data/test/test_model/invoice_item.rb +5 -4
  38. data/test/test_model/name.rb +2 -2
  39. data/test/test_model/part_info.rb +2 -2
  40. data/test/test_model/party.rb +16 -22
  41. data/test/test_model/price.rb +2 -2
  42. data/test/test_util/application.rb +36 -86
  43. data/test/test_util/destination.rb +11 -19
  44. data/test/test_util/invoicer.rb +3 -3
  45. data/test/test_util/polling_manager.rb +11 -11
  46. data/test/test_util/transaction.rb +31 -55
  47. data/xmlconv.gemspec +45 -0
  48. metadata +378 -78
  49. data/.gemtest +0 -0
  50. data/lib/xmlconv/i2/parser.rb +0 -23
  51. data/lib/xmlconv.rb +0 -3
  52. data/test/mock.rb +0 -149
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46d35b7a65ef782dbe67831fecd80f57d9232459
4
+ data.tar.gz: 810608f3c9a8a737804bc9808c9b2796ffeb8a62
5
+ SHA512:
6
+ metadata.gz: c8ac3b021484be356b929461097a3ef31dd4655373cbe49c31752c8120e84ea1b437696be054502604e6b4fc884dd2320789ba52d6870c13bdb7c4546a721108
7
+ data.tar.gz: 809229409f64acf59c88cb3a6c80a3557bed1691856adc37b753dfc49c9ceb2e63bf802b7eb3e27cb5b56972bb4eeaea964ef48287348c9dc04a930dacdf9e7d
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :debugger do
5
+ if RUBY_VERSION.match(/^1/)
6
+ gem 'pry-debugger'
7
+ else
8
+ gem 'pry-byebug'
9
+ gem 'pry-doc'
10
+ end
11
+ end
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.0.2 / 08.06.2016
2
+
3
+ * Ported to Ruby 2.3.0
4
+ * Uses mail instead of tmail
5
+ * mock -> flexmock
6
+ * test/unit => minitest
7
+ * For sending mail use config options from config.yml given
8
+
1
9
  === 1.0.1 / 23.02.2011
2
10
 
3
11
  * Export Feature added
data/README.txt CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  * http://scm.ywesee.com/?p=xmlconv/.git;a=summary
4
4
 
5
- for a graphical overview please see
6
-
7
- * http://xmlconv.rubyforge.org/xmlconv.jpeg
8
-
9
5
  == DESCRIPTION:
10
6
 
11
7
  xmlconverter, convert XML to flat files.
data/Rakefile CHANGED
@@ -1,37 +1,21 @@
1
- # -*- ruby -*-
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'xmlconv/version'
6
+ require "bundler/gem_tasks"
7
+ require 'rspec/core/rake_task'
2
8
 
3
- require 'rubygems'
4
- require 'hoe'
9
+ RSpec::Core::RakeTask.new(:spec)
5
10
 
6
- Hoe.plugin :git
11
+ # dependencies are now declared in bbmb.gemspec
7
12
 
8
- # Hoe.plugin :compiler
9
- # Hoe.plugin :compiler
10
- # Hoe.plugin :cucumberfeatures
11
- # Hoe.plugin :gem_prelude_sucks
12
- # Hoe.plugin :gem_prelude_sucks
13
- # Hoe.plugin :git
14
- # Hoe.plugin :inline
15
- # Hoe.plugin :inline
16
- # Hoe.plugin :inline
17
- # Hoe.plugin :manifest
18
- # Hoe.plugin :newgem
19
- # Hoe.plugin :racc
20
- # Hoe.plugin :racc
21
- # Hoe.plugin :rubyforge
22
- # Hoe.plugin :rubyforge
23
- # Hoe.plugin :rubyforge
24
- # Hoe.plugin :website
25
- # Hoe.plugin :yard
26
-
27
- Hoe.spec 'xmlconv' do
28
- # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
29
- # you'll never have to touch them again!
30
- # (delete this comment too, of course)
31
-
32
- developer('Masaomi Hatakeyama, Zeno R.R. Davatz', 'mhatakeyama@ywesee.com, zdavatz@ywesee.com')
33
-
34
- # self.rubyforge_name = 'xmlconvx' # if different than 'xmlconv'
13
+ desc 'Offer a gem task like hoe'
14
+ task :gem => :build do
15
+ Rake::Task[:build].invoke
35
16
  end
36
17
 
37
- # vim: syntax=ruby
18
+ task :spec => :clean
19
+
20
+ require 'rake/clean'
21
+ CLEAN.include FileList['pkg/*.gem']
@@ -0,0 +1,235 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ puts "#{Time.now}: Loading #{__FILE__}"
4
+ STDOUT.sync = true
5
+
6
+ require 'syck'
7
+
8
+ if ARGV.size != 1 || !File.exist?(ARGV[0])
9
+ puts "#{__FILE__}: Must specify a config yaml for the database connection"
10
+ exit
11
+ end
12
+ config = YAML.load_file(ARGV[0])
13
+ puts "DB used is DBI:Pg:#{config['db_name']} #{config['db_user']} #{config['db_auth']}"
14
+
15
+ here = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'lib'))
16
+ $: << here
17
+ require 'logger'
18
+ require 'needle'
19
+ require 'odba/id_server'
20
+ require 'rrba/server'
21
+ require 'yus/entity'
22
+ require 'yus/privilege'
23
+ require 'ydim/autoinvoicer'
24
+ require 'ydim/client'
25
+ require 'ydim/currency_converter'
26
+ require 'ydim/currency_updater'
27
+ require 'ydim/factory'
28
+ require 'ydim/root_user'
29
+ require 'ydim/server'
30
+ require 'ydim/util'
31
+ require 'odba/connection_pool'
32
+ require 'odba/drbwrapper'
33
+ require 'ydim/root_user'
34
+ require 'ydim/autoinvoicer'
35
+ require 'xmlconv/model/address'
36
+ require 'xmlconv/model/delivery'
37
+ require 'xmlconv/model/name'
38
+ require 'xmlconv/model/party'
39
+ require 'xmlconv/model/bdd'
40
+ require 'xmlconv/model/item'
41
+ require 'xmlconv/model/bsr'
42
+ require 'xmlconv/model/delivery_item'
43
+ require 'xmlconv/util/application'
44
+ require 'xmlconv/util/session'
45
+ require 'xmlconv/util/transaction'
46
+
47
+ module XmlConv
48
+ class Server
49
+ # http://stackoverflow.com/questions/2982677/ruby-1-9-invalid-byte-sequence-in-utf-8
50
+ # https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences
51
+ def sanitize_utf8(string)
52
+ return nil if string.nil?
53
+ # return string.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
54
+ return string if string.valid_encoding?
55
+ if string.force_encoding(Encoding::ISO_8859_1).valid_encoding?
56
+ string.force_encoding(Encoding::ISO_8859_1).clone.encode(Encoding::UTF_8)
57
+ else
58
+ string.chars.select { |c| c.valid_encoding? }.join
59
+ end
60
+ end
61
+ def _migrate_to_utf8 queue, table, opts={}
62
+ while obj = queue.shift do
63
+ if obj.is_a?(Numeric)
64
+ begin
65
+ obj = ODBA.cache.fetch obj
66
+ rescue ODBA::OdbaError
67
+ return
68
+ end
69
+ else
70
+ obj = obj.odba_instance
71
+ end
72
+ puts " #{__LINE__}: #{Time.now} Migrating #{obj.class} #{obj.to_s}" if obj.is_a?(XmlConv::Model::Bdd) # if $VERBOSE
73
+ return unless obj
74
+ _migrate_obj_to_utf8 obj, queue, table, opts
75
+ obj.odba_store unless obj.odba_unsaved?
76
+ end
77
+ end
78
+ def _migrate_obj_to_utf8 obj, queue, table, opts={}
79
+ obj.instance_variables.each do |name|
80
+ child = obj.instance_variable_get name
81
+ if child.respond_to?(:odba_unsaved?) && !child.odba_unsaved? \
82
+ && obj.respond_to?(:odba_serializables) \
83
+ && obj.odba_serializables.include?(name)
84
+ child.instance_variable_set '@odba_persistent', nil
85
+ end
86
+ child = _migrate_child_to_utf8 child, queue, table, opts
87
+ obj.instance_variable_set name, child
88
+ end
89
+ if obj.is_a?(Array)
90
+ obj.collect! do |child|
91
+ _migrate_child_to_utf8 child, queue, table, opts
92
+ end
93
+ end
94
+ if obj.is_a?(Hash)
95
+ obj.dup.each do |key, child|
96
+ obj.store key, _migrate_child_to_utf8(child, queue, table, opts)
97
+ end
98
+ end
99
+ obj
100
+ end
101
+ def _migrate_child_to_utf8 child, queue, table, opts={}
102
+ @serialized ||= {}
103
+ case child
104
+ when ODBA::Persistable, ODBA::Stub
105
+ if child = child.odba_instance
106
+ if child.odba_unsaved?
107
+ _migrate_to_utf8 [child], table, opts
108
+ elsif opts[:all]
109
+ odba_id = child.odba_id
110
+ unless table[odba_id]
111
+ table.store odba_id, true
112
+ queue.push odba_id
113
+ end
114
+ end
115
+ end
116
+ when String
117
+ old = child.encoding
118
+ if ( child.encoding != Encoding::UTF_8 && child.force_encoding(Encoding::ISO_8859_1).valid_encoding? ) ||
119
+ ( child.encoding == Encoding::UTF_8 && !child.valid_encoding? )
120
+ child = child.force_encoding(Encoding::ISO_8859_1).clone.encode(Encoding::UTF_8)
121
+ puts "force_encoding from ISO_8859_1 #{old}. is now #{child}" if $VERBOSE
122
+ end
123
+ case child.encoding.to_s
124
+ when /ASCII-8BIT|US-ASCII/
125
+ # nothing todo
126
+ when /UTF-8/
127
+ puts "UTF-8: for #{child.to_s}" if $VERBOSE
128
+ child = sanitize_utf8(child)
129
+ when /ISO-8859-1/i
130
+ child = sanitize_utf8(child)
131
+ # child = child.force_encoding('UTF-8')
132
+ puts "force_encoding from #{old}. is now #{child}" if $VERBOSE
133
+ else
134
+ puts "Unhandeled encoding #{child.encoding}"
135
+ # child = child.force_encoding
136
+ end
137
+ when
138
+ Yus::Entity,
139
+ Yus::Privilege,
140
+ YDIM::AutoInvoice,
141
+ YDIM::Debitor,
142
+ YDIM::Debitor,
143
+ YDIM::Invoice,
144
+ YDIM::Invoice::Info,
145
+ YDIM::Item,
146
+ XmlConv::Model::Bdd
147
+ child = _migrate_obj_to_utf8 child, queue, table, opts
148
+ when Float, Fixnum, TrueClass, FalseClass, NilClass,
149
+ XmlConv::Model::Name,
150
+ XmlConv::Model::Item,
151
+ XmlConv::Model::Party,
152
+ XmlConv::Model::Bsr,
153
+ Symbol, Time, Date, DateTime
154
+ # do nothing
155
+ else
156
+ @ignored ||= {}
157
+ unless @ignored[child.class]
158
+ @ignored.store child.class, true
159
+ warn "ignoring #{child.class}"
160
+ end
161
+ end
162
+ child
163
+ rescue SystemStackError
164
+ puts child.class
165
+ raise
166
+ end
167
+ end
168
+ end
169
+
170
+ @logger = Logger.new('/tmp/ migrate_to_utf8.log')
171
+ @logger.level = Logger::DEBUG
172
+ module Yus
173
+ class Entity
174
+ include ODBA::Persistable
175
+ class << self
176
+ alias :all :odba_extent
177
+ end
178
+ end
179
+ class Privilege
180
+ include ODBA::Persistable
181
+ class << self
182
+ alias :all :odba_extent
183
+ end
184
+ end
185
+ end
186
+ module XmlConv
187
+ module Model
188
+ class Address
189
+ include ODBA::Persistable
190
+ class << self
191
+ alias :all :odba_extent
192
+ end
193
+ end
194
+ class Transaction
195
+ include ODBA::Persistable
196
+ class << self
197
+ alias :all :odba_extent
198
+ end
199
+ end
200
+ class Bdd
201
+ include ODBA::Persistable
202
+ class << self
203
+ alias :all :odba_extent
204
+ end
205
+ end
206
+ class Party
207
+ include ODBA::Persistable
208
+ class << self
209
+ alias :all :odba_extent
210
+ end
211
+ end if false
212
+ class Bsr
213
+ include ODBA::Persistable
214
+ class << self
215
+ alias :all :odba_extent
216
+ end
217
+ end if false
218
+ end
219
+ end
220
+
221
+ ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:Pg:#{config['db_name']}", config['db_user'], config['db_auth'], :client_encoding => 'LATIN1')
222
+ ODBA.cache.setup
223
+ DRb.install_id_conv ODBA::DRbIdConv.new
224
+
225
+ @server = XmlConv::Server.new
226
+ @server.extend(DRbUndumped)
227
+ session = YDIM::RootSession.new(YDIM::RootUser.new(1))
228
+
229
+ session.serv = @server
230
+ { :bdds => XmlConv::Model::Bdd.odba_extent,
231
+ }.each do |name, to_migrate|
232
+ puts "#{Time.now}: Start migrating #{to_migrate.size} #{name}"
233
+ @server._migrate_to_utf8(to_migrate, {})
234
+ end
235
+ puts "#{Time.now}: Finished #{__FILE__}"
File without changes
data/bin/xmlconvd CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # XmlConv -- xmlconv2 -- 10.05.2012 -- yasaka@ywesee.com
2
3
  # XmlConv -- xmlconv2 -- 07.06.2004 -- hwyss@ywesee.com
3
4
 
4
5
  require 'drb/drb'
@@ -27,9 +28,10 @@ XmlConv::LOGGER = logger
27
28
  XmlConv::Util.autoload(config.plugin_dir, 'plugin')
28
29
  XmlConv::Util.autoload(config.postproc_dir, 'postproc')
29
30
 
30
- ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:pg:#{config.db_name}",
31
+ ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:Pg:#{config.db_name}",
31
32
  config.db_user, config.db_auth)
32
33
  ODBA.cache.setup
34
+ ODBA.cache.prefetch
33
35
 
34
36
  $0 = config.program_name
35
37
  DRb.start_service(config.server_url, XmlConvApp.new)
@@ -0,0 +1,23 @@
1
+ #!/usr/local/bin/ruby186/bin/ruby
2
+
3
+ require 'rubygems'
4
+
5
+ $: << '/usr/local/share/src/xmlconv/lib'
6
+
7
+ require 'lib/conversion/propharma_bdd'
8
+ require 'lib/conversion/pharmacieplus_bdd'
9
+ require 'lib/conversion/bdd_csv'
10
+ require 'lib/conversion/bdd_i2'
11
+
12
+ source_xml = ARGV.first
13
+
14
+ #reader = XmlConv::Conversion::ProPharmaBdd
15
+ reader = XmlConv::Conversion::PharmaciePlusBdd
16
+ #input = reader.parse(File.read('input.txt'))
17
+ input = reader.parse(File.read(source_xml))
18
+ model = reader.convert(input)
19
+ #writer = XmlConv::Conversion::BddCsv
20
+ writer = XmlConv::Conversion::BddI2
21
+ output = writer.convert(model)
22
+
23
+ print output.to_s
@@ -34,6 +34,12 @@ module XmlConv
34
34
  'invoice_item_format' => "Commission %s\n%s %1.2f Turnover\nout of %i transmitted invoices",
35
35
  'log_file' => STDERR,
36
36
  'log_level' => 'INFO',
37
+ 'mail_suppress_sending' => false,
38
+ 'smtp_server' => 'localhost',
39
+ 'smtp_port' => 587,
40
+ 'smtp_user' => 'username@domain',
41
+ 'smtp_pass' => 'topsecret',
42
+ 'smtp_domain' => 'localdomain',
37
43
  'mail_host' => 'localhost',
38
44
  'mail_from' => 'xmlconv@ywesee.com',
39
45
  'pass_hash' => nil,
@@ -34,7 +34,7 @@ module XmlConv
34
34
  :th_commit_time => 'Zeit',
35
35
  :th_error => 'Fehler',
36
36
  :th_input => 'Input',
37
- :th_uri_comparable => 'Empf�nger',
37
+ :th_uri_comparable => 'Empfänger',
38
38
  :th_filename => 'Filename',
39
39
  :th_transaction_id => 'ID',
40
40
  :th_origin => 'Absender',
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # I2::Header -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
2
+ # XmlConv::I2::Header -- xmlconv -- 27.07.2011 -- mhatakeyama@ywesee.com
3
+ # XmlConv::I2::Header -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
3
4
 
4
5
  module XmlConv
5
6
  module I2
@@ -10,8 +11,9 @@ module XmlConv
10
11
  @recipient_id = recipient_id
11
12
  @prefix = @recipient_id
12
13
  time = Time.now
13
- msec = sprintf('%03i', (time.to_f * 1000).to_i % 100)
14
- @transaction_id = time.strftime("%Y%m%d%H%M%S#{msec}")
14
+ # msec = sprintf('%03i', (time.to_f * 1000).to_i % 100)
15
+ #@transaction_id = time.strftime("%Y%m%d%H%M#{msec}")
16
+ @transaction_id = time.strftime("%Y%m%d%H%M")
15
17
  end
16
18
  def suffix=(suffix)
17
19
  @suffix = "_" << suffix.to_s
@@ -16,10 +16,11 @@ module XmlConv
16
16
  def to_s
17
17
  output = <<-EOS
18
18
  500:#{@number}
19
- 501:#{@article_ean}
20
19
  EOS
20
+ #501:#{@article_ean}
21
21
  [@customer_id, @pharmacode].compact.each { |id|
22
- output << sprintf("502:%s\n", id)
22
+ #output << sprintf("502:%s\n", id)
23
+ output << sprintf("501:%s\n", id)
23
24
  }
24
25
  output << sprintf("520:%s\n", @qty)
25
26
  if(@unit)
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # XmlConv::Application -- xmlconv -- 10.05.2012 -- yasaka@ywesee.com
3
+ # XmlConv::Application -- xmlconv -- 29.09.2011 -- mhatakeyama@ywesee.com
2
4
  # XmlConv::Application -- xmlconv2 -- 07.06.2004 -- hwyss@ywesee.com
3
5
 
4
6
  require 'sbsm/drbserver'
@@ -37,12 +39,13 @@ module XmlConv
37
39
  transaction.postprocess
38
40
  rescue Exception => error
39
41
  transaction.error = error
40
- ensure
41
- @transactions.push(transaction)
42
- ODBA.transaction {
43
- @transactions.odba_store
44
- }
45
- end
42
+ ensure
43
+ ODBA.transaction {
44
+ transaction.odba_store
45
+ @transactions.push(transaction)
46
+ @transactions.odba_isolated_store
47
+ }
48
+ end
46
49
  def next_transaction_id
47
50
  @id_mutex.synchronize {
48
51
  @next_transaction_id ||= @transactions.collect { |transaction|
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # Destination -- xmlconv2 -- 08.06.2004 -- hwyss@ywesee.com
2
+ # XmlConv::Destination -- xmlconv -- 22.09.2011 -- mhatakeyama@ywesee.com
3
+ # XmlConv::Destination -- xmlconv2 -- 08.06.2004 -- hwyss@ywesee.com
3
4
 
4
5
  require 'fileutils'
5
6
  require 'uri'
@@ -134,17 +135,21 @@ module XmlConv
134
135
  end
135
136
  def deliver_to_connection(connection, delivery, idx=nil)
136
137
  if(delivery.is_a?(Array))
137
- delivery.each_with_index { |part, idx|
138
- deliver_to_connection(connection, part, idx)
138
+ #delivery.each_with_index { |part, idx|
139
+ delivery.each { |part|
140
+ #deliver_to_connection(connection, part, idx)
141
+ deliver_to_connection(connection, part)
139
142
  }
140
143
  else
141
144
  fh = Tempfile.new('xmlconv')
142
145
  fh.puts(delivery)
143
146
  fh.flush
144
147
  target = delivery.filename
145
- if(idx)
146
- target = sprintf("%03i_%s", idx, target)
147
- end
148
+ # if(idx)
149
+ #target = sprintf("%03i_%s", idx, target)
150
+ # target.gsub!(/\.dat/, "%03i.dat" % idx)
151
+ # target.gsub!(/(CO_\d{13})/, '\1%02d' % idx)
152
+ # end
148
153
  if(@tmp)
149
154
  tmp = File.join(@tmp.path, target)
150
155
  connection.puttextfile(fh.path, tmp)
@@ -1,30 +1,42 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Util::Mail -- XmlConv -- 23.04.2009 -- hwyss@ywesee.com
3
4
 
4
- require 'net/smtp'
5
- require 'tmail'
5
+ require 'mail'
6
6
  require 'xmlconv/config'
7
7
 
8
8
  module XmlConv
9
9
  module Util
10
10
  module Mail
11
11
  SMTP_HANDLER = Net::SMTP
12
- def Mail.notify recipients, subject, body
12
+ def Mail.notify recipients, my_subject, my_body
13
+ config = XmlConv::CONFIG
14
+ if config.mail_suppress_sending
15
+ puts "#{__FILE__}:#{__LINE__} Suppress sending mail with subject: #{my_subject}"
16
+ ::Mail.defaults do delivery_method :test end
17
+ else
18
+ puts "Mail.sendmail #{config.smtp_server} #{config.smtp_port} smtp_user: #{config.smtp_user} subject #{my_subject}"
19
+ ::Mail.defaults do
20
+ options = { :address => config.smtp_server,
21
+ :port => config.smtp_port,
22
+ :domain => config.smtp_domain,
23
+ :user_name => config.smtp_user,
24
+ :password => config.smtp_pass,
25
+ :authentication => 'plain',
26
+ :enable_starttls_auto => true }
27
+ delivery_method :smtp, options
28
+ end
29
+ end
13
30
  recipients.flatten!
14
31
  recipients.compact!
15
32
  recipients.uniq!
16
33
  return if(recipients.empty?)
17
- mail = TMail::Mail.new
18
- mail.set_content_type('text', 'plain', 'charset'=>'ISO-8859-1')
19
- mail.body = body
20
- mail.from = XmlConv::CONFIG.mail_from
21
- mail.to = recipients
22
- mail.subject = subject
23
- mail.date = Time.now
24
- mail['User-Agent'] = 'XmlConv::Util::Mail'
25
- SMTP_HANDLER.start(XmlConv::CONFIG.mail_host) { |smtp|
26
- smtp.sendmail(mail.encoded, XmlConv::CONFIG.mail_from, recipients)
27
- }
34
+ mail = ::Mail.deliver do
35
+ from (config.mail_from || 'dummy@test.com')
36
+ to recipients
37
+ subject my_subject
38
+ body my_body
39
+ end
28
40
  end
29
41
  end
30
42
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # Util::Transaction -- xmlconv2 -- 10.05.2012 -- yasaka@ywesee.com
2
3
  # Util::Transaction -- xmlconv2 -- 04.06.2004 -- hwyss@ywesee.com
3
4
 
4
5
  require 'odba'
@@ -10,6 +11,7 @@ module XmlConv
10
11
  class Transaction
11
12
  include ODBA::Persistable
12
13
  ODBA_SERIALIZABLE = ['@postprocs', '@responses', '@arguments']
14
+ ODBA_PREFETCH = true
13
15
  odba_index :invoice_ids
14
16
  attr_accessor :input, :reader, :writer, :destination, :origin,
15
17
  :transaction_id, :partner, :error, :postprocs,
@@ -28,7 +30,7 @@ module XmlConv
28
30
  @arguments ||= []
29
31
  @model = reader_instance.convert(input_model, *@arguments)
30
32
  output_model = writer_instance.convert(@model, *@arguments)
31
- @output = output_model.to_s
33
+ @output = output_model.is_a?(Array) ? output_model.join("\n").to_s : output_model.to_s
32
34
  @destination.deliver(output_model)
33
35
  @commit_time = Time.now
34
36
  @output
@@ -0,0 +1,3 @@
1
+ module XmlConv
2
+ VERSION = '1.0.2'
3
+ end
data/readme.md ADDED
@@ -0,0 +1,46 @@
1
+ # xmlconv
2
+
3
+ * https://github.com/zdavatz/xmlconv
4
+
5
+ ## DESCRIPTION:
6
+
7
+ xmlconverter, convert XML to flat files.
8
+
9
+ ## REQUIREMENTS:
10
+
11
+ * xmlconv - sudo gem install sandozxmlconv
12
+
13
+ ## INSTALL:
14
+
15
+ * sudo gem install xmlconv
16
+
17
+ ## Debugging
18
+
19
+ Use the `bin/xmlconv_admin config=/path/to/your/config.yml`. There you may call stuff like
20
+
21
+ ```transactions.size
22
+ transactions.last.status
23
+ transactions.last.output[0..120]
24
+ transactions.last.uri
25
+ transactions.last.commit_time
26
+ transactions.last.destination.uri
27
+ transactions.last.arguments
28
+ transactions.last.transaction_id
29
+ transactions.last.update_status
30
+ transactions.last.response
31
+ transactions.last.output_model
32
+ transactions.last.partner
33
+ transactions.last.reader
34
+ transactions.last.writer```
35
+
36
+
37
+ ## DEVELOPERS:
38
+
39
+ * Zeno R.R. Davatz
40
+ * Masaomi Hatakeyama
41
+ * Hannes Wyss (up to Version 1.0)
42
+ * Niklaus Giger (Ported to Ruby 2.3.1)
43
+
44
+ ## LICENSE:
45
+
46
+ GPLv2.0
@@ -0,0 +1,10 @@
1
+ --- !ruby/object:XmlConv::Util::PollingMission
2
+ reader: I2Bdd
3
+ directory: "./test/test_util/data/i2"
4
+ writer: BddXml
5
+ destination: "http://example.com:12345"
6
+ --- !ruby/object:XmlConv::Util::PollingMission
7
+ directory: "./test/test_util/data/xml"
8
+ destination: "http://user:pass@foo.bar.baz"
9
+ writer: BddI2
10
+ reader: XmlBdd
@@ -4,12 +4,12 @@
4
4
  $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
6
 
7
- require 'test/unit'
8
7
  require 'xmlconv/i2/address'
8
+ require 'minitest/autorun'
9
9
 
10
10
  module XmlConv
11
11
  module I2
12
- class TestAddress < Test::Unit::TestCase
12
+ class TestAddress < ::Minitest::Test
13
13
  def setup
14
14
  @address = I2::Address.new
15
15
  end
data/test/test_i2/date.rb CHANGED
@@ -4,12 +4,12 @@
4
4
  $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
6
 
7
- require 'test/unit'
8
7
  require 'xmlconv/i2/date'
8
+ require 'minitest/autorun'
9
9
 
10
10
  module XmlConv
11
11
  module I2
12
- class TestDate < Test::Unit::TestCase
12
+ class TestDate < ::Minitest::Test
13
13
  def test_from_date
14
14
  a_date = Date.new(1975, 8, 21)
15
15
  date = I2::Date.from_date(a_date)