Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/jm 8074 #735

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -867,24 +867,6 @@ void bureauProcessJurorActivePoolPaper() {
assertThat(deferral.isPresent()).isFalse();
}

@Test
void bureauProcessJurorAlreadyInBulkPrintForGivenDate() {
final String bureauJwt = createJwt(BUREAU_USER, OWNER_400);

httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt);

ResponseEntity<String> response = template.exchange(new RequestEntity<>(
createDeferralReasonRequestDtoToActivePool(ReplyMethod.PAPER),
httpHeaders, POST, URI.create(URL_PREFIX + JUROR_555555552)), String.class);

assertThat(response.getStatusCode()).as("HTTP status unprocessable entity expected")
.isEqualTo(UNPROCESSABLE_ENTITY);

assertBusinessRuleViolation(response, "Letter already exists in bulk print queue for the same day",
DAY_ALREADY_EXISTS);
}


@Test
void bureauOwnedCourtUserProcessJurorActivePoolPaper() {
final String bureauJwt = createJwt(COURT_USER, OWNER_415);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/uk/gov/hmcts/juror/api/moj/domain/FormCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import uk.gov.hmcts.juror.api.moj.exception.MojException;
import uk.gov.hmcts.juror.api.moj.service.PrintDataService;

import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

@Getter
public enum FormCode {
Expand Down Expand Up @@ -51,5 +54,11 @@ public static FormCode getFormCode(String code) {
throw new MojException.InternalServerError("Unknown form code '" + code + "'", null);
}

public static List<FormCode> getFormCodesForJurorStatus(int jurorStatus) {
return Arrays.stream(FormCode.values())
.filter(formCode -> formCode.getJurorStatus() == jurorStatus)
.collect(Collectors.toList());
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ List<BulkPrintData> findByJurorNoAndIdAndCreationDate(
List<BulkPrintData> findByJurorNoAndFormAttributeFormTypeInOrderByCreationDateDesc(String jurorNo,
List<String> formCodes);

List<BulkPrintData> findByJurorNoAndCreationDateAndFormAttributeFormTypeIn(String jurorNo, LocalDate creationDate,
List<String> formCodes);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.juror.api.moj.service;

import uk.gov.hmcts.juror.api.moj.domain.FormCode;
import uk.gov.hmcts.juror.api.moj.domain.JurorPool;

import java.time.LocalDate;
Expand Down Expand Up @@ -37,4 +38,6 @@ default void printSummonsLetter(JurorPool jurorPool) {
void printWithdrawalLetter(JurorPool jurorPool);

void checkLetterInBulkPrint(String jurorNumber, String formType, LocalDate creationDate, boolean extractedFlag);

void removeQueuedLetterForJuror(JurorPool jurorPool, List<FormCode> formCodes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;
import uk.gov.hmcts.juror.api.juror.domain.WelshCourtLocationRepository;
import uk.gov.hmcts.juror.api.moj.domain.BulkPrintData;
import uk.gov.hmcts.juror.api.moj.domain.FormCode;
import uk.gov.hmcts.juror.api.moj.domain.IJurorStatus;
import uk.gov.hmcts.juror.api.moj.domain.JurorPool;
import uk.gov.hmcts.juror.api.moj.exception.MojException;
Expand Down Expand Up @@ -240,4 +241,16 @@ public void commitData(LetterBase letter) {
bulkPrintData.setJurorNo(letter.getJurorNumber());
bulkPrintDataRepository.save(bulkPrintData);
}

@Override
public void removeQueuedLetterForJuror(JurorPool jurorPool, List<FormCode> formCodes) {

List<BulkPrintData> bulkPrintDataList = bulkPrintDataRepository
.findByJurorNoAndCreationDateAndFormAttributeFormTypeIn(
jurorPool.getJuror().getJurorNumber(), LocalDate.now(),
formCodes.stream().map(FormCode::getCode).toList()
);

bulkPrintDataRepository.deleteAll(bulkPrintDataList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ public void processJurorDeferral(BureauJwtPayload payload, String jurorNumber,
updateJurorHistory(newJurorPool, newJurorPool.getPoolNumber(), auditorUsername,
JurorHistory.ADDED, HistoryCodeMod.DEFERRED_POOL_MEMBER);

printDeferralAndConfirmationLetters(payload.getOwner(), jurorPool, newJurorPool);
printDeferralLetter(payload.getOwner(), jurorPool);
printConfirmationLetter(payload.getOwner(), newJurorPool);
} else {
//this is for the deferral journey to move them to deferred state
setupDeferralEntry(deferralReasonDto, auditorUsername, jurorPool);
Expand Down Expand Up @@ -256,7 +257,8 @@ public void changeJurorDeferralDate(BureauJwtPayload payload, String jurorNumber
updateJurorHistory(newJurorPool, newJurorPool.getPoolNumber(), auditorUsername, JurorHistory.ADDED,
HistoryCodeMod.DEFERRED_POOL_MEMBER);

printDeferralAndConfirmationLetters(payload.getOwner(), jurorPool, newJurorPool);
printConfirmationLetter(payload.getOwner(), newJurorPool);
printDeferralLetter(payload.getOwner(), jurorPool);

} else {
//this is for the deferral journey to move them to DEFER_DBF
Expand Down Expand Up @@ -646,44 +648,25 @@ public void setDeletedDeferralJurorPool(JurorPool jurorPool, String auditorUsern
jurorRepository.save(juror);
}

private void printDeferralAndConfirmationLetters(String owner, JurorPool jurorPool, JurorPool newJurorPool) {
// send letters via bulk print for Bureau users only
if (JurorDigitalApplication.JUROR_OWNER.equals(owner)) {
printDataService.checkLetterInBulkPrint(jurorPool.getJurorNumber(), getLetterCode(newJurorPool),
LocalDate.now(), false);

printDataService.printDeferralLetter(jurorPool);
jurorHistoryService.createDeferredLetterHistory(jurorPool);
Juror juror = jurorPool.getJuror();
if (juror.getPoliceCheck() != null && juror.getPoliceCheck().isChecked()) {
printDataService.printConfirmationLetter(newJurorPool);
jurorHistoryService.createConfirmationLetterHistory(newJurorPool, "Confirmation Letter");
}
}
}

private void printDeferralLetter(String owner, JurorPool jurorPool) {
// send letter via bulk print for Bureau users only
if (JurorDigitalApplication.JUROR_OWNER.equals(owner)) {
printDataService.checkLetterInBulkPrint(jurorPool.getJurorNumber(), getLetterCode(jurorPool),
LocalDate.now(), false);

printDataService.removeQueuedLetterForJuror(jurorPool, List.of(FormCode.ENG_DEFERRAL,
FormCode.BI_DEFERRAL));

printDataService.printDeferralLetter(jurorPool);
jurorHistoryService.createDeferredLetterHistory(jurorPool);
}
}

private String getLetterCode(JurorPool jurorPool) {
CourtLocation courtLocation = jurorPool.getCourt();

return CourtLocationUtils.isWelshCourtLocation(welshCourtLocationRepository,
courtLocation.getLocCode())
? FormCode.BI_DEFERRAL.getCode() : FormCode.ENG_DEFERRAL.getCode();
}

private void printConfirmationLetter(String owner, JurorPool jurorPool) {
if (JurorDigitalApplication.JUROR_OWNER.equals(owner)) {
// send letter via bulk print for Bureau users only

printDataService.removeQueuedLetterForJuror(jurorPool, List.of(FormCode.ENG_CONFIRMATION,
FormCode.BI_CONFIRMATION));

Juror juror = jurorPool.getJuror();
if (juror.getPoliceCheck() != null && juror.getPoliceCheck().isChecked()) {
printDataService.printConfirmationLetter(jurorPool);
Expand Down
Loading