Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resources:
type: github
name: hmcts/cpp-azure-devops-templates
endpoint: 'hmcts'
ref: 'main'
ref: 'pr-debug'

pool:
name: "MDV-ADO-AGENT-AKS-01"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,15 @@ private InitiateCourtApplicationEntity getInitiateCourtApplication(final CourtAp
private void addCourtApplicationToCase(final CourtApplication courtApplication, final UUID prosecutionCaseId, final String caseReference) {
final CourtApplicationEntity courtApplicationEntity = courtApplicationRepository.findBy(courtApplication.getId());
if (nonNull(courtApplicationEntity)) {
final CourtApplicationCaseEntity courtApplicationCaseEntity = new CourtApplicationCaseEntity();
final CourtApplicationCaseKey courtApplicationCaseKey = new CourtApplicationCaseKey(randomUUID(), courtApplication.getId(), prosecutionCaseId);
courtApplicationCaseEntity.setId(courtApplicationCaseKey);
courtApplicationCaseEntity.setCourtApplication(courtApplicationEntity);
courtApplicationCaseEntity.setCaseReference(caseReference);
courtApplicationCaseRepository.save(courtApplicationCaseEntity);
CourtApplicationCaseEntity courtApplicationCase = courtApplicationCaseRepository.findByApplicationIdAndCaseId(courtApplication.getId(), prosecutionCaseId);
if(courtApplicationCase == null) {
final CourtApplicationCaseEntity courtApplicationCaseEntity = new CourtApplicationCaseEntity();
final CourtApplicationCaseKey courtApplicationCaseKey = new CourtApplicationCaseKey(randomUUID(), courtApplication.getId(), prosecutionCaseId);
courtApplicationCaseEntity.setId(courtApplicationCaseKey);
courtApplicationCaseEntity.setCourtApplication(courtApplicationEntity);
courtApplicationCaseEntity.setCaseReference(caseReference);
courtApplicationCaseRepository.save(courtApplicationCaseEntity);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,49 @@ public void shouldUpdateRespondentsAddressOnApplication_LegalEntityDefendant(){
verify(initiateCourtApplicationRepository).save(initiateCourtApplicationEntityArgumentCaptor.capture());
}

@Test
public void shouldHandleCourtApplicationAddedWillBeSkippedIfWeHaveApplicationAndCaseInsideTable() {
final UUID applicationId = randomUUID();
final CourtApplicationEntity persistedEntity = new CourtApplicationEntity();
persistedEntity.setApplicationId(applicationId);
persistedEntity.setPayload(payload.toString());
final UUID caseId = randomUUID();

final CourtApplication courtApplication = CourtApplication.courtApplication()
.withId(applicationId)
.withCourtApplicationCases(
singletonList(
CourtApplicationCase.courtApplicationCase()
.withProsecutionCaseId(caseId)
.withProsecutionCaseIdentifier(ProsecutionCaseIdentifier.prosecutionCaseIdentifier()
.withCaseURN("CaseURN")
.build())
.build()
)
)
.withCourtOrder(CourtOrder.courtOrder().withId(randomUUID())
.withOrderingCourt(CourtCentre.courtCentre().withId(randomUUID()).build())
.withCourtOrderOffences(singletonList(courtOrderOffence().withOffence(offence()
.withJudicialResults(null)

.build())
.withProsecutionCaseId(caseId)
.withProsecutionCaseIdentifier(ProsecutionCaseIdentifier.prosecutionCaseIdentifier().withCaseURN("CaseURN").build())
.build()))
.build())
.build();
CourtApplicationCaseEntity courtApplicationCase = new CourtApplicationCaseEntity();
courtApplicationCase.setCaseReference(caseId.toString());
courtApplicationCase.setCourtApplication(persistedEntity);
when(envelope.payloadAsJsonObject()).thenReturn(payload);
when(jsonObjectToObjectConverter.convert(payload, CourtApplicationAddedToCase.class))
.thenReturn(courtApplicationAddedToCase);
when(courtApplicationAddedToCase.getCourtApplication()).thenReturn(courtApplication);
when(courtApplicationCaseRepository.findByApplicationIdAndCaseId(courtApplication.getId(),caseId)).thenReturn(courtApplicationCase);
when(repository.findBy(applicationId)).thenReturn(persistedEntity);
eventListener.processCourtApplicationAddedToCase(envelope);
}

private static CourtApplicationParty buildOriginalDefendant(boolean isPersonDefendant, final UUID masterDefendantId) {
final Address originalAddress = Address.address().withAddress1("Old Address 1").withAddress2("Old Address 2").withPostcode("RG2 1WE").build();
if(isPersonDefendant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.deltaspike.data.api.Query;
import org.apache.deltaspike.data.api.QueryParam;
import org.apache.deltaspike.data.api.Repository;
import org.apache.deltaspike.data.api.SingleResultType;

@Repository
public interface CourtApplicationCaseRepository extends EntityRepository<CourtApplicationCaseEntity, CourtApplicationCaseKey> {
Expand All @@ -27,4 +28,7 @@ public interface CourtApplicationCaseRepository extends EntityRepository<CourtAp
@Modifying
@Query("delete from CourtApplicationCaseEntity entity where entity.id.applicationId = :applicationId")
void removeByApplicationId(@QueryParam("applicationId") UUID applicationId);

@Query(value = "from CourtApplicationCaseEntity entity WHERE entity.id.applicationId = :applicationId AND entity.id.caseId = :caseId", singleResult = SingleResultType.OPTIONAL)
CourtApplicationCaseEntity findByApplicationIdAndCaseId(@QueryParam("applicationId") final UUID applicationId, @QueryParam("caseId") final UUID caseId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,11 @@ public void shouldDeleteByApplicationId() {
assertThat(actual.size(), is(0));
}

@Test
public void shouldFindCourtApplicationCaseEntityByApplicationIdAndCaseId() {
CourtApplicationCaseEntity byApplicationIdAndCaseId = courtApplicationCaseRepository.findByApplicationIdAndCaseId(APPLICATION_ID, CASE_ID);
assertThat(byApplicationIdAndCaseId.getCourtApplication(), is(notNullValue()));
assertThat(byApplicationIdAndCaseId.getCourtApplication().getApplicationId(), is(APPLICATION_ID));
}

}
Loading