Skip to content

Commit

Permalink
Merge branch 'master' into Sprint_PI32S5_t4
Browse files Browse the repository at this point in the history
  • Loading branch information
sankhajuria authored Jan 10, 2024
2 parents cc36ca6 + 25c9e7e commit 2051a36
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions charts/civil-service/values.aat.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ ccd:

ccd-api-gateway-web:
nodejs:
image: hmctspublic.azurecr.io/ccd/api-gateway-web:prod-66e26b9-20231116094420
imagePullPolicy: Always
environment:
ADDRESS_LOOKUP_TOKEN: ${ADDRESS_LOOKUP_TOKEN}
Expand Down
1 change: 1 addition & 0 deletions charts/civil-service/values.preview.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ ccd:

ccd-api-gateway-web:
nodejs:
image: hmctspublic.azurecr.io/ccd/api-gateway-web:prod-66e26b9-20231116094420
imagePullPolicy: Always
environment:
ADDRESS_LOOKUP_TOKEN: ${ADDRESS_LOOKUP_TOKEN}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import uk.gov.hmcts.reform.civil.service.search.CaseStateSearchService;

import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
Expand All @@ -36,14 +38,22 @@ public class GenerateCsvAndTransferTaskHandler implements BaseExternalTaskHandle
private final MediationCSVEmailConfiguration mediationCSVEmailConfiguration;
private static final String subject = "OCMC Mediation Data";
private static final String filename = "ocmc_mediation_data.csv";
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("dd-MM-yyyy");

@Override
public void handleTask(ExternalTask externalTask) {

List<CaseDetails> cases = caseSearchService.getCases();
List<CaseData> inMediationCases = cases.stream()
.map(caseDetailsConverter::toCaseData)
.filter(checkMediationMovedDate).toList();
List<CaseData> inMediationCases;
if (externalTask.getVariable("claimMovedDate") != null) {
LocalDate erroredDate = LocalDate.parse(externalTask.getVariable("claimMovedDate").toString(), DATE_FORMATTER);
inMediationCases = cases.stream()
.map(caseDetailsConverter::toCaseData)
.filter(checkErrorCasesWithDate(erroredDate)).toList();
} else {
inMediationCases = cases.stream()
.map(caseDetailsConverter::toCaseData)
.filter(checkMediationMovedDate).toList();
}
log.info("Job '{}' found {} case(s)", externalTask.getTopicName(), inMediationCases.size());
String[] headers = {"SITE_ID", "CASE_NUMBER", "CASE_TYPE", "AMOUNT", "PARTY_TYPE", "COMPANY_NAME",
"CONTACT_NAME", "CONTACT_NUMBER", "CHECK_LIST", "PARTY_STATUS", "CONTACT_EMAIL", "PILOT"};
Expand All @@ -63,6 +73,12 @@ public void handleTask(ExternalTask externalTask) {
caseData.getClaimMovedToMediationOn() != null
&& now().minusDays(1).equals(caseData.getClaimMovedToMediationOn());

private Predicate<CaseData> checkErrorCasesWithDate(LocalDate errorDate) {
return caseData ->
caseData.getClaimMovedToMediationOn() != null && errorDate != null
&& errorDate.equals(caseData.getClaimMovedToMediationOn());
}

private Optional<EmailData> prepareEmail(String generateCsvData) {
InputStreamSource inputSource = new ByteArrayResource(generateCsvData.getBytes(StandardCharsets.UTF_8));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -106,6 +108,21 @@ void shouldNotGenerateCsvAndSendEmail() {
verify(externalTaskService).complete(externalTask);
}

@Test
void should_handle_task_from_external_variable() {
String date = (claimToBeProcessed.format(DateTimeFormatter.ofPattern("dd-MM-yyyy", Locale.UK))).toString();
when(externalTask.getVariable(any())).thenReturn(date);
when(searchService.getCases()).thenReturn(List.of(caseDetailsWithInMediationState, caseDetailsWithInMediationStateNotToProcess));
when(caseDetailsConverter.toCaseData(caseDetailsWithInMediationState)).thenReturn(caseDataInMediation);
when(caseDetailsConverter.toCaseData(caseDetailsWithInMediationStateNotToProcess)).thenReturn(caseDataInMediationNotToProcess);

inMediationCsvHandler.execute(externalTask, externalTaskService);
verify(searchService).getCases();
verify(sendGridClient).sendEmail(anyString(), any());
verify(sendGridClient, times(1)).sendEmail(anyString(), any());
verify(externalTaskService).complete(externalTask);
}

private CaseDetails getCaseDetails(Long ccdId, LocalDate claimMovedToMediation) {

return CaseDetails.builder().id(ccdId).data(
Expand Down

0 comments on commit 2051a36

Please sign in to comment.