Skip to content

Commit

Permalink
Update income evidence within the Orchestration Service
Browse files Browse the repository at this point in the history
This commit makes changes in line with a new decision to update the
income evidence not within the Evidence Service as initially thought
but instead to do this within the Orchestration Service.

As such, the CMA client and calls to it are removed, with
new fields instead introduced via an update of the mod schemas
to version `1.16.0` to replace the information previously
obtained from the CMA Service.
  • Loading branch information
karlbaker02 committed Oct 25, 2024
1 parent 781d73d commit 77f500d
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 424 deletions.
2 changes: 1 addition & 1 deletion crime-evidence/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jacoco {
def versions = [
pitest : "1.16.0",
crimeCommonsClasses : "3.29.3",
commonsModSchemas : "1.14.0",
commonsModSchemas : "1.16.0",
commonsRestClient : "3.4.0",
wmStubRunnerVersion : "4.1.2",
springDocWebMVCVersion: "2.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public static UpdateEvidenceDTO build(final ApiUpdateIncomeEvidenceRequest reque
.partnerPensionAmount(request.getPartnerPensionAmount() != null ? request.getPartnerPensionAmount() : BigDecimal.ZERO)
.applicantIncomeEvidenceItems(request.getApplicantEvidenceItems() != null ? request.getApplicantEvidenceItems().getIncomeEvidenceItems() : null)
.partnerIncomeEvidenceItems(request.getPartnerEvidenceItems() != null ? request.getPartnerEvidenceItems().getIncomeEvidenceItems() : null)
.evidencePending(request.getMetadata().getEvidencePending())
.evidenceDueDate(request.getEvidenceDueDate())
.evidenceReceivedDate(request.getEvidenceReceivedDate())
.previousEvidenceDueDate(request.getPreviousEvidenceDueDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,12 @@
@ConfigurationProperties(prefix = "services")
public class ServicesConfiguration {

@NotNull
private CmaApi cmaApi;

@NotNull
private MaatApi maatApi;

@NotNull
private boolean oAuthEnabled;

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class CmaApi {
@NotNull
private String baseUrl;

@NotNull
private Endpoints endpoints;

@Data
@NoArgsConstructor
@AllArgsConstructor
public static class Endpoints {
@NotNull
private String findUrl;

@NotNull
private String updateUrl;
}
}

@Data
@AllArgsConstructor
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class UpdateEvidenceDTO {
private BigDecimal applicantPensionAmount;
private BigDecimal partnerPensionAmount;
private LocalDate applicationReceivedDate;
private boolean evidencePending;
private LocalDateTime evidenceDueDate;
private LocalDateTime evidenceReceivedDate;
private LocalDateTime previousEvidenceDueDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
import uk.gov.justice.laa.crime.common.model.evidence.ApiIncomeEvidenceItems;
import uk.gov.justice.laa.crime.common.model.evidence.ApiUpdateIncomeEvidenceResponse;
import uk.gov.justice.laa.crime.common.model.meansassessment.ApiEvidenceType;
import uk.gov.justice.laa.crime.common.model.meansassessment.ApiGetMeansAssessmentResponse;
import uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidenceSummary;
import uk.gov.justice.laa.crime.common.model.meansassessment.ApiMeansAssessmentResponse;
import uk.gov.justice.laa.crime.common.model.meansassessment.ApiUpdateMeansAssessmentRequest;
import uk.gov.justice.laa.crime.enums.EvidenceFeeLevel;
import uk.gov.justice.laa.crime.enums.evidence.IncomeEvidenceType;
import uk.gov.justice.laa.crime.evidence.builder.EvidenceFeeRulesDTOBuilder;
Expand All @@ -25,7 +21,6 @@
import uk.gov.justice.laa.crime.util.DateUtil;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Slf4j
Expand All @@ -35,7 +30,6 @@ public class EvidenceService {
private final IncomeEvidenceService incomeEvidenceService;
private final IncomeEvidenceValidationService incomeEvidenceValidationService;
private final MaatCourtDataService maatCourtDataService;
private final MeansAssessmentApiService meansAssessmentApiService;

public ApiCalculateEvidenceFeeResponse calculateEvidenceFee(CrimeEvidenceDTO crimeEvidenceDTO) {
ApiCalculateEvidenceFeeResponse apiProcessRepOrderResponse = new ApiCalculateEvidenceFeeResponse();
Expand Down Expand Up @@ -98,14 +92,10 @@ public ApiUpdateIncomeEvidenceResponse updateEvidence(UpdateEvidenceDTO updateEv
incomeEvidenceValidationService.checkExtraEvidenceDescriptions(applicantEvidenceItems);
incomeEvidenceValidationService.checkExtraEvidenceDescriptions(partnerEvidenceItems);

ApiGetMeansAssessmentResponse oldMeansAssessmentResponse = meansAssessmentApiService.find(updateEvidenceDTO.getFinancialAssessmentId());
ApiIncomeEvidenceSummary incomeEvidenceSummary = oldMeansAssessmentResponse.getIncomeEvidenceSummary();

incomeEvidenceValidationService.checkEvidenceDueDates(
DateUtil.parseLocalDate(updateEvidenceDTO.getEvidenceDueDate()),
DateUtil.parseLocalDate(incomeEvidenceSummary.getFirstReminderDate()),
DateUtil.parseLocalDate(incomeEvidenceSummary.getSecondReminderDate()),
DateUtil.parseLocalDate(incomeEvidenceSummary.getEvidenceDueDate()));
DateUtil.parseLocalDate(updateEvidenceDTO.getPreviousEvidenceDueDate()),
updateEvidenceDTO.isEvidencePending());

boolean applicantEvidenceItemsReceived = true;
boolean partnerEvidenceItemsReceived = true;
Expand Down Expand Up @@ -133,28 +123,15 @@ public ApiUpdateIncomeEvidenceResponse updateEvidence(UpdateEvidenceDTO updateEv

boolean allEvidenceItemsReceived = applicantEvidenceItemsReceived && partnerEvidenceItemsReceived;

updateEvidenceReceivedDate(incomeEvidenceSummary, allEvidenceItemsReceived, updateEvidenceDTO.getEvidenceReceivedDate());
updateEvidenceDueDate(incomeEvidenceSummary, updateEvidenceDTO.getEvidenceDueDate());

ApiMeansAssessmentResponse updateAssessmentResponse = updateMeansAssessment(
incomeEvidenceSummary,
updateEvidenceDTO.getFinancialAssessmentId(),
updateEvidenceDTO.getApplicantDetails().getId(),
updateEvidenceDTO.getPartnerDetails() != null ? updateEvidenceDTO.getPartnerDetails().getId() : null,
applicantEvidenceItems,
partnerEvidenceItems
);

applicantEvidenceItems = getUpdatedEvidenceItems(updateAssessmentResponse, updateEvidenceDTO.getApplicantDetails().getId());
updateEvidenceReceivedDate(updateEvidenceDTO, allEvidenceItemsReceived);
updateEvidenceDueDate(updateEvidenceDTO);

ApiUpdateIncomeEvidenceResponse response = new ApiUpdateIncomeEvidenceResponse()
.withApplicantEvidenceItems(new ApiIncomeEvidenceItems(updateEvidenceDTO.getApplicantDetails(), applicantEvidenceItems))
.withDueDate(DateUtil.parseLocalDate(incomeEvidenceSummary.getEvidenceDueDate()))
.withAllEvidenceReceivedDate(DateUtil.parseLocalDate(incomeEvidenceSummary.getEvidenceReceivedDate()));
.withDueDate(DateUtil.parseLocalDate(updateEvidenceDTO.getEvidenceDueDate()))
.withAllEvidenceReceivedDate(DateUtil.parseLocalDate(updateEvidenceDTO.getEvidenceReceivedDate()));

if (!partnerEvidenceItems.isEmpty()) {
partnerEvidenceItems = getUpdatedEvidenceItems(updateAssessmentResponse, updateEvidenceDTO.getPartnerDetails().getId());

response.setPartnerEvidenceItems(new ApiIncomeEvidenceItems(updateEvidenceDTO.getPartnerDetails(), partnerEvidenceItems));
}

Expand All @@ -167,36 +144,36 @@ protected boolean isCalcRequired(CrimeEvidenceDTO crimeEvidenceDTO) {
(crimeEvidenceDTO.getEvidenceFee() == null || crimeEvidenceDTO.getEvidenceFee().getFeeLevel() == null);
}

private List<ApiIncomeEvidence> getUpdatedEvidenceItems(ApiMeansAssessmentResponse meansAssessmentResponse,
int personId) {
return meansAssessmentResponse.getIncomeEvidence()
.stream()
.filter(evidence -> evidence.getApplicantId() == personId)
.map(this::mapApiIncomeEvidence)
.toList();
}

private ApiMeansAssessmentResponse updateMeansAssessment(
ApiIncomeEvidenceSummary currentIncomeEvidenceSummary,
int financialAssessmentId,
int applicantId,
Integer partnerId,
List<ApiIncomeEvidence> applicantEvidenceItems,
List<ApiIncomeEvidence> partnerEvidenceItems) {
// Note: the ApiIncomeEvidenceSummary is being passed only to update the evidence due and
// received dates. Evidence items are passed directly as part of the request and not set via
// the evidence summary object.
List<uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence> incomeEvidenceItems = new ArrayList<>();
applicantEvidenceItems.forEach(applicantEvidenceItem -> incomeEvidenceItems.add(mapApiIncomeEvidence(applicantEvidenceItem, applicantId)));
partnerEvidenceItems.forEach(partnerEvidenceItem -> incomeEvidenceItems.add(mapApiIncomeEvidence(partnerEvidenceItem, partnerId)));

ApiUpdateMeansAssessmentRequest request = new ApiUpdateMeansAssessmentRequest()
.withFinancialAssessmentId(financialAssessmentId)
.withIncomeEvidence(incomeEvidenceItems)
.withIncomeEvidenceSummary(currentIncomeEvidenceSummary);

return meansAssessmentApiService.update(request);
}
// private List<ApiIncomeEvidence> getUpdatedEvidenceItems(ApiMeansAssessmentResponse meansAssessmentResponse,
// int personId) {
// return meansAssessmentResponse.getIncomeEvidence()
// .stream()
// .filter(evidence -> evidence.getApplicantId() == personId)
// .map(this::mapApiIncomeEvidence)
// .toList();
// }

// private ApiMeansAssessmentResponse updateMeansAssessment(
// ApiIncomeEvidenceSummary currentIncomeEvidenceSummary,
// int financialAssessmentId,
// int applicantId,
// Integer partnerId,
// List<ApiIncomeEvidence> applicantEvidenceItems,
// List<ApiIncomeEvidence> partnerEvidenceItems) {
// // Note: the ApiIncomeEvidenceSummary is being passed only to update the evidence due and
// // received dates. Evidence items are passed directly as part of the request and not set via
// // the evidence summary object.
// List<uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence> incomeEvidenceItems = new ArrayList<>();
// applicantEvidenceItems.forEach(applicantEvidenceItem -> incomeEvidenceItems.add(mapApiIncomeEvidence(applicantEvidenceItem, applicantId)));
// partnerEvidenceItems.forEach(partnerEvidenceItem -> incomeEvidenceItems.add(mapApiIncomeEvidence(partnerEvidenceItem, partnerId)));
//
// ApiUpdateMeansAssessmentRequest request = new ApiUpdateMeansAssessmentRequest()
// .withFinancialAssessmentId(financialAssessmentId)
// .withIncomeEvidence(incomeEvidenceItems)
// .withIncomeEvidenceSummary(currentIncomeEvidenceSummary);
//
// return meansAssessmentApiService.update(request);
// }

private uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence mapApiIncomeEvidence(ApiIncomeEvidence apiIncomeEvidence, Integer applicantId) {
return new uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence()
Expand All @@ -215,19 +192,19 @@ private ApiIncomeEvidence mapApiIncomeEvidence(
.withEvidenceType(IncomeEvidenceType.getFrom(apiIncomeEvidence.getApiEvidenceType().getCode()));
}

private void updateEvidenceDueDate(ApiIncomeEvidenceSummary incomeEvidenceSummary, LocalDateTime evidenceDueDate) {
LocalDateTime previousEvidenceDueDate = incomeEvidenceSummary.getEvidenceDueDate();
private void updateEvidenceDueDate(UpdateEvidenceDTO updateEvidenceDTO) {
LocalDateTime previousEvidenceDueDate = updateEvidenceDTO.getPreviousEvidenceDueDate();

if (evidenceDueDate == null && previousEvidenceDueDate != null) {
incomeEvidenceSummary.setEvidenceDueDate(previousEvidenceDueDate);
if (updateEvidenceDTO.getEvidenceDueDate() == null && previousEvidenceDueDate != null) {
updateEvidenceDTO.setEvidenceDueDate(previousEvidenceDueDate);
}
}

private void updateEvidenceReceivedDate(ApiIncomeEvidenceSummary incomeEvidenceSummary, boolean evidenceReceived, LocalDateTime evidenceReceivedDate) {
if (evidenceReceived && incomeEvidenceSummary.getEvidenceReceivedDate() == null) {
incomeEvidenceSummary.setEvidenceReceivedDate(evidenceReceivedDate != null ? evidenceReceivedDate : LocalDateTime.now());
} else if (!evidenceReceived && incomeEvidenceSummary.getEvidenceReceivedDate() != null) {
incomeEvidenceSummary.setEvidenceReceivedDate(null);
private void updateEvidenceReceivedDate(UpdateEvidenceDTO updateEvidenceDTO, boolean evidenceReceived) {
if (evidenceReceived && updateEvidenceDTO.getEvidenceReceivedDate() == null) {
updateEvidenceDTO.setEvidenceReceivedDate(LocalDateTime.now());
} else if (!evidenceReceived && updateEvidenceDTO.getEvidenceReceivedDate() != null) {
updateEvidenceDTO.setEvidenceReceivedDate(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ public class IncomeEvidenceValidationService {
IncomeEvidenceType.OTHER_BUSINESS);
public static final String MISSING_OTHER_EVIDENCE_DESCRIPTION = "When other evidence is requested, you must provide descriptive text.";

public void validate(EvidenceDTO evidenceDTO){
checkExtraEvidenceDescription(evidenceDTO.getIncomeExtraEvidence(),
evidenceDTO.getIncomeExtraEvidenceText());

checkEvidenceReceivedDate(
DateUtil.parseLocalDate(evidenceDTO.getIncomeEvidenceReceivedDate()),
DateUtil.parseLocalDate(evidenceDTO.getApplicationReceivedDate()));

checkEvidenceDueDates(DateUtil.parseLocalDate(evidenceDTO.getEvidenceDueDate()),
DateUtil.parseLocalDate(evidenceDTO.getFirstReminderDate()),
DateUtil.parseLocalDate(evidenceDTO.getSecondReminderDate()),
DateUtil.parseLocalDate(evidenceDTO.getExistingEvidenceDueDate()));
}

public void checkEvidenceReceivedDate(LocalDate incomeEvidenceReceivedDate, LocalDate applicationReceivedDate) {
LocalDate currentDate = LocalDate.now();
if (incomeEvidenceReceivedDate != null && incomeEvidenceReceivedDate.isAfter(currentDate)) {
Expand All @@ -53,11 +39,9 @@ public void checkExtraEvidenceDescription(String incomeExtraEvidence, String inc
}
}

public void checkEvidenceDueDates(LocalDate evidenceDueDate, LocalDate firstReminderDate, LocalDate secondReminderDate,
LocalDate existingEvidenceDueDate) {
public void checkEvidenceDueDates(LocalDate evidenceDueDate, LocalDate existingEvidenceDueDate, boolean evidencePending) {
LocalDate currentDate = LocalDate.now();
if ((evidenceDueDate == null && existingEvidenceDueDate != null) && (
firstReminderDate != null || secondReminderDate != null)) {
if (evidenceDueDate == null && existingEvidenceDueDate != null && evidencePending) {
throw new IllegalArgumentException("Evidence due date cannot be null");
}

Expand Down

This file was deleted.

11 changes: 0 additions & 11 deletions crime-evidence/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ spring:
oauth2:
client:
provider:
cma:
token-uri: ${CMA_API_OAUTH_URL}
maat-api:
token-uri: ${MAAT_API_OAUTH_URL}
registration:
cma:
client-id: ${CMA_API_OAUTH_CLIENT_ID}
client-secret: ${CMA_API_OAUTH_CLIENT_SECRET}
authorization-grant-type: client_credentials
maat-api:
client-id: ${MAAT_API_OAUTH_CLIENT_ID}
client-secret: ${MAAT_API_OAUTH_CLIENT_SECRET}
Expand All @@ -79,11 +73,6 @@ retry-config:
jitter-value: 0.75

services:
cma-api:
base-url: ${CMA_API_BASE_URL}
endpoints:
find-url: ${services.cma-api.base-url}/api/internal/v1/assessment/means/{financialAssessmentId}
update-url: ${services.cma-api.base-url}/api/internal/v1/assessment/means
maat-api:
base-url: ${MAAT_API_BASE_URL}
assessments-domain: ${services.maat-api.base-url}/api/internal/v1/assessment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,17 @@ public static ServicesConfiguration getConfiguration(int port) {

ServicesConfiguration servicesConfiguration = new ServicesConfiguration();
ServicesConfiguration.MaatApi maatApiConfiguration = new ServicesConfiguration.MaatApi();
ServicesConfiguration.CmaApi cmaApiConfiguration = new ServicesConfiguration.CmaApi();

ServicesConfiguration.MaatApi.RepOrderEndpoints repOrderEndpoints =
new ServicesConfiguration.MaatApi.RepOrderEndpoints(
"/rep-orders/capital/reporder/{repId}"
);

ServicesConfiguration.CmaApi.Endpoints cmaEndpoints =
new ServicesConfiguration.CmaApi.Endpoints(
"/assessment/means/{financialAssessmentId}",
"/assessment/means");

maatApiConfiguration.setBaseUrl(host);
maatApiConfiguration.setRepOrderEndpoints(repOrderEndpoints);

cmaApiConfiguration.setBaseUrl(host);
cmaApiConfiguration.setEndpoints(cmaEndpoints);

servicesConfiguration.setOAuthEnabled(false);
servicesConfiguration.setMaatApi(maatApiConfiguration);
servicesConfiguration.setCmaApi(cmaApiConfiguration);

return servicesConfiguration;
}
Expand Down
Loading

0 comments on commit 77f500d

Please sign in to comment.