From 87ec170d99188dd5426c6cd9310ab04e6e393b43 Mon Sep 17 00:00:00 2001 From: akikrahman1 <149579836+akikrahman1@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:46:57 +0000 Subject: [PATCH] Interim 5 release (#815) * Task/JS-151 When a juror is returned from a trial, unable to check out juror (#812) * task/JS-151 When a juror is returned from a trial, unable to check out juror * Update PanelRepositoryImpl.java * Update PanelRepositoryImpl.java * task/JS-139 Empanelled juror can show in juror in waiting (#813) * task/JS-139 Empanelled juror can show in juror in waiting * update to logic after testing * task/JS-156 Confirming old trial attendance doesn't add trial number to appearance record (#814) * Task/js 139 (#816) * task/JS-139 Empanelled juror can show in juror in waiting * update to logic after testing * Update ITrialRepositoryImpl.java --- .../JurorManagementControllerITest.java | 69 ++++++++++--------- .../jurormanagement/ConfirmJuryAttendance.sql | 7 +- .../repository/IAppearanceRepositoryImpl.java | 18 ++--- .../trial/ITrialRepositoryImpl.java | 3 +- .../repository/trial/PanelRepositoryImpl.java | 8 ++- .../JurorAppearanceServiceImpl.java | 26 ++++--- .../moj/service/trial/PanelServiceImpl.java | 2 +- 7 files changed, 74 insertions(+), 59 deletions(-) diff --git a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorManagementControllerITest.java b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorManagementControllerITest.java index c1d44d6dc..fc51e013f 100644 --- a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorManagementControllerITest.java +++ b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorManagementControllerITest.java @@ -2164,38 +2164,43 @@ void confirmAttendanceHappy() { assertThat(response.getStatusCode()).as("HTTP status OK expected") .isEqualTo(OK); - // verify attendance records have been updated - Optional appearanceOpt = - appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate( - "415", "222222222", now().minusDays(2)); - assertThat(appearanceOpt).isNotEmpty(); - Appearance appearance = appearanceOpt.get(); - assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30)); - assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 00)); - assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED); - assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456"); - assertThat(appearance.getSatOnJury()).isTrue(); - assertThat(appearance.isAppearanceConfirmed()).isTrue(); - - appearanceOpt = appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate( - "415", "333333333", now().minusDays(2)); - assertThat(appearanceOpt).isNotEmpty(); - appearance = appearanceOpt.get(); - assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30)); - assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 0)); - assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED); - assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456"); - assertThat(appearance.getSatOnJury()).isTrue(); - assertThat(appearance.isAppearanceConfirmed()).isTrue(); - - // verify juror history records have been created - assertThat(jurorHistoryRepository.findByJurorNumberOrderById("222222222") - .stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE) - && "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue(); - - assertThat(jurorHistoryRepository.findByJurorNumberOrderById("333333333") - .stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE) - && "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue(); + executeInTransaction(() -> { + + // verify attendance records have been updated + Optional appearanceOpt = + appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate( + "415", "222222222", now().minusDays(2)); + assertThat(appearanceOpt).isNotEmpty(); + Appearance appearance = appearanceOpt.get(); + assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30)); + assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 00)); + assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED); + assertThat(appearance.getTrialNumber()).isEqualTo("T10000001"); + assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456"); + assertThat(appearance.getSatOnJury()).isTrue(); + assertThat(appearance.isAppearanceConfirmed()).isTrue(); + + appearanceOpt = appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate( + "415", "333333333", now().minusDays(2)); + assertThat(appearanceOpt).isNotEmpty(); + appearance = appearanceOpt.get(); + assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30)); + assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 0)); + assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED); + assertThat(appearance.getTrialNumber()).isEqualTo("T10000001"); + assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456"); + assertThat(appearance.getSatOnJury()).isTrue(); + assertThat(appearance.isAppearanceConfirmed()).isTrue(); + + // verify juror history records have been created + assertThat(jurorHistoryRepository.findByJurorNumberOrderById("222222222") + .stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE) + && "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue(); + + assertThat(jurorHistoryRepository.findByJurorNumberOrderById("333333333") + .stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE) + && "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue(); + }); } diff --git a/src/integration-test/resources/db/jurormanagement/ConfirmJuryAttendance.sql b/src/integration-test/resources/db/jurormanagement/ConfirmJuryAttendance.sql index 48dc1c9c4..73dfead9f 100644 --- a/src/integration-test/resources/db/jurormanagement/ConfirmJuryAttendance.sql +++ b/src/integration-test/resources/db/jurormanagement/ConfirmJuryAttendance.sql @@ -1,11 +1,12 @@ insert into juror_mod.trial (trial_number, loc_code, description, judge, trial_type, trial_start_date, anonymous, courtroom) -values ('T10000000', '415', 'TEST DEFENDANT', 999992, 'CIV', current_date, false, 99995); +values ('T10000000', '415', 'TEST DEFENDANT', 999992, 'CIV', current_date, false, 99995), + ('T10000001', '415', 'TEST DEFENDANT2', 999992, 'CIV', current_date, false, 99995); INSERT INTO juror_mod.juror_trial (loc_code, juror_number, trial_number, rand_number, date_selected, "result", completed) -values ('415', '222222222', 'T10000000', 10, '2024-02-22 13:50:59.110', 'J', true), - ('415', '333333333', 'T10000000', 5, '2024-02-22 13:50:58.821', 'J', true); +values ('415', '222222222', 'T10000001', 10, '2024-02-22 13:50:59.110', 'J', true), + ('415', '333333333', 'T10000001', 5, '2024-02-22 13:50:58.821', 'J', true); --JUROR_MOD.POOL INSERT INTO JUROR_MOD.POOL (OWNER, POOL_NO, RETURN_DATE, TOTAL_NO_REQUIRED, NO_REQUESTED, POOL_TYPE, LOC_CODE, diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/repository/IAppearanceRepositoryImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/repository/IAppearanceRepositoryImpl.java index 21c90559d..3ec5f9881 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/repository/IAppearanceRepositoryImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/repository/IAppearanceRepositoryImpl.java @@ -155,7 +155,8 @@ private JPAQuery sqlFetchAppearanceRecords(String locCode, LocalDate date .on(JUROR.jurorNumber.eq(APPEARANCE.jurorNumber) .and(APPEARANCE.courtLocation.eq(JUROR_POOL.pool.courtLocation))) .leftJoin(PANEL) - .on(APPEARANCE.jurorNumber.eq(PANEL.juror.jurorNumber)) + .on(APPEARANCE.jurorNumber.eq(PANEL.juror.jurorNumber) + .and(APPEARANCE.trialNumber.eq(PANEL.trial.trialNumber))) .where(APPEARANCE.courtLocation.locCode.eq(locCode)) .where(APPEARANCE.attendanceDate.eq(date)) .where(JUROR_POOL.isActive.isTrue()); @@ -163,13 +164,12 @@ private JPAQuery sqlFetchAppearanceRecords(String locCode, LocalDate date if (statusGroup == JurorStatusGroup.IN_WAITING) { query.where(APPEARANCE.attendanceAuditNumber.isNull() .or(APPEARANCE.attendanceAuditNumber.startsWith("J").not())); - query.where(APPEARANCE.trialNumber.isNull().or(APPEARANCE.trialNumber.eq(PANEL.trial.trialNumber) - .and(PANEL.empanelledDate.isNull() + query.where(APPEARANCE.trialNumber.isNull().or(PANEL.empanelledDate.isNull() .and(PANEL.result.isNotNull())) .or(PANEL.returnDate.isNotNull() .and(PANEL.empanelledDate.isNotNull()) .and(PANEL.returnDate.loe(date) - .or(PANEL.empanelledDate.after(date)))))); + .or(PANEL.empanelledDate.after(date))))); } @@ -180,15 +180,9 @@ private JPAQuery sqlFetchAppearanceRecords(String locCode, LocalDate date } if (statusGroup == JurorStatusGroup.ON_TRIAL) { - query.where((APPEARANCE.trialNumber.isNotNull().and(APPEARANCE.trialNumber.eq(PANEL.trial.trialNumber) - .and(PANEL.empanelledDate.isNotNull() - .and(PANEL.empanelledDate.loe(date) - .and(PANEL.returnDate.isNull() - .or(PANEL.returnDate - .goe(date))))))) - .or(PANEL.empanelledDate.isNotNull() + query.where(PANEL.empanelledDate.isNotNull() .and(PANEL.empanelledDate.loe(date)) - .and(PANEL.returnDate.isNull().or(PANEL.returnDate.goe(date))))); + .and(PANEL.returnDate.isNull().or(PANEL.returnDate.after(date)))); } return query; diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/ITrialRepositoryImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/ITrialRepositoryImpl.java index a90fc858e..84791dbb2 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/ITrialRepositoryImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/ITrialRepositoryImpl.java @@ -13,7 +13,6 @@ import uk.gov.hmcts.juror.api.moj.domain.trial.QPanel; import uk.gov.hmcts.juror.api.moj.domain.trial.QTrial; import uk.gov.hmcts.juror.api.moj.domain.trial.Trial; -import uk.gov.hmcts.juror.api.moj.enumeration.trial.PanelResult; import uk.gov.hmcts.juror.api.moj.utils.PaginationUtil; import uk.gov.hmcts.juror.api.moj.utils.SecurityUtil; @@ -82,7 +81,7 @@ public List getActiveTrialsWithJurorCount(String locationCode, LocalDate .where(TRIAL.trialEndDate.isNull().or(TRIAL.trialEndDate.goe(attendanceDate))) //If they are a JUROR or Panelled or have an appearance with a jury confirmation audit number .where((PANEL.empanelledDate.isNotNull().and(PANEL.returnDate.isNull() - .or(PANEL.returnDate.goe(attendanceDate)))) + .or(PANEL.returnDate.after(attendanceDate)))) .or(APPEARANCE.isNotNull()) .or(PANEL.empanelledDate.isNull().and(PANEL.result.isNull()))) .groupBy(TRIAL.trialNumber, TRIAL.description, TRIAL.trialType, TRIAL.courtroom.description, diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/PanelRepositoryImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/PanelRepositoryImpl.java index 15c395a31..16c3eb57e 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/PanelRepositoryImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/repository/trial/PanelRepositoryImpl.java @@ -5,6 +5,7 @@ import jakarta.persistence.PersistenceContext; import uk.gov.hmcts.juror.api.juror.domain.QCourtLocation; import uk.gov.hmcts.juror.api.moj.domain.IJurorStatus; +import uk.gov.hmcts.juror.api.moj.domain.QAppearance; import uk.gov.hmcts.juror.api.moj.domain.QJurorPool; import uk.gov.hmcts.juror.api.moj.domain.trial.Panel; import uk.gov.hmcts.juror.api.moj.domain.trial.QPanel; @@ -22,6 +23,7 @@ public class PanelRepositoryImpl implements IPanelRepository { private static final QTrial TRIAL = QTrial.trial; private static final QCourtLocation COURT_LOCATION = QCourtLocation.courtLocation; private static final QJurorPool JUROR_POOL = QJurorPool.jurorPool; + private static final QAppearance APPEARANCE = QAppearance.appearance; /** * Retrieves members that are on trial i.e. panel/jury. @@ -57,13 +59,17 @@ public boolean isEmpanelledJuror(String jurorNumber, String locationCode, LocalD .from(PANEL) .join(JUROR_POOL) .on(PANEL.juror.eq(JUROR_POOL.juror)) + .leftJoin(APPEARANCE) + .on(PANEL.trial.trialNumber.eq(APPEARANCE.trialNumber) + .and(PANEL.juror.jurorNumber.eq(APPEARANCE.jurorNumber)) + .and(APPEARANCE.attendanceDate.eq(date))) .where(PANEL.juror.jurorNumber.eq(jurorNumber)) .where(JUROR_POOL.pool.courtLocation.locCode.eq(locationCode)) .where(JUROR_POOL.isActive.isTrue()) .where(PANEL.completed.isTrue()) .where(PANEL.empanelledDate.isNotNull().and(PANEL.empanelledDate.loe(date) .and(PANEL.returnDate.isNull() - .or(PANEL.returnDate.goe(date))))) + .or(PANEL.returnDate.after(date))))) .fetch().isEmpty(); } diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/jurormanagement/JurorAppearanceServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/jurormanagement/JurorAppearanceServiceImpl.java index cc1cd145c..d7602731e 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/jurormanagement/JurorAppearanceServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/jurormanagement/JurorAppearanceServiceImpl.java @@ -597,8 +597,11 @@ public void confirmJuryAttendance(UpdateAttendanceDto request) { final String locCode = request.getCommonData().getLocationCode(); // see if there is an attendance record for the date to get the audit number + String trialNumber = request.getTrialNumber(); List appearances = appearanceRepository.findByLocCodeAndAttendanceDateAndTrialNumber(locCode, - request.getCommonData().getAttendanceDate(), request.getTrialNumber()); + request.getCommonData().getAttendanceDate(), + trialNumber + ); final String juryAttendancePrefix = "J"; String juryAttendanceNumber; @@ -660,15 +663,22 @@ public void confirmJuryAttendance(UpdateAttendanceDto request) { appearance.setSatOnJury(true); // update appearance by adding the trial number - if (IJurorStatus.JUROR == jurorPool.getStatus().getStatus()) { - // get the currently active trial the juror is on - Panel panel = panelRepository.findActivePanel(locCode, jurorNumber); - if (panel != null) { - appearance.setTrialNumber(panel.getTrial().getTrialNumber()); - jurorHistoryService.createJuryAttendanceHistory(jurorPool, appearance, panel); - } + Panel panel; + if (trialNumber == null) { + panel = panelRepository.findActivePanel(locCode, jurorNumber); + } else { + panel = panelRepository.findByTrialTrialNumberAndTrialCourtLocationLocCodeAndJurorJurorNumber( + trialNumber, locCode, jurorNumber); } + if (panel == null) { + log.info("Panel not found for juror {} on trial {}", jurorNumber, trialNumber); + throw new MojException.NotFound("Panel not found for juror " + jurorNumber, null); + } + + appearance.setTrialNumber(panel.getTrial().getTrialNumber()); + jurorHistoryService.createJuryAttendanceHistory(jurorPool, appearance, panel); + appearanceRepository.saveAndFlush(appearance); jurorExpenseService.applyDefaultExpenses(appearance, jurorPool.getJuror()); diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/trial/PanelServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/trial/PanelServiceImpl.java index 0a8106132..4b5950a53 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/trial/PanelServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/trial/PanelServiceImpl.java @@ -329,7 +329,7 @@ public List getPanelSummary(String trialNumber, String locCode, Lo panelRepository.findByTrialTrialNumberAndTrialCourtLocationLocCode(trialNumber, locCode); for (Panel panel : panelList) { if (panel.getResult() == null || panel.getResult() == PanelResult.JUROR - || (date != null && panel.getReturnDate() != null && panel.getReturnDate().isAfter(date.minusDays(1)) + || (date != null && panel.getReturnDate() != null && panel.getReturnDate().isAfter(date) && date.atTime(23,59).isAfter(panel.getDateSelected()))) { dtoList.add(createPanelListDto(panel)); }