et_fake_ccd 0.1.15 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98f01c0ec54cb21eff60bfdd6bd59ecd100219efb7b4258b46307dccb1f856bd
4
- data.tar.gz: f99db7b939cc55c46a1af436bdcec04c79ba95fee7b86786f1c5df863b98f3ad
3
+ metadata.gz: 3650d5f2910829691719778ec18ca0da089581e9126468cf404704513c9b34f2
4
+ data.tar.gz: 4792f9cd762c5ba1b8b5f79e5a655a6a6602908571a79abe20ce5e3609556c4b
5
5
  SHA512:
6
- metadata.gz: 5f28ae1acf991e1447bc3d0bb4b8a09955f5af4ecc3948cb32a838cafe2a265fde9c2e1b803f4b1039fbc5bf1c7a7948dfdc84ea1674feb690e6eed01f7aa893
7
- data.tar.gz: ceae468e63c16b5207fc83faf3224e8208953265d5312b89d66dd3609d6c8ffff87ab6633b41e9a1774e5980d25bc856a8fcd3dc8103a9bcf21ad6015a21cc1d
6
+ metadata.gz: 7902fff2cc94e78d8fa52eadf4cfcbdfb9567c8bf4aea3a418f32c31d24c6af2305299d65acc4d5ad404895464048befea0efbcf8dcd8e0b8e5845b8d52af7c1
7
+ data.tar.gz: 37ac8465908e78804bcf5f4df3210a6882557da67df8e76b58070f12dfd60581b5263871503796c5f254bd7057bde64738e695a794b917c325317de8c1a7b242
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- et_fake_ccd (0.1.15)
4
+ et_fake_ccd (0.1.17)
5
5
  activemodel (~> 5.2, >= 5.2.3)
6
6
  puma (~> 3.12)
7
7
  roda (~> 3.21)
@@ -0,0 +1,27 @@
1
+ require 'active_model'
2
+ module EtFakeCcd
3
+ module Command
4
+ class UploadDocumentCommand
5
+ include ActiveModel::Model
6
+ include ActiveModel::Attributes
7
+
8
+ attribute :data
9
+
10
+ def self.from_json(json)
11
+ new data: json
12
+ end
13
+
14
+ validate :validate_data
15
+
16
+ private
17
+
18
+ def validate_data
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ #{"exception":"uk.gov.hmcts.ccd.endpoint.exceptions.CaseValidationException","timestamp":"2019-07-01T15:33:41.417","status":422,"error":"Unprocessable Entity","message":"Case data validation failed","path":"/caseworkers/22/jurisdictions/EMPLOYMENT/case-types/EmpTrib_MVP_1.0_Manc/cases","details":{"field_errors":[{"id":"claimantType.claimant_phone_number","message":"The data entered is not valid for this type of field, please delete and re-enter using only valid data"}]},"callbackErrors":null,"callbackWarnings":null}
26
+ #{"exception":"uk.gov.hmcts.ccd.endpoint.exceptions.CaseValidationException","timestamp":"2019-07-01T15:51:15.291","status":422,"error":"Unprocessable Entity","message":"Case data validation failed","path":"/caseworkers/22/jurisdictions/EMPLOYMENT/case-types/EmpTrib_MVP_1.0_Manc/cases","details":{"field_errors":[{"id":"claimantType.claimant_mobile_number","message":"The data entered is not valid for this type of field, please delete and re-enter using only valid data"},{"id":"claimantType.claimant_phone_number","message":"The data entered is not valid for this type of field, please delete and re-enter using only valid data"}]},"callbackErrors":null,"callbackWarnings":null}
27
+ #{"exception":"uk.gov.hmcts.ccd.endpoint.exceptions.CaseValidationException","timestamp":"2019-07-01T16:02:28.045","status":422,"error":"Unprocessable Entity","message":"Case data validation failed","path":"/caseworkers/22/jurisdictions/EMPLOYMENT/case-types/EmpTrib_MVP_1.0_Manc/cases","details":{"field_errors":[{"id":"claimant_TypeOfClaimant","message":"Wrong is not a valid value"},{"id":"claimantType.claimant_mobile_number","message":"The data entered is not valid for this type of field, please delete and re-enter using only valid data"},{"id":"claimantType.claimant_phone_number","message":"The data entered is not valid for this type of field, please delete and re-enter using only valid data"}]},"callbackErrors":null,"callbackWarnings":null}
@@ -2,3 +2,4 @@ require 'et_fake_ccd/command/lease_command'
2
2
  require 'et_fake_ccd/command/login_user_command'
3
3
  require 'et_fake_ccd/command/create_case_command'
4
4
  require 'et_fake_ccd/command/create_bulk_action_case_command'
5
+ require 'et_fake_ccd/command/upload_document_command'
@@ -4,6 +4,7 @@ module EtFakeCcd
4
4
  include Singleton
5
5
 
6
6
  attr_accessor :microservice, :microservice_secret, :valid_credentials, :oauth2_client_id, :oauth2_redirect_url
7
+ attr_accessor :file_storage_path
7
8
  end
8
9
 
9
10
  Config.instance.tap do |c|
@@ -15,5 +16,7 @@ module EtFakeCcd
15
16
  ]
16
17
  c.oauth2_client_id = "ccd_gateway"
17
18
  c.oauth2_redirect_url = "http://localhost:3451/oauth2redirect" # The contents of this at the moment are not important
19
+ c.file_storage_path = File.join Dir.pwd, 'tmp', 'file_storage'
20
+ FileUtils.mkdir_p(c.file_storage_path)
18
21
  end
19
22
  end
@@ -0,0 +1,70 @@
1
+ require "singleton"
2
+ require "securerandom"
3
+ module EtFakeCcd
4
+ class DocumentStoreService
5
+ include Singleton
6
+ def self.store_file(filename:, type:, file:, classification:)
7
+ instance.store_file(filename: filename, type: type, file: file, classification: classification)
8
+ end
9
+
10
+ def self.find_by_id(id)
11
+ instance.find_by_id(id)
12
+ end
13
+
14
+ def self.find_file_by_id(id)
15
+ instance.find_file_by_id(id)
16
+ end
17
+
18
+ def store_file(filename:, type:, file:, classification:)
19
+ adapter.store(filename: filename, type: type, file: file, classification: classification)
20
+ end
21
+
22
+ def find_by_id(id)
23
+ adapter.fetch_by_id(id)
24
+ end
25
+
26
+ def find_file_by_id(id)
27
+ adapter.fetch_file_by_id(id)
28
+ end
29
+
30
+ def adapter
31
+ @adapter ||= InMemoryAdapter.new
32
+ end
33
+
34
+ class InMemoryAdapter
35
+ def initialize(file_storage_path: ::EtFakeCcd.config.file_storage_path)
36
+ self.data = {}
37
+ self.file_storage_path = file_storage_path
38
+ end
39
+
40
+ def store(filename:, type:, file:, classification:)
41
+ uuid = SecureRandom.uuid
42
+ file_path = File.join(file_storage_path, uuid)
43
+ FileUtils.cp file.path, file_path
44
+ data[uuid] = {
45
+ 'filename' => filename,
46
+ 'type' => type,
47
+ 'file_path' => uuid,
48
+ 'size' => file.size,
49
+ 'classification' => classification
50
+ }
51
+ uuid
52
+ end
53
+
54
+ def fetch_by_id(id)
55
+ data[id]
56
+ end
57
+
58
+ def fetch_file_by_id(id)
59
+ document = fetch_by_id(id)
60
+ return nil if document.nil?
61
+
62
+ File.new(File.join(file_storage_path, document['file_path']), 'rb')
63
+ end
64
+
65
+ private
66
+
67
+ attr_accessor :data, :file_storage_path
68
+ end
69
+ end
70
+ end
@@ -2,6 +2,7 @@ require "roda"
2
2
  require "et_fake_ccd/service/sidam_app"
3
3
  require "et_fake_ccd/service/auth_app"
4
4
  require "et_fake_ccd/service/data_store_app"
5
+ require "et_fake_ccd/service/document_store_app"
5
6
  require "et_fake_ccd/service/authentication_web_app"
6
7
  require "et_fake_ccd/service/case_management_web_app"
7
8
  require "et_fake_ccd/service/api_gateway_web_app"
@@ -11,6 +12,7 @@ module EtFakeCcd
11
12
  run "idam", Service::SidamApp
12
13
  run "auth", Service::AuthApp
13
14
  run "data_store", Service::DataStoreApp
15
+ run "document_store", Service::DocumentStoreApp
14
16
  run "authentication-web", Service::AuthenticationWebApp
15
17
  run "case-management-web", Service::CaseManagementWebApp
16
18
  run "api-gateway", Service::ApiGatewayWebApp
@@ -0,0 +1,125 @@
1
+ require 'roda'
2
+ require 'json'
3
+ require 'et_fake_ccd/commands'
4
+ require 'et_fake_ccd/auth_service'
5
+ require 'et_fake_ccd/document_store_service'
6
+ module EtFakeCcd
7
+ module Service
8
+ class DocumentStoreApp < Roda
9
+ plugin :request_headers
10
+ plugin :halt
11
+ plugin :sinatra_helpers
12
+ route do |r|
13
+ r.is "documents" do
14
+ r.post do
15
+ unless EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
16
+ r.halt 403, forbidden_error_for(r)
17
+ break
18
+ end
19
+ command = ::EtFakeCcd::Command::UploadDocumentCommand.from_json(r.params)
20
+ unless command.valid?
21
+ r.halt 422, render_error_for(command, r)
22
+ break
23
+ end
24
+
25
+ upload_document(r)
26
+ end
27
+ end
28
+ r.is "documents", String, "binary" do |uuid|
29
+ r.get do
30
+ file = ::EtFakeCcd::DocumentStoreService.find_file_by_id(uuid)
31
+ unless file
32
+ r.halt 404, not_found_error_for(r)
33
+ break
34
+ end
35
+ send_file file.path
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def upload_document(request)
43
+ file = request.params['files']
44
+ id = ::EtFakeCcd::DocumentStoreService.store_file filename: file[:filename], type: file[:type], file: file[:tempfile], classification: request.params['classification']
45
+ document = ::EtFakeCcd::DocumentStoreService.find_by_id(id)
46
+ render_document id: id, document: document, documents_root: request.url
47
+ end
48
+
49
+ def render_document(id:, document:, documents_root:)
50
+ now = Time.now.strftime("%Y-%m-%dT%H:%M:%S%z")
51
+ j = {
52
+ "_embedded": {
53
+ "documents": [
54
+ {
55
+ "size": document['size'],
56
+ "mimeType": document['type'],
57
+ "originalDocumentName": document['filename'],
58
+ "createdBy": "42f46280-24b4-4f4d-b93c-8c92cbb2b93f",
59
+ "lastModifiedBy": "42f46280-24b4-4f4d-b93c-8c92cbb2b93f",
60
+ "modifiedOn": now,
61
+ "createdOn": now,
62
+ "classification": document['classification'],
63
+ "_links": {
64
+ "self": {
65
+ "href": "#{documents_root}/#{id}"
66
+ },
67
+ "binary": {
68
+ "href": "#{documents_root}/#{id}/binary"
69
+ },
70
+ "thumbnail": {
71
+ "href": "#{documents_root}/#{id}/thumbnail"
72
+ }
73
+ },
74
+ "_embedded": {
75
+ "allDocumentVersions": {
76
+ "_embedded": {
77
+ "documentVersions": [
78
+ {
79
+ "size": document['size'],
80
+ "mimeType": document['type'],
81
+ "originalDocumentName": document['filename'],
82
+ "createdBy": "42f46280-24b4-4f4d-b93c-8c92cbb2b93f",
83
+ "createdOn": now,
84
+ "_links": {
85
+ "document": {
86
+ "href": "#{documents_root}/#{id}"
87
+ },
88
+ "self": {
89
+ "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d"
90
+ },
91
+ "binary": {
92
+ "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d/binary"
93
+ },
94
+ "thumbnail": {
95
+ "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d/thumbnail"
96
+ },
97
+ "migrate": {
98
+ "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d/migrate"
99
+ }
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ }
105
+ }
106
+ }
107
+ ]
108
+ }
109
+ }
110
+ JSON.generate(j)
111
+ end
112
+
113
+
114
+ def forbidden_error_for(r)
115
+ j = {"timestamp":"2019-07-01T07:46:35.405+0000","status":403,"error":"Forbidden","message":"Access Denied","path": r.path}
116
+ JSON.generate(j)
117
+ end
118
+
119
+ def not_found_error_for(r)
120
+ j = {"timestamp":"2019-07-01T07:46:35.405+0000","status":404,"error":"Not Found","message":"Not Found","path": r.path}
121
+ JSON.generate(j)
122
+ end
123
+ end
124
+ end
125
+ end
@@ -1,3 +1,3 @@
1
1
  module EtFakeCcd
2
- VERSION = "0.1.15"
2
+ VERSION = "0.1.17"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: et_fake_ccd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-24 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda
@@ -176,15 +176,18 @@ files:
176
176
  - lib/et_fake_ccd/command/create_case_command.rb
177
177
  - lib/et_fake_ccd/command/lease_command.rb
178
178
  - lib/et_fake_ccd/command/login_user_command.rb
179
+ - lib/et_fake_ccd/command/upload_document_command.rb
179
180
  - lib/et_fake_ccd/commands.rb
180
181
  - lib/et_fake_ccd/config.rb
181
182
  - lib/et_fake_ccd/data_store_service.rb
183
+ - lib/et_fake_ccd/document_store_service.rb
182
184
  - lib/et_fake_ccd/root_app.rb
183
185
  - lib/et_fake_ccd/service/api_gateway_web_app.rb
184
186
  - lib/et_fake_ccd/service/auth_app.rb
185
187
  - lib/et_fake_ccd/service/authentication_web_app.rb
186
188
  - lib/et_fake_ccd/service/case_management_web_app.rb
187
189
  - lib/et_fake_ccd/service/data_store_app.rb
190
+ - lib/et_fake_ccd/service/document_store_app.rb
188
191
  - lib/et_fake_ccd/service/sidam_app.rb
189
192
  - lib/et_fake_ccd/validator/otp_validator.rb
190
193
  - lib/et_fake_ccd/version.rb