From 0d825a7b41d95101a2f22a5611b3ccc167063aa1 Mon Sep 17 00:00:00 2001 From: Andrew Porritt <109674546+porritta@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:46:06 +0000 Subject: [PATCH] fix(ccls-2061): update mapper to default all booleans to false --- caab-api/open-api-specification.yml | 4 +-- .../caab/api/mapper/ApplicationMapper.java | 35 +++++++++++-------- .../api/mapper/ApplicationMapperTest.java | 11 +++--- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/caab-api/open-api-specification.yml b/caab-api/open-api-specification.yml index 296de70..b3f9632 100644 --- a/caab-api/open-api-specification.yml +++ b/caab-api/open-api-specification.yml @@ -1133,13 +1133,13 @@ components: type: 'string' new_entry: type: 'boolean' - default: true lsc_resource_id: type: 'string' resource_name: type: 'string' submitted: type: 'boolean' + default: 'true' audit_trail: $ref: "#/components/schemas/auditDetail" baseClient: @@ -1299,7 +1299,6 @@ components: type: 'string' lead_proceeding_ind: type: 'boolean' - default: false lar_scope: type: 'string' granted_using_devolved_powers: @@ -1455,7 +1454,6 @@ components: type: 'boolean' app_mode: type: 'boolean' - default: true amendment: type: 'boolean' award: diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java index 98c483b..14dd16c 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java @@ -55,7 +55,7 @@ public interface ApplicationMapper { @Mapping(target = "clientFirstName", source = "client.firstName") @Mapping(target = "clientSurname", source = "client.surname") @Mapping(target = "clientReference", source = "client.reference") - @Mapping(target = "costLimitChanged", source = "costLimit.changed", defaultValue = "false") + @Mapping(target = "costLimitChanged", source = "costLimit.changed") @Mapping(target = "costLimitAtTimeOfMerits", source = "costLimit.limitAtTimeOfMerits") @Mapping(target = "applicationType", source = "applicationType.id") @Mapping(target = "applicationTypeDisplayValue", source = "applicationType.displayValue") @@ -64,16 +64,11 @@ public interface ApplicationMapper { source = "applicationType.devolvedPowers.dateUsed") @Mapping(target = "devolvedPowersContractFlag", source = "applicationType.devolvedPowers.contractFlag") - @Mapping(target = "meritsReassessmentReqdInd", source = "meritsReassessmentRequired", - defaultValue = "false") - @Mapping(target = "leadProceedingChangedOpaInput", source = "leadProceedingChanged", - defaultValue = "false") - @Mapping(target = "meansAssessmentAmended", source = "meansAssessmentAmended", - defaultValue = "false") - @Mapping(target = "meritsAssessmentAmended", source = "meritsAssessmentAmended", - defaultValue = "false") - @Mapping(target = "amendment", source = "amendment", - defaultValue = "false") + @Mapping(target = "meritsReassessmentReqdInd", source = "meritsReassessmentRequired") + @Mapping(target = "leadProceedingChangedOpaInput", source = "leadProceedingChanged") + @Mapping(target = "meansAssessmentAmended", source = "meansAssessmentAmended") + @Mapping(target = "meritsAssessmentAmended", source = "meritsAssessmentAmended") + @Mapping(target = "amendment", source = "amendment") @Mapping(target = "costs", source = "costs", qualifiedByName = "toCostStructure") @Mapping(target = "correspondenceAddress", source = "correspondenceAddress", qualifiedByName = "toAddress") @@ -138,7 +133,7 @@ default void setParentInChildEntities(@MappingTarget Application application) { @Mapping(target = "status", source = "status.id") @Mapping(target = "displayStatus", source = "status.displayValue") @Mapping(target = "typeOfOrder", source = "typeOfOrder.id") - @Mapping(target = "leadProceedingInd", source = "leadProceedingInd", defaultValue = "false") + @Mapping(target = "leadProceedingInd", source = "leadProceedingInd") Proceeding toProceeding(uk.gov.laa.ccms.caab.model.Proceeding proceeding); @InheritInverseConfiguration(name = "toProceeding") @@ -178,9 +173,9 @@ uk.gov.laa.ccms.caab.model.ScopeLimitation toScopeLimitationModel( @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "address", source = "address", qualifiedByName = "toAddress") @Mapping(target = "appMode", source = "appMode", defaultValue = "true") - @Mapping(target = "amendment", source = "amendment", defaultValue = "false") - @Mapping(target = "award", source = "award", defaultValue = "false") - @Mapping(target = "sharedInd", source = "sharedInd", defaultValue = "false") + @Mapping(target = "amendment", source = "amendment") + @Mapping(target = "award", source = "award") + @Mapping(target = "sharedInd", source = "sharedInd") @Mapping(target = "deleteInd", source = "deleteInd", defaultValue = "true") Opponent toOpponent(uk.gov.laa.ccms.caab.model.Opponent opponent); @@ -228,6 +223,7 @@ void updateOpponent( @InheritInverseConfiguration(name = "toCostStructure") uk.gov.laa.ccms.caab.model.CostStructure toCostStructureModel(CostStructure costs); + @Mapping(target = "newEntry", source = "newEntry", defaultValue = "true") @Mapping(target = "auditTrail", ignore = true) CostEntry toCostEntry(uk.gov.laa.ccms.caab.model.CostEntry costEntry); @@ -377,4 +373,13 @@ void updateScopeLimitation( BaseApplication toBaseApplication(Application application); ApplicationDetails toApplicationDetails(Page application); + + /** + * Global mapper to default Booleans to FALSE in the case of a null source value. + * @param flag - the source value + * @return the source value, or FALSE. + */ + default Boolean toBoolean(Boolean flag) { + return flag != null ? flag : Boolean.FALSE; + } } diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java index 356f3a7..3eea04a 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java @@ -128,7 +128,7 @@ public void testApplicationMapping() { } @Test - public void testApplicationMapping_unsetBooleansFalse() { + public void testApplicationMapping_nullBooleansDefaultCorrectly() { ApplicationDetail detail = new ApplicationDetail(); Application application = mapper.toApplication(detail); @@ -273,6 +273,7 @@ public void testProceedingMapping_checkBooleanDefaults() { Proceeding proceeding = mapper.toProceeding(proceedingModel); assertFalse(proceeding.getLeadProceedingInd()); + assertFalse(proceeding.getEdited()); } @Test @@ -426,11 +427,13 @@ public void testToScopeLimitation() { @Test public void testToScopeLimitation_checkBooleanDefaults() { - uk.gov.laa.ccms.caab.model.ScopeLimitation scopeLimitationModel = new uk.gov.laa.ccms.caab.model.ScopeLimitation(); + uk.gov.laa.ccms.caab.model.ScopeLimitation scopeLimitationModel = + new uk.gov.laa.ccms.caab.model.ScopeLimitation(); ScopeLimitation scopeLimitation = mapper.toScopeLimitation(scopeLimitationModel); assertFalse(scopeLimitation.getDelegatedFuncApplyInd()); + assertFalse(scopeLimitation.getDefaultInd()); } @Test @@ -513,7 +516,6 @@ public void testToOpponent() { public void testToOpponent_checkBooleanDefaults() { uk.gov.laa.ccms.caab.model.Opponent opponentDetail = new uk.gov.laa.ccms.caab.model.Opponent(); - opponentDetail.setAppMode(null); Opponent opponent = mapper.toOpponent(opponentDetail); @@ -627,7 +629,8 @@ public void testToLinkedCaseModel_null() { @Test public void testAddressMapping() { - uk.gov.laa.ccms.caab.model.Address detailAddress = new uk.gov.laa.ccms.caab.model.Address(); + uk.gov.laa.ccms.caab.model.Address detailAddress = + new uk.gov.laa.ccms.caab.model.Address(); detailAddress.setNoFixedAbode(true); detailAddress.setPostcode("12345"); detailAddress.setHouseNameOrNumber("House 123");