diff --git a/caab-api/open-api-specification.yml b/caab-api/open-api-specification.yml index 9355313..db4a871 100644 --- a/caab-api/open-api-specification.yml +++ b/caab-api/open-api-specification.yml @@ -259,6 +259,8 @@ components: type: 'string' submitted: type: 'boolean' + audit_trail: + $ref: "#/components/schemas/auditDetail" client: type: 'object' properties: @@ -310,6 +312,8 @@ components: type: 'string' preferred_address: type: 'string' + audit_trail: + $ref: "#/components/schemas/auditDetail" scopeLimitation: type: 'object' properties: @@ -446,12 +450,6 @@ components: type: 'string' status: type: 'string' - client_reference: - type: 'string' - client_first_name: - type: 'string' - client_surname: - type: 'string' audit_trail: $ref: "#/components/schemas/auditDetail" priorAuthority: @@ -532,7 +530,7 @@ components: type: 'string' employer_name: type: 'string' - employment_address: + employer_address: type: 'string' legal_aided: type: 'boolean' diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java index 5457fe8..d2b83a3 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java @@ -1,5 +1,6 @@ package uk.gov.laa.ccms.data.api; +import java.util.Random; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.test.annotation.DirtiesContext; diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ApplicationControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ApplicationControllerIntegrationTest.java new file mode 100644 index 0000000..df6f167 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ApplicationControllerIntegrationTest.java @@ -0,0 +1,254 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.List; +import java.util.Random; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; +import uk.gov.laa.ccms.caab.api.controller.ApplicationController; +import uk.gov.laa.ccms.caab.api.entity.AuditTrail; +import uk.gov.laa.ccms.caab.api.service.ApplicationService; +import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.data.api.AbstractIntegrationTest; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +//@ActiveProfiles("local") +//public class ApplicationControllerIntegrationTest { +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") +public class ApplicationControllerIntegrationTest extends AbstractIntegrationTest { + + @Autowired + private ApplicationController applicationController; + + @Autowired + private ApplicationService applicationService; + + /** + * Loads the JSON file from the classpath and parses it into an ApplicationDetail object. + * + * @param jsonFilePath The path to the JSON file to load + */ + private ApplicationDetail loadApplicationDetailFromJsonFile(String jsonFilePath) throws + IOException { + ObjectMapper objectMapper = new ObjectMapper(); + ClassPathResource resource = new ClassPathResource(jsonFilePath); + return objectMapper.readValue(resource.getInputStream(), ApplicationDetail.class); + } + + /** + * Generates a random 12-digit number string to be used as a case reference number. + */ + private String generateTestCaseRef(){ + Random random = new Random(); + StringBuilder stringBuilder = new StringBuilder(12); + + for (int i = 0; i < 12; i++) { + int digit = random.nextInt(10); // Generate a random digit (0-9) + stringBuilder.append(digit); + } + + return stringBuilder.toString(); + } + + /** + * Arguments for the testCreateApplication test method. + */ + private static Stream createApplicationArguments() { + return Stream.of( + Arguments.of("/json/applicationDetail_base.json", + "getAuditTrail", + List.of("auditTrail")), + Arguments.of("/json/applicationDetail_costStructure.json", + "getCosts.getAuditTrail", + List.of("costs.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_costEntries.json", + "getCosts.getCostEntries.getAuditTrail", + List.of("costs.costEntries.auditTrail","costs.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_correspondenceAddress.json", + "getCorrespondenceAddress.getAuditTrail", + List.of("correspondenceAddress.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_proceedings.json", + "getProceedings.getAuditTrail", + List.of("proceedings.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_scopeLimitation.json", + "getProceedings.getScopeLimitations.getAuditTrail", + List.of("proceedings.scopeLimitations.auditTrail","proceedings.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_linkedCase.json", + "getLinkedCases.getAuditTrail", + List.of("linkedCases.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_priorAuthority.json", + "getPriorAuthorities.getAuditTrail", + List.of("priorAuthorities.auditTrail", "auditTrail")), + + //No Audit data for reference data items + Arguments.of("/json/applicationDetail_referenceDataItem.json", + "getPriorAuthorities.getAuditTrail", + List.of("priorAuthorities.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_opponent.json", + "getOpponents.getAuditTrail", + List.of("opponents.auditTrail", "auditTrail")), + Arguments.of("/json/applicationDetail_opponentAddress.json", + "getOpponents.getAddress.getAuditTrail", + List.of("opponents.address.auditTrail","opponents.auditTrail", "auditTrail")) + ); + } + + /** + * Parameterized test to create an application and verify that the audit trail and non-transient + * variables are set correctly. + * + * @param fileInput The path to the JSON file to load + * @param auditTrailMethod The method to call to get the audit trail object + * (e.g. "getAuditTrail" or "getCosts.getAuditTrail") + * @param auditTrailsToNull A list of audit trails to set to null + * (e.g. "auditTrail" or "costs.auditTrail") + */ + @ParameterizedTest + @MethodSource("createApplicationArguments") + public void testCreateApplication(String fileInput, String auditTrailMethod, List auditTrailsToNull) + throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, + NoSuchFieldException { + // Load and parse the JSON file into yourApplicationDetailObject + ApplicationDetail applicationDetail = loadApplicationDetailFromJsonFile( + fileInput); + + String caseReference = generateTestCaseRef(); + applicationDetail.setCaseReferenceNumber(caseReference); + + String auditUser = "audit@user.com"; + // Call the createApplication method directly + ResponseEntity responseEntity = applicationController.createApplication(auditUser, applicationDetail); + + assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); + URI locationUri = responseEntity.getHeaders().getLocation(); + + String path = locationUri.getPath(); + String id = path.substring(path.lastIndexOf('/') + 1); + + ApplicationDetail savedApplicationDetails = applicationService.getApplication(Long.valueOf(id)); + + assertAuditTrail(savedApplicationDetails, auditTrailMethod, auditUser); + setAuditPropertiesToNull(savedApplicationDetails, auditTrailsToNull); + assertEquals(applicationDetail, savedApplicationDetails); + } + + /** + * Assert that the audit trail is set correctly in the object. Uses reflection to navigate the + * auditTrailMethod path and assert that the audit trail is set correctly. + */ + private void assertAuditTrail(Object object, String auditMethod, String expectedAuditUser) + throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { + String[] methodCalls = auditMethod.split("\\."); + assertAuditTrailRecursive(object, methodCalls, 0, expectedAuditUser); + } + + /** + * Recursively navigate the object using the methodCalls array and assert that the audit trail is + * set correctly. + */ + private void assertAuditTrailRecursive(Object object, String[] methodCalls, int index, String expectedAuditUser) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + if (index >= methodCalls.length || object == null) { + return; + } + + Method method = object.getClass().getMethod(methodCalls[index]); + object = method.invoke(object); + + if (object instanceof List) { + List list = (List) object; + for (Object item : list) { + assertAuditTrailRecursive(item, methodCalls, index + 1, expectedAuditUser); + } + } else { + if (index == methodCalls.length - 1) { + assertAuditDetailsInObject(object, expectedAuditUser); + } else { + assertAuditTrailRecursive(object, methodCalls, index + 1, expectedAuditUser); + } + } + } + + /** + * Used to assert that the audit trail is set correctly in the object. + * + * @param object The object to check + * @param expectedAuditUser The expected audit user + */ + private void assertAuditDetailsInObject(Object object, String expectedAuditUser) { + if (object instanceof AuditTrail auditTrail) { + assertNotNull(auditTrail); + assertEquals(expectedAuditUser, auditTrail.getCreatedBy()); + assertEquals(expectedAuditUser, auditTrail.getLastSavedBy()); + assertNotNull(auditTrail.getCreated()); + assertNotNull(auditTrail.getLastSaved()); + } + } + + /** + * Sets the audit trail properties to null in the object. Uses reflection to navigate the + * list of auditTrailsToNull and set the audit trail to null. + */ + private void setAuditPropertiesToNull(Object object, List auditTrailsToNull) throws NoSuchFieldException, IllegalAccessException { + if (object == null || auditTrailsToNull == null) { + return; + } + for (String trail : auditTrailsToNull) { + String[] fields = trail.split("\\."); + nullifyFieldRecursive(object, fields, 0); + } + } + + /** + * Recursively navigate the object using the fields array and set the field to null. + */ + private static void nullifyFieldRecursive(Object object, String[] fields, int index) + throws NoSuchFieldException, IllegalAccessException { + if (object == null || index >= fields.length) { + return; + } + + if (object instanceof List) { + // Handle List objects + List list = (List) object; + for (Object item : list) { + nullifyFieldRecursive(item, fields, index); + } + } else { + Field field = object.getClass().getDeclaredField(fields[index]); + field.setAccessible(true); + + if (index == fields.length - 1) { + // Last field in the path, set to null + field.set(object, null); + } else { + // Not the last field, navigate to the next object or list in the path + Object nextObject = field.get(object); + nullifyFieldRecursive(nextObject, fields, index + 1); + } + } + } +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java index af5cc19..6ccf0cb 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java @@ -5,22 +5,30 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; +import static uk.gov.laa.ccms.caab.api.audit.AuditorAwareImpl.currentUserHolder; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.transaction.Transactional; +import java.io.IOException; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.time.Instant; import java.util.Date; import java.util.TimeZone; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpStatus; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlMergeMode; import uk.gov.laa.ccms.caab.api.CaabApiApplication; @@ -45,6 +53,8 @@ @Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") @Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") public class ApplicationServiceIntegrationTest extends AbstractIntegrationTest { +//@ActiveProfiles("local") +//public class ApplicationServiceIntegrationTest { @Autowired private ApplicationService applicationService; @@ -84,8 +94,6 @@ public class ApplicationServiceIntegrationTest extends AbstractIntegrationTest { private final Boolean meritsReassessmentReqdInd = false; private final Boolean larScopeFlag = true; private final Boolean leadProceedingChanged = false; - private final String createdBy = "Test User"; - private final String modifiedBy = "Test User"; //cost structure private final BigDecimal defaultCostLimitation = BigDecimal.valueOf(11111.11); @@ -104,13 +112,18 @@ public class ApplicationServiceIntegrationTest extends AbstractIntegrationTest { private final String careOf = "Prime Minister's Office"; private final String preferredAddress = "PROVIDER"; + private final String caabUserLoginId = "audit@user.com"; + @BeforeEach + public void setup() { + currentUserHolder.set(caabUserLoginId); + } @Test public void testSaveApplication_requiredFields(){ ApplicationDetail application = buildRequiredApplicationDetail(); - Long savedId = applicationService.createApplication(modifiedBy, application); + Long savedId = applicationService.createApplication(application); // Assert that the saved application has been assigned an ID assertNotNull(savedId); @@ -131,7 +144,7 @@ public void testSaveApplication_requiredFields(){ public void testSaveApplication_allFields(){ ApplicationDetail application = buildApplication(); - Long savedId = applicationService.createApplication(modifiedBy, application); + Long savedId = applicationService.createApplication(application); // Assert that the saved application has been assigned an ID assertNotNull(savedId); @@ -180,10 +193,10 @@ public void testSaveApplication_allFields(){ assertEquals(larScopeFlag, fetchedApplication.getLarScopeFlag()); assertEquals(leadProceedingChanged, fetchedApplication.isLeadProceedingChangedOpaInput()); - assertEquals(modifiedBy, fetchedApplication.getAuditTrail().getModifiedBy()); - assertEquals(createdBy, fetchedApplication.getAuditTrail().getCreatedBy()); + assertEquals(caabUserLoginId, fetchedApplication.getAuditTrail().getLastSavedBy()); + assertEquals(caabUserLoginId, fetchedApplication.getAuditTrail().getCreatedBy()); assertNotNull(fetchedApplication.getAuditTrail().getCreated()); - assertNotNull(fetchedApplication.getAuditTrail().getModified()); + assertNotNull(fetchedApplication.getAuditTrail().getLastSaved()); } @@ -194,7 +207,7 @@ public void testSaveApplication_costStructure(){ ApplicationDetail application = buildRequiredApplicationDetail(); application.setCosts(buildCosts()); - Long savedId = applicationService.createApplication(modifiedBy, application); + Long savedId = applicationService.createApplication(application); // Fetch the saved application from the database Application fetchedApplication = applicationRepository.findById(savedId).orElse(null); @@ -206,8 +219,8 @@ public void testSaveApplication_costStructure(){ assertEquals(grantedCostLimitation, fetchedApplication.getCosts().getGrantedCostLimitation()); assertEquals(requestedCostLimitation, fetchedApplication.getCosts().getRequestedCostLimitation()); - assertEquals(modifiedBy, fetchedApplication.getCosts().getAuditTrail().getModifiedBy()); - assertEquals(createdBy, fetchedApplication.getCosts().getAuditTrail().getCreatedBy()); + assertEquals(caabUserLoginId, fetchedApplication.getCosts().getAuditTrail().getLastSavedBy()); + assertEquals(caabUserLoginId, fetchedApplication.getCosts().getAuditTrail().getCreatedBy()); } @Test @@ -216,7 +229,7 @@ public void testSaveApplication_address(){ ApplicationDetail application = buildRequiredApplicationDetail(); application.setCorrespondenceAddress(buildAddress()); - Long savedId = applicationService.createApplication(modifiedBy, application); + Long savedId = applicationService.createApplication(application); // Fetch the saved application from the database Application fetchedApplication = applicationRepository.findById(savedId).orElse(null); @@ -238,8 +251,8 @@ public void testSaveApplication_address(){ assertEquals(preferredAddress, fetchedApplication.getCorrespondenceAddress().getPreferredAddress()); // Audit Trail asserts for the address - assertEquals(modifiedBy, fetchedApplication.getCorrespondenceAddress().getAuditTrail().getModifiedBy()); - assertEquals(createdBy, fetchedApplication.getCorrespondenceAddress().getAuditTrail().getCreatedBy()); + assertEquals(caabUserLoginId, fetchedApplication.getCorrespondenceAddress().getAuditTrail().getLastSavedBy()); + assertEquals(caabUserLoginId, fetchedApplication.getCorrespondenceAddress().getAuditTrail().getCreatedBy()); } @Test @@ -325,7 +338,7 @@ public void testPatchApplicationType() { .displayValue(amendedApplicationTypeDisplay); // Call the service method - applicationService.patchApplicationType(applicationId, "TESTER", amendedApplicationType); + applicationService.patchApplicationType(applicationId, amendedApplicationType); Application result = applicationRepository.findById(applicationId).orElse(null); @@ -351,7 +364,7 @@ public void testPatchProviderDetails( String newFeeEarnerId, String newSupervisorId, String newProviderContactId, - String caabUserLoginId) { + String patchedCaabUserLoginId) { // Create an ApplicationProviderDetails instance with the provided values ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); @@ -368,8 +381,10 @@ public void testPatchProviderDetails( providerDetails.setSupervisor(supervisor); providerDetails.setProviderContact(providerContact); + currentUserHolder.set(patchedCaabUserLoginId); + // Call the patchProviderDetails method - applicationService.patchProviderDetails(applicationId, caabUserLoginId, providerDetails); + applicationService.patchProviderDetails(applicationId, providerDetails); // Fetch the application from the database after the update Application updatedApplication = applicationRepository.findById(applicationId).orElse(null); @@ -385,6 +400,9 @@ public void testPatchProviderDetails( assertEquals(feeEarner.getId(), updatedApplication.getFeeEarner()); assertEquals(supervisor.getId(), updatedApplication.getSupervisor()); assertEquals(providerContact.getId(), updatedApplication.getProviderContact()); + + assertEquals(patchedCaabUserLoginId, updatedApplication.getAuditTrail().getLastSavedBy()); + assertTrue(updatedApplication.getAuditTrail().getLastSaved().after(updatedApplication.getAuditTrail().getCreated())); } @Test @@ -396,7 +414,7 @@ public void testPatchProviderDetails_ApplicationNotFound() { // Use assertThrows to check if the method throws the expected exception CaabApiException exception = assertThrows(CaabApiException.class, () -> { - applicationService.patchProviderDetails(nonExistentApplicationId, "TestUser", providerDetails); + applicationService.patchProviderDetails(nonExistentApplicationId, providerDetails); }); assertEquals( diff --git a/caab-service/src/integrationTest/resources/application-local.yml b/caab-service/src/integrationTest/resources/application-local.yml new file mode 100644 index 0000000..b931eee --- /dev/null +++ b/caab-service/src/integrationTest/resources/application-local.yml @@ -0,0 +1,11 @@ +spring: + datasource: + url: jdbc:oracle:thin:@localhost:1521:CCMSPUI + driver-class-name: oracle.jdbc.OracleDriver + username: XXCCMS_PUI + password: XXCCMS_PUI + + jpa: + database-platform: org.hibernate.dialect.OracleDialect + hibernate: + ddl-auto: none \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/application.yml b/caab-service/src/integrationTest/resources/application.yml deleted file mode 100644 index e69de29..0000000 diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_base.json b/caab-service/src/integrationTest/resources/json/applicationDetail_base.json new file mode 100644 index 0000000..be71e48 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_base.json @@ -0,0 +1,61 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [], + "proceedings": [] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_caseOutcome.json b/caab-service/src/integrationTest/resources/json/applicationDetail_caseOutcome.json new file mode 100644 index 0000000..be71e48 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_caseOutcome.json @@ -0,0 +1,61 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [], + "proceedings": [] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_correspondenceAddress.json b/caab-service/src/integrationTest/resources/json/applicationDetail_correspondenceAddress.json new file mode 100644 index 0000000..d230a8b --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_correspondenceAddress.json @@ -0,0 +1,73 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [], + "proceedings": [], + "correspondence_address": { + "no_fixed_abode": false, + "postcode": "PL1 1AA", + "house_name_or_number": "1", + "address_line_1": "address line 1", + "address_line_2": "address line 2", + "city": "city", + "county": "county", + "country": "GBR", + "care_of": "care of", + "preferred_address": "some address" + } +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_costEntries.json b/caab-service/src/integrationTest/resources/json/applicationDetail_costEntries.json new file mode 100644 index 0000000..5fb0c18 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_costEntries.json @@ -0,0 +1,74 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [], + "proceedings": [], + "costs": { + "default_cost_limitation": 5000, + "granted_cost_limitation": 5000, + "requested_cost_limitation": 0, + "cost_entries": [{ + "requested_costs": 150, + "cost_category": "Office Supplies", + "ebs_id": "EBS12345", + "new_entry": true, + "lsc_resource_id": "LSC67890", + "resource_name": "Printer Paper" + }] + } +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_costStructure.json b/caab-service/src/integrationTest/resources/json/applicationDetail_costStructure.json new file mode 100644 index 0000000..2d92061 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_costStructure.json @@ -0,0 +1,67 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [], + "proceedings": [], + "costs": { + "default_cost_limitation": 5000, + "granted_cost_limitation": 5000, + "requested_cost_limitation": 0, + "cost_entries": [] + } +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_linkedCase.json b/caab-service/src/integrationTest/resources/json/applicationDetail_linkedCase.json new file mode 100644 index 0000000..5e2c4dd --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_linkedCase.json @@ -0,0 +1,73 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [{ + "lsc_case_reference": "LSC123456", + "relation_to_case": "Relation to Case Example", + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "provider_case_reference": "ProviderCaseRef123", + "category_of_law": "Category of Law Example", + "fee_earner": "Fee Earner Name", + "status": "Active" + }], + "prior_authorities": [], + "opponents": [], + "proceedings": [] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_opponent.json b/caab-service/src/integrationTest/resources/json/applicationDetail_opponent.json new file mode 100644 index 0000000..222f8a4 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_opponent.json @@ -0,0 +1,102 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [{ + "ebs_id": "EBS123456", + "type": "Type Example", + "title": "Mr.", + "first_name": "John", + "middle_names": "Albert", + "surname": "Doe", + "date_of_birth": null, + "national_insurance_number": "AB123456C", + "address": null, + "relationship_to_case": "Relationship to Case Example", + "relationship_to_client": "Relationship to Client Example", + "telephone_home": "0123456789", + "telephone_work": "9876543210", + "telephone_mobile": "1122334455", + "fax_number": "1234567890", + "email_address": "example@email.com", + "other_information": "Other relevant information", + "employment_status": "Employed", + "employer_name": "Employer Inc.", + "employer_address": "Employer Address", + "legal_aided": true, + "certificate_number": "CERT123456", + "court_ordered_means_assessment": false, + "assessed_income": 30000, + "assessed_income_frequency": "Annual", + "assessed_assets": 50000, + "assessment_date": null, + "organisation_name": "Organisation Name", + "organisation_type": { + "id": "Org" + }, + "currently_trading": true, + "contact_name_role": "Contact Role", + "confirmed": true, + "app_mode": true, + "amendment": false, + "award": true, + "public_funding_applied": false, + "shared_ind": false, + "delete_ind": true + }], + "proceedings": [] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_opponentAddress.json b/caab-service/src/integrationTest/resources/json/applicationDetail_opponentAddress.json new file mode 100644 index 0000000..21ee8e1 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_opponentAddress.json @@ -0,0 +1,113 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [{ + "ebs_id": "EBS123456", + "type": "Type Example", + "title": "Mr.", + "first_name": "John", + "middle_names": "Albert", + "surname": "Doe", + "date_of_birth": null, + "national_insurance_number": "AB123456C", + "address": { + "no_fixed_abode": false, + "postcode": "PL1 1AA", + "house_name_or_number": "1", + "address_line_1": "address line 1", + "address_line_2": "address line 2", + "city": "city", + "county": "county", + "country": "GBR", + "care_of": "care of", + "preferred_address": "some address" + }, + "relationship_to_case": "Relationship to Case Example", + "relationship_to_client": "Relationship to Client Example", + "telephone_home": "0123456789", + "telephone_work": "9876543210", + "telephone_mobile": "1122334455", + "fax_number": "1234567890", + "email_address": "example@email.com", + "other_information": "Other relevant information", + "employment_status": "Employed", + "employer_name": "Employer Inc.", + "employer_address": "Employer Address", + "legal_aided": true, + "certificate_number": "CERT123456", + "court_ordered_means_assessment": false, + "assessed_income": 30000, + "assessed_income_frequency": "Annual", + "assessed_assets": 50000, + "assessment_date": null, + "organisation_name": "Organisation Name", + "organisation_type": { + "id": "Org" + }, + "currently_trading": true, + "contact_name_role": "Contact Role", + "confirmed": true, + "app_mode": true, + "amendment": false, + "award": true, + "public_funding_applied": false, + "shared_ind": false, + "delete_ind": true + }], + "proceedings": [] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_priorAuthority.json b/caab-service/src/integrationTest/resources/json/applicationDetail_priorAuthority.json new file mode 100644 index 0000000..eb1bace --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_priorAuthority.json @@ -0,0 +1,73 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [{ + "ebs_id": "EBS123456", + "status": "Pending", + "type": { + "id": "Type Value", + "display_value": "Type Display Value" + }, + "summary": "Summary of Prior Authority", + "justification": "Justification for Prior Authority", + "value_required": true, + "amount_requested": 5000, + "items": [] + }], + "opponents": [], + "proceedings": [] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_proceedings.json b/caab-service/src/integrationTest/resources/json/applicationDetail_proceedings.json new file mode 100644 index 0000000..ae3811b --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_proceedings.json @@ -0,0 +1,98 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [], + "proceedings": [{ + "ebs_id": "EBS123456", + "matter_type": { + "id": "Matter Type Example", + "display_value": "Matter Type Display" + }, + "proceeding_type": { + "id": "Proceeding Type Example", + "display_value": "Proceeding Type Display" + }, + "level_of_service": { + "id": "Level of Service Example", + "display_value": "Level of Service Display" + }, + "client_involvement": { + "id": "Client Involvement Example", + "display_value": "Client Involvement Display" + }, + "type_of_order": { + "id": "Type of Order Example" + }, + "cost_limitation": 100000, + "status": { + "id": "Status Example", + "display_value": "Status Display" + }, + "description": "Description of Proceeding", + "date_granted": null, + "date_costs_valid": null, + "edited": true, + "scope_limitations": [], + "default_scope_limitation": "Default Scope Limitation", + "stage": "Stage", + "lead_proceeding_ind": false, + "lar_scope": "LAR Scope", + "date_devolved_powers_used": null, + "outcome": null + }] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_referenceDataItem.json b/caab-service/src/integrationTest/resources/json/applicationDetail_referenceDataItem.json new file mode 100644 index 0000000..0b939c4 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_referenceDataItem.json @@ -0,0 +1,85 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [{ + "ebs_id": "EBS123456", + "status": "Pending", + "type": { + "id": "Type Value", + "display_value": "Type Display Value" + }, + "summary": "Summary of Prior Authority", + "justification": "Justification for Prior Authority", + "value_required": true, + "amount_requested": 5000, + "items": [{ + "code": { + "id": "Code Value", + "display_value": "Code Display Value" + }, + "type": "Type", + "mandatory": true, + "lov_look_up": "LOV Lookup Value", + "value": { + "id": "Value Example", + "display_value": "Value Display Value" + } + }] + }], + "opponents": [], + "proceedings": [] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/json/applicationDetail_scopeLimitation.json b/caab-service/src/integrationTest/resources/json/applicationDetail_scopeLimitation.json new file mode 100644 index 0000000..f852c37 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/applicationDetail_scopeLimitation.json @@ -0,0 +1,107 @@ +{ + "provider": { + "id": 26517, + "display_value": "SWITALSKI'S SOLICITORS LTD" + }, + "provider_case_reference": "329635", + "office": { + "id": 145512, + "display_value": "SWITALSKI'S SOLICITORS LTD-2L847Q" + }, + "supervisor": { + "id":"2854148", + "display_value": "David Greenwood" + }, + "fee_earner": { + "id":"2027148", + "display_value": "Carole Spencer" + }, + "provider_contact": { + "id":"2027079", + "display_value": "CAROLE.SPENCER@SWITALSKIS.COM" + }, + "category_of_law": { + "id":"AAP", + "display_value": "Claim Against Public Authority" + }, + "relation_to_linked_case": null, + "opponent_applied_for_funding": null, + "status": { + "id":"UNSUBMITTED", + "display_value": "Unsubmitted" + }, + "client": { + "first_name":"Phil", + "surname": "Payne", + "reference": "PhilTest" + }, + "amendment": false, + "means_assessment_amended": false, + "merits_assessment_amended": false, + "cost_limit": { + "changed": false, + "limit_at_time_of_merits": 1350 + }, + "application_type": { + "id": "ECF", + "display_value": "Exceptional Case Funding", + "devolved_powers": { + "used": false, + "date_used": "null", + "contract_flag": "Yes - Excluding JR Proceedings" + } + }, + "merits_reassessment_required": false, + "lar_scope_flag": "true", + "lead_proceeding_changed": false, + "linked_cases": [], + "prior_authorities": [], + "opponents": [], + "proceedings": [{ + "ebs_id": "EBS123456", + "matter_type": { + "id": "Matter Type Example", + "display_value": "Matter Type Display" + }, + "proceeding_type": { + "id": "Proceeding Type Example", + "display_value": "Proceeding Type Display" + }, + "level_of_service": { + "id": "Level of Service Example", + "display_value": "Level of Service Display" + }, + "client_involvement": { + "id": "Client Involvement Example", + "display_value": "Client Involvement Display" + }, + "type_of_order": { + "id": "Type of Order Example" + }, + "cost_limitation": 100000, + "status": { + "id": "Status Example", + "display_value": "Status Display" + }, + "description": "Description of Proceeding", + "date_granted": null, + "date_costs_valid": null, + "edited": true, + "scope_limitations": [{ + "scope_limitation": { + "id": "Scope Limitation Value", + "display_value": "Scope Limitation Display Value" + }, + "ebs_id": "EBS123456", + "scope_limitation_wording": "Detailed wording for the scope limitation", + "default_ind": true, + "delegated_func_apply_ind": { + "flag": true + } + }], + "default_scope_limitation": "Default Scope Limitation", + "lead_proceeding_ind": false, + "lar_scope": "LAR Scope", + "date_devolved_powers_used": null + }] +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql b/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql index c184cff..c9c913f 100644 --- a/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql +++ b/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql @@ -193,6 +193,39 @@ create table XXCCMS_PROCEEDING_OUTCOME ( primary key (ID) ); +create table XXCCMS_REFERENCE_DATA_ITEM ( + ID number(19,0) not null, + CODE varchar2(50 char), + LABEL varchar2(150 char), + TYPE varchar2(5 char), + MANDATORY varchar2(5 char), + LOV_LOOKUP varchar2(200 char), + VALUE varchar2(200 char), + DISPLAY_VALUE varchar2(200 char), + FK_PRIOR_AUTHORITY number(19,0) not null, + primary key (ID) +); + +create index XXCCMS_DATA_ITEM_I1 on XXCCMS_REFERENCE_DATA_ITEM (FK_PRIOR_AUTHORITY); + +create table XXCCMS_SCOPE_LIMITATION ( + ID number(19,0) not null, + EBS_ID varchar2(50 char), + SCOPE_LIMITATION varchar2(50 char), + SCOPE_LIMITATION_DISPLAY_VALUE varchar2(100 char), + SCOPE_LIMITATION_WORDING varchar2(1000 char), + DEFAULT_IND number(1,0), + DELEGATED_FUNC_APPLY_IND number(1,0), + FK_PROCEEDING number(19,0), + CREATED timestamp, + CREATED_BY varchar2(50 char), + MODIFIED timestamp, + MODIFIED_BY varchar2(50 char), + primary key (ID) +); + +create index XXCCMS_SCOPE_LIMITATION_I1 on XXCCMS_SCOPE_LIMITATION (FK_PROCEEDING); + create table XXCCMS_OPPONENT ( "ID" NUMBER(19,0) NOT NULL ENABLE, EBS_ID varchar(50), diff --git a/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql b/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql index 709e8ec..82983da 100644 --- a/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql +++ b/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql @@ -5,6 +5,8 @@ DROP INDEX SYS_C0010984; DROP INDEX SYS_C0010985; DROP INDEX XXCCMS_APPLICATION_I3; DROP INDEX XXCCMS_APPLICATION_I2; +DROP INDEX XXCCMS_SCOPE_LIMITATION_I1; +DROP INDEX XXCCMS_DATA_ITEM_I1; -- drop tables DROP TABLE XXCCMS_APPLICATION; @@ -17,6 +19,8 @@ DROP TABLE XXCCMS_PRIOR_AUTHORITY; DROP TABLE XXCCMS_PROCEEDING; DROP TABLE XXCCMS_PROCEEDING_OUTCOME; DROP TABLE XXCCMS_OPPONENT; +DROP TABLE XXCCMS_REFERENCE_DATA_ITEM; +DROP TABLE XXCCMS_SCOPE_LIMITATION; DROP TABLE XXCCMS_CASE_OUTCOME; -- drop sequence diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/CaabApiApplication.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/CaabApiApplication.java index 092da11..e05cbb1 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/CaabApiApplication.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/CaabApiApplication.java @@ -2,6 +2,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; /** * Entry point for the CAAB application. diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/audit/AuditorAwareImpl.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/audit/AuditorAwareImpl.java new file mode 100644 index 0000000..6405d79 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/audit/AuditorAwareImpl.java @@ -0,0 +1,20 @@ +package uk.gov.laa.ccms.caab.api.audit; + + +import java.util.Optional; +import org.springframework.data.domain.AuditorAware; + +/** + * Auditor provider implementation for the application. This class is responsible for storing the + * current user in a thread local variable, and returning it when requested. + */ +public class AuditorAwareImpl implements AuditorAware { + + public static final ThreadLocal currentUserHolder = new ThreadLocal(); + + @Override + public Optional getCurrentAuditor() { + return Optional.of(currentUserHolder.get()); + } + +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/config/ApplicationConfig.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/config/ApplicationConfig.java new file mode 100644 index 0000000..93c90d4 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/config/ApplicationConfig.java @@ -0,0 +1,21 @@ +package uk.gov.laa.ccms.caab.api.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.domain.AuditorAware; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import uk.gov.laa.ccms.caab.api.audit.AuditorAwareImpl; + +/** + * Configuration for the application, and the auditor provider. + */ +@Configuration +@EnableJpaAuditing(auditorAwareRef = "auditorProvider") +public class ApplicationConfig { + + @Bean("auditorProvider") + public AuditorAware auditorProvider() { + return new AuditorAwareImpl(); + } + +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java index ddfc4db..958d51f 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java @@ -1,6 +1,8 @@ package uk.gov.laa.ccms.caab.api.controller; +import static uk.gov.laa.ccms.caab.api.audit.AuditorAwareImpl.currentUserHolder; + import java.net.URI; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpHeaders; @@ -31,7 +33,8 @@ public ResponseEntity createApplication( final String caabUserLoginId, final ApplicationDetail applicationDetail) { - Long id = applicationService.createApplication(caabUserLoginId, applicationDetail); + currentUserHolder.set(caabUserLoginId); + Long id = applicationService.createApplication(applicationDetail); URI uri = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{id}") @@ -77,7 +80,8 @@ public ResponseEntity patchApplicationProviderDetails( String caabUserLoginId, ApplicationProviderDetails applicationProviderDetails) { - applicationService.patchProviderDetails(id, caabUserLoginId, applicationProviderDetails); + currentUserHolder.set(caabUserLoginId); + applicationService.patchProviderDetails(id, applicationProviderDetails); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -88,7 +92,8 @@ public ResponseEntity patchApplicationType( final String caabUserLoginId, final ApplicationType applicationType) { - applicationService.patchApplicationType(id, caabUserLoginId, applicationType); + currentUserHolder.set(caabUserLoginId); + applicationService.patchApplicationType(id, applicationType); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Address.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Address.java index 7187430..e53dcfe 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Address.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Address.java @@ -7,6 +7,7 @@ import jakarta.persistence.Convert; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.SequenceGenerator; @@ -15,6 +16,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents an address entity from the "XXCCMS_ADDRESS" table. @@ -23,6 +25,7 @@ * sequence for generating unique identifiers. */ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_ADDRESS") @Setter @Getter @@ -71,10 +74,7 @@ public class Address implements Serializable { @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); - public Address(AuditTrail auditTrail) { - this.auditTrail = auditTrail; - } } diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Application.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Application.java index 197308a..f980d87 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Application.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Application.java @@ -6,6 +6,7 @@ import jakarta.persistence.Convert; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; @@ -24,6 +25,10 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; +import org.hibernate.annotations.LazyGroup; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents an application entity from the "XXCCMS_APPLICATION" table. @@ -32,6 +37,7 @@ * sequence for generating unique identifiers. */ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_APPLICATION") @SequenceGenerator( allocationSize = 1, @@ -158,19 +164,19 @@ public class Application implements Serializable { @JoinColumn(name = "FK_CORRESPONDENCE_ADDRESS") private Address correspondenceAddress; - @OneToMany(mappedBy = "application") + @OneToMany(mappedBy = "application", cascade = CascadeType.ALL) @OrderBy("id asc") private List proceedings; - @OneToMany(mappedBy = "application") + @OneToMany(mappedBy = "application", cascade = CascadeType.ALL) @OrderBy("id asc") private List priorAuthorities; - @OneToMany(mappedBy = "application") + @OneToMany(mappedBy = "application", cascade = CascadeType.ALL) @OrderBy("id asc") private List opponents; - @OneToMany(mappedBy = "application") + @OneToMany(mappedBy = "application", cascade = CascadeType.ALL) @OrderBy("id asc") private List linkedCases; diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/AuditTrail.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/AuditTrail.java index 4db5dab..42d6386 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/AuditTrail.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/AuditTrail.java @@ -7,6 +7,8 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.LastModifiedBy; /** * Represents an audit trail for various entities within the CCMS system. @@ -21,7 +23,6 @@ */ @Embeddable @Data -@NoArgsConstructor public class AuditTrail { /** @@ -36,22 +37,20 @@ public class AuditTrail { */ @Column(name = "MODIFIED") @UpdateTimestamp - private Date modified; + private Date lastSaved; /** * modified by. */ + @LastModifiedBy @Column(name = "MODIFIED_BY") - private String modifiedBy; + private String lastSavedBy; /** * created by. */ + @CreatedBy @Column(name = "CREATED_BY", updatable = false) private String createdBy; - public AuditTrail(String modifiedBy, String createdBy) { - this.modifiedBy = modifiedBy; - this.createdBy = createdBy; - } } diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CaseOutcome.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CaseOutcome.java index 6a899c8..ca3437e 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CaseOutcome.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CaseOutcome.java @@ -3,6 +3,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.SequenceGenerator; @@ -11,6 +12,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents a case outcome entity associated with the "XXCCMS_CASE_OUTCOME" table. @@ -20,6 +22,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_CASE_OUTCOME") @SequenceGenerator( allocationSize = 1, @@ -37,7 +40,7 @@ public class CaseOutcome { * audit trail info. */ @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); @Column(name = "LSC_CASE_REFERENCE", length = 50, nullable = false) private String lscCaseReference; diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostEntry.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostEntry.java index e93cf5a..76dc2be 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostEntry.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostEntry.java @@ -3,6 +3,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -14,6 +15,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents a cost entry entity associated with the "XXCCMS_COST_ENTRY" table. @@ -23,6 +25,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_COST_ENTRY") @SequenceGenerator( allocationSize = 1, @@ -84,5 +87,5 @@ public class CostEntry implements Serializable { private CostStructure costStructure; @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); } diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostStructure.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostStructure.java index f3a9462..c0439c4 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostStructure.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/CostStructure.java @@ -4,6 +4,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; @@ -16,6 +17,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents a cost structure entity associated with the "XXCCMS_COST_STRUCTURE" table. @@ -25,6 +27,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_COST_STRUCTURE") @Getter @Setter @@ -53,11 +56,7 @@ public class CostStructure implements Serializable { private List costEntries; @Embedded - private AuditTrail auditTrail; - - public CostStructure(AuditTrail auditTrail) { - this.auditTrail = auditTrail; - } + private AuditTrail auditTrail = new AuditTrail(); } diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/LinkedCase.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/LinkedCase.java index 0f8afbf..acbab0c 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/LinkedCase.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/LinkedCase.java @@ -5,6 +5,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -15,6 +16,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents a linked case entity associated with the "XXCCMS_LINKED_CASE" table. @@ -24,6 +26,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_LINKED_CASE") @SequenceGenerator( allocationSize = 1, @@ -44,7 +47,7 @@ public class LinkedCase implements Serializable { private Long id; @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); @ManyToOne @JoinColumn(name = "FK_APPLICATION", nullable = false) @@ -68,6 +71,12 @@ public class LinkedCase implements Serializable { @Column(name = "PROVIDER_CASE_REFERENCE", length = 35) private String providerCaseReference; + /** + * category of law. + */ + @Column(name = "CATEGORY_OF_LAW", length = 50, nullable = false) + private String categoryOfLaw; + /** * feeEarner. */ diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Opponent.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Opponent.java index 41336de..34ec9f8 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Opponent.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Opponent.java @@ -4,6 +4,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -16,6 +17,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** @@ -26,6 +28,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_OPPONENT") @SequenceGenerator( allocationSize = 1, @@ -41,7 +44,7 @@ public class Opponent implements Serializable { private Long id; @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); @ManyToOne @JoinColumn(name = "FK_APPLICATION", nullable = false) diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/PriorAuthority.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/PriorAuthority.java index e27f3b9..1975d22 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/PriorAuthority.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/PriorAuthority.java @@ -4,6 +4,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -18,6 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** @@ -28,6 +30,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_PRIOR_AUTHORITY") @SequenceGenerator( allocationSize = 1, @@ -46,7 +49,7 @@ public class PriorAuthority implements Serializable { * audit trail info. */ @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); @ManyToOne @JoinColumn(name = "FK_APPLICATION", nullable = false) diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Proceeding.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Proceeding.java index f5ee2a5..2200bef 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Proceeding.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/Proceeding.java @@ -4,6 +4,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -19,6 +20,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents a proceeding entity associated with the "XXCCMS_PROCEEDING" table. @@ -28,6 +30,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_PROCEEDING") @SequenceGenerator( allocationSize = 1, @@ -43,7 +46,7 @@ public class Proceeding implements Serializable { private Long id; @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); @Column(name = "EBS_ID", length = 50) private String ebsId; diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/ScopeLimitation.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/ScopeLimitation.java index 5639506..4ac654c 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/ScopeLimitation.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/ScopeLimitation.java @@ -3,6 +3,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -14,6 +15,7 @@ import lombok.Setter; import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOneOption; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * Represents a scope limitation entity associated with the "XXCCMS_SCOPE_LIMITATION" table. @@ -23,6 +25,7 @@ * sequence for generating unique identifiers.

*/ @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "XXCCMS_SCOPE_LIMITATION") @SequenceGenerator( allocationSize = 1, @@ -53,7 +56,7 @@ public class ScopeLimitation { * audit trail info. */ @Embedded - private AuditTrail auditTrail; + private AuditTrail auditTrail = new AuditTrail(); @Column(name = "SCOPE_LIMITATION", length = 50) private String scopeLimitation; 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 a2ab5b2..ae148d4 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 @@ -1,6 +1,7 @@ package uk.gov.laa.ccms.caab.api.mapper; import lombok.Generated; +import org.mapstruct.AfterMapping; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -9,6 +10,7 @@ import uk.gov.laa.ccms.caab.api.entity.Address; import uk.gov.laa.ccms.caab.api.entity.Application; import uk.gov.laa.ccms.caab.api.entity.AuditTrail; +import uk.gov.laa.ccms.caab.api.entity.CostEntry; import uk.gov.laa.ccms.caab.api.entity.CostStructure; import uk.gov.laa.ccms.caab.api.entity.LinkedCase; import uk.gov.laa.ccms.caab.api.entity.Opponent; @@ -61,12 +63,55 @@ public interface ApplicationMapper { source = "applicationType.devolvedPowers.contractFlag") @Mapping(target = "meritsReassessmentReqdInd", source = "meritsReassessmentRequired") @Mapping(target = "leadProceedingChangedOpaInput", source = "leadProceedingChanged") + @Mapping(target = "costs", source = "costs", qualifiedByName = "toCostStructure") Application toApplication(ApplicationDetail applicationDetail); + /** + * After mapping, set the parent entity in the child entities. + * + * @param application the application entity containing parent and child entities. + */ + default void setParentInChildEntities(@MappingTarget Application application) { + if (application.getCosts() != null) { + if (application.getCosts().getCostEntries() != null) { + application.getCosts().getCostEntries().forEach( + costEntry -> costEntry.setCostStructure(application.getCosts())); + } + } + + if (application.getProceedings() != null) { + application.getProceedings().forEach(proceeding -> { + proceeding.setApplication(application); + if (proceeding.getScopeLimitations() != null) { + proceeding.getScopeLimitations().forEach( + scopeLimitation -> scopeLimitation.setProceeding(proceeding)); + } + }); + } + + if (application.getPriorAuthorities() != null) { + application.getPriorAuthorities().forEach(priorAuthority -> { + priorAuthority.setApplication(application); + if (priorAuthority.getItems() != null) { + priorAuthority.getItems().forEach(item -> item.setPriorAuthority(priorAuthority)); + } + }); + } + + if (application.getOpponents() != null) { + application.getOpponents().forEach(opponent -> opponent.setApplication(application)); + } + + if (application.getLinkedCases() != null) { + application.getLinkedCases().forEach(linkedCase -> linkedCase.setApplication(application)); + } + } + + @Mapping(target = "costs", source = "costs", qualifiedByName = "toCostStructureModel") @InheritInverseConfiguration - @Mapping(target = "auditTrail", source = "auditTrail", qualifiedByName = "toAuditDetail") ApplicationDetail toApplicationDetail(Application application); + @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "matterType", source = "matterType.id") @Mapping(target = "matterTypeDisplayValue", source = "matterType.displayValue") @Mapping(target = "proceedingType", source = "proceedingType.id") @@ -81,15 +126,14 @@ public interface ApplicationMapper { Proceeding toProceeding(uk.gov.laa.ccms.caab.model.Proceeding proceeding); @InheritInverseConfiguration - @Mapping(target = "auditTrail", source = "auditTrail", qualifiedByName = "toAuditDetail") uk.gov.laa.ccms.caab.model.Proceeding toProceedingModel(Proceeding proceeding); + @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "type", source = "type.id") @Mapping(target = "typeDisplayValue", source = "type.displayValue") PriorAuthority toPriorAuthority(uk.gov.laa.ccms.caab.model.PriorAuthority priorAuthority); @InheritInverseConfiguration - @Mapping(target = "auditTrail", source = "auditTrail", qualifiedByName = "toAuditDetail") uk.gov.laa.ccms.caab.model.PriorAuthority toPriorAuthorityModel(PriorAuthority priorAuthority); @Mapping(target = "code", source = "code.id") @@ -103,28 +147,30 @@ ReferenceDataItem toReferenceDataItem( uk.gov.laa.ccms.caab.model.ReferenceDataItem toReferenceDataItemModel( ReferenceDataItem referenceDataItem); + @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "scopeLimitation", source = "scopeLimitation.id") @Mapping(target = "scopeLimitationDisplayValue", source = "scopeLimitation.displayValue") @Mapping(target = "delegatedFuncApplyInd", source = "delegatedFuncApplyInd.flag") ScopeLimitation toScopeLimitation(uk.gov.laa.ccms.caab.model.ScopeLimitation scopeLimitation); @InheritInverseConfiguration - @Mapping(target = "auditTrail", source = "auditTrail", qualifiedByName = "toAuditDetail") uk.gov.laa.ccms.caab.model.ScopeLimitation toScopeLimitationModel( ScopeLimitation scopeLimitation); @Mapping(target = "organisationType", source = "organisationType.id") + @Mapping(target = "auditTrail", ignore = true) Opponent toOpponent(uk.gov.laa.ccms.caab.model.Opponent opponent); @InheritInverseConfiguration - @Mapping(target = "auditTrail", source = "auditTrail", qualifiedByName = "toAuditDetail") uk.gov.laa.ccms.caab.model.Opponent toOpponentModel(Opponent opponent); + @Mapping(target = "auditTrail", ignore = true) + @Mapping(target = "clientSurname", source = "client.surname") + @Mapping(target = "clientReference", source = "client.reference") + @Mapping(target = "clientFirstName", source = "client.firstName") LinkedCase toLinkedCase(uk.gov.laa.ccms.caab.model.LinkedCase linkedCase); @InheritInverseConfiguration - @Mapping(target = "auditTrail", source = "auditTrail", - qualifiedByName = "toAuditDetail") uk.gov.laa.ccms.caab.model.LinkedCase toLinkedCaseModel(LinkedCase linkedCase); @Mapping(target = "id", ignore = true) @@ -136,18 +182,22 @@ uk.gov.laa.ccms.caab.model.ScopeLimitation toScopeLimitationModel( @InheritInverseConfiguration uk.gov.laa.ccms.caab.model.Address toAddressModel(Address address); + @Named("toCostStructure") + @Mapping(target = "auditTrail", ignore = true) CostStructure toCostStructure(uk.gov.laa.ccms.caab.model.CostStructure costs); + @Named("toCostStructureModel") @InheritInverseConfiguration - @Mapping(target = "auditTrail", source = "auditTrail", qualifiedByName = "toAuditDetail") uk.gov.laa.ccms.caab.model.CostStructure toCostStructureModel(CostStructure costs); - @Mapping(target = "lastSaved", source = "modified") - @Mapping(target = "lastSavedBy", source = "modifiedBy") - @Named("toAuditDetail") - AuditDetail toAuditDetail(AuditTrail auditTrail); + @Mapping(target = "auditTrail", ignore = true) + CostEntry toCostEntry(uk.gov.laa.ccms.caab.model.CostEntry costEntry); + + @InheritInverseConfiguration + uk.gov.laa.ccms.caab.model.CostEntry toCostEntryModel(CostEntry costEntry); @Mapping(target = "id", ignore = true) + @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "applicationType", source = "applicationType.id") @Mapping(target = "applicationTypeDisplayValue", source = "applicationType.displayValue") @Mapping(target = "devolvedPowersUsed", source = "applicationType.devolvedPowers.used") @@ -155,11 +205,8 @@ uk.gov.laa.ccms.caab.model.ScopeLimitation toScopeLimitationModel( source = "applicationType.devolvedPowers.dateUsed") @Mapping(target = "devolvedPowersContractFlag", source = "applicationType.devolvedPowers.contractFlag") - @Mapping(target = "auditTrail.modifiedBy", - source = "caabUserLoginId") void addApplicationType(@MappingTarget Application application, - ApplicationType applicationType, - String caabUserLoginId); + ApplicationType applicationType); @Mapping(target = "id", source = "applicationType") @Mapping(target = "displayValue", source = "applicationTypeDisplayValue") @@ -171,6 +218,7 @@ void addApplicationType(@MappingTarget Application application, ApplicationType toApplicationType(Application application); @Mapping(target = "id", ignore = true) + @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "providerId", source = "providerDetails.provider.id") @Mapping(target = "providerDisplayValue", source = "providerDetails.provider.displayValue") @Mapping(target = "officeId", source = "providerDetails.office.id") @@ -182,11 +230,8 @@ void addApplicationType(@MappingTarget Application application, @Mapping(target = "providerContact", source = "providerDetails.providerContact.id") @Mapping(target = "providerContactDisplayValue", source = "providerDetails.providerContact.displayValue") - @Mapping(target = "auditTrail.modifiedBy", - source = "caabUserLoginId") void addProviderDetails(@MappingTarget Application application, - ApplicationProviderDetails providerDetails, - String caabUserLoginId); + ApplicationProviderDetails providerDetails); @Mapping(target = "provider.id", source = "providerId") @Mapping(target = "provider.displayValue", source = "providerDisplayValue") diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java index a9ae01a..9825439 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java @@ -9,6 +9,7 @@ import uk.gov.laa.ccms.caab.api.entity.Application; import uk.gov.laa.ccms.caab.api.entity.AuditTrail; import uk.gov.laa.ccms.caab.api.entity.CostStructure; +import uk.gov.laa.ccms.caab.api.entity.Proceeding; import uk.gov.laa.ccms.caab.api.exception.CaabApiException; import uk.gov.laa.ccms.caab.api.mapper.ApplicationMapper; import uk.gov.laa.ccms.caab.api.repository.ApplicationRepository; @@ -43,36 +44,14 @@ public class ApplicationService { * initializes or updates the correspondence address and cost structure, and persists * the application in the repository.

* - * @param caabUserLoginId the CAAB user login ID responsible for the application creation. * @param applicationDetail the details of the application to be created. * @return the unique ID of the newly created application. */ public Long createApplication( - final String caabUserLoginId, final ApplicationDetail applicationDetail) { - AuditTrail auditTrail = new AuditTrail(); - auditTrail.setCreatedBy(caabUserLoginId); - auditTrail.setModifiedBy(caabUserLoginId); - Application application = applicationMapper.toApplication(applicationDetail); - application.setAuditTrail(auditTrail); - - //set correspondence address - if (application.getCorrespondenceAddress() == null) { - Address address = new Address(auditTrail); - application.setCorrespondenceAddress(address); - } else { - application.getCorrespondenceAddress().setAuditTrail(auditTrail); - } - - //Set Cost Structure - if (application.getCosts() == null) { - CostStructure costs = new CostStructure(auditTrail); - application.setCosts(costs); - } else { - application.getCosts().setAuditTrail(auditTrail); - } + applicationMapper.setParentInChildEntities(application); applicationRepository.save(application); @@ -124,19 +103,17 @@ public ApplicationType getApplicationType(final Long id) { * Patch an application with new provider details. * * @param id the TDS id for the application. - * @param caabUserLoginId the CAAB user login ID responsible for the application creation. * @param providerDetails the new application provider details to update the application with */ public void patchProviderDetails( final Long id, - final String caabUserLoginId, final ApplicationProviderDetails providerDetails) { Application application = applicationRepository.findById(id) .orElseThrow(() -> new CaabApiException( String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); - applicationMapper.addProviderDetails(application, providerDetails, caabUserLoginId); + applicationMapper.addProviderDetails(application, providerDetails); applicationRepository.save(application); } @@ -144,19 +121,17 @@ public void patchProviderDetails( * Patch an application with new application type. * * @param id the TDS id for the application. - * @param caabUserLoginId the CAAB user login ID responsible for the application creation. * @param applicationType the new application type to update the application with */ public void patchApplicationType( final Long id, - final String caabUserLoginId, final ApplicationType applicationType) { Application application = applicationRepository.findById(id) .orElseThrow(() -> new CaabApiException( String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); - applicationMapper.addApplicationType(application, applicationType, caabUserLoginId); + applicationMapper.addApplicationType(application, applicationType); applicationRepository.save(application); } } diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java index c1d6a96..258e5be 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java @@ -66,13 +66,9 @@ public void createApplication_isCreated() throws Exception { StringDisplayValue categoryOfLaw = new StringDisplayValue() .id(categoryOfLawId); - ApplicationDetail applicationDetail = new ApplicationDetail() - .caseReferenceNumber(caseReferenceNumber) - .provider(provider) - .client(client) - .categoryOfLaw(categoryOfLaw); + ApplicationDetail applicationDetail = new ApplicationDetail(caseReferenceNumber, categoryOfLaw, client, provider); - when(applicationService.createApplication(loginId, applicationDetail)).thenReturn(id); + when(applicationService.createApplication(applicationDetail)).thenReturn(id); this.mockMvc.perform(post("/applications") .header("Caab-user-Login-Id", loginId) @@ -86,7 +82,7 @@ public void createApplication_isCreated() throws Exception { public void getApplication() throws Exception { Long id = 123456L; - when(applicationService.getApplication(id)).thenReturn(new ApplicationDetail()); + when(applicationService.getApplication(id)).thenReturn(new ApplicationDetail(null,null,null,null)); this.mockMvc.perform(get("/applications/{id}", id)) .andDo(print()) @@ -111,7 +107,7 @@ public void patchApplicationType() throws Exception { ApplicationType applicationType = new ApplicationType(); // Assuming that your service method returns void (no return value) - doNothing().when(applicationService).patchApplicationType(id, caabUserLoginId, applicationType); + doNothing().when(applicationService).patchApplicationType(id, applicationType); this.mockMvc.perform(patch("/applications/{id}/application-type", id) .header("Caab-user-Login-Id", caabUserLoginId) @@ -119,7 +115,7 @@ public void patchApplicationType() throws Exception { .content(objectMapper.writeValueAsString(applicationType))) .andExpect(status().isNoContent()); - verify(applicationService).patchApplicationType(id, caabUserLoginId, applicationType); + verify(applicationService).patchApplicationType(id, applicationType); } @Test @@ -139,7 +135,7 @@ public void patchApplicationProviderDetails() throws Exception { String caabUserLoginId = "test"; ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); - doNothing().when(applicationService).patchProviderDetails(id, caabUserLoginId, providerDetails); + doNothing().when(applicationService).patchProviderDetails(id, providerDetails); this.mockMvc.perform(patch("/applications/{id}/provider-details", id) .header("Caab-user-Login-Id", caabUserLoginId) @@ -147,6 +143,6 @@ public void patchApplicationProviderDetails() throws Exception { .content(objectMapper.writeValueAsString(providerDetails))) .andExpect(status().isNoContent()); - verify(applicationService).patchProviderDetails(id, caabUserLoginId, providerDetails); + verify(applicationService).patchProviderDetails(id, providerDetails); } } \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/entity/AuditTrailTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/entity/AuditTrailTest.java index a087ead..11662ca 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/entity/AuditTrailTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/entity/AuditTrailTest.java @@ -12,13 +12,13 @@ class AuditTrailTest { @BeforeEach public void setUp() { - auditTrail = new AuditTrail("modifiedByUser", "createdByUser"); + auditTrail = new AuditTrail(); } @Test public void testAuditTrailConstructor() { - assertEquals("modifiedByUser", auditTrail.getModifiedBy()); - assertEquals("createdByUser", auditTrail.getCreatedBy()); + assertNull(auditTrail.getLastSavedBy()); + assertNull(auditTrail.getCreatedBy()); } 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 c2f51f9..74be2c0 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 @@ -42,6 +42,8 @@ public class ApplicationMapperTest { private final ApplicationMapper mapper = new ApplicationMapperImpl(); + private static final String CAAB_USER_LOGIN_ID = "testUser"; + private Date createdAt; private Date updatedAt; @@ -132,10 +134,12 @@ public void testApplicationMapping_unsetBooleansFalse() { @Test public void testToApplication_costStructure_costEntry() { // Construct an ApplicationDetail instance with costEntry - ApplicationDetail applicationDetail = new ApplicationDetail(); + ApplicationDetail applicationDetail = new ApplicationDetail(null, null,null,null); + uk.gov.laa.ccms.caab.model.CostEntry costEntryModel = new uk.gov.laa.ccms.caab.model.CostEntry(); costEntryModel.setRequestedCosts(BigDecimal.valueOf(1000)); costEntryModel.setCostCategory("Legal Fees"); + uk.gov.laa.ccms.caab.model.CostStructure costStructureModel = new uk.gov.laa.ccms.caab.model.CostStructure(); costStructureModel.setCostEntries(Collections.singletonList(costEntryModel)); applicationDetail.setCosts(costStructureModel); @@ -237,13 +241,6 @@ public void testProceedingMapping() { assertEquals("Status", proceeding.getDisplayStatus()); assertEquals("TOO", proceeding.getTypeOfOrder()); - assertEquals("CreatedBy", proceeding.getAuditTrail().getCreatedBy()); - assertEquals(createdAt, proceeding.getAuditTrail().getCreated()); - - //This is set via the DB not the mapper - assertNull(proceeding.getAuditTrail().getModifiedBy()); - assertNull(proceeding.getAuditTrail().getModified()); - assertEquals("EBSID", proceeding.getEbsId()); assertEquals(BigDecimal.valueOf(111112), proceeding.getCostLimitation()); @@ -284,7 +281,6 @@ public void testToProceedingModel() { uk.gov.laa.ccms.caab.model.Proceeding proceedingDetail = mapper.toProceedingModel(proceeding); // Assertions - assertEquals(mapper.toAuditDetail(auditTrail), proceedingDetail.getAuditTrail()); assertEquals("Stage1", proceedingDetail.getStage()); } @@ -319,11 +315,6 @@ public void testToPriorAuthority(){ assertTrue(priorAuthority.getValueRequired()); assertEquals(new BigDecimal("0.123456"), priorAuthority.getAmountRequested()); assertEquals(0, priorAuthority.getItems().size()); // Assuming you expect an empty list - - assertEquals("CreatedBy", priorAuthority.getAuditTrail().getCreatedBy()); - assertEquals(createdAt, priorAuthority.getAuditTrail().getCreated()); - assertNull(priorAuthority.getAuditTrail().getModifiedBy()); - assertNull(priorAuthority.getAuditTrail().getModified()); } @Test @@ -342,8 +333,7 @@ public void testToPriorAuthorityModel() { uk.gov.laa.ccms.caab.model.PriorAuthority priorAuthorityDetail = mapper.toPriorAuthorityModel(priorAuthority); - // Assertions - assertEquals(mapper.toAuditDetail(auditTrail), priorAuthorityDetail.getAuditTrail()); + //TODO } @Test @@ -522,10 +512,6 @@ public void testToOpponent() { Opponent opponent = mapper.toOpponent(opponentDetail); assertEquals("OT", opponent.getOrganisationType()); - assertEquals("CreatedBy", opponent.getAuditTrail().getCreatedBy()); - assertEquals(createdAt, opponent.getAuditTrail().getCreated()); - assertNull(opponent.getAuditTrail().getModifiedBy()); - assertNull(opponent.getAuditTrail().getModified()); assertEquals("EBSID", opponent.getEbsId()); assertEquals("Type", opponent.getType()); assertEquals("Title", opponent.getTitle()); @@ -603,7 +589,6 @@ public void testToOpponentModel() { uk.gov.laa.ccms.caab.model.Opponent opponentDetail = mapper.toOpponentModel(opponent); - assertEquals(mapper.toAuditDetail(buildAuditTrail()), opponentDetail.getAuditTrail()); assertEquals("Relation1", opponentDetail.getRelationshipToCase()); assertEquals("Type1", opponentDetail.getType()); assertEquals("John", opponentDetail.getFirstName()); @@ -628,16 +613,14 @@ public void testToLinkedCase() { linkedCaseModel.setProviderCaseReference("Provider123"); linkedCaseModel.setFeeEarner("FeeEarner1"); linkedCaseModel.setStatus("Active"); - linkedCaseModel.setClientReference("Client123"); - linkedCaseModel.setClientFirstName("John"); - linkedCaseModel.setClientSurname("Doe"); + Client linkedCaseClient = new Client(); + linkedCaseClient.setReference("Client123"); + linkedCaseClient.setFirstName("John"); + linkedCaseClient.setSurname("Doe"); + linkedCaseModel.setClient(linkedCaseClient); LinkedCase linkedCase = mapper.toLinkedCase(linkedCaseModel); - assertEquals("CreatedBy", linkedCase.getAuditTrail().getCreatedBy()); - assertEquals(createdAt, linkedCase.getAuditTrail().getCreated()); - assertNull(linkedCase.getAuditTrail().getModifiedBy()); - assertNull(linkedCase.getAuditTrail().getModified()); assertEquals("LSC123", linkedCase.getLscCaseReference()); assertEquals("Relation1", linkedCase.getRelationToCase()); assertEquals("Provider123", linkedCase.getProviderCaseReference()); @@ -671,15 +654,14 @@ public void testToLinkedCaseModel() { uk.gov.laa.ccms.caab.model.LinkedCase linkedCaseModel = mapper.toLinkedCaseModel(linkedCase); // Assert the values in the mapped result - assertEquals(mapper.toAuditDetail(buildAuditTrail()), linkedCaseModel.getAuditTrail()); assertEquals("LSC123", linkedCaseModel.getLscCaseReference()); assertEquals("Relation1", linkedCaseModel.getRelationToCase()); assertEquals("Provider123", linkedCaseModel.getProviderCaseReference()); assertEquals("FeeEarner1", linkedCaseModel.getFeeEarner()); assertEquals("Active", linkedCaseModel.getStatus()); - assertEquals("Client123", linkedCaseModel.getClientReference()); - assertEquals("John", linkedCaseModel.getClientFirstName()); - assertEquals("Doe", linkedCaseModel.getClientSurname()); + assertEquals("Client123", linkedCaseModel.getClient().getReference()); + assertEquals("John", linkedCaseModel.getClient().getFirstName()); + assertEquals("Doe", linkedCaseModel.getClient().getSurname()); } @Test @@ -838,18 +820,6 @@ public void testToApplicationDetailCostsMapping() { } - @Test - public void testToAuditDetail() { - // Construct AuditTrail - AuditTrail auditTrail = buildAuditTrail(); - - // Convert AuditTrail to AuditDetail - AuditDetail auditDetail = mapper.toAuditDetail(auditTrail); - - // Assertions - assertEquals(buildAuditDetail(), auditDetail); - } - @Test void testToApplicationDetailWithNullInput() { assertNull(mapper.toApplicationDetail(null)); @@ -998,14 +968,13 @@ public void testAddApplicationTypeWithNullType() { Application application = new Application(); String caabUserLoginId = "user123"; - mapper.addApplicationType(application, null, caabUserLoginId); + mapper.addApplicationType(application, null); assertNull(application.getApplicationType()); assertNull(application.getApplicationTypeDisplayValue()); assertNull(application.getDevolvedPowersUsed()); assertNull(application.getDateDevolvedPowersUsed()); assertNull(application.getDevolvedPowersContractFlag()); - assertEquals("user123", application.getAuditTrail().getModifiedBy()); } @Test @@ -1020,14 +989,13 @@ public void testAddApplicationType() { applicationType.setDevolvedPowers(devolvedPowers); String caabUserLoginId = "user123"; - mapper.addApplicationType(application, applicationType, caabUserLoginId); + mapper.addApplicationType(application, applicationType); assertEquals("TEST",application.getApplicationType()); assertEquals("TEST123",application.getApplicationTypeDisplayValue()); assertFalse(application.getDevolvedPowersUsed()); assertNull(application.getDateDevolvedPowersUsed()); assertEquals("Y",application.getDevolvedPowersContractFlag()); - assertEquals("user123", application.getAuditTrail().getModifiedBy()); } private Application getApplicationWithProceedings() { @@ -1116,7 +1084,7 @@ public void testAddProviderDetailsWithNullDetails() { Application application = new Application(); String caabUserLoginId = "user123"; - mapper.addProviderDetails(application, null, caabUserLoginId); + mapper.addProviderDetails(application, null); assertNull(application.getProviderId()); assertNull(application.getProviderDisplayValue()); @@ -1128,7 +1096,6 @@ public void testAddProviderDetailsWithNullDetails() { assertNull(application.getFeeEarnerDisplayValue()); assertNull(application.getProviderContact()); assertNull(application.getProviderContactDisplayValue()); - assertEquals("user123", application.getAuditTrail().getModifiedBy()); } @Test @@ -1142,7 +1109,7 @@ public void testAddProviderDetails() { providerDetails.setProviderContact(new StringDisplayValue().id("ProviderContact").displayValue("Provider Contact Display Value")); String caabUserLoginId = "user123"; - mapper.addProviderDetails(application, providerDetails, caabUserLoginId); + mapper.addProviderDetails(application, providerDetails); assertEquals("123", application.getProviderId()); assertEquals("Provider Display", application.getProviderDisplayValue()); @@ -1154,7 +1121,6 @@ public void testAddProviderDetails() { assertEquals("Fee Earner Display Value", application.getFeeEarnerDisplayValue()); assertEquals("ProviderContact", application.getProviderContact()); assertEquals("Provider Contact Display Value", application.getProviderContactDisplayValue()); - assertEquals("user123", application.getAuditTrail().getModifiedBy()); } @Test @@ -1194,9 +1160,9 @@ private AuditDetail buildAuditDetail() { private AuditTrail buildAuditTrail() { AuditTrail auditTrail = new AuditTrail(); auditTrail.setCreated(createdAt); - auditTrail.setModified(updatedAt); + auditTrail.setLastSaved(updatedAt); auditTrail.setCreatedBy("CreatedBy"); - auditTrail.setModifiedBy("LastSavedBy"); + auditTrail.setLastSavedBy("LastSavedBy"); return auditTrail; } } diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java index 8d37e4f..f7d5a9c 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java @@ -49,10 +49,9 @@ void createApplication_createsApplicationWithCorrespondenceAddressAndCosts() { mockMapperAndRepository(applicationDetail, application); - applicationService.createApplication(CAAB_USER_LOGIN_ID, applicationDetail); + applicationService.createApplication(applicationDetail); verifyInteractionsWithMocks(applicationDetail, application); - verifyAuditTrailSetOnEntities(application); } /** @@ -60,15 +59,14 @@ void createApplication_createsApplicationWithCorrespondenceAddressAndCosts() { */ @Test void createApplication_updatesExistingAddressAndCosts() { - ApplicationDetail applicationDetail = new ApplicationDetail(); + ApplicationDetail applicationDetail = new ApplicationDetail(null,null,null,null); Application application = createApplicationWithExistingAddressAndCosts(); mockMapperAndRepository(applicationDetail, application); - applicationService.createApplication(CAAB_USER_LOGIN_ID, applicationDetail); + applicationService.createApplication(applicationDetail); verifyInteractionsWithMocks(applicationDetail, application); - verifyAuditTrailSetOnEntities(application); } /** @@ -77,7 +75,7 @@ void createApplication_updatesExistingAddressAndCosts() { @Test void getApplication_returnsData() { Application application = new Application(); - ApplicationDetail expectedResponse = new ApplicationDetail(); + ApplicationDetail expectedResponse = new ApplicationDetail(null,null,null,null); when(applicationMapper.toApplicationDetail(application)).thenReturn(expectedResponse); when(applicationRepository.findById(any())).thenReturn(Optional.of(application)); @@ -157,10 +155,10 @@ void patchApplicationType_whenExists_updatesApplicationType() { when(applicationRepository.findById(id)).thenReturn(Optional.of(application)); // Assuming Application exists - applicationService.patchApplicationType(id, CAAB_USER_LOGIN_ID, applicationType); + applicationService.patchApplicationType(id, applicationType); verify(applicationRepository).findById(id); - verify(applicationMapper).addApplicationType(application, applicationType, CAAB_USER_LOGIN_ID); + verify(applicationMapper).addApplicationType(application, applicationType); verify(applicationRepository).save(application); } @@ -176,7 +174,7 @@ void patchApplicationType_whenNotExists_throwsException() { // Use assertThrows to check if the method throws the expected exception CaabApiException exception = assertThrows(CaabApiException.class, () -> { - applicationService.patchApplicationType(id, CAAB_USER_LOGIN_ID, applicationType); + applicationService.patchApplicationType(id, applicationType); }); verify(applicationRepository).findById(id); @@ -230,10 +228,10 @@ void patchProviderDetails_whenExists_updatesProviderDetails() { when(applicationRepository.findById(id)).thenReturn(Optional.of(application)); // Assuming Application exists - applicationService.patchProviderDetails(id, caabUserLoginId, providerDetails); + applicationService.patchProviderDetails(id, providerDetails); verify(applicationRepository).findById(id); - verify(applicationMapper).addProviderDetails(application, providerDetails, caabUserLoginId); + verify(applicationMapper).addProviderDetails(application, providerDetails); verify(applicationRepository).save(application); } @@ -246,7 +244,7 @@ void patchProviderDetails_whenNotExists_throwsException() { when(applicationRepository.findById(id)).thenReturn(Optional.empty()); CaabApiException exception = assertThrows(CaabApiException.class, () -> { - applicationService.patchProviderDetails(id, caabUserLoginId, providerDetails); + applicationService.patchProviderDetails(id, providerDetails); }); verify(applicationRepository).findById(id); @@ -286,17 +284,15 @@ private void verifyAuditTrailSetOnEntities(Application application) { private void assertAuditTrailSet(String userId, AuditTrail auditTrail) { assert auditTrail != null; assert userId.equals(auditTrail.getCreatedBy()); - assert userId.equals(auditTrail.getModifiedBy()); + assert userId.equals(auditTrail.getLastSavedBy()); } /** * Helper method to create an Application with existing Address and CostStructure. */ private Application createApplicationWithExistingAddressAndCosts() { - AuditTrail auditTrailOld = createAuditTrail(OLD_USER); - - Address existingAddress = new Address(auditTrailOld); - CostStructure existingCosts = new CostStructure(auditTrailOld); + Address existingAddress = new Address(); + CostStructure existingCosts = new CostStructure(); Application application = new Application(); application.setCorrespondenceAddress(existingAddress); @@ -308,10 +304,10 @@ private Application createApplicationWithExistingAddressAndCosts() { /** * Helper method to create a new AuditTrail object. */ - private AuditTrail createAuditTrail(String userId) { + private AuditTrail createAuditTrail() { AuditTrail auditTrail = new AuditTrail(); - auditTrail.setCreatedBy(userId); - auditTrail.setModifiedBy(userId); + auditTrail.setCreatedBy(OLD_USER); + auditTrail.setLastSavedBy(OLD_USER); return auditTrail; } }