Skip to content

Commit

Permalink
Update evidence service to use updated items in response
Browse files Browse the repository at this point in the history
  • Loading branch information
karlbaker02 committed Oct 25, 2024
1 parent da62fe5 commit 5caa4ef
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
package uk.gov.justice.laa.crime.evidence.service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.justice.laa.crime.common.model.evidence.ApiIncomeEvidence;
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.ApiAssessmentDetail;
import uk.gov.justice.laa.crime.common.model.meansassessment.ApiAssessmentSectionSummary;
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.EmploymentStatus;
import uk.gov.justice.laa.crime.enums.Frequency;
import uk.gov.justice.laa.crime.enums.MagCourtOutcome;
import uk.gov.justice.laa.crime.enums.evidence.IncomeEvidenceType;
import uk.gov.justice.laa.crime.evidence.builder.EvidenceFeeRulesDTOBuilder;
import uk.gov.justice.laa.crime.evidence.common.Constants;
import uk.gov.justice.laa.crime.evidence.dto.CrimeEvidenceDTO;
Expand Down Expand Up @@ -132,12 +128,11 @@ public ApiUpdateIncomeEvidenceResponse updateEvidence(UpdateEvidenceDTO updateEv
partnerEvidenceItems
);

meansAssessmentApiService.update(updateMeansAssessmentRequest);
ApiMeansAssessmentResponse updateEvidenceResponse = meansAssessmentApiService.update(updateMeansAssessmentRequest);

// TODO: Map ids of new income evidence items.

// TODO: Should the due date be what it was previously, or should this have been updated and
// available somewhere else?
applicantEvidenceItems = getUpdatedEvidenceItems(updateEvidenceResponse, updateEvidenceDTO.getApplicantDetails().getId());
partnerEvidenceItems = getUpdatedEvidenceItems(updateEvidenceResponse, updateEvidenceDTO.getPartnerDetails().getId());

return new ApiUpdateIncomeEvidenceResponse()
.withApplicantEvidenceItems(new ApiIncomeEvidenceItems(updateEvidenceDTO.getApplicantDetails(), applicantEvidenceItems))
.withPartnerEvidenceItems(new ApiIncomeEvidenceItems(updateEvidenceDTO.getPartnerDetails(), partnerEvidenceItems))
Expand All @@ -151,6 +146,16 @@ 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 boolean checkEvidenceReceived(
List<ApiIncomeEvidence> applicantEvidenceItems,
List<ApiIncomeEvidence> partnerEvidenceItems,
Expand Down Expand Up @@ -223,11 +228,20 @@ private ApiUpdateMeansAssessmentRequest createUpdateMeansAssessmentRequest(
private uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence mapApiIncomeEvidence(ApiIncomeEvidence apiIncomeEvidence, int applicantId) {
return new uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence()
.withId(apiIncomeEvidence.getId())
.withDateReceived(DateUtil.convertDateToDateTime(apiIncomeEvidence.getDateReceived()))
.withApplicantId(applicantId)
.withDateReceived(DateUtil.convertDateToDateTime(apiIncomeEvidence.getDateReceived()))
.withApiEvidenceType(new ApiEvidenceType(apiIncomeEvidence.getEvidenceType().getName(), apiIncomeEvidence.getEvidenceType().getDescription()));
}

private ApiIncomeEvidence mapApiIncomeEvidence(
uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence apiIncomeEvidence) {
return new ApiIncomeEvidence()
.withId(apiIncomeEvidence.getId())
.withDateReceived(DateUtil.parseLocalDate(apiIncomeEvidence.getDateReceived()))
.withDescription(apiIncomeEvidence.getOtherText())
.withEvidenceType(IncomeEvidenceType.getFrom(apiIncomeEvidence.getApiEvidenceType().getCode()));
}

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

Expand Down

0 comments on commit 5caa4ef

Please sign in to comment.