-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #483 from slovensko-digital/GO-128/download_messag…
…es_from_fs GO-128 Download messages from FS
- Loading branch information
Showing
45 changed files
with
4,306 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Fs::MessageHelper | ||
def self.build_html_visualization(message) | ||
return [ActionController::Base.new.render_to_string('fs/messages/_submission', layout: false, locals: { message: message }), build_html_visualization_from_form(message)].compact.join('<hr>') if message.outbox? | ||
|
||
# TODO: Vieme aj lepsie identifikovat? Nejake dalsie typy v tejto kategorii neexistuju? | ||
template = if message.title.in?(['Informácia o podaní', 'Informácia o odmietnutí podania']) | ||
'fs/messages/_delivery_report' | ||
else | ||
'fs/messages/_generic_message' | ||
end | ||
|
||
ActionController::Base.new.render_to_string(template, layout: false, locals: { message: message }) | ||
end | ||
|
||
def self.build_html_visualization_from_form(message) | ||
raise 'Missing Fs::Form XSLT' unless message.form&.xslt_txt | ||
return unless message.form_object&.unsigned_content | ||
|
||
template = Nokogiri::XSLT(message.form.xslt_txt) | ||
|
||
ActionController::Base.new.render_to_string('fs/messages/_style', layout: false, locals: { message: message }) + ActionController::Base.helpers.simple_format(template.transform(message.form_object.xml_unsigned_content).to_s) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Fs | ||
class DownloadReceivedMessageJob < ApplicationJob | ||
def perform(fs_message_id, box:, fs_client: FsEnvironment.fs_client) | ||
raise unless box.is_a?(Fs::Box) | ||
return unless box.syncable? | ||
|
||
return if box.messages.where("metadata ->> 'fs_message_id' = ?", fs_message_id).any? | ||
|
||
ActiveRecord::Base.transaction do | ||
fs_api = fs_client.api(api_connection: box.api_connection, box: box) | ||
|
||
raw_message = fs_api.fetch_received_message(fs_message_id) | ||
|
||
Fs::Message.create_inbox_message_with_thread!(raw_message, box: box) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Fs | ||
class DownloadSentMessageJob < ApplicationJob | ||
def perform(fs_message_id, box:, fs_client: FsEnvironment.fs_client) | ||
raise unless box.is_a?(Fs::Box) | ||
return unless box.syncable? | ||
|
||
return if box.messages.where(type: [nil, 'Message']).where("metadata ->> 'fs_message_id' = ?", fs_message_id).any? | ||
|
||
ActiveRecord::Base.transaction do | ||
fs_api = fs_client.api(api_connection: box.api_connection, box: box) | ||
|
||
raw_message = fs_api.fetch_sent_message(fs_message_id) | ||
|
||
message = Fs::Message.create_outbox_message_with_thread!(raw_message, box: box) | ||
|
||
DownloadSentMessageRelatedMessagesJob.set(wait: 3.minutes).perform_later(message) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Fs | ||
class DownloadSentMessageRelatedMessagesJob < ApplicationJob | ||
def perform(outbox_message, from: nil, to: nil, fs_client: FsEnvironment.fs_client, batch_size: 25) | ||
raise unless outbox_message.box.is_a?(Fs::Box) | ||
return unless outbox_message.box.syncable? | ||
|
||
fs_api = fs_client.api(api_connection: outbox_message.box.api_connection, box: outbox_message.box) | ||
|
||
0.step do |k| | ||
received_messages = fs_api.fetch_received_messages(sent_message_id: outbox_message.metadata['fs_message_id'], page: k + 1, count: batch_size, from: from, to: to) | ||
|
||
received_messages['messages'].each do |received_message| | ||
::Fs::DownloadReceivedMessageJob.perform_later(received_message['message_id'], box: outbox_message.box) | ||
end | ||
|
||
break if received_messages['messages'].size < batch_size | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Fs | ||
class SyncAllBoxesJob < ApplicationJob | ||
def perform | ||
Fs::Box.where(syncable: true).find_each do |box| | ||
SyncBoxJob.perform_later(box) | ||
end | ||
|
||
# TODO ponastavovat v BetterUptime | ||
BetterUptimeApi.ping_heartbeat('FS_SYNC') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Fs | ||
class SyncBoxJob < ApplicationJob | ||
def perform(box, from: Date.today - 1.week, to: Date.tomorrow) | ||
raise unless box.is_a?(Fs::Box) | ||
return unless box.syncable? | ||
|
||
box.messages.outbox.find_each do |outbox_message| | ||
DownloadSentMessageRelatedMessagesJob.perform_later(outbox_message, from: from, to: to) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.