Class: XmlConv::Util::Transaction
- Inherits:
-
Object
- Object
- XmlConv::Util::Transaction
- Includes:
- ODBA::Persistable
- Defined in:
- lib/xmlconv/util/transaction.rb
Constant Summary collapse
- ODBA_SERIALIZABLE =
['@postprocs', '@responses', '@arguments']
- ODBA_PREFETCH =
true
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#commit_time ⇒ Object
readonly
Returns the value of attribute commit_time.
-
#debug_recipients ⇒ Object
Returns the value of attribute debug_recipients.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#error ⇒ Object
Returns the value of attribute error.
-
#error_recipients ⇒ Object
Returns the value of attribute error_recipients.
-
#input ⇒ Object
Returns the value of attribute input.
-
#input_model ⇒ Object
readonly
Returns the value of attribute input_model.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#output_model ⇒ Object
readonly
Returns the value of attribute output_model.
-
#partner ⇒ Object
Returns the value of attribute partner.
-
#postprocs ⇒ Object
Returns the value of attribute postprocs.
-
#reader ⇒ Object
Returns the value of attribute reader.
-
#response ⇒ Object
Returns the value of attribute response.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#writer ⇒ Object
Returns the value of attribute writer.
Instance Method Summary collapse
-
#encode(input_body) ⇒ Object
Assumes its encoding once as ISO-8859-1 (latin1) at here, Because input_body is passed from ruby 1.8.6.
- #execute ⇒ Object
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
- #invoice_ids ⇒ Object
- #notify ⇒ Object
- #odba_store ⇒ Object
- #postprocess ⇒ Object
- #respond(delivery, response) ⇒ Object
- #responses ⇒ Object
- #status ⇒ Object
- #status=(status) ⇒ Object
- #status_comparable ⇒ Object
- #update_status ⇒ Object
- #uri ⇒ Object
- #uri_comparable ⇒ Object
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
22 23 24 |
# File 'lib/xmlconv/util/transaction.rb', line 22 def initialize @postprocs = [] end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def arguments @arguments end |
#commit_time ⇒ Object (readonly)
Returns the value of attribute commit_time.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def commit_time @commit_time end |
#debug_recipients ⇒ Object
Returns the value of attribute debug_recipients.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def debug_recipients @debug_recipients end |
#destination ⇒ Object
Returns the value of attribute destination.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def destination @destination end |
#domain ⇒ Object
Returns the value of attribute domain.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def domain @domain end |
#error ⇒ Object
Returns the value of attribute error.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def error @error end |
#error_recipients ⇒ Object
Returns the value of attribute error_recipients.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def error_recipients @error_recipients end |
#input ⇒ Object
Returns the value of attribute input.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def input @input end |
#input_model ⇒ Object (readonly)
Returns the value of attribute input_model.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def input_model @input_model end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def model @model end |
#origin ⇒ Object
Returns the value of attribute origin.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def origin @origin end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def output @output end |
#output_model ⇒ Object (readonly)
Returns the value of attribute output_model.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def output_model @output_model end |
#partner ⇒ Object
Returns the value of attribute partner.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def partner @partner end |
#postprocs ⇒ Object
Returns the value of attribute postprocs.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def postprocs @postprocs end |
#reader ⇒ Object
Returns the value of attribute reader.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def reader @reader end |
#response ⇒ Object
Returns the value of attribute response.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def response @response end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def start_time @start_time end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def transaction_id @transaction_id end |
#writer ⇒ Object
Returns the value of attribute writer.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def writer @writer end |
Instance Method Details
#encode(input_body) ⇒ Object
Assumes its encoding once as ISO-8859-1 (latin1) at here, Because input_body is passed from ruby 1.8.6
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xmlconv/util/transaction.rb', line 50 def encode(input_body) src = input_body.to_s begin # ISO-8859-1 (latin1) and WINDOWS-1252 src.encode('ISO-8859-1').force_encoding('UTF-8') rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError begin src.force_encoding('ISO-8859-1').encode('UTF-8') rescue src end end end |
#execute ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/xmlconv/util/transaction.rb', line 25 def execute reader_instance = Conversion.const_get(@reader) writer_instance = Conversion.const_get(@writer) @start_time = Time.now if !@input.valid_encoding? @input = @input.encode("UTF-8", :invalid=>:replace, :replace=>"?") else @input = @input.encode("UTF-8") end @input.gsub!(/\t+|\s+/, ' ') input_model = reader_instance.parse(@input) @arguments ||= [] @model = reader_instance.convert(input_model, *@arguments) output_model = writer_instance.convert(@model, *@arguments) @output = output_model.is_a?(Array) ? output_model.join("\n").to_s : output_model.to_s SBSM.info("_execute #{input_model.class} => #{@output} #{@destination.inspect}") @destination.deliver(output_model) @commit_time = Time.now @output ensure @destination.forget_credentials! end |
#invoice_ids ⇒ Object
65 66 67 68 69 |
# File 'lib/xmlconv/util/transaction.rb', line 65 def invoice_ids @model.invoices.collect do |inv| inv.invoice_id.last.to_s.gsub /^0+/, '' end end |
#notify ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/xmlconv/util/transaction.rb', line 70 def notify recipients = [@debug_recipients] subject = 'XmlConv2 - Debug-Notification' if(@error) recipients.push(@error_recipients) subject = 'XmlConv2 - Error-Notification' end recipients.flatten! recipients.compact! recipients.uniq! return if(recipients.empty?) body = <<-EOS Date: #{@start_time.strftime("%d.%m.%Y")} Time: #{@start_time.strftime("%H:%M:%S")} Status: #{status} Error: #{@error} Link: http://#{@domain}/de/transaction/transaction_id/#{@transaction_id} Input: # input start #{@input} # input end Output: # output start #{@output} # output end EOS Util::Mail.notify recipients, subject, body end |
#odba_store ⇒ Object
100 101 102 103 104 |
# File 'lib/xmlconv/util/transaction.rb', line 100 def odba_store @input.extend(ODBA::Persistable) if(@input) @output.extend(ODBA::Persistable) if(@output) super end |
#postprocess ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/xmlconv/util/transaction.rb', line 105 def postprocess if(@postprocs.respond_to?(:each)) @postprocs.each do |klass, *args| next if args.empty? SBSM.info(msg = "Postprocess calling for klass #{klass} #{args.inspect}") args.push(self) res = PostProcess.const_get(klass).send(*args) SBSM.info(msg = "Postprocess returned #{res} for klass #{klass}") end end end |
#respond(delivery, response) ⇒ Object
116 117 118 |
# File 'lib/xmlconv/util/transaction.rb', line 116 def respond delivery, response responses[delivery] = response end |
#responses ⇒ Object
125 126 127 |
# File 'lib/xmlconv/util/transaction.rb', line 125 def responses @responses ||= [] end |
#status ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/xmlconv/util/transaction.rb', line 128 def status if(@error) :error elsif(@model.nil? || @model.empty?) :empty elsif(@destination.respond_to?(:status)) @destination.status end end |
#status=(status) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/xmlconv/util/transaction.rb', line 137 def status=(status) if @destination.respond_to?(:status=) @destination.status = status @destination.odba_store @destination.status end end |
#status_comparable ⇒ Object
144 145 146 147 148 |
# File 'lib/xmlconv/util/transaction.rb', line 144 def status_comparable if(@destination.respond_to?(:status_comparable)) @destination.status_comparable end end |
#update_status ⇒ Object
149 150 151 152 153 |
# File 'lib/xmlconv/util/transaction.rb', line 149 def update_status if(@destination.respond_to?(:update_status)) @destination.update_status end end |
#uri ⇒ Object
154 155 156 |
# File 'lib/xmlconv/util/transaction.rb', line 154 def uri @destination.uri if(@destination.respond_to?(:uri)) end |
#uri_comparable ⇒ Object
157 158 159 |
# File 'lib/xmlconv/util/transaction.rb', line 157 def uri_comparable self.uri.to_s end |