Class: EtCcdClient::UiClient

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
CommonRestClient
Defined in:
lib/et_ccd_client/ui_client.rb

Overview

A client to interact with the CCD UI API (front end)

Instance Method Summary collapse

Methods included from CommonRestClient

#get_request, #post_request

Constructor Details

#initialize(ui_idam_client: UiIdamClient.new, config: ::EtCcdClient.config) ⇒ UiClient

Returns a new instance of UiClient.



15
16
17
18
19
# File 'lib/et_ccd_client/ui_client.rb', line 15

def initialize(ui_idam_client: UiIdamClient.new, config: ::EtCcdClient.config)
  self.ui_idam_client = ui_idam_client
  self.config = config
  self.logger = config.logger
end

Instance Method Details

#caseworker_case_create(data, case_type_id:, extra_headers: {}) ⇒ Hash

Returns The json response.

Parameters:

  • data (Hash)
  • case_type_id (String)

Returns:

  • (Hash)

    The json response



166
167
168
169
170
171
172
173
# File 'lib/et_ccd_client/ui_client.rb', line 166

def caseworker_case_create(data, case_type_id:, extra_headers: {})
  logger.tagged('EtCcdClient::Client') do
    tpl = Addressable::Template.new(config.create_case_path)
    path = tpl.expand(uid: ui_idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id).to_s
    url = "#{config.gateway_api_url}/aggregated#{path}"
    post_request(url, data, log_subject: 'Case worker create case', extra_headers: { content_type: 'application/json', accept: 'application/json' }, cookies: { accessToken: ui_idam_client.user_token })
  end
end

#caseworker_list_cases(case_type_id:, page: 1, sort_direction: 'desc') ⇒ Array<Hash>

List all cases (paginated)

Parameters:

  • case_type_id (String)

    The case type ID to set the search scope to

  • page (Integer) (defaults to: 1)
    • The page number to fetch

  • sort_direction (String) (defaults to: 'desc')

    (defaults to ‘desc’) - Change to ‘asc’ to do oldest first

Returns:

  • (Array<Hash>)

    The json response from the server



139
140
141
142
143
144
145
146
147
# File 'lib/et_ccd_client/ui_client.rb', line 139

def caseworker_list_cases(case_type_id:, page: 1, sort_direction: 'desc')
  logger.tagged('EtCcdClient::UiClient') do
    tpl = Addressable::Template.new(config.cases_path)
    path = tpl.expand(uid: ui_idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { page: page, 'sortDirection' => sort_direction }).to_s
    url = "#{config.gateway_api_url}/aggregated#{path}"
    resp = get_request(url, log_subject: 'List all cases', extra_headers: { content_type: 'application/json', accept: 'application/json' }, cookies: { accessToken: ui_idam_client.user_token })
    resp["results"]
  end
end

#caseworker_search_by_bulk_case_title(case_title, case_type_id:, page: 1, sort_direction: 'desc') ⇒ Array<Hash>

Search for cases by bulk case title - useful for testing

Parameters:

  • case_title (String)

    The bulk case title to search for

  • case_type_id (String)

    The case type ID to set the search scope to

  • page (Integer) (defaults to: 1)
    • The page number to fetch

  • sort_direction (String) (defaults to: 'desc')

    (defaults to ‘desc’) - Change to ‘asc’ to do oldest first

Returns:

  • (Array<Hash>)

    The json response from the server



114
115
116
117
118
119
120
121
122
# File 'lib/et_ccd_client/ui_client.rb', line 114

def caseworker_search_by_bulk_case_title(case_title, case_type_id:, page: 1, sort_direction: 'desc')
  logger.tagged('EtCcdClient::UiClient') do
    tpl = Addressable::Template.new(config.cases_path)
    path = tpl.expand(uid: ui_idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { 'case.multipleName' => case_title, page: page, 'sortDirection' => sort_direction }).to_s
    url = "#{config.gateway_api_url}/aggregated#{path}"
    resp = get_request(url, log_subject: 'Case worker search by bulk case title', extra_headers: { content_type: 'application/json', accept: 'application/json' }, cookies: { accessToken: ui_idam_client.user_token })
    resp["results"]
  end
end

#caseworker_search_by_ethos_case_reference(reference, case_type_id:, page: 1, sort_direction: 'desc') ⇒ Array<Hash>

Search for cases by ethos case reference - useful for testing

Parameters:

  • reference (String)

    The ethos case reference number to search for

  • case_type_id (String)

    The case type ID to set the search scope to

  • page (Integer) (defaults to: 1)
    • The page number to fetch

  • sort_direction (String) (defaults to: 'desc')

    (defaults to ‘desc’) - Change to ‘asc’ to do oldest first

Returns:

  • (Array<Hash>)

    The json response from the server



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/et_ccd_client/ui_client.rb', line 59

def caseworker_search_by_ethos_case_reference(reference, case_type_id:, page: 1, sort_direction: 'desc')
  logger.tagged('EtCcdClient::UiClient') do
    tpl = Addressable::Template.new(config.cases_path)
    path = tpl.expand(uid: ui_idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { 'case.ethosCaseReference' => reference, page: page, 'sortDirection' => sort_direction }).to_s
    url = "#{config.gateway_api_url}/aggregated#{path}"
    resp = get_request(url, log_subject: 'Caseworker search by ethos case reference', extra_headers: { content_type: 'application/json', accept: 'application/json' }, cookies: { accessToken: ui_idam_client.user_token })
    unless config.document_store_url_rewrite == false
      resp = reverse_rewrite_document_store_urls(resp)
    end
    resp["results"]
  end
end

#caseworker_search_by_multiple_reference(reference, case_type_id:, page: 1, sort_direction: 'desc') ⇒ Array<Hash>

Search for cases by multiples reference - useful for testing

Parameters:

  • reference (String)

    The multiples reference number to search for

  • case_type_id (String)

    The case type ID to set the search scope to

  • page (Integer) (defaults to: 1)
    • The page number to fetch

  • sort_direction (String) (defaults to: 'desc')

    (defaults to ‘desc’) - Change to ‘asc’ to do oldest first

Returns:

  • (Array<Hash>)

    The json response from the server



88
89
90
91
92
93
94
95
96
# File 'lib/et_ccd_client/ui_client.rb', line 88

def caseworker_search_by_multiple_reference(reference, case_type_id:, page: 1, sort_direction: 'desc')
  logger.tagged('EtCcdClient::UiClient') do
    tpl = Addressable::Template.new(config.cases_path)
    path = tpl.expand(uid: ui_idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { 'case.multipleReference' => reference, page: page, 'sortDirection' => sort_direction }).to_s
    url = "#{config.gateway_api_url}/aggregated#{path}"
    resp = get_request(url, log_subject: 'Case worker search by multiple reference', extra_headers: { content_type: 'application/json', accept: 'application/json' }, cookies: { accessToken: ui_idam_client.user_token })
    resp["results"]
  end
end

#caseworker_search_by_reference(reference, case_type_id:, page: 1, sort_direction: 'desc') ⇒ Array<Hash>

Search for cases by reference - useful for testing

Parameters:

  • reference (String)

    The reference number to search for

  • case_type_id (String)

    The case type ID to set the search scope to

  • page (Integer) (defaults to: 1)
    • The page number to fetch

  • sort_direction (String) (defaults to: 'desc')

    (defaults to ‘desc’) - Change to ‘asc’ to do oldest first

Returns:

  • (Array<Hash>)

    The json response from the server



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/et_ccd_client/ui_client.rb', line 30

def caseworker_search_by_reference(reference, case_type_id:, page: 1, sort_direction: 'desc')
  logger.tagged('EtCcdClient::UiClient') do
    tpl = Addressable::Template.new(config.cases_path)
    path = tpl.expand(uid: ui_idam_client.user_details['id'], jid: config.jurisdiction_id, ctid: case_type_id, query: { 'case.feeGroupReference' => reference, page: page, 'sortDirection' => sort_direction }).to_s
    url = "#{config.gateway_api_url}/aggregated#{path}"
    resp = get_request(url, log_subject: 'Caseworker search by reference', extra_headers: { content_type: 'application/json', accept: 'application/json' }, cookies: { accessToken: ui_idam_client.user_token })
    unless config.document_store_url_rewrite == false
      resp = reverse_rewrite_document_store_urls(resp)
    end
    resp["results"]
  end
end

#caseworker_search_latest_by_bulk_case_title(case_title, case_type_id:) ⇒ Hash

Search for the latest case matching the bulk case title. Useful for testing

Parameters:

  • case-title (String)

    The bulk case title to search for

  • case_type_id (String)

    The case type ID to set the search scope to

Returns:

  • (Hash)

    The case object returned from the server



128
129
130
131
# File 'lib/et_ccd_client/ui_client.rb', line 128

def caseworker_search_latest_by_bulk_case_title(case_title, case_type_id:)
  results = caseworker_search_by_bulk_case_title(case_title, case_type_id: case_type_id, page: 1, sort_direction: 'desc')
  results.first
end

#caseworker_search_latest_by_ethos_case_reference(reference, case_type_id:) ⇒ Hash

Search for the latest case matching the ethos case reference. Useful for testing

Parameters:

  • reference (String)

    The ethos case reference number to search for

  • case_type_id (String)

    The case type ID to set the search scope to

Returns:

  • (Hash)

    The case object returned from the server



76
77
78
79
# File 'lib/et_ccd_client/ui_client.rb', line 76

def caseworker_search_latest_by_ethos_case_reference(reference, case_type_id:)
  results = caseworker_search_by_ethos_case_reference(reference, case_type_id: case_type_id, page: 1, sort_direction: 'desc')
  results.first
end

#caseworker_search_latest_by_multiple_reference(reference, case_type_id:) ⇒ Hash

Search for the latest case matching the multiple reference. Useful for testing

Parameters:

  • reference (String)

    The multiples reference number to search for

  • case_type_id (String)

    The case type ID to set the search scope to

Returns:

  • (Hash)

    The case object returned from the server



102
103
104
105
# File 'lib/et_ccd_client/ui_client.rb', line 102

def caseworker_search_latest_by_multiple_reference(reference, case_type_id:)
  results = caseworker_search_by_multiple_reference(reference, case_type_id: case_type_id, page: 1, sort_direction: 'desc')
  results.first
end

#caseworker_search_latest_by_reference(reference, case_type_id:) ⇒ Hash

Search for the latest case matching the reference. Useful for testing

Parameters:

  • reference (String)

    The reference number to search for

  • case_type_id (String)

    The case type ID to set the search scope to

Returns:

  • (Hash)

    The case object returned from the server



47
48
49
50
# File 'lib/et_ccd_client/ui_client.rb', line 47

def caseworker_search_latest_by_reference(reference, case_type_id:)
  results = caseworker_search_by_reference(reference, case_type_id: case_type_id, page: 1, sort_direction: 'desc')
  results.first
end

#caseworker_start_case_creation(case_type_id:, extra_headers: {}) ⇒ Hash

Initiate the case ready for creation

Parameters:

  • case_type_id (String)

Returns:

  • (Hash)

    The json response



153
154
155
156
157
158
159
160
# File 'lib/et_ccd_client/ui_client.rb', line 153

def caseworker_start_case_creation(case_type_id:, extra_headers: {})
  logger.tagged('EtCcdClient::Client') do
    path = initiate_case_path(case_type_id, config.initiate_claim_event_id)
    url = "#{config.gateway_api_url}/aggregated#{path}"

    get_request(url, log_subject: 'Start case creation', extra_headers: { content_type: 'application/json', accept: 'application/json' }, cookies: { accessToken: ui_idam_client.user_token })
  end
end