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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/xmlconv/util/transaction.rb', line 49 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 |
# 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 @destination.deliver(output_model) @commit_time = Time.now @output ensure @destination.forget_credentials! end |
#invoice_ids ⇒ Object
64 65 66 67 68 |
# File 'lib/xmlconv/util/transaction.rb', line 64 def invoice_ids @model.invoices.collect do |inv| inv.invoice_id.last.to_s.gsub /^0+/, '' end end |
#notify ⇒ Object
69 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 |
# File 'lib/xmlconv/util/transaction.rb', line 69 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
99 100 101 102 103 |
# File 'lib/xmlconv/util/transaction.rb', line 99 def odba_store @input.extend(ODBA::Persistable) if(@input) @output.extend(ODBA::Persistable) if(@output) super end |
#postprocess ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/xmlconv/util/transaction.rb', line 104 def postprocess if(@postprocs.respond_to?(:each)) @postprocs.each { |klass, *args| next if args.empty? args.push(self) PostProcess.const_get(klass).send(*args) } end end |
#respond(delivery, response) ⇒ Object
113 114 115 |
# File 'lib/xmlconv/util/transaction.rb', line 113 def respond delivery, response responses[delivery] = response end |
#responses ⇒ Object
122 123 124 |
# File 'lib/xmlconv/util/transaction.rb', line 122 def responses @responses ||= [] end |
#status ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/xmlconv/util/transaction.rb', line 125 def status if(@error) :error elsif(@model.nil? || @model.empty?) :empty elsif(@destination.respond_to?(:status)) @destination.status end end |
#status=(status) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/xmlconv/util/transaction.rb', line 134 def status=(status) if @destination.respond_to?(:status=) @destination.status = status @destination.odba_store @destination.status end end |
#status_comparable ⇒ Object
141 142 143 144 145 |
# File 'lib/xmlconv/util/transaction.rb', line 141 def status_comparable if(@destination.respond_to?(:status_comparable)) @destination.status_comparable end end |
#update_status ⇒ Object
146 147 148 149 150 |
# File 'lib/xmlconv/util/transaction.rb', line 146 def update_status if(@destination.respond_to?(:update_status)) @destination.update_status end end |
#uri ⇒ Object
151 152 153 |
# File 'lib/xmlconv/util/transaction.rb', line 151 def uri @destination.uri if(@destination.respond_to?(:uri)) end |
#uri_comparable ⇒ Object
154 155 156 |
# File 'lib/xmlconv/util/transaction.rb', line 154 def uri_comparable self.uri.to_s end |