et_fake_ccd 1.0.2 → 1.0.3

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: 0def94d9184f152f118a1af854734057f4405d8ad9cb2ae0597b7c27374c06f8
4
- data.tar.gz: 025afae9203d9caf1f15bf15b6cac111c018d3b0940b5f2940e2f392d3e5d3a1
3
+ metadata.gz: 046a15f5ec00b9ee6bc4040f1355a8a11a13284dd08dc0e336d0f3d45e76323d
4
+ data.tar.gz: eb43a97b2993b04d99e528a0acfde42a8c1a36a05032581ae334d4f3f6c653e6
5
5
  SHA512:
6
- metadata.gz: 0001d2dd15b3e9e52161bf1d1ef51381177c2ec064362eb0191912d0c52dd2fb0c9e22609be72edba645bdf767e72fbe5d42666ce639d4b233fad9267f007423
7
- data.tar.gz: 9cf416e8c28dcecb922f00232b58d60802e99fb270501e74783e7b557276fdc57d51d093e40db180de912e4561cfd46387bd28a2c2fb5e10630fc16f871566bd
6
+ metadata.gz: 9c6a761f55be8b5ead977131d1b1e2ea00b7e05c2032ac053a5bb41c0223bbce8cc2ab23e02e9561614bcda0950d37384849ad237f6c5625a246b0ad425879bf
7
+ data.tar.gz: 0db76474da029c262c7256f69f0a8c51753263d65eac40e81152e9be13b734658233410906383298a2b473915a387169ea332f786ddb7dbdb5d7b5f48d8a86f6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- et_fake_ccd (1.0.2)
4
+ et_fake_ccd (1.0.3)
5
5
  activemodel (>= 5.2.3)
6
6
  iodine (~> 0.7)
7
7
  json-schema (~> 2.5)
@@ -13,9 +13,9 @@ PATH
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activemodel (6.0.2.1)
17
- activesupport (= 6.0.2.1)
18
- activesupport (6.0.2.1)
16
+ activemodel (6.0.2.2)
17
+ activesupport (= 6.0.2.2)
18
+ activesupport (6.0.2.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 0.7, < 2)
21
21
  minitest (~> 5.1)
@@ -31,10 +31,10 @@ GEM
31
31
  json-schema (2.8.1)
32
32
  addressable (>= 2.4)
33
33
  minitest (5.14.0)
34
- public_suffix (4.0.3)
34
+ public_suffix (4.0.4)
35
35
  rack (2.2.2)
36
36
  rake (13.0.1)
37
- roda (3.29.0)
37
+ roda (3.30.0)
38
38
  rack
39
39
  rotp (5.1.0)
40
40
  addressable (~> 2.5)
@@ -54,9 +54,9 @@ GEM
54
54
  thor (1.0.1)
55
55
  thread_safe (0.3.6)
56
56
  tilt (2.0.10)
57
- tzinfo (1.2.6)
57
+ tzinfo (1.2.7)
58
58
  thread_safe (~> 0.1)
59
- zeitwerk (2.2.2)
59
+ zeitwerk (2.3.0)
60
60
 
61
61
  PLATFORMS
62
62
  ruby
@@ -0,0 +1,23 @@
1
+ require 'active_model'
2
+ module EtFakeCcd
3
+ module Command
4
+ class StartMultipleCommand
5
+ include ActiveModel::Model
6
+ include ActiveModel::Attributes
7
+
8
+ # @!attribute case_ref_number_count
9
+ # @return [Integer] The number of case references to generate
10
+ attribute :case_ref_number_count
11
+
12
+ # @!attribute case_type_id
13
+ # @return [String] The ccd case type id (e.g. Manchester, Glasgow)
14
+ attribute :case_type_id
15
+
16
+ def self.from_json(json)
17
+ case_ref_number_count = json.dig('case_details', 'case_data', 'caseRefNumberCount')
18
+ case_type_id = json.dig('case_details', 'case_type_id')
19
+ new case_ref_number_count: case_ref_number_count, case_type_id: case_type_id
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,3 +4,4 @@ require 'et_fake_ccd/command/create_case_command'
4
4
  require 'et_fake_ccd/command/create_bulk_action_case_command'
5
5
  require 'et_fake_ccd/command/upload_document_command'
6
6
  require 'et_fake_ccd/command/upload_documents_to_case_command'
7
+ require 'et_fake_ccd/command/start_multiple_command'
@@ -0,0 +1,75 @@
1
+ module EtFakeCcd
2
+ #noinspection RubyStringKeysInHashInspection
3
+ class EcmService
4
+ OFFICE_CODE_LOOKUP = {
5
+ 'Manchester' => '24',
6
+ 'Glasgow' => '41'
7
+ }
8
+ Response = Struct.new(:case_reference_count, :start_reference, :multiple_reference)
9
+ # @param [EtFakeCcd::Command::StartMultipleCommand] command
10
+ # @return [EtFakeCcd::EcmService::Response] The response
11
+ def self.start_multiple(command)
12
+ new(command).call
13
+ end
14
+
15
+ # @param [EtFakeCcd::Command::StartMultipleCommand] command
16
+ def initialize(command)
17
+ @command = command
18
+ end
19
+
20
+ def call
21
+ adapter.reserve_reference_numbers_for(command.case_type_id, quantity: command.case_ref_number_count)
22
+ start_reference = adapter.last_case_reference(command.case_type_id) - command.case_ref_number_count
23
+ formatted_ref = "#{office_code_for(command.case_type_id)}#{start_reference.to_s.rjust(5, '0')}/#{Time.now.year}"
24
+ formatted_multiple = "#{office_code_for(command.case_type_id)}#{adapter.build_multiple_reference(command.case_type_id).to_s.rjust(5, '0')}/#{Time.now.year}"
25
+ Response.new(command.case_ref_number_count, formatted_ref, formatted_multiple).freeze
26
+ end
27
+
28
+ private
29
+
30
+ def adapter
31
+ Thread.current[:ecm_service_adapter] ||= InMemoryAdapter.new
32
+ end
33
+
34
+ def office_code_for(case_type_id)
35
+ office_code = OFFICE_CODE_LOOKUP[case_type_id]
36
+ raise "Case type id #{case_type_id} has no office lookup defined in the fake ccd server" if office_code.nil?
37
+
38
+ office_code
39
+ end
40
+
41
+ # @return [EtFakeCcd::Command::StartMultipleCommand] command
42
+ attr_reader :command
43
+
44
+ class InMemoryAdapter
45
+ def initialize
46
+ self.data = {}
47
+ end
48
+
49
+ def last_case_reference(case_type_id)
50
+ last_ref = data.dig(case_type_id, :case_reference)
51
+ raise "Case reference not generated for #{case_type_id}" if last_ref.nil?
52
+
53
+ last_ref
54
+ end
55
+
56
+
57
+ def reserve_reference_numbers_for(case_type_id, quantity:)
58
+ data[case_type_id] ||= {}
59
+ data[case_type_id][:case_reference] ||= 0
60
+ data[case_type_id][:case_reference] += quantity
61
+ end
62
+
63
+ def build_multiple_reference(case_type_id)
64
+ data[case_type_id] ||= {}
65
+ data[case_type_id][:multiple_reference] ||= 0
66
+ data[case_type_id][:multiple_reference] += 1
67
+ end
68
+
69
+ private
70
+
71
+ attr_accessor :data
72
+ end
73
+
74
+ end
75
+ end
@@ -6,6 +6,7 @@ require "et_fake_ccd/service/document_store_app"
6
6
  require "et_fake_ccd/service/authentication_web_app"
7
7
  require "et_fake_ccd/service/case_management_web_app"
8
8
  require "et_fake_ccd/service/api_gateway_web_app"
9
+ require "et_fake_ccd/service/ecm_app"
9
10
  module EtFakeCcd
10
11
  class RootApp < Roda
11
12
  plugin :multi_run
@@ -16,6 +17,7 @@ module EtFakeCcd
16
17
  run "authentication-web", Service::AuthenticationWebApp
17
18
  run "case-management-web", Service::CaseManagementWebApp
18
19
  run "api-gateway", Service::ApiGatewayWebApp
20
+ run "ecm", Service::EcmApp
19
21
 
20
22
  route do |r|
21
23
  r.multi_run
@@ -0,0 +1,64 @@
1
+ require 'roda'
2
+ require 'json'
3
+ require 'et_fake_ccd/commands'
4
+ require 'et_fake_ccd/auth_service'
5
+ require 'et_fake_ccd/ecm_service'
6
+ module EtFakeCcd
7
+ module Service
8
+ class EcmApp < Roda
9
+ plugin :request_headers
10
+ plugin :halt
11
+ route do |r|
12
+ r.is "startMultiple" do
13
+ r.post do
14
+ unless EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
15
+ r.halt 403, forbidden_error_for(r)
16
+ break
17
+ end
18
+ json = JSON.parse(r.body.read)
19
+ command = ::EtFakeCcd::Command::StartMultipleCommand.from_json json
20
+ if command.valid?
21
+ response = ::EtFakeCcd::EcmService.start_multiple(command)
22
+ start_multiple_response(response)
23
+ else
24
+ r.halt 422, render_error_for(command, r)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def render_error403(r)
33
+ r.halt 403, forbidden_error_for(r)
34
+ end
35
+
36
+ def start_multiple_response(response)
37
+ j = {
38
+ "caseRefNumberCount": response.case_reference_count,
39
+ "startCaseRefNumber": response.start_reference,
40
+ "multipleRefNumber": response.multiple_reference
41
+ }
42
+ JSON.generate(j)
43
+ end
44
+
45
+ def render_error_for(command, request)
46
+ j = {
47
+ "exception": "uk.gov.hmcts.ccd.endpoint.exceptions.CaseValidationException",
48
+ "timestamp": "2019-07-01T16:02:28.045",
49
+ "status": 422,
50
+ "error": "Unprocessable Entity",
51
+ "message": "Start multiple command validation failed",
52
+ "path": request.path,
53
+ "details": {
54
+ "field_errors": command.errors.details[:data].map {|e| e[:field_error]}
55
+ },
56
+ "callbackErrors": nil,
57
+ "callbackWarnings": nil
58
+ }
59
+
60
+ JSON.generate(j)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,3 @@
1
1
  module EtFakeCcd
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
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: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-21 00:00:00.000000000 Z
11
+ date: 2020-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda
@@ -184,12 +184,14 @@ files:
184
184
  - lib/et_fake_ccd/command/create_case_command.rb
185
185
  - lib/et_fake_ccd/command/lease_command.rb
186
186
  - lib/et_fake_ccd/command/login_user_command.rb
187
+ - lib/et_fake_ccd/command/start_multiple_command.rb
187
188
  - lib/et_fake_ccd/command/upload_document_command.rb
188
189
  - lib/et_fake_ccd/command/upload_documents_to_case_command.rb
189
190
  - lib/et_fake_ccd/commands.rb
190
191
  - lib/et_fake_ccd/config.rb
191
192
  - lib/et_fake_ccd/data_store_service.rb
192
193
  - lib/et_fake_ccd/document_store_service.rb
194
+ - lib/et_fake_ccd/ecm_service.rb
193
195
  - lib/et_fake_ccd/iodine.rb
194
196
  - lib/et_fake_ccd/request_store_service.rb
195
197
  - lib/et_fake_ccd/root_app.rb
@@ -199,6 +201,7 @@ files:
199
201
  - lib/et_fake_ccd/service/case_management_web_app.rb
200
202
  - lib/et_fake_ccd/service/data_store_app.rb
201
203
  - lib/et_fake_ccd/service/document_store_app.rb
204
+ - lib/et_fake_ccd/service/ecm_app.rb
202
205
  - lib/et_fake_ccd/service/sidam_app.rb
203
206
  - lib/et_fake_ccd/validator/otp_validator.rb
204
207
  - lib/et_fake_ccd/version.rb