cmor_transports 0.0.56.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +19 -0
  5. data/app/assets/config/cmor/transports_manifest.js +1 -0
  6. data/app/assets/javascripts/cmor/transports/application.js +2 -0
  7. data/app/assets/javascripts/cmor/transports/application/keep.js +0 -0
  8. data/app/assets/javascripts/cmor_transports.js +2 -0
  9. data/app/assets/stylesheets/cmor/transports/application.css +3 -0
  10. data/app/assets/stylesheets/cmor/transports/application/keep.css +0 -0
  11. data/app/assets/stylesheets/cmor_transports.css +3 -0
  12. data/app/concerns/cmor/transports/models/uuid_concern.rb +20 -0
  13. data/app/concerns/cmor/transports/resources_controller/export_concern.rb +63 -0
  14. data/app/concerns/cmor/transports/routing/export_resources_concern.rb +30 -0
  15. data/app/controllers/cmor/transports/api/incoming/create_services_controller.rb +22 -0
  16. data/app/controllers/cmor/transports/api/incoming/show_services_controller.rb +22 -0
  17. data/app/controllers/cmor/transports/export_sidebars_controller.rb +11 -0
  18. data/app/controllers/cmor/transports/exports_controller.rb +24 -0
  19. data/app/controllers/cmor/transports/home_controller.rb +6 -0
  20. data/app/controllers/cmor/transports/incomings_controller.rb +16 -0
  21. data/app/controllers/cmor/transports/outgoings_controller.rb +16 -0
  22. data/app/controllers/cmor/transports/systems_controller.rb +14 -0
  23. data/app/models/cmor/transports/export.rb +61 -0
  24. data/app/models/cmor/transports/import.rb +37 -0
  25. data/app/models/cmor/transports/incoming.rb +40 -0
  26. data/app/models/cmor/transports/outgoing.rb +98 -0
  27. data/app/models/cmor/transports/outgoing_export.rb +8 -0
  28. data/app/models/cmor/transports/outgoing_target.rb +20 -0
  29. data/app/models/cmor/transports/system.rb +15 -0
  30. data/app/services/cmor/transports/api/incoming/create_service.rb +45 -0
  31. data/app/services/cmor/transports/api/incoming/show_service.rb +22 -0
  32. data/app/services/cmor/transports/exports/base.rb +74 -0
  33. data/app/services/cmor/transports/exports/csv_service.rb +32 -0
  34. data/app/services/cmor/transports/exports/json_service.rb +25 -0
  35. data/app/services/cmor/transports/exports/yaml_service.rb +25 -0
  36. data/app/services/cmor/transports/packs/base.rb +19 -0
  37. data/app/services/cmor/transports/packs/zip_service.rb +28 -0
  38. data/app/services/cmor/transports/transfers/api/incoming_state_service.rb +39 -0
  39. data/app/services/cmor/transports/transfers/api/push_service.rb +47 -0
  40. data/app/view_helpers/cmor/transports/application_view_helper.rb +6 -0
  41. data/app/view_helpers/cmor/transports/export_view_helper.rb +63 -0
  42. data/app/views/cmor/core/backend/resources_controller/base/_export_form.html.haml +3 -0
  43. data/app/views/cmor/core/backend/resources_controller/base/export.html.haml +6 -0
  44. data/app/views/cmor/transports/export_sidebars/show.html.haml +1 -0
  45. data/app/views/cmor/transports/exports/_after_show_table.html.haml +9 -0
  46. data/app/views/cmor/transports/exports/_form.html.haml +6 -0
  47. data/app/views/cmor/transports/exports/_index_table.html.haml +14 -0
  48. data/app/views/cmor/transports/exports/_show_table.html.haml +17 -0
  49. data/app/views/cmor/transports/incomings/_index_table.html.haml +12 -0
  50. data/app/views/cmor/transports/outgoings/_after_show_table.html.haml +26 -0
  51. data/app/views/cmor/transports/outgoings/_form.html.haml +2 -0
  52. data/app/views/cmor/transports/outgoings/_index_table.html.haml +8 -0
  53. data/app/views/cmor/transports/outgoings/_show_table.html.haml +11 -0
  54. data/config/initializers/assets.rb +2 -0
  55. data/config/initializers/cmor.rb +3 -0
  56. data/config/initializers/include_routing_concerns.rb +1 -0
  57. data/config/locales/de.yml +43 -0
  58. data/config/locales/en.yml +41 -0
  59. data/config/routes.rb +31 -0
  60. data/db/migrate/20200525095216_create_cmor_transports_exports.rb +20 -0
  61. data/db/migrate/20200607101713_create_cmor_transports_outgoings.rb +15 -0
  62. data/db/migrate/20200607102346_create_cmor_transports_outgoing_exports.rb +10 -0
  63. data/db/migrate/20200607105529_create_cmor_transports_systems.rb +11 -0
  64. data/db/migrate/20200607105839_create_cmor_transports_outgoing_targets.rb +10 -0
  65. data/db/migrate/20200607110930_create_cmor_transports_incomings.rb +16 -0
  66. data/db/migrate/20200607111046_create_cmor_transports_imports.rb +17 -0
  67. data/lib/cmor/transports/configuration.rb +41 -0
  68. data/lib/cmor/transports/engine.rb +19 -0
  69. data/lib/cmor/transports/version.rb +7 -0
  70. data/lib/cmor_transports.rb +18 -0
  71. data/lib/generators/cmor/transports/install/install_generator.rb +26 -0
  72. data/lib/generators/cmor/transports/install/templates/initializer.rb +45 -0
  73. data/lib/generators/cmor/transports/install/templates/routes.source +4 -0
  74. data/lib/tasks/cmor/transports_tasks.rake +5 -0
  75. data/spec/factories/cmor_transports_exports.rb +11 -0
  76. data/spec/factories/cmor_transports_imports.rb +7 -0
  77. data/spec/factories/cmor_transports_incomings.rb +7 -0
  78. data/spec/factories/cmor_transports_outgoing_exports.rb +8 -0
  79. data/spec/factories/cmor_transports_outgoing_targets.rb +8 -0
  80. data/spec/factories/cmor_transports_outgoings.rb +6 -0
  81. data/spec/factories/cmor_transports_systems.rb +9 -0
  82. data/spec/files/cmor/transports/outgoing/output/example.zip +0 -0
  83. metadata +601 -0
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmor
4
+ module Transports
5
+ module Transfers
6
+ module Api
7
+ class IncomingStateService < Rao::Service::Base
8
+ class Result < Rao::Service::Result::Base
9
+ attr_accessor :incoming
10
+ end
11
+
12
+ attr_accessor :system_identifier, :endpoint, :api_key, :outgoing_uuid
13
+
14
+ private
15
+ def target_url
16
+ [endpoint.chomp("/"), "incoming", "show_services.json"].join("/")
17
+ end
18
+
19
+ def _perform
20
+ fetch_import_status!
21
+ end
22
+
23
+ def fetch_import_status!
24
+ headers = { "Content-Type" => "application/json", authorization: "Bearer #{api_key}" }
25
+ params = { show_service: { outgoing_uuid: outgoing_uuid } }
26
+ response = HTTParty.post(target_url, headers: headers, body: params.to_json)
27
+ parsed_response_body = JSON.parse(response.body)
28
+ if response.created?
29
+ say "success fetching incoming for outgoing with uuid #{outgoing_uuid} on system #{system_identifier}. Incoming: #{parsed_response_body.inspect}"
30
+ @result.incoming = @incoming = parsed_response_body["incoming"]
31
+ else
32
+ add_error_and_say(:base, "http error #{response.code} fetching import status for outgoing with uuid #{outgoing_uuid} on system #{system_identifier}: #{parsed_response_body["message"]}")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmor
4
+ module Transports
5
+ module Transfers
6
+ module Api
7
+ class PushService < Rao::Service::Base
8
+ class Result < Rao::Service::Result::Base
9
+ end
10
+
11
+ attr_accessor :outgoing
12
+
13
+ private
14
+ def target_url(endpoint)
15
+ [endpoint.chomp("/"), "incoming", "create_services.json"].join("/")
16
+ end
17
+
18
+
19
+ def _perform
20
+ push_to_all_systems!
21
+ end
22
+
23
+ def push_to_all_systems!
24
+ outgoing.reload.start_transferring!
25
+ outgoing.systems.each do |system|
26
+ push_to_system(system)
27
+ end
28
+ outgoing.succeed_transferring! if outgoing.may_succeed_transferring?
29
+ end
30
+
31
+ def push_to_system(system)
32
+ headers = { "Content-Type" => "application/json", authorization: "Bearer #{system.api_key}" }
33
+ params = { create_service: { outgoing: outgoing.as_json(methods: :output_base64) } }
34
+ response = HTTParty.post(target_url(system.endpoint), headers: headers, body: params.to_json)
35
+ if response.created?
36
+ say "success pushing outgoing #{outgoing.uuid} to system #{system.identifier}"
37
+ else
38
+ parsed_response_body = JSON.parse(response.body)
39
+ add_error_and_say(:base, "http error #{response.code} transferring outgoing #{outgoing.uuid} to system #{system.identifier}: #{parsed_response_body["message"]}")
40
+ outgoing.failed_transferring!
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmor::Transports
4
+ class ApplicationViewHelper < Rao::ViewHelper::Base
5
+ end
6
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cmor::Transports
4
+ # First you have to add the helper and the export concern to your controller:
5
+ #
6
+ # # app/controllers/application_controller.rb
7
+ # class ApplicationController < ActionController::Base
8
+ # include Cmor::Transports::ResourcesController::ExportConcern
9
+ # view_helper Cmor::Transports::ExportViewHelper, as: :export_helper
10
+ # # ....
11
+ # end
12
+ #
13
+ class ExportViewHelper < Rao::ViewHelper::Base
14
+ # Example:
15
+ #
16
+ # # app/views/posts/index.html.haml
17
+ # = export_helper(self).form_for(@posts, url: posts_path, method: :get) do |f|
18
+ # = f.input :email_cont, association: :author
19
+ # = f.input :title_cont
20
+ # = f.input :body_cont
21
+ # = f.boolean :published_eq
22
+ # = f.submit nil, class: 'btn btn-primary'
23
+ # = f.reset nil, class: 'btn btn-default'
24
+ #
25
+ # # app/controllers/posts_controller.rb
26
+ # class ApplicationController < ActionController::Base
27
+ # def index
28
+ # @posts = with_conditions_from_query(Post).all
29
+ # end
30
+ #
31
+ # If you are using bootstrap you may want to display the form inline for a
32
+ # more compact view:
33
+ #
34
+ # = query_helper(self).form_for(collection, html: { class: 'form-inline' }) do |f|
35
+ #
36
+ def form_for(collection, options = {}, &block)
37
+ handle_simple_form_missing unless c.respond_to?(:simple_form_for)
38
+ wrapped_collection = ExportableCollection.new(collection)
39
+ c.simple_form_for(wrapped_collection, options.reverse_merge(as: :q, url: { action: :export }), &block)
40
+ end
41
+
42
+ class ExportableCollection
43
+ include ActiveModel::Model
44
+ extend ActiveModel::Translation
45
+
46
+ def initialize(collection)
47
+ @collection = collection
48
+ end
49
+
50
+ def original_model_class_name
51
+ @collection.class.to_s.deconstantize
52
+ end
53
+
54
+ def original_model_class
55
+ @collection.klass
56
+ end
57
+ end
58
+
59
+ def handle_simple_form_missing
60
+ raise "simple_form_for is not available. Please add simple_form to your Gemfile."
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ = form.input :output_format, as: :select, collection: Cmor::Transports.export_formats.call.keys
2
+ = form.input :output_attributes, as: :check_boxes, collection: controller.send(:attributes_for_export)
3
+ = form.input :description
@@ -0,0 +1,6 @@
1
+ %h1= t('.title', inflections)
2
+
3
+ = simple_form_for(@resource, url: dump_path) do |f|
4
+ = render 'form_errors', resource: f.object
5
+ = render 'export_form', form: f
6
+ = render 'form_buttons', form: f
@@ -0,0 +1,9 @@
1
+ -# .row
2
+ -# .col-12
3
+ -# %h2= @resource.root_model.constantize.model_name.human(count: :other)
4
+
5
+ -# .row
6
+ -# .col-12
7
+ -# = collection_table(collection: @resource.root_model.constantize.find_by_sql(@resource.query), resource_class: @resource.root_model.constantize) do |table|
8
+ -# - @resource.output_attributes.each do |attribute|
9
+ -# = table.column attribute
@@ -0,0 +1,6 @@
1
+ = form.input :root_model
2
+ = form.input :query
3
+ = form.input :count_query
4
+ = form.input :output_attributes
5
+ = form.input :output_format, collection: Cmor::Transports.export_formats.call.keys
6
+ = form.input :description
@@ -0,0 +1,14 @@
1
+ = table.batch_actions
2
+ = table.id
3
+ = table.column :uuid
4
+ = table.column :root_model
5
+ = table.column :query
6
+ = table.column :count
7
+ = table.column :output_format
8
+ = table.aasm_state
9
+ = table.aasm_actions
10
+ = table.column :description
11
+ = table.association :creator, label_method: ->(r) { administrador_helper(self).label_for(r) }
12
+ = table.column :job_id
13
+ = table.attachment :output
14
+ = table.timestamps
@@ -0,0 +1,17 @@
1
+ = table.id
2
+ = table.row :uuid
3
+ = table.row :root_model
4
+ = table.row :query
5
+ = table.row :count_query
6
+ = table.row :count
7
+ = table.row :output_format
8
+ = table.row :output_attributes
9
+ = table.aasm_state
10
+ = table.aasm_actions
11
+ = table.row :service_errors
12
+ = table.row :service_messages
13
+ = table.row :description
14
+ = table.association :creator, label_method: ->(r) { administrador_helper(self).label_for(r) }
15
+ = table.row :job_id
16
+ = table.attachment :output
17
+ = table.timestamps
@@ -0,0 +1,12 @@
1
+ = table.batch_actions
2
+ = table.id
3
+ = table.column :uuid
4
+ = table.column :outgoing_uuid
5
+ = table.aasm_state
6
+ = table.column :source
7
+ = table.column :creator_type
8
+ = table.column :creator_id
9
+ = table.column :job_id
10
+ = table.attachment :input
11
+ = table.attachment :payload
12
+ = table.timestamps
@@ -0,0 +1,26 @@
1
+ .row
2
+ .col-12
3
+ %h1= Cmor::Transports::System.model_name.human(count: :other)
4
+
5
+ .row
6
+ .col-12
7
+ = collection_table(collection: @resource.outgoing_targets, resource_class: Cmor::Transports::System) do |table|
8
+ = table.id
9
+ = table.column :incoming_status
10
+ = table.column :system_identifier
11
+ = table.column :system_endpoint
12
+ = table.timestamps
13
+
14
+ .row
15
+ .col-12
16
+ %h1= Cmor::Transports::Export.model_name.human(count: :other)
17
+
18
+ .row
19
+ .col-12
20
+ = collection_table(collection: @resource.exports, resource_class: Cmor::Transports::Export) do |table|
21
+ = table.column :id
22
+ = table.column :uuid
23
+ = table.column :root_model
24
+ = table.column :count
25
+ = table.column :description
26
+ = table.timestamps
@@ -0,0 +1,2 @@
1
+ = form.association :exports, as: :check_boxes, collection: Cmor::Transports::Export.all, label_method: :human
2
+ = form.association :systems, as: :check_boxes, collection: Cmor::Transports::System.all, label_method: :human
@@ -0,0 +1,8 @@
1
+ = table.batch_actions
2
+ = table.id
3
+ = table.column :uuid
4
+ = table.aasm_state
5
+ = table.association :creator
6
+ = table.column :job_id
7
+ = table.attachment :output
8
+ = table.timestamps
@@ -0,0 +1,11 @@
1
+ = table.id
2
+ = table.row :uuid
3
+ = table.aasm_state
4
+ = table.aasm_actions
5
+ = table.row :service_errors
6
+ = table.row :service_messages
7
+ = table.row :description
8
+ = table.association :creator, label_method: ->(r) { administrador_helper(self).label_for(r) }
9
+ = table.row :job_id
10
+ = table.attachment :output
11
+ = table.timestamps
@@ -0,0 +1,2 @@
1
+ Rails.application.config.assets.precompile += %w( cmor_transports.css )
2
+ Rails.application.config.assets.precompile += %w( cmor_transports.js )
@@ -0,0 +1,3 @@
1
+ Cmor.configure do |config|
2
+ config.administrador.register_engine('Cmor::Transports::Engine', {})
3
+ end
@@ -0,0 +1 @@
1
+ ActionDispatch::Routing::Mapper.send(:include, Cmor::Transports::Routing::ExportResourcesConcern)
@@ -0,0 +1,43 @@
1
+ de:
2
+ activerecord:
3
+ models:
4
+ cmor/transports/export:
5
+ one: Export
6
+ other: Exporte
7
+ attributes:
8
+ cmor/transports/export:
9
+ id: ID
10
+ count_query: Zähl-Abfrage
11
+ creator_id: Ersteller
12
+ creator: Ersteller
13
+ creator_type: Ersteller-Typ
14
+ description: Beschreibung
15
+ job_id: Job ID
16
+ output_attributes: Ausgabe-Attribute
17
+ output_format: Ausgabe-Format
18
+ query: Abfrage
19
+ root_model: Wurzel-Modell
20
+ service_errors: Dienstfehler
21
+ service_messages: Dienstnachrichten
22
+ state: Status
23
+ uuid: UUID
24
+ created_at: Erstellt am
25
+ updated_at: Aktualisiert am
26
+ classes:
27
+ cmor/transports/engine: Transporte
28
+ cmor:
29
+ core:
30
+ backend:
31
+ resources_controller:
32
+ base:
33
+ export:
34
+ title: "%{collection_name} exportieren"
35
+ index:
36
+ export: "Exportieren"
37
+ transports:
38
+ exports:
39
+ export:
40
+ success: "Ihr Export wurde eingeplant. Klicken Sie <a href=\"%{url}\" class=\"alert-link\">hier</a> um ihn sich anzeigen zu lassen."
41
+ error: "Ihr Export konnte nicht eingeplant werden."
42
+ routes:
43
+ cmor-transports-engine: transporte
@@ -0,0 +1,41 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ cmor/transports/export:
5
+ one: Export
6
+ other: Exports
7
+ attributes:
8
+ cmor/transports/export:
9
+ id: ID
10
+ count_query: Count query
11
+ creator: Creator
12
+ creator_id: Creator
13
+ creator_type: Creator type
14
+ description: Description
15
+ job_id: Job ID
16
+ output_attributes: Output attributes
17
+ output_format: Output format
18
+ query: Query
19
+ root_model: Root model
20
+ service_errors: Service errors
21
+ service_messages: Service messages
22
+ state: State
23
+ uuid: UUID
24
+ created_at: Created at
25
+ updated_at: Updated at
26
+ classes:
27
+ cmor/transports/engine: Transports
28
+ cmor:
29
+ core:
30
+ backend:
31
+ resources_controller:
32
+ base:
33
+ index:
34
+ export: "Export"
35
+ transports:
36
+ exports:
37
+ export:
38
+ success: "The export was scheduled. Click on <a href=\"%{url}\" class=\"alert-link\">hier</a> to see details."
39
+ error: "The export could not be scheduled."
40
+ routes:
41
+ cmor-transports-engine: transports
@@ -0,0 +1,31 @@
1
+ Cmor::Transports::Engine.routes.draw do
2
+ resources :exports do
3
+ post :destroy_many, on: :collection
4
+ post 'trigger_event/:machine_name/:event_name', on: :member, action: 'trigger_event', as: :trigger_event
5
+ end
6
+
7
+ resources :outgoings do
8
+ post :destroy_many, on: :collection
9
+ post 'trigger_event/:machine_name/:event_name', on: :member, action: 'trigger_event', as: :trigger_event
10
+ end
11
+
12
+ resources :incomings do
13
+ post :destroy_many, on: :collection
14
+ post 'trigger_event/:machine_name/:event_name', on: :member, action: 'trigger_event', as: :trigger_event
15
+ end
16
+
17
+ resources :systems do
18
+ post :destroy_many, on: :collection
19
+ end
20
+
21
+ namespace :api do
22
+ namespace :incoming do
23
+ resources :create_services, only: [:create]
24
+ resources :show_services, only: [:create]
25
+ end
26
+ end
27
+
28
+ resource :export_sidebar, only: [:show]
29
+
30
+ root to: 'home#index'
31
+ end
@@ -0,0 +1,20 @@
1
+ class CreateCmorTransportsExports < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :cmor_transports_exports do |t|
4
+ t.string :uuid, null: :false
5
+ t.string :root_model
6
+ t.text :query
7
+ t.text :count_query
8
+ t.text :output_attributes, default: [].to_yaml
9
+ t.string :output_format
10
+ t.string :state
11
+ t.text :service_messages
12
+ t.text :service_errors
13
+ t.text :description
14
+ t.references :creator, foreign_key: false, index: true, polymorphic: true
15
+ t.references :job, foreign_key: false, index: true
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end