Skip to content

Commit

Permalink
Stabilisation 11 (#697)
Browse files Browse the repository at this point in the history
* Hotfix/JM-7788 Juror search name fix (#694)

* hotfix/JM-7783 Duplicate bureau users showing in assign response list (#587)

* hotfix/JM-7788 Juror search name search fix

* updated to handle multi part surnames

* Update for PMD

* updated name search logic

* Update PoolRequestServiceImpl.java

* Confirming a trial attendance can override an existing confirmed attendance (#698)

* Fix issue where confirming a jury attendance could override attendances

* Fixed styles

* Updated Bureau response processing to exclude court owned jurors (#700)

* Court names incorrect on records (#699)

* Updated court names

* order of operations update

* Fixed issue where total count for the user did not exclude transferred jurors (#703)

* Expense Process. Optimising queries that take over 30 seconds to complete (#701)

* Improved Expense performance

* Improved pool creation performance

* Fixed styles

* Updated deferral processing to close responses (#705)

* Fixed issue where bulk printing summons reminder letters could fail due to a null creation date (#704)

* Fixed issue with confirming jury attendances on a day with a deleted attendance (#706)

---------

Co-authored-by: akikrahman1 <[email protected]>
  • Loading branch information
Ben-Edwards-cgi and akikrahman1 authored Aug 16, 2024
1 parent c46ef76 commit c99b99b
Show file tree
Hide file tree
Showing 42 changed files with 744 additions and 560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ void positiveTypical() {
List<Appearance> modifiedAppearances =
appearances.stream().filter(app -> appearanceDates.contains(app.getAttendanceDate())).toList();
assertThat(modifiedAppearances).hasSize(2);
verifyExpenseSubmittedForApproval(modifiedAppearances.get(0), 2);
verifyExpenseSubmittedForApproval(modifiedAppearances.get(0), 3);
verifyExpenseSubmittedForApproval(modifiedAppearances.get(1), 3);

List<Appearance> unmodifiedAppearances =
Expand Down Expand Up @@ -1513,7 +1513,7 @@ void positiveTypicalNonAttendance() {
List<Appearance> modifiedAppearances =
appearances.stream().filter(app -> appearanceDates.contains(app.getAttendanceDate())).toList();
assertThat(modifiedAppearances).hasSize(1);
verifyExpenseSubmittedForApproval(modifiedAppearances.get(0), 2);
verifyExpenseSubmittedForApproval(modifiedAppearances.get(0), 3);

List<Appearance> unmodifiedAppearances =
appearances.stream().filter(app -> !appearanceDates.contains(app.getAttendanceDate())).toList();
Expand Down Expand Up @@ -2508,7 +2508,7 @@ void typicalApprovalBacs() throws Exception {
long id = assertFinancialAuditDetailsApproved(financialAuditDetails.get(0),
LocalDateTime.now(), FinancialAuditDetails.Type.APPROVED_BACS);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(0),
id, LocalDate.of(2023, 1, 8), 2);
id, LocalDate.of(2023, 1, 8), 3);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(1),
id, LocalDate.of(2023, 1, 9), 4);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(2),
Expand Down Expand Up @@ -2563,7 +2563,7 @@ void typicalApprovalCash() throws Exception {
long id = assertFinancialAuditDetailsApproved(financialAuditDetails.get(0),
LocalDateTime.now(), FinancialAuditDetails.Type.APPROVED_CASH);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(0),
id, LocalDate.of(2023, 2, 8), 2);
id, LocalDate.of(2023, 2, 8), 3);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(1),
id, LocalDate.of(2023, 2, 9), 3);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(2),
Expand Down Expand Up @@ -3244,7 +3244,7 @@ void typicalApproved() throws Exception {
financialAuditDetailsAppearancesRepository.findAll().forEach(financialAuditDetailsAppearances::add);
assertThat(financialAuditDetailsAppearances).hasSize(1);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(0),
2, LocalDate.of(2023, 1, 11), 2);
2, LocalDate.of(2023, 1, 11), 3);
assertJurorHistory(jurorNumber, HistoryCodeMod.EDIT_PAYMENTS, "COURT_USER", "£62.03",
"415230101", LocalDate.of(2023, 1, 11), "F2", 1, 0);
}
Expand Down Expand Up @@ -3308,7 +3308,7 @@ void typicalReApproved() throws Exception {
financialAuditDetailsAppearancesRepository.findAll().forEach(financialAuditDetailsAppearances::add);
assertThat(financialAuditDetailsAppearances).hasSize(1);
assertFinancialAuditDetailsAppearances(financialAuditDetailsAppearances.get(0),
2, LocalDate.of(2023, 1, 15), 2);
2, LocalDate.of(2023, 1, 15), 3);
assertJurorHistory(jurorNumber, HistoryCodeMod.EDIT_PAYMENTS, "COURT_USER", "£65.54",
"415230101", LocalDate.of(2023, 1, 15), "F2", 1, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5455,13 +5455,112 @@ void searchForJurorRecordsCourtSorted() throws Exception {

}

@Test
void searchForJurorRecordsByNameFNameInitialNotSupplied() throws Exception {

String bureauJwt = createBureauJwt("Court_User", "417", "417");
httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt);
JurorRecordFilterRequestQuery request = JurorRecordFilterRequestQuery.builder()
.jurorName("fnametwo lnametwo")
.pageNumber(1)
.pageLimit(10)
.sortMethod(SortMethod.DESC)
.sortField(JurorRecordFilterRequestQuery.SortField.JUROR_NUMBER)
.build();

ResponseEntity<PaginatedList<FilterJurorRecord>> response =
restTemplate.exchange(new RequestEntity<>(request, httpHeaders, POST,
URI.create(URL)), new ParameterizedTypeReference<>() {});
assertThat(response.getStatusCode())
.as("Expect the HTTP POST request (GET With Body) to be successful")
.isEqualTo(HttpStatus.OK);

assertThat(response.getBody()).isNotNull();
PaginatedList<FilterJurorRecord> responseBody = response.getBody();

List<FilterJurorRecord> data = responseBody.getData();
assertThat(data.size()).as("Expect the response body to contain all 1 data items").isEqualTo(1);
FilterJurorRecord juror = data.get(0);
assertThat(juror.getJurorNumber()).as("Expect the response body to contain the correct juror number")
.isEqualTo("641700120");
assertThat(juror.getJurorName()).as("Expect the response body to contain the correct juror name")
.isEqualTo("Fnametwo I Lnametwo");

}

@Test
void searchForJurorRecordsByNameLastnameFirstPartOnly() throws Exception {

String bureauJwt = createBureauJwt("Court_User", "417", "417");
httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt);
JurorRecordFilterRequestQuery request = JurorRecordFilterRequestQuery.builder()
.jurorName("fnamethree lnamethree")
.pageNumber(1)
.pageLimit(10)
.sortMethod(SortMethod.DESC)
.sortField(JurorRecordFilterRequestQuery.SortField.JUROR_NUMBER)
.build();

ResponseEntity<PaginatedList<FilterJurorRecord>> response =
restTemplate.exchange(new RequestEntity<>(request, httpHeaders, POST,
URI.create(URL)), new ParameterizedTypeReference<>() {});
assertThat(response.getStatusCode())
.as("Expect the HTTP POST request (GET With Body) to be successful")
.isEqualTo(HttpStatus.OK);

assertThat(response.getBody()).isNotNull();
PaginatedList<FilterJurorRecord> responseBody = response.getBody();

List<FilterJurorRecord> data = responseBody.getData();
assertThat(data.size()).as("Expect the response body to contain all 1 data items").isEqualTo(1);
FilterJurorRecord juror = data.get(0);
assertThat(juror.getJurorNumber()).as("Expect the response body to contain the correct juror number")
.isEqualTo("641700123");
assertThat(juror.getJurorName()).as("Expect the response body to contain the correct juror name")
.isEqualTo("Fnamethree Lnamethree I");

}

@Test
void searchForJurorRecordsByNameLastnameTwoParts() throws Exception {

String bureauJwt = createBureauJwt("Court_User", "417", "417");
httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt);
JurorRecordFilterRequestQuery request = JurorRecordFilterRequestQuery.builder()
.jurorName("fnamethree lnamethree I")
.pageNumber(1)
.pageLimit(10)
.sortMethod(SortMethod.DESC)
.sortField(JurorRecordFilterRequestQuery.SortField.JUROR_NUMBER)
.build();

ResponseEntity<PaginatedList<FilterJurorRecord>> response =
restTemplate.exchange(new RequestEntity<>(request, httpHeaders, POST,
URI.create(URL)), new ParameterizedTypeReference<>() {});
assertThat(response.getStatusCode())
.as("Expect the HTTP POST request (GET With Body) to be successful")
.isEqualTo(HttpStatus.OK);

assertThat(response.getBody()).isNotNull();
PaginatedList<FilterJurorRecord> responseBody = response.getBody();

List<FilterJurorRecord> data = responseBody.getData();
assertThat(data.size()).as("Expect the response body to contain all 1 data items").isEqualTo(1);
FilterJurorRecord juror = data.get(0);
assertThat(juror.getJurorNumber()).as("Expect the response body to contain the correct juror number")
.isEqualTo("641700123");
assertThat(juror.getJurorName()).as("Expect the response body to contain the correct juror name")
.isEqualTo("Fnamethree Lnamethree I");

}

@Test
void searchForJurorRecordsByName() throws Exception {

String bureauJwt = createBureauJwt("Court_User", "415", "415");
httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt);
JurorRecordFilterRequestQuery request = JurorRecordFilterRequestQuery.builder()
.jurorName("Lnameninefive")
.jurorName("LNAMENINEFIVE")
.pageNumber(1)
.pageLimit(10)
.sortMethod(SortMethod.DESC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;
import uk.gov.hmcts.juror.api.moj.repository.VotersRepository;
import uk.gov.hmcts.juror.api.moj.service.VotersService;
import uk.gov.hmcts.juror.api.testsupport.ContainerTest;

import java.sql.SQLException;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

@RunWith(SpringRunner.class)
@Slf4j
Expand All @@ -28,7 +26,7 @@
public class PoolCreateITest extends ContainerTest {

@Autowired
VotersRepository votersRepository;
VotersService votersService;

/*
* This test will invoke the Get_Voters function in the database to randomly
Expand All @@ -37,20 +35,14 @@ public class PoolCreateITest extends ContainerTest {
@Test
@Sql({"/db/mod/truncate.sql", "/db/CreatePoolController_loadVoters.sql"})
public void test_poolCreate_getVoters_success() {
try {
// load voters from the database
List<String> resultSet = votersRepository.callGetVoters(5,
LocalDate.now().minusYears(75),
LocalDate.now().minusYears(18),
"415",
"CH1,CH2,CH3",
"N");
assertThat(resultSet).isNotEmpty();
assertThat(resultSet.size()).isEqualTo(7); // should be 5 * 1.4 = 7
} catch (SQLException e) {
log.error("Unexpected error", e);
fail("Unexpected error", e);
}
// load voters from the database
List<Voters> resultSet = votersService.getVoters(List.of("CH1", "CH2", "CH3"),
5,
LocalDate.now(),
"415",
false);
assertThat(resultSet).isNotEmpty();
assertThat(resultSet.size()).isEqualTo(7); // should be 5 * 1.4 = 7
}

@Test
Expand All @@ -61,28 +53,19 @@ public void test_poolCreate_getVoters_distribution() {
int loopCount = 100;
Map<String, Integer> jurorIdMap = new ConcurrentHashMap<>();

for (int i = 0;
i < loopCount;
i++) {

try {
// load voters from the database
List<String> resultSet = votersRepository.callGetVoters(5,
LocalDate.now().minusYears(75),
LocalDate.now().minusYears(18),
"415",
"CH1,CH2,CH3",
"N");
assertThat(resultSet).isNotEmpty();
for (int i = 0; i < loopCount; i++) {
// load voters from the database
List<Voters> resultSet = votersService.getVoters(List.of("CH1", "CH2", "CH3"),
5, LocalDate.now(),
"415",
false);
assertThat(resultSet).isNotEmpty();

resultSet.forEach(row -> {
String jurorNumber = row.split(",")[0];
jurorIdMap.computeIfPresent(jurorNumber, (key, val) -> val + 1);
jurorIdMap.putIfAbsent(jurorNumber, 1);
});
} catch (SQLException e) {
log.error(e.getMessage());
}
resultSet.forEach(row -> {
String jurorNumber = row.getJurorNumber();
jurorIdMap.computeIfPresent(jurorNumber, (key, val) -> val + 1);
jurorIdMap.putIfAbsent(jurorNumber, 1);
});
}
jurorIdMap.forEach((key, val) -> log.info("There were {} occurrences of juror number {}", val, key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ VALUES ('416220901', '416', '2022-12-03', 5, 5, 'CRO', '416', 'N'),
('416220902', '416', '2022-12-03', 5, 5, 'CRO', '416', 'N'),
('415220901', '415', '2022-12-03', 5, 5, 'CRO', '415', 'N'),
('767220901', '415', '2022-12-03', 5, 5, 'CRO', '767', 'N'),
('417220902', '417', '2022-12-03', 5, 5, 'CRO', '417', 'N'),
('767220902', '400', '2022-12-03', 5, 5, 'CRO', '767', 'N');

INSERT INTO juror_mod.juror (juror_number, title, last_name, first_name, dob, address_line_1, address_line_4, postcode, responded)
Expand All @@ -19,7 +20,9 @@ VALUES ('641600091', 'MR','LNAMEFIVEFOURZERO','FNAMEFIVEFOURZERO', '1989-03-31',
('641500098', 'MR','Lnamenineeight','Fnamenineeight', '1988-01-01', '543 STREET NAME', 'ANYTOWN', 'CH1 2AN', true),
('641500099', 'MR','Lnameninenine','Fnameninenine', '1988-01-01', '543 STREET NAME', 'ANYTOWN', 'CH1 2AN', true),
('641500100', 'MR','Lnamenineten','Fnamenineten', '1988-01-01', '543 STREET NAME', 'ANYTOWN', 'CH1 2AN', true),
('641500101', 'MR','Lnamenineten','Fnamenineten', '1988-01-01', '543 STREET NAME', 'ANYTOWN', 'CH1 2AN', true);
('641500101', 'MR','Lnamenineten','Fnamenineten', '1988-01-01', '543 STREET NAME', 'ANYTOWN', 'CH1 2AN', true),
('641700120', 'MR','Lnametwo','Fnametwo I', '1988-01-01', '543 STREET NAME', 'ANYTOWN', 'CH1 2AN', true),
('641700123', 'MR','Lnamethree I','Fnamethree', '1988-01-01', '543 STREET NAME', 'ANYTOWN', 'CH1 2AN', true);

INSERT INTO juror_mod.juror_pool (owner, juror_number, pool_number, is_active, status)
VALUES ('416', '641600091', '416220901', false, 7),
Expand All @@ -35,4 +38,6 @@ VALUES ('416', '641600091', '416220901', false, 7),
('415', '641500098', '415220901', true, 2),
('415', '641500099', '415220901', true, 2),
('415', '641500100', '415220901', true, 2),
('417', '641700120', '417220902', true, 2),
('417', '641700123', '417220902', true, 2),
('400', '641500101', '767220902', true, 2);
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ private void performAllocations(List<BureauBacklogAllocateRequestDto.StaffAlloca
);
if (staffMemberNonUrgentCount > 0) {
toBeAllocated.addAll(allocateResponses(
JurorResponseQueries.byUnassignedTodoNonUrgent(),
JurorResponseQueries.byUnassignedTodoNonUrgent()
.and(JurorResponseQueries.jurorIsNotTransferred()),
staffMember,
staffMemberNonUrgentCount
));
Expand All @@ -109,7 +110,8 @@ private void performAllocations(List<BureauBacklogAllocateRequestDto.StaffAlloca
);
if (staffMemberUrgentCount > 0) {
toBeAllocated.addAll(allocateResponses(
JurorResponseQueries.byUnassignedTodoUrgent(),
JurorResponseQueries.byUnassignedTodoUrgent()
.and(JurorResponseQueries.jurorIsNotTransferred()),
staffMember,
staffMemberUrgentCount
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.juror.api.bureau.controller.response.BureauBacklogCountData;
import uk.gov.hmcts.juror.api.bureau.controller.response.BureauOfficerAllocatedData;
import uk.gov.hmcts.juror.api.bureau.controller.response.BureauOfficerAllocatedResponses;
Expand All @@ -21,6 +22,7 @@ public class BureauOfficerAllocatedRepliesServiceImpl implements BureauOfficerAl
private final JurorDigitalResponseRepositoryMod jurorResponseRepository;

@Override
@Transactional
public BureauOfficerAllocatedResponses getBackLogData() {
Tuple backlogStats = jurorResponseRepository.getAssignRepliesStatistics();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import uk.gov.hmcts.juror.api.moj.domain.JurorPool;
import uk.gov.hmcts.juror.api.moj.domain.ModJurorDetail;
import uk.gov.hmcts.juror.api.moj.domain.PoolRequest;
import uk.gov.hmcts.juror.api.moj.domain.QJuror;
import uk.gov.hmcts.juror.api.moj.domain.QJurorPool;
import uk.gov.hmcts.juror.api.moj.domain.QModJurorDetail;
import uk.gov.hmcts.juror.api.moj.domain.QPoolRequest;
Expand Down Expand Up @@ -128,7 +127,8 @@ public BureauResponseSummaryWrapper getDetailsByProcessingStatus(String category
private Map<ProcessingStatus, Long> getJurorResponseCounts(String username) {
return jurorCommonResponseRepositoryMod.getJurorResponseCounts(
QCombinedJurorResponse.combinedJurorResponse.staff.username.eq(username),
QCombinedJurorResponse.combinedJurorResponse.processingStatus.ne(ProcessingStatus.CLOSED)
QCombinedJurorResponse.combinedJurorResponse.processingStatus.ne(ProcessingStatus.CLOSED),
QCombinedJurorResponse.combinedJurorResponse.juror.bureauTransferDate.isNull()
);
}

Expand Down Expand Up @@ -179,7 +179,7 @@ private BureauResponseSummaryWrapper getBureauResponseSummaryWrapperFromUsername
.map(tuple -> {
CombinedJurorResponse jurorResponseRepository1 =
tuple.get(QCombinedJurorResponse.combinedJurorResponse);
Juror juror = tuple.get(QJuror.juror);
Juror juror = jurorResponseRepository1.getJuror();
JurorPool jurorPool = tuple.get(QJurorPool.jurorPool);
PoolRequest pool = tuple.get(QPoolRequest.poolRequest);
return bureauTransformsService.detailToDto(jurorResponseRepository1, juror, jurorPool, pool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ public ResponseEntity<ReissueLetterListResponseDto> reissueLetterList(
@IsBureauUser
public ResponseEntity<ReissueLetterReponseDto> reissueLetter(
@RequestBody @Valid @NotNull ReissueLetterRequestDto request) {

ReissueLetterReponseDto response = reissueLetterService.reissueLetter(request);

return ResponseEntity.ok(response);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/uk/gov/hmcts/juror/api/moj/domain/Voters.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public class Voters implements Serializable {
@Length(max = 10)
private String postcode;

@Column(name = "postcode_start", updatable = false, insertable = false)
private String postcodeStart;

@Column(name = "DATE_SELECTED1")
private Date dateSelected1;

Expand Down
Loading

0 comments on commit c99b99b

Please sign in to comment.