Skip to content

Commit

Permalink
Merge branch 'handle-data-conflict-issue' into olock
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmendrak committed Nov 7, 2024
2 parents bb3c068 + 6c5fc87 commit 8087638
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -20,7 +21,7 @@ public interface PocApiClient {

@PostMapping(value = "/ccd/cases", consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
CaseDetails createCase(@RequestBody POCCaseDetails caseDetails);
ResponseEntity<CaseDetails> createCase(@RequestBody POCCaseDetails caseDetails);

@GetMapping(value = "/ccd/cases/{case-ref}/history")
List<AuditEvent> getEvents(@PathVariable("case-ref") String caseReference);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package uk.gov.hmcts.ccd.domain.service.createcase;

import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.StaleObjectStateException;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.ccd.clients.PocApiClient;
import uk.gov.hmcts.ccd.data.casedetails.CaseDetailsEntity;
import uk.gov.hmcts.ccd.domain.model.aggregated.IdamUser;
import uk.gov.hmcts.ccd.domain.model.aggregated.POCCaseDetails;
import uk.gov.hmcts.ccd.domain.model.aggregated.POCEventDetails;
Expand All @@ -13,6 +19,9 @@
import uk.gov.hmcts.ccd.domain.model.std.Event;
import uk.gov.hmcts.ccd.domain.service.common.CaseTypeService;
import uk.gov.hmcts.ccd.domain.service.stdapi.AboutToSubmitCallbackResponse;
import uk.gov.hmcts.ccd.endpoint.exceptions.CaseConcurrencyException;
import uk.gov.hmcts.ccd.endpoint.exceptions.CasePersistenceException;
import uk.gov.hmcts.ccd.endpoint.exceptions.ReferenceKeyUniqueConstraintException;

@Slf4j
@Service
Expand Down Expand Up @@ -54,15 +63,21 @@ public CaseDetails saveAuditEventForCaseDetails(AboutToSubmitCallbackResponse re
POCCaseDetails pocCaseDetails = POCCaseDetails.builder()
.caseDetails(newCaseDetails).eventDetails(eventDetails.build()).build();

final CaseDetails savedPocCaseDetails = pocApiClient.createCase(pocCaseDetails);

log.info("pocCaseDetails: {}", savedPocCaseDetails);
log.info("pocCaseDetails id: {}", savedPocCaseDetails.getId());
log.info("pocCaseDetails reference before: {}", savedPocCaseDetails.getReference());
savedPocCaseDetails.setId(savedPocCaseDetails.getReference().toString());
savedPocCaseDetails.setReference(newCaseDetails.getReference());
log.info("pocCaseDetails reference: {}", savedPocCaseDetails.getReference());
return savedPocCaseDetails;

var createdCaseResponse = pocApiClient.createCase(pocCaseDetails);
if (createdCaseResponse.getStatusCode().equals(HttpStatus.CONFLICT)) {
throw new CaseConcurrencyException("""
Unfortunately we were unable to save your work to the case as \
another action happened at the same time.
Please review the case and try again.""");
}
CaseDetails caseDetails = createdCaseResponse.getBody();
log.info("pocCaseDetails: {}", createdCaseResponse);
log.info("pocCaseDetails id: {}", caseDetails.getId());
log.info("pocCaseDetails reference before: {}", caseDetails.getReference());
caseDetails.setId(caseDetails.getReference().toString());
caseDetails.setReference(caseDetails.getReference());
log.info("pocCaseDetails reference: {}", caseDetails.getReference());
return caseDetails;
}
}

0 comments on commit 8087638

Please sign in to comment.