From 9868416d5ab34dd99aef705da3cd365299f0a794 Mon Sep 17 00:00:00 2001 From: echo liang Date: Tue, 17 Oct 2023 19:40:55 -0700 Subject: [PATCH] Added logic to skip autoCalc for saveFormAnswers triggered by form clone --- .../ca/bc/gov/open/jag/api/form/FormsApiImpl.java | 2 +- .../open/jag/api/service/ClientDataService.java | 3 ++- .../jag/api/service/ClientDataServiceImpl.java | 4 ++-- .../jag/api/service/ClientFormSaveServiceImpl.java | 2 +- .../open/jag/api/service/ObridgeClientService.java | 1 + .../form/SaveClientFormAnswersUsingPUTTest.java | 2 +- .../dataservice/clientForm/CloneFormTest.java | 14 +++++++------- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/form/FormsApiImpl.java b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/form/FormsApiImpl.java index 650f88b1..75308e0c 100644 --- a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/form/FormsApiImpl.java +++ b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/form/FormsApiImpl.java @@ -78,7 +78,7 @@ public String saveClientFormAnswersUsingPUT(BigDecimal clientFormId, String clie loadLatestValues = Boolean.FALSE; } - return clientDataService.saveClientFormAnswers(clientNumber, clientFormId, answerPayload, loadLatestValues, xLocationId); + return clientDataService.saveClientFormAnswers(clientNumber, clientFormId, answerPayload, false, loadLatestValues, xLocationId); } @Override diff --git a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataService.java b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataService.java index 99be961f..7981872c 100644 --- a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataService.java +++ b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataService.java @@ -26,11 +26,12 @@ public interface ClientDataService { * @param clientNumber * @param clientFormId the form Id * @param payload the JSON representation of the form data + * @param skipAutoCalc set true to bypass the autoCalc logic while saving the form answers, e.g., set it to true while cloning form. * @param loadLatestAnswers set true to return latest answers - has performance overhead so only use if saving the whole form, not a single question * * @return {@link String} JSON value of answers if loadLatest is requested */ - String saveClientFormAnswers(String clientNumber, BigDecimal clientFormId, String payload, boolean loadLatestAnswers, String location); + String saveClientFormAnswers(String clientNumber, BigDecimal clientFormId, String payload, boolean skipAutoCalc, boolean loadLatestAnswers, String location); /** diff --git a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataServiceImpl.java b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataServiceImpl.java index 3607977a..811d6b9d 100644 --- a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataServiceImpl.java +++ b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientDataServiceImpl.java @@ -278,9 +278,9 @@ public ClientFormSummary getClientFormSummary(BigDecimal clientFormId, String cl } @Override - public String saveClientFormAnswers(String clientNumber,BigDecimal clientFormId, String payload, boolean loadLatestValues, String location) { + public String saveClientFormAnswers(String clientNumber,BigDecimal clientFormId, String payload, boolean skipAutoCalc, boolean loadLatestValues, String location) { logger.debug("Saving client form answers {}", clientFormId); - return obridgeClientService.saveClientFormAnswers(clientNumber,clientFormId, payload, loadLatestValues, new BigDecimal(location)); + return obridgeClientService.saveClientFormAnswers(clientNumber,clientFormId, payload, skipAutoCalc, loadLatestValues, new BigDecimal(location)); } diff --git a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientFormSaveServiceImpl.java b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientFormSaveServiceImpl.java index ded7ae20..3876c3a3 100644 --- a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientFormSaveServiceImpl.java +++ b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ClientFormSaveServiceImpl.java @@ -355,7 +355,7 @@ private BigDecimal cloneFormAndAnswers(ClientFormSummary clientFormSummary, Clon String answers = obridgeClientService.getClientFormAnswers(cloneFormRequest.getClientNumber(), clientFormSummary.getId(), new BigDecimal(location)); //Insert Answers Use Clone Config for ignore String strippedAnswers = stripAnswers(answers, cloneConfig.getForms().stream().filter(cloneForm -> cloneForm.getFormType().equalsIgnoreCase(clientFormSummary.getModule())).findFirst().get()); - obridgeClientService.saveClientFormAnswers(cloneFormRequest.getClientNumber(), clientFormId, strippedAnswers, false, new BigDecimal(location)); + obridgeClientService.saveClientFormAnswers(cloneFormRequest.getClientNumber(), clientFormId, strippedAnswers, true, false, new BigDecimal(location)); return clientFormId; diff --git a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ObridgeClientService.java b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ObridgeClientService.java index 58629281..3753a7f3 100644 --- a/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ObridgeClientService.java +++ b/cccm-backend/cccm-api/src/main/java/ca/bc/gov/open/jag/api/service/ObridgeClientService.java @@ -166,6 +166,7 @@ String getClientFormAsJSON(@PathParam("clientNumber") String clientNumber, String saveClientFormAnswers(@PathParam("clientNumber") String clientNumber, @PathParam("clientFormId") BigDecimal clientFormId, @RequestBody String payload, + @QueryParam("skipAutoCalc") boolean skipAutoCalc, @QueryParam("loadLatestValues") boolean loadLatestValues, @QueryParam("location") BigDecimal location); diff --git a/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/form/SaveClientFormAnswersUsingPUTTest.java b/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/form/SaveClientFormAnswersUsingPUTTest.java index 73071dfd..0932f509 100644 --- a/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/form/SaveClientFormAnswersUsingPUTTest.java +++ b/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/form/SaveClientFormAnswersUsingPUTTest.java @@ -47,7 +47,7 @@ public class SaveClientFormAnswersUsingPUTTest { @DisplayName("201: should link form") public void testGetSuccess() { - Mockito.when(clientDataService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString())).thenReturn(TEST); + Mockito.when(clientDataService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyString())).thenReturn(TEST); LinkFormInput linkFormInput = new LinkFormInput(); linkFormInput.setClientFormId(BigDecimal.ONE); diff --git a/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/service/dataservice/clientForm/CloneFormTest.java b/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/service/dataservice/clientForm/CloneFormTest.java index 74bab66e..c2979b2d 100644 --- a/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/service/dataservice/clientForm/CloneFormTest.java +++ b/cccm-backend/cccm-api/src/test/java/ca/bc/gov/open/jag/api/service/dataservice/clientForm/CloneFormTest.java @@ -128,7 +128,7 @@ public void testCloneCrnaForm() throws IOException { Mockito.when(obridgeClientService.createForm(Mockito.any())).thenReturn(BigDecimal.ONE); Mockito.when(obridgeClientService.getFormTypes(Mockito.any())).thenReturn(Collections.singletonList(createCodeTable(CRNA_FORM_TYPE, BigDecimal.ONE.toPlainString()))); Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(DATA_ONE); - Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); + Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); BigDecimal result = sut.cloneClientForm(new CloneFormRequest("TEST", BigDecimal.ONE, BigDecimal.ONE, true), "TEST@idir", "1"); @@ -144,7 +144,7 @@ public void testCloneSaraForm() throws IOException { Mockito.when(obridgeClientService.createForm(Mockito.any())).thenReturn(BigDecimal.ONE); Mockito.when(obridgeClientService.getFormTypes(Mockito.any())).thenReturn(Collections.singletonList(createCodeTable(SARA_FORM_TYPE, BigDecimal.ONE.toPlainString()))); Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(DATA_ONE); - Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); + Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); BigDecimal result = sut.cloneClientForm(new CloneFormRequest("TEST", BigDecimal.ONE, BigDecimal.ONE, true), "TEST@idir", "1"); @@ -160,7 +160,7 @@ public void testCloneSaraChildForm() throws IOException { Mockito.when(obridgeClientService.createForm(Mockito.any())).thenReturn(BigDecimal.ONE); Mockito.when(obridgeClientService.getFormTypes(Mockito.any())).thenReturn(Collections.singletonList(createCodeTable(SARA_FORM_TYPE, BigDecimal.ONE.toPlainString()))); Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(DATA_ONE); - Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); + Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); BigDecimal result = sut.cloneClientForm(new CloneFormRequest("TEST", BigDecimal.ONE, BigDecimal.ONE, true), "TEST@idir", "1"); @@ -176,7 +176,7 @@ public void testCloneAcuteForm() throws IOException { Mockito.when(obridgeClientService.createForm(Mockito.any())).thenReturn(BigDecimal.ONE); Mockito.when(obridgeClientService.getFormTypes(Mockito.any())).thenReturn(Collections.singletonList(createCodeTable(ACUTE_FORM_TYPE, BigDecimal.ONE.toPlainString()))); Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(DATA_ONE); - Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); + Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); BigDecimal result = sut.cloneClientForm(new CloneFormRequest("TEST", BigDecimal.ONE, BigDecimal.ONE, true), "TEST@idir", "1"); @@ -193,7 +193,7 @@ public void testCloneStatic99RChildForm() throws IOException { Mockito.when(obridgeClientService.createForm(Mockito.any())).thenReturn(BigDecimal.ONE); Mockito.when(obridgeClientService.getFormTypes(Mockito.any())).thenReturn(Collections.singletonList(createCodeTable(STATIC99R_FORM_TYPE, BigDecimal.ONE.toPlainString()))); Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(DATA_ONE); - Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); + Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); BigDecimal result = sut.cloneClientForm(new CloneFormRequest("TEST", BigDecimal.ONE, BigDecimal.ONE, true), "TEST@idir", "1"); @@ -209,7 +209,7 @@ public void testCloneCannotClone() throws IOException { Mockito.when(obridgeClientService.createForm(Mockito.any())).thenReturn(BigDecimal.ONE); Mockito.when(obridgeClientService.getFormTypes(Mockito.any())).thenReturn(Collections.singletonList(createCodeTable(SARA_FORM_TYPE, BigDecimal.TEN.toPlainString()))); Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(DATA_ONE); - Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); + Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); Assertions.assertThrows(CCCMException.class, () -> sut.cloneClientForm(new CloneFormRequest("TEST", BigDecimal.ONE, BigDecimal.ONE, false), "NOTTEST@idir", "1")); @@ -224,7 +224,7 @@ public void testCloneFormTypeInvalid() throws IOException { Mockito.when(obridgeClientService.createForm(Mockito.any())).thenReturn(BigDecimal.ONE); Mockito.when(obridgeClientService.getFormTypes(Mockito.any())).thenReturn(Collections.singletonList(createCodeTable(SARA_FORM_TYPE, BigDecimal.TEN.toPlainString()))); Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(DATA_ONE); - Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); + Mockito.when(obridgeClientService.saveClientFormAnswers(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any())).thenReturn(""); Assertions.assertThrows(CCCMException.class, () -> sut.cloneClientForm(new CloneFormRequest("TEST", BigDecimal.ONE, BigDecimal.ONE, true), "TEST@idir", "1"));