Skip to content

Commit

Permalink
Added endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilDigitalJustice committed Jan 10, 2024
1 parent d0d1c24 commit 6d7ae14
Show file tree
Hide file tree
Showing 22 changed files with 2,141 additions and 180 deletions.
472 changes: 462 additions & 10 deletions caab-api/open-api-specification.yml

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions caab-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ jacocoTestReport {
sourceDirectories.from files('build/generated/sources/annotationProcessor/java/main')
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/CaabApiApplication.class'])
fileTree(dir: it, exclude: [
'**/CaabApiApplication.class',
'**/ApplicationConfig.class',
'**/AuditorAwareImpl.class'])
}))
}

Expand All @@ -79,7 +82,10 @@ jacocoTestCoverageVerification {

afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/CaabApiApplication.class'])
fileTree(dir: it, exclude: [
'**/CaabApiApplication.class',
'**/ApplicationConfig.class',
'**/AuditorAwareImpl.class'])
}))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
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.caab.model.LinkedCase;
import uk.gov.laa.ccms.caab.model.ApplicationDetails;
import uk.gov.laa.ccms.caab.model.BaseApplication;
import uk.gov.laa.ccms.caab.model.LinkedCase;
import uk.gov.laa.ccms.caab.model.Proceeding;
import uk.gov.laa.ccms.caab.model.ScopeLimitation;
import uk.gov.laa.ccms.data.api.AbstractIntegrationTest;

@SpringBootTest(classes = CaabApiApplication.class)
Expand Down Expand Up @@ -154,7 +156,8 @@ public void testCreateApplication(String fileInput, String auditTrailMethod, Lis

String auditUser = "[email protected]";
// Call the createApplication method directly
ResponseEntity<Void> responseEntity = applicationController.createApplication(auditUser, applicationDetail);
ResponseEntity<Void> responseEntity =
applicationController.createApplication(auditUser, applicationDetail);

assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
URI locationUri = responseEntity.getHeaders().getLocation();
Expand All @@ -167,15 +170,34 @@ public void testCreateApplication(String fileInput, String auditTrailMethod, Lis
assertAuditTrail(savedApplicationDetails, auditTrailMethod, auditUser);
setAuditPropertiesToNull(savedApplicationDetails, auditTrailsToNull);

//null out the id's as they are generated by the database
//theses will always be different
if (savedApplicationDetails.getLinkedCases() != null){
for (LinkedCase linkedCase : savedApplicationDetails.getLinkedCases()){
nullIds(applicationDetail);

assertEquals(applicationDetail, savedApplicationDetails);
}

private void nullIds(ApplicationDetail applicationDetail) {
if (applicationDetail.getLinkedCases() != null) {
for (LinkedCase linkedCase : applicationDetail.getLinkedCases()) {
linkedCase.setId(null);
}
}

assertEquals(applicationDetail, savedApplicationDetails);
if (applicationDetail.getProceedings() != null) {
for (Proceeding proceeding : applicationDetail.getProceedings()) {
proceeding.setId(null);
if (proceeding.getScopeLimitations() != null) {
for (ScopeLimitation scopeLimitation : proceeding.getScopeLimitations()) {
scopeLimitation.setId(null);
}
}
}
}

if (applicationDetail.getPriorAuthorities() != null) {
for (uk.gov.laa.ccms.caab.model.PriorAuthority priorAuthority : applicationDetail.getPriorAuthorities()) {
priorAuthority.setId(null);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import uk.gov.laa.ccms.caab.api.ApplicationsApi;
import uk.gov.laa.ccms.caab.api.LinkedCasesApi;
import uk.gov.laa.ccms.caab.api.PriorAuthoritiesApi;
import uk.gov.laa.ccms.caab.api.ProceedingsApi;
import uk.gov.laa.ccms.caab.api.ScopeLimitationsApi;
import uk.gov.laa.ccms.caab.api.service.ApplicationService;
import uk.gov.laa.ccms.caab.api.service.LinkedCaseService;
import uk.gov.laa.ccms.caab.api.service.PriorAuthorityService;
import uk.gov.laa.ccms.caab.api.service.ProceedingService;
import uk.gov.laa.ccms.caab.api.service.ScopeLimitationService;
import uk.gov.laa.ccms.caab.model.Address;
import uk.gov.laa.ccms.caab.model.ApplicationDetail;
import uk.gov.laa.ccms.caab.model.ApplicationDetails;
import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails;
import uk.gov.laa.ccms.caab.model.ApplicationType;
import uk.gov.laa.ccms.caab.model.CostStructure;
import uk.gov.laa.ccms.caab.model.LinkedCase;
import uk.gov.laa.ccms.caab.model.PriorAuthority;
import uk.gov.laa.ccms.caab.model.Proceeding;
import uk.gov.laa.ccms.caab.model.ScopeLimitation;

/**
* Represents the main controller handling application-related requests.
Expand All @@ -27,10 +39,14 @@
*/
@RestController
@RequiredArgsConstructor
public class ApplicationController implements ApplicationsApi {
public class ApplicationController implements ApplicationsApi, LinkedCasesApi, ProceedingsApi,
ScopeLimitationsApi, PriorAuthoritiesApi {

private final ApplicationService applicationService;

private final LinkedCaseService linkedCaseService;
private final ProceedingService proceedingService;
private final PriorAuthorityService priorAuthorityService;
private final ScopeLimitationService scopeLimitationService;

/**
* Creates a new application and returns the URI of the created resource.
Expand Down Expand Up @@ -98,9 +114,7 @@ public ResponseEntity<ApplicationDetails> getApplications(
@Override
public ResponseEntity<ApplicationDetail> getApplication(
final Long applicationId) {

ApplicationDetail application = applicationService.getApplication(applicationId);

return new ResponseEntity<>(application, HttpStatus.OK);
}

Expand All @@ -117,7 +131,6 @@ public ResponseEntity<Address> getApplicationCorrespondenceAddress(
final Long applicationId) {
Address correspondenceAddress =
applicationService.getApplicationCorrespondenceAddress(applicationId);

return new ResponseEntity<>(correspondenceAddress, HttpStatus.OK);
}

Expand All @@ -135,7 +148,6 @@ public ResponseEntity<Void> putApplicationCorrespondenceAddress(
final String caabUserLoginId,
final Address address) {
applicationService.putCorrespondenceAddress(applicationId, address);

return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

Expand All @@ -152,7 +164,6 @@ public ResponseEntity<ApplicationProviderDetails> getApplicationProviderDetails(
final Long applicationId) {
ApplicationProviderDetails applicationProviderDetails =
applicationService.getApplicationProviderDetails(applicationId);

return new ResponseEntity<>(applicationProviderDetails, HttpStatus.OK);
}

Expand All @@ -170,7 +181,6 @@ public ResponseEntity<Void> putApplicationProviderDetails(
final String caabUserLoginId,
final ApplicationProviderDetails applicationProviderDetails) {
applicationService.putProviderDetails(applicationId, applicationProviderDetails);

return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

Expand All @@ -186,7 +196,6 @@ public ResponseEntity<Void> putApplicationProviderDetails(
public ResponseEntity<ApplicationType> getApplicationType(
final Long applicationId) {
ApplicationType applicationType = applicationService.getApplicationType(applicationId);

return new ResponseEntity<>(applicationType, HttpStatus.OK);
}

Expand All @@ -204,7 +213,24 @@ public ResponseEntity<Void> putApplicationType(
final String caabUserLoginId,
final ApplicationType applicationType) {
applicationService.putApplicationType(applicationId, applicationType);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

//Cost Structure

@Override
public ResponseEntity<CostStructure> getApplicationCostStructure(final Long applicationId) {
CostStructure costStructure =
applicationService.getApplicationCostStructure(applicationId);
return new ResponseEntity<>(costStructure, HttpStatus.OK);
}

@Override
public ResponseEntity<Void> updateApplicationCostStructure(
final Long applicationId,
final String caabUserLoginId,
final CostStructure costStructure) {
applicationService.putCostStructure(applicationId, costStructure);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

Expand All @@ -219,7 +245,6 @@ public ResponseEntity<Void> putApplicationType(
@Override
public ResponseEntity<List<LinkedCase>> getApplicationLinkedCases(final Long applicationId) {
List<LinkedCase> linkedCases = applicationService.getLinkedCasesForApplication(applicationId);

return new ResponseEntity<>(linkedCases, HttpStatus.OK);
}

Expand All @@ -237,44 +262,145 @@ public ResponseEntity<Void> addApplicationLinkedCase(
final String caabUserLoginId,
final LinkedCase linkedCase) {
applicationService.createLinkedCaseForApplication(applicationId, linkedCase);

return new ResponseEntity<>(HttpStatus.CREATED);
}

/**
* Updates a linked case of a specific application.
* Updates a linked case.
*
* @param applicationId the unique identifier of the application
* @param linkedCaseId the unique identifier of the linked case
* @param caabUserLoginId the user login ID used for audit trail
* @param linkedCase the updated linked case
* @return a ResponseEntity with no content
*/
@Override
public ResponseEntity<Void> updateApplicationLinkedCase(
final Long applicationId, final Long linkedCaseId,
final Long linkedCaseId,
final String caabUserLoginId,
final LinkedCase linkedCase) {
applicationService.updateLinkedCaseForApplication(applicationId, linkedCaseId, linkedCase);

linkedCaseService.updateLinkedCase(linkedCaseId, linkedCase);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

/**
* Removes a linked case from a specific application.
*
* @param applicationId the unique identifier of the application
* @param linkedCaseId the unique identifier of the linked case
* @param caabUserLoginId the user login ID used for audit trail
* @return a ResponseEntity indicating the case was successfully removed
*/
@Override
public ResponseEntity<Void> removeApplicationLinkedCase(
final Long applicationId,
final Long linkedCaseId,
final String caabUserLoginId) {
applicationService.removeLinkedCaseFromApplication(applicationId, linkedCaseId);
linkedCaseService.removeLinkedCase(linkedCaseId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

//proceedings

@Override
public ResponseEntity<Void> addApplicationProceeding(
final Long applicationId,
final String caabUserLoginId,
final Proceeding proceeding) {
applicationService.createProceedingForApplication(applicationId, proceeding);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@Override
public ResponseEntity<List<Proceeding>> getApplicationProceedings(
final Long applicationId) {
List<Proceeding> proceedings = applicationService.getProceedingsForApplication(applicationId);
return new ResponseEntity<>(proceedings, HttpStatus.OK);
}

@Override
public ResponseEntity<Void> removeProceeding(
final Long proceedingId,
final String caabUserLoginId) {
proceedingService.removeProceeding(proceedingId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Override
public ResponseEntity<Void> updateProceeding(
final Long proceedingId,
final String caabUserLoginId,
final Proceeding proceeding) {
proceedingService.updateProceeding(proceedingId, proceeding);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

//scope limitations

@Override
public ResponseEntity<Void> addProceedingScopeLimitation(
final Long proceedingId,
final String caabUserLoginId,
final ScopeLimitation scopeLimitation) {
proceedingService.createScopeLimitationForProceeding(proceedingId, scopeLimitation);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@Override
public ResponseEntity<List<ScopeLimitation>> getApplicationScopeLimitations(
final Long proceedingId) {
List<ScopeLimitation> scopeLimitations =
proceedingService.getScopeLimitationsForProceeding(proceedingId);
return new ResponseEntity<>(scopeLimitations, HttpStatus.OK);
}

@Override
public ResponseEntity<Void> removeScopeLimitation(
final Long scopeLimitationId,
final String caabUserLoginId) {
scopeLimitationService.removeScopeLimitation(scopeLimitationId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Override
public ResponseEntity<Void> updateScopeLimitation(
final Long scopeLimitationId,
final String caabUserLoginId,
final ScopeLimitation scopeLimitation) {
scopeLimitationService.updateScopeLimitation(scopeLimitationId, scopeLimitation);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

//prior authorities

@Override
public ResponseEntity<Void> addApplicationPriorAuthority(
final Long id,
final String caabUserLoginId,
final PriorAuthority priorAuthority) {
applicationService.createPriorAuthorityForApplication(id, priorAuthority);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@Override
public ResponseEntity<List<PriorAuthority>> getApplicationPriorAuthorities(
final Long id) {
List<PriorAuthority> priorAuthorities =
applicationService.getPriorAuthoritiesForApplication(id);
return new ResponseEntity<>(priorAuthorities, HttpStatus.OK);
}

@Override
public ResponseEntity<Void> removePriorAuthority(
final Long priorAuthorityId,
final String caabUserLoginId) {
priorAuthorityService.removePriorAuthority(priorAuthorityId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Override
public ResponseEntity<Void> updatePriorAuthority(
final Long priorAuthorityId,
final String caabUserLoginId,
final PriorAuthority priorAuthority) {
priorAuthorityService.updatePriorAuthority(priorAuthorityId, priorAuthority);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ public class Application implements Serializable {
@JoinColumn(name = "FK_CORRESPONDENCE_ADDRESS")
private Address correspondenceAddress;

@OneToMany(mappedBy = "application", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "application", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("id asc")
private List<Proceeding> proceedings;

@OneToMany(mappedBy = "application", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "application", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("id asc")
private List<PriorAuthority> priorAuthorities;

@OneToMany(mappedBy = "application", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "application", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("id asc")
private List<Opponent> opponents;

Expand Down
Loading

0 comments on commit 6d7ae14

Please sign in to comment.