@@ -75,7 +75,7 @@ public CourtScheduleResponse getCourtScheduleByCaseId(final String caseId) {
7575 }
7676
7777 private List <Hearing > getHearings (final String caseId ) {
78- List <Hearing > hearingResult = Collections .emptyList ();
78+ List <Hearing > hearingSchedule = Collections .emptyList ();
7979 try {
8080 final HttpRequest request = HttpRequest .newBuilder ()
8181 .uri (new URI (buildUrl (caseId )))
@@ -85,22 +85,22 @@ private List<Hearing> getHearings(final String caseId) {
8585 .build ();
8686
8787 final HttpResponse <String > response = httpClient .send (request , HttpResponse .BodyHandlers .ofString ());
88- if (response .statusCode () != HttpStatus .OK .value ()) {
89- LOG .atError ().log ("Failed to fetch hearing data. HTTP Status: {}" , response .statusCode ());
90- } else {
88+ if (response .statusCode () == HttpStatus .OK .value ()){
9189 final ObjectMapper objectMapper = new ObjectMapper ();
9290 final HearingResponse hearingResponse = objectMapper .readValue (
9391 response .body (),
9492 HearingResponse .class
9593 );
9694
97- hearingResult = getHearingData (hearingResponse );
95+ hearingSchedule = getHearingData (hearingResponse );
9896 LOG .atInfo ().log ("Response Code: {}" , response .statusCode ());
97+ } else {
98+ LOG .atError ().log ("Failed to fetch hearing data. HTTP Status: {}" , response .statusCode ());
9999 }
100100 } catch (Exception e ) {
101101 LOG .atError ().log ("Exception occurred while fetching hearing data: {}" , e .getMessage (), e );
102102 }
103- return hearingResult ;
103+ return hearingSchedule ;
104104 }
105105
106106
@@ -114,7 +114,7 @@ private String buildUrl(final String caseId) {
114114
115115 private List <Hearing > getHearingData (final HearingResponse hearingResponse ) {
116116 final List <Hearing > hearings = new ArrayList <>();
117- hearingResponse .getHearings ().forEach ( hr -> {
117+ hearingResponse .getHearings ().stream (). filter ( HearingResponse . HearingSchedule :: isAllocated ). forEach (hr -> {
118118 final Hearing hearing = new Hearing ();
119119 hearing .setHearingId (hr .getId ());
120120 hearing .setHearingType (hr .getType ().getDescription ());
@@ -123,7 +123,7 @@ private List<Hearing> getHearingData(final HearingResponse hearingResponse) {
123123 final List <CourtSitting > courtSittings = new ArrayList <>();
124124 final String judiciaryId = hr .getJudiciary ().stream ().map (a -> a .getJudicialId ()).collect (Collectors .joining ("," ));
125125
126- for (final HearingResponse .HearingResult .HearingDay hearingDay : hr .getHearingDays ()) {
126+ for (final HearingResponse .HearingSchedule .HearingDay hearingDay : hr .getHearingDays ()) {
127127 final CourtSitting courtSitting = getCourtSitting (hearingDay , judiciaryId );
128128 courtSittings .add (courtSitting );
129129 }
@@ -133,7 +133,7 @@ private List<Hearing> getHearingData(final HearingResponse hearingResponse) {
133133 return hearings ;
134134 }
135135
136- private static CourtSitting getCourtSitting (final HearingResponse .HearingResult .HearingDay hearingDay , final String judiciaryId ) {
136+ private static CourtSitting getCourtSitting (final HearingResponse .HearingSchedule .HearingDay hearingDay , final String judiciaryId ) {
137137 final CourtSitting courtSitting = new CourtSitting ();
138138 courtSitting .setSittingStart (OffsetDateTime .parse (hearingDay .getStartTime ()));
139139 courtSitting .setSittingEnd (OffsetDateTime .parse (hearingDay .getEndTime ()));
0 commit comments