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
- #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.
23 24 25 |
# File 'lib/xmlconv/util/transaction.rb', line 23 def initialize @postprocs = [] end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def arguments @arguments end |
#commit_time ⇒ Object (readonly)
Returns the value of attribute commit_time.
21 22 23 |
# File 'lib/xmlconv/util/transaction.rb', line 21 def commit_time @commit_time end |
#debug_recipients ⇒ Object
Returns the value of attribute debug_recipients.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def debug_recipients @debug_recipients end |
#destination ⇒ Object
Returns the value of attribute destination.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def destination @destination end |
#domain ⇒ Object
Returns the value of attribute domain.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def domain @domain end |
#error ⇒ Object
Returns the value of attribute error.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def error @error end |
#error_recipients ⇒ Object
Returns the value of attribute error_recipients.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def error_recipients @error_recipients end |
#input ⇒ Object
Returns the value of attribute input.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def input @input end |
#input_model ⇒ Object (readonly)
Returns the value of attribute input_model.
21 22 23 |
# File 'lib/xmlconv/util/transaction.rb', line 21 def input_model @input_model end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
21 22 23 |
# File 'lib/xmlconv/util/transaction.rb', line 21 def model @model end |
#origin ⇒ Object
Returns the value of attribute origin.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def origin @origin end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
21 22 23 |
# File 'lib/xmlconv/util/transaction.rb', line 21 def output @output end |
#output_model ⇒ Object (readonly)
Returns the value of attribute output_model.
21 22 23 |
# File 'lib/xmlconv/util/transaction.rb', line 21 def output_model @output_model end |
#partner ⇒ Object
Returns the value of attribute partner.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def partner @partner end |
#postprocs ⇒ Object
Returns the value of attribute postprocs.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def postprocs @postprocs end |
#reader ⇒ Object
Returns the value of attribute reader.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def reader @reader end |
#response ⇒ Object
Returns the value of attribute response.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def response @response end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
21 22 23 |
# File 'lib/xmlconv/util/transaction.rb', line 21 def start_time @start_time end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def transaction_id @transaction_id end |
#writer ⇒ Object
Returns the value of attribute writer.
17 18 19 |
# File 'lib/xmlconv/util/transaction.rb', line 17 def writer @writer end |
Instance Method Details
#execute ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xmlconv/util/transaction.rb', line 26 def execute reader_instance = Conversion.const_get(@reader) writer_instance = Conversion.const_get(@writer) @start_time = Time.now @input = @input.force_encoding("UTF-8") @input = @input.encode("UTF-8", :invalid=>:replace, :replace=>"?") if !@input.valid_encoding? @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
46 47 48 49 50 |
# File 'lib/xmlconv/util/transaction.rb', line 46 def invoice_ids @model.invoices.collect do |inv| inv.invoice_id.last.to_s.gsub /^0+/, '' end end |
#notify ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/xmlconv/util/transaction.rb', line 51 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
81 82 83 84 85 |
# File 'lib/xmlconv/util/transaction.rb', line 81 def odba_store @input.extend(ODBA::Persistable) if(@input) @output.extend(ODBA::Persistable) if(@output) super end |
#postprocess ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/xmlconv/util/transaction.rb', line 86 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
97 98 99 |
# File 'lib/xmlconv/util/transaction.rb', line 97 def respond delivery, response responses[delivery] = response end |
#responses ⇒ Object
106 107 108 |
# File 'lib/xmlconv/util/transaction.rb', line 106 def responses @responses ||= [] end |
#status ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/xmlconv/util/transaction.rb', line 109 def status if(@error) :error elsif(@model.nil? || @model.empty?) :empty elsif(@destination.respond_to?(:status)) @destination.status end end |
#status=(status) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/xmlconv/util/transaction.rb', line 118 def status=(status) if @destination.respond_to?(:status=) @destination.status = status @destination.odba_store @destination.status end end |
#status_comparable ⇒ Object
125 126 127 128 129 |
# File 'lib/xmlconv/util/transaction.rb', line 125 def status_comparable if(@destination.respond_to?(:status_comparable)) @destination.status_comparable end end |
#update_status ⇒ Object
130 131 132 133 134 |
# File 'lib/xmlconv/util/transaction.rb', line 130 def update_status if(@destination.respond_to?(:update_status)) @destination.update_status end end |
#uri ⇒ Object
135 136 137 |
# File 'lib/xmlconv/util/transaction.rb', line 135 def uri @destination.uri if(@destination.respond_to?(:uri)) end |
#uri_comparable ⇒ Object
138 139 140 |
# File 'lib/xmlconv/util/transaction.rb', line 138 def uri_comparable self.uri.to_s end |