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

DTSCCI-884 fix repeatative address1 #5593

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -16,7 +16,6 @@
import uk.gov.hmcts.reform.civil.model.docmosis.common.Party;
import uk.gov.hmcts.reform.civil.model.docmosis.common.RepaymentPlanTemplateData;
import uk.gov.hmcts.reform.civil.model.docmosis.lip.LipFormParty;
import uk.gov.hmcts.reform.civil.prd.model.ContactInformation;
import uk.gov.hmcts.reform.civil.service.JudgementService;
import uk.gov.hmcts.reform.civil.service.OrganisationService;
import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService;
Expand Down Expand Up @@ -188,17 +187,6 @@ private Party getClaimantLipOrLRDetailsForPaymentAddress(CaseData caseData) {
}
}

private Address getAddress(ContactInformation address) {
return uk.gov.hmcts.reform.civil.model.Address.builder().addressLine1(address.getAddressLine1())
.addressLine2(address.getAddressLine1())
.addressLine3(address.getAddressLine1())
.country(address.getCountry())
.county(address.getCounty())
.postCode(address.getPostCode())
.postTown(address.getTownCity())
.build();
}

private Party getRespondentLROrLipDetails(CaseData caseData) {
if (caseData.isRespondent1LiP()) {
return getPartyDetails(caseData.getRespondent1());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.hmcts.reform.civil.service.docmosis.dj;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.model.Organisation;
import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy;
Expand All @@ -10,20 +11,19 @@
import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF;
import uk.gov.hmcts.reform.civil.enums.RepaymentFrequencyDJ;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper;
import uk.gov.hmcts.reform.civil.helpers.DateFormatHelper;
import uk.gov.hmcts.reform.civil.model.Address;
import uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument;
import uk.gov.hmcts.reform.civil.model.docmosis.common.Party;
import uk.gov.hmcts.reform.civil.model.docmosis.dj.DefaultJudgmentForm;
import uk.gov.hmcts.reform.civil.prd.model.ContactInformation;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.service.FeesService;
import uk.gov.hmcts.reform.civil.service.OrganisationService;
import uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates;
import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService;
import uk.gov.hmcts.reform.civil.service.docmosis.TemplateDataGenerator;
import uk.gov.hmcts.reform.civil.utils.AddressUtils;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;
import uk.gov.hmcts.reform.civil.utils.InterestCalculator;
import uk.gov.hmcts.reform.civil.utils.MonetaryConversions;
Expand All @@ -49,6 +49,7 @@
import static uk.gov.hmcts.reform.civil.utils.JudgmentOnlineUtils.getRespondent2SolicitorRef;

@Service
@Slf4j
@RequiredArgsConstructor
public class DefaultJudgmentFormGenerator implements TemplateDataGenerator<DefaultJudgmentForm> {

Expand All @@ -69,6 +70,7 @@ public List<CaseDocument> generate(CaseData caseData, String authorisation, Stri
DocmosisDocument docmosisDocument2;
List<DefaultJudgmentForm> templateData = getDefaultJudgmentForms(caseData, event);
DocmosisTemplates docmosisTemplate = getDocmosisTemplate(event);
log.info("Template for case {} for caseId {}", docmosisTemplate.getTemplate(), caseData.getCcdCaseReference());
DocmosisDocument docmosisDocument1 =
documentGeneratorService.generateDocmosisDocument(templateData.get(0), docmosisTemplate);
caseDocuments.add(documentManagementService.uploadDocument(
Expand Down Expand Up @@ -108,10 +110,10 @@ private String getFileName(CaseData caseData, DocmosisTemplates docmosisTemplate
private List<DefaultJudgmentForm> getDefaultJudgmentForms(CaseData caseData, String event) {
List<DefaultJudgmentForm> defaultJudgmentForms = new ArrayList<>();

defaultJudgmentForms.add(getDefaultJudgmentForm(caseData, caseData.getRespondent1(), event));
defaultJudgmentForms.add(getDefaultJudgmentForm(caseData, caseData.getRespondent1(), event, true));
if (caseData.getRespondent2() != null) {

defaultJudgmentForms.add(getDefaultJudgmentForm(caseData, caseData.getRespondent2(), event));
defaultJudgmentForms.add(getDefaultJudgmentForm(caseData, caseData.getRespondent2(), event, false));
}

return defaultJudgmentForms;
Expand All @@ -120,12 +122,16 @@ private List<DefaultJudgmentForm> getDefaultJudgmentForms(CaseData caseData, Str

private DefaultJudgmentForm getDefaultJudgmentForm(CaseData caseData,
uk.gov.hmcts.reform.civil.model.Party respondent,
String event) {
String event,
boolean addReferenceOfSecondRes) {
BigDecimal debtAmount = event.equals(GENERATE_DJ_FORM_SPEC.name())
? JudgmentsOnlineHelper.getDebtAmount(caseData, interestCalculator).setScale(2) : new BigDecimal(0);
BigDecimal cost = event.equals(GENERATE_DJ_FORM_SPEC.name())
? getClaimFee(caseData) : new BigDecimal(0);

String respReference = addReferenceOfSecondRes ? caseData.getSolicitorReferences()
.getRespondentSolicitor1Reference() : null;

return DefaultJudgmentForm.builder()
.caseNumber(caseData.getLegacyCaseReference())
.formText("No response,")
Expand All @@ -140,8 +146,7 @@ private DefaultJudgmentForm getDefaultJudgmentForm(CaseData caseData,
? null : caseData.getSolicitorReferences()
.getApplicantSolicitor1Reference())
.respondentReference(Objects.isNull(caseData.getSolicitorReferences())
? null : caseData.getSolicitorReferences()
.getRespondentSolicitor1Reference()).build();
? null : respReference).build();
}

private DefaultJudgmentForm getDefaultJudgmentFormNonDivergent(CaseData caseData, String partyType) {
Expand Down Expand Up @@ -260,21 +265,10 @@ private Party getApplicantOrgDetails(OrganisationPolicy organisationPolicy) {
.map(organisationService::findOrganisationById)
.flatMap(value -> value.map(o -> Party.builder()
.name(o.getName())
.primaryAddress(getAddress(o.getContactInformation().get(0)))
.primaryAddress(AddressUtils.getAddress(o.getContactInformation().get(0)))
.build())).orElse(null);
}

private Address getAddress(ContactInformation address) {
return Address.builder().addressLine1(address.getAddressLine1())
.addressLine2(address.getAddressLine1())
.addressLine3(address.getAddressLine1())
.country(address.getCountry())
.county(address.getCounty())
.postCode(address.getPostCode())
.postTown(address.getTownCity())
.build();
}

private BigDecimal getClaimFee(CaseData caseData) {
var claimfee = feesService.getFeeDataByTotalClaimAmount(caseData.getTotalClaimAmount());
var claimFeePounds = MonetaryConversions.penniesToPounds(claimfee.getCalculatedAmountInPence());
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/civil/utils/AddressUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import camundajar.impl.scala.collection.mutable.StringBuilder;
import uk.gov.hmcts.reform.civil.model.Address;
import uk.gov.hmcts.reform.civil.prd.model.ContactInformation;

import java.util.Objects;

public class AddressUtils {

Expand All @@ -26,4 +29,14 @@ private static String formatAddressLine(String line) {
return line != null ? line + ", " : "";
}

public static Address getAddress(ContactInformation address) {
return Address.builder().addressLine1(address.getAddressLine1())
.addressLine2(Objects.toString(address.getAddressLine2(), ""))
.addressLine3(Objects.toString(address.getAddressLine3(), ""))
.country(address.getCountry())
.county(address.getCounty())
.postCode(address.getPostCode())
.postTown(address.getTownCity())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static List<Party> getApplicant(uk.gov.hmcts.reform.civil.model.Party app
.build());
if (applicant2 != null) {
applicants.add(Party.builder()
.name(applicant2.getPartyName())
.name(" and " + applicant2.getPartyName())
.primaryAddress(applicant2.getPrimaryAddress())
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_DJ_FORM_SPEC;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GEN_DJ_FORM_NON_DIVERGENT_SPEC_DEFENDANT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GEN_DJ_FORM_NON_DIVERGENT_SPEC_CLAIMANT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GEN_DJ_FORM_NON_DIVERGENT_SPEC_DEFENDANT;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT_CLAIMANT1;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT_CLAIMANT2;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT_DEFENDANT1;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT_DEFENDANT2;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.N121_SPEC;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.N121_SPEC_CLAIMANT;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.N121_SPEC_DEFENDANT;
Expand All @@ -58,7 +58,7 @@
DefaultJudgmentFormGenerator.class,
JacksonAutoConfiguration.class
})
public class DefaultJudgmentFormGeneratorTest {
class DefaultJudgmentFormGeneratorTest {

private static final String BEARER_TOKEN = "Bearer Token";
private static final String REFERENCE_NUMBER = "000DC001";
Expand Down Expand Up @@ -111,8 +111,8 @@ void shouldDefaultJudgmentFormGeneratorOneForm_whenValidDataIsProvided() {
.build();
List<CaseDocument> caseDocuments = generator.generate(caseData, BEARER_TOKEN, GENERATE_DJ_FORM_SPEC.name());

assertThat(caseDocuments.size()).isEqualTo(1);

assertThat(caseDocuments).hasSize(1);
verify(organisationService).findOrganisationById(any());
verify(documentManagementService)
.uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, DEFAULT_JUDGMENT));

Expand Down Expand Up @@ -142,8 +142,8 @@ void shouldDefaultJudgmentFormGeneratorOneForm_whenClaimIssueWithHWF() {
.build();
List<CaseDocument> caseDocuments = generator.generate(caseData, BEARER_TOKEN, GENERATE_DJ_FORM_SPEC.name());

assertThat(caseDocuments.size()).isEqualTo(1);

assertThat(caseDocuments).hasSize(1);
verify(organisationService).findOrganisationById(any());
verify(documentManagementService)
.uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, DEFAULT_JUDGMENT));

Expand Down Expand Up @@ -173,8 +173,8 @@ void shouldDefaultJudgmentFormGeneratorOneForm_whenClaimIssueWithHWFAndFullRemis
.build();
List<CaseDocument> caseDocuments = generator.generate(caseData, BEARER_TOKEN, GENERATE_DJ_FORM_SPEC.name());

assertThat(caseDocuments.size()).isEqualTo(1);

assertThat(caseDocuments).hasSize(1);
verify(organisationService).findOrganisationById(any());
verify(documentManagementService)
.uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, DEFAULT_JUDGMENT));

Expand Down Expand Up @@ -202,8 +202,8 @@ void shouldDefaultJudgmentFormGeneratorOneForm_whenFixedAmountCostSelected() {
.build();
List<CaseDocument> caseDocuments = generator.generate(caseData, BEARER_TOKEN, GENERATE_DJ_FORM_SPEC.name());

assertThat(caseDocuments.size()).isEqualTo(1);

assertThat(caseDocuments).hasSize(1);
verify(organisationService).findOrganisationById(any());
verify(documentManagementService)
.uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, DEFAULT_JUDGMENT));

Expand All @@ -229,7 +229,8 @@ void shouldDefaultJudgmentFormGeneratorTwoForms_whenValidDataIsProvided() {
.build();
List<CaseDocument> caseDocuments = generator.generate(caseData, BEARER_TOKEN, GENERATE_DJ_FORM_SPEC.name());

assertThat(caseDocuments.size()).isEqualTo(2);
assertThat(caseDocuments).hasSize(2);
verify(organisationService, times(2)).findOrganisationById(any());
}

@Test
Expand Down Expand Up @@ -262,7 +263,7 @@ void shouldGenerateClaimantDocsNonDivergent_whenValidDataIsProvided() {
.build();
List<CaseDocument> caseDocuments = generator.generateNonDivergentDocs(caseData, BEARER_TOKEN,
GEN_DJ_FORM_NON_DIVERGENT_SPEC_CLAIMANT.name());

verify(organisationService, times(6)).findOrganisationById(any());
verify(assignCategoryId, times(2))
.assignCategoryIdToCaseDocument(CASE_DOCUMENT, "judgments");
assertThat(caseDocuments).hasSize(2);
Expand Down Expand Up @@ -293,7 +294,7 @@ void shouldGenerateDefendantDocsNonDivergent_whenValidDataIsProvided() {
.build();
List<CaseDocument> caseDocuments = generator.generateNonDivergentDocs(caseData, BEARER_TOKEN,
GEN_DJ_FORM_NON_DIVERGENT_SPEC_DEFENDANT.name());

verify(organisationService, times(6)).findOrganisationById(any());
verify(assignCategoryId, times(2))
.assignCategoryIdToCaseDocument(CASE_DOCUMENT, "judgments");
assertThat(caseDocuments).hasSize(2);
Expand Down Expand Up @@ -322,7 +323,7 @@ void shouldGenerateDefendantDocNonDivergent_whenValidDataIsProvidedLip() {
.build();
List<CaseDocument> caseDocuments = generator.generateNonDivergentDocs(caseData, BEARER_TOKEN,
GEN_DJ_FORM_NON_DIVERGENT_SPEC_DEFENDANT.name());

verify(organisationService, times(2)).findOrganisationById(any());
verify(assignCategoryId)
.assignCategoryIdToCaseDocument(CASE_DOCUMENT, "judgments");
assertThat(caseDocuments).hasSize(1);
Expand Down Expand Up @@ -358,6 +359,7 @@ void shouldGenerateClaimantDocsNonDivergent_whenValidDataIsProvidedLip() {
GEN_DJ_FORM_NON_DIVERGENT_SPEC_CLAIMANT.name());
verify(assignCategoryId)
.assignCategoryIdToCaseDocument(CASE_DOCUMENT, "judgments");
verify(organisationService, times(3)).findOrganisationById(any());
assertThat(caseDocuments).hasSize(1);
}

Expand Down Expand Up @@ -393,6 +395,7 @@ void shouldGenerateClaimantDocsNonDivergent1v2_whenValidDataIsProvidedLip() {

verify(assignCategoryId, times(2))
.assignCategoryIdToCaseDocument(CASE_DOCUMENT, "judgments");
verify(organisationService, times(5)).findOrganisationById(any());
assertThat(caseDocuments).hasSize(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.civil.model.Address;
import uk.gov.hmcts.reform.civil.prd.model.ContactInformation;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AddressUtilsTest {
class AddressUtilsTest {

@Test
public void testFormatAddress() {
void testFormatAddress() {
Address address = Address.builder()
.addressLine1("123 Street")
.addressLine2("Apartment 4B")
Expand All @@ -24,7 +25,7 @@ public void testFormatAddress() {
}

@Test
public void testFormatAddressWithNullFields() {
void testFormatAddressWithNullFields() {
Address address = Address.builder()
.addressLine1("123 Street")
.country("Country")
Expand All @@ -37,11 +38,52 @@ public void testFormatAddressWithNullFields() {
}

@Test
public void testFormatEmptyAddress() {
void testFormatEmptyAddress() {
Address address = Address.builder().build();

String formattedAddress = AddressUtils.formatAddress(address);

assertEquals("", formattedAddress);
}

@Test
void getAddress() {
ContactInformation contactInformation = ContactInformation.builder()
.addressLine1("Hello")
.addressLine2("World")
.addressLine3("AI")
.county("MDX")
.country("United Kingdom")
.townCity("London")
.postCode("SW19 2PQ")
.build();

Address address = AddressUtils.getAddress(contactInformation);
assertEquals("Hello", address.getAddressLine1());
assertEquals("World", address.getAddressLine2());
assertEquals("AI", address.getAddressLine3());
assertEquals("London", address.getPostTown());
assertEquals("MDX", address.getCounty());
assertEquals("United Kingdom", address.getCountry());
assertEquals("SW19 2PQ", address.getPostCode());

contactInformation = ContactInformation.builder()
.addressLine1("Hello")
.addressLine2(null)
.addressLine3(null)
.townCity("London")
.county("MDX")
.country("United Kingdom")
.postCode("SW19 2PQ")
.build();

Address address1 = AddressUtils.getAddress(contactInformation);
assertEquals("Hello", address1.getAddressLine1());
assertEquals("", address1.getAddressLine2());
assertEquals("", address1.getAddressLine3());
assertEquals("MDX", address1.getCounty());
assertEquals("London", address1.getPostTown());
assertEquals("United Kingdom", address1.getCountry());
assertEquals("SW19 2PQ", address1.getPostCode());
}
}
Loading