3
3
import com .nimbusds .oauth2 .sdk .util .CollectionUtils ;
4
4
import feign .FeignException ;
5
5
import lombok .RequiredArgsConstructor ;
6
- import org .slf4j .Logger ;
7
- import org .slf4j .LoggerFactory ;
8
- import org .springframework .beans .factory .annotation .Autowired ;
6
+ import lombok .extern .slf4j .Slf4j ;
9
7
import org .springframework .beans .factory .annotation .Value ;
10
8
import org .springframework .stereotype .Service ;
11
9
import org .springframework .web .client .HttpClientErrorException ;
12
10
import org .springframework .web .client .HttpServerErrorException ;
13
- import org .springframework .web .client .RestTemplate ;
14
11
import uk .gov .hmcts .reform .authorisation .generators .AuthTokenGenerator ;
15
12
import uk .gov .hmcts .reform .hmc .api .config .IdamTokenGenerator ;
16
13
import uk .gov .hmcts .reform .hmc .api .mapper .AutomatedHearingTransformer ;
39
36
40
37
@ Service
41
38
@ RequiredArgsConstructor
42
- @ SuppressWarnings ( "unchecked" )
39
+ @ Slf4j
43
40
public class HearingsServiceImpl implements HearingsService {
44
41
45
- public static final String HEARING_API_CALL_HTTP_CLIENT_ERROR_EXCEPTION = "Hearing api call HttpClientError exception {}" ;
46
- public static final String HEARING_API_CALL_FEIGN_EXCEPTION = "Hearing api call Feign exception {}" ;
47
- public static final String HEARING_API_CALL_EXCEPTION_EXCEPTION = "Hearing api call Exception exception {}" ;
48
- private static Logger log = LoggerFactory .getLogger (HearingsServiceImpl .class );
49
-
50
42
@ Value ("${ccd.ui.url}" )
51
43
private String ccdBaseUrl ;
52
44
53
45
@ Value ("${hearing.specialCharacters}" )
54
46
private String specialCharacters ;
55
47
56
- @ Autowired AuthTokenGenerator authTokenGenerator ;
57
-
58
- @ Autowired IdamTokenGenerator idamTokenGenerator ;
59
-
60
- @ Autowired RefDataService refDataService ;
61
-
62
- @ Autowired RefDataJudicialService refDataJudicialService ;
63
-
64
- @ Autowired HearingApiClient hearingApiClient ;
65
- RestTemplate restTemplate = new RestTemplate ();
66
-
67
48
@ Value ("${hearing_component.api.url}" )
68
49
private String basePath ;
69
50
@@ -73,7 +54,11 @@ public class HearingsServiceImpl implements HearingsService {
73
54
@ Value ("#{'${hearing_component.futureHearingStatus}'.split(',')}" )
74
55
private List <String > futureHearingStatusList ;
75
56
76
- private Hearings hearingDetails ;
57
+ private final AuthTokenGenerator authTokenGenerator ;
58
+ private final IdamTokenGenerator idamTokenGenerator ;
59
+ private final RefDataService refDataService ;
60
+ private final RefDataJudicialService refDataJudicialService ;
61
+ private final HearingApiClient hearingApiClient ;
77
62
78
63
/**
79
64
* This method will fetch all the hearings which belongs to a particular caseRefNumber.
@@ -198,8 +183,7 @@ public List<Hearings> getHearingsByListOfCaseIds(
198
183
ROLE_ASSIGNMENT_ATTRIBUTE_CASE_TYPE );
199
184
for (var hearing : hearingDetailsList ) {
200
185
try {
201
- hearingDetails = hearing ;
202
- List <CaseHearing > filteredHearings = hearingDetails .getCaseHearings ();
186
+ List <CaseHearing > filteredHearings = hearing .getCaseHearings ();
203
187
log .info ("Excluded hearing statuses {}" , hearingStatesToBeExcluded );
204
188
if (CollectionUtils .isNotEmpty (hearingStatesToBeExcluded )) {
205
189
filteredHearings = filteredHearings .stream ()
@@ -211,8 +195,8 @@ public List<Hearings> getHearingsByListOfCaseIds(
211
195
Hearings filteredCaseHearingsWithCount =
212
196
Hearings .hearingsWith ()
213
197
.caseHearings (filteredHearings )
214
- .caseRef (hearingDetails .getCaseRef ())
215
- .hmctsServiceCode (hearingDetails .getHmctsServiceCode ())
198
+ .caseRef (hearing .getCaseRef ())
199
+ .hmctsServiceCode (hearing .getHmctsServiceCode ())
216
200
.build ();
217
201
casesWithHearings .add (filteredCaseHearingsWithCount );
218
202
} catch (HttpClientErrorException | HttpServerErrorException exception ) {
@@ -228,7 +212,7 @@ public List<Hearings> getHearingsByListOfCaseIds(
228
212
if (!casesWithHearings .isEmpty ()) {
229
213
List <CourtDetail > allVenues =
230
214
refDataService .getCourtDetailsByServiceCode (
231
- hearingDetails .getHmctsServiceCode ());
215
+ hearingDetailsList . get ( 0 ) .getHmctsServiceCode ());
232
216
233
217
integrateVenueDetailsForCaseId (allVenues , casesWithHearings , caseIdWithRegionIdMap );
234
218
}
@@ -259,9 +243,8 @@ public List<Hearings> getHearingsByListOfCaseIdsWithoutCourtVenueDetails(
259
243
log .info ("fis processing {}" ,hearing .getCaseRef ());
260
244
try {
261
245
log .info ("try block hit" );
262
- hearingDetails = hearing ;
263
246
List <CaseHearing > filteredHearings =
264
- hearingDetails .getCaseHearings ().stream ()
247
+ hearing .getCaseHearings ().stream ()
265
248
.filter (
266
249
eachHearing ->
267
250
eachHearing .getHmcStatus ().equals (LISTED )
@@ -272,12 +255,12 @@ public List<Hearings> getHearingsByListOfCaseIdsWithoutCourtVenueDetails(
272
255
.getHmcStatus ()
273
256
.equals (COMPLETED ))
274
257
.toList ();
275
- log .info ("checking hearings for case id {}" , hearingDetails .getCaseRef ());
258
+ log .info ("checking hearings for case id {}" , hearing .getCaseRef ());
276
259
Hearings filteredCaseHearingsWithCount =
277
260
Hearings .hearingsWith ()
278
261
.caseHearings (filteredHearings )
279
- .caseRef (hearingDetails .getCaseRef ())
280
- .hmctsServiceCode (hearingDetails .getHmctsServiceCode ())
262
+ .caseRef (hearing .getCaseRef ())
263
+ .hmctsServiceCode (hearing .getHmctsServiceCode ())
281
264
.build ();
282
265
log .info ("adding hearing with case id {}" , filteredCaseHearingsWithCount .getCaseRef ());
283
266
casesWithHearings .add (filteredCaseHearingsWithCount );
@@ -306,15 +289,8 @@ public Map<String, List<String>> getHearingsListedForCurrentDateByListOfCaseIdsW
306
289
try {
307
290
hearingDetailsList .addAll (hearingApiClient .getListOfHearingDetails (userToken , s2sToken , listOfCaseIds ,
308
291
ROLE_ASSIGNMENT_ATTRIBUTE_CASE_TYPE ));
309
- } catch (HttpClientErrorException | HttpServerErrorException exception ) {
310
- log .error (
311
- HEARING_API_CALL_HTTP_CLIENT_ERROR_EXCEPTION ,
312
- exception .getMessage ()
313
- );
314
- } catch (FeignException exception ) {
315
- log .error (HEARING_API_CALL_FEIGN_EXCEPTION , exception .getMessage ());
316
292
} catch (Exception exception ) {
317
- log .error (HEARING_API_CALL_EXCEPTION_EXCEPTION , exception .getMessage ());
293
+ log .error ("Hearing api call Exception exception {}" , exception .getMessage ());
318
294
}
319
295
Map <String , List <String >> caseIdHearingIdMap = new HashMap <>();
320
296
if (CollectionUtils .isNotEmpty (hearingDetailsList )) {
@@ -461,7 +437,7 @@ public Hearings getFutureHearings(String caseReference) {
461
437
final String s2sToken = authTokenGenerator .generate ();
462
438
Hearings futureHearingsResponse = null ;
463
439
try {
464
- hearingDetails = hearingApiClient .getHearingDetails (userToken , s2sToken , caseReference );
440
+ Hearings hearingDetails = hearingApiClient .getHearingDetails (userToken , s2sToken , caseReference );
465
441
466
442
final List <String > hearingStatuses =
467
443
futureHearingStatusList .stream ().map (String ::trim ).toList ();
0 commit comments