Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2df2452
HDPI-6368 - adding support for LR counter claim persistence
jonathanditcher-solirius Jul 15, 2026
e7b9fb1
Remove unused import
jonathanditcher-solirius Jul 15, 2026
984ba0f
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 16, 2026
2c86d91
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 16, 2026
5e7bfbf
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 16, 2026
aa073bc
Removed unused dependencies
jonathanditcher-solirius Jul 16, 2026
e0eafbb
Bumping chart version/ fixing aliases
hmcts-jenkins-j-to-z[bot] Jul 16, 2026
52e23c7
Removed unused dependencies
jonathanditcher-solirius Jul 16, 2026
7826d8a
Merge remote-tracking branch 'origin/HDPI-6368_LR_counter_claim_persi…
jonathanditcher-solirius Jul 16, 2026
eb6380c
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 16, 2026
81894d0
Removed unused import
jonathanditcher-solirius Jul 16, 2026
53dd6b0
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 17, 2026
16c8d80
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
sngiri2012sree Jul 17, 2026
c1be511
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 20, 2026
db4f475
Resolving comments
jonathanditcher-solirius Jul 20, 2026
581eef9
Merge remote-tracking branch 'origin/HDPI-6368_LR_counter_claim_persi…
jonathanditcher-solirius Jul 20, 2026
a44b497
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 21, 2026
8aafbc4
Updated var name
jonathanditcher-solirius Jul 21, 2026
c01b059
Merge branch 'master' into HDPI-6368_LR_counter_claim_persistence
jonathanditcher-solirius Jul 21, 2026
53c55de
Updated unit test
jonathanditcher-solirius Jul 21, 2026
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
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
package uk.gov.hmcts.reform.pcs.ccd.event.respondpossessionclaim.strategy;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.api.EventPayload;
import uk.gov.hmcts.ccd.sdk.api.callback.SubmitResponse;
import uk.gov.hmcts.reform.pcs.ccd.accesscontrol.UserRole;
import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase;
import uk.gov.hmcts.reform.pcs.ccd.domain.State;
import uk.gov.hmcts.reform.pcs.ccd.domain.respondpossessionclaim.PossessionClaimResponse;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
import uk.gov.hmcts.reform.pcs.ccd.service.DraftCaseDataService;
import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.CounterClaimSubmitConfirmationService;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.RespondPossessionClaimSubmitPersistenceResult;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.RespondPossessionClaimSubmitService;
import uk.gov.hmcts.reform.pcs.exception.DraftNotFoundException;
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;
import uk.gov.hmcts.reform.pcs.model.JourneyType;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static uk.gov.hmcts.reform.pcs.ccd.event.EventId.respondPossessionClaim;

@Component
@RequiredArgsConstructor
@Slf4j
public class CitizenSubmissionEventStrategy implements RespondPossessionClaimSubmissionEventStrategy {

private final DraftCaseDataService draftCaseDataService;
private final SubmitResponseFactory submitResponseFactory;
private final RespondPossessionClaimSubmitService respondPossessionClaimSubmitService;
private final CounterClaimSubmitConfirmationService counterClaimSubmitConfirmationService;
private final PartyService partyService;
private final SecurityContextService securityContextService;

@Override
public boolean supports(List<String> roles) {
Expand All @@ -35,6 +44,12 @@ public boolean supports(List<String> roles) {

@Override
public SubmitResponse<State> process(EventPayload<PCSCase, State> eventPayload) {
UUID currentUserIdamId = securityContextService.getCurrentUserId();
if (currentUserIdamId == null) {
log.error("Cannot save contact preferences: current user IDAM ID is null");
throw new IllegalStateException("Current user IDAM ID is null");
}

Long caseReference = eventPayload.caseReference();
PCSCase draftData = draftCaseDataService
.getUnsubmittedCaseData(caseReference, respondPossessionClaim)
Expand All @@ -49,9 +64,12 @@ public SubmitResponse<State> process(EventPayload<PCSCase, State> eventPayload)
return validationResult.get();
}

RespondPossessionClaimSubmitPersistenceResult persistenceResult =
respondPossessionClaimSubmitService.persistFinalSubmit(caseReference, responseDraftData);
PartyEntity defendantParty = partyService.getPartyEntityByIdamId(currentUserIdamId, caseReference);

RespondPossessionClaimSubmitPersistenceResult persistenceResult = respondPossessionClaimSubmitService
.persistFinalSubmit(caseReference, responseDraftData, defendantParty, JourneyType.CITIZEN);

return counterClaimSubmitConfirmationService.buildSubmitResponse(caseReference, persistenceResult);
return counterClaimSubmitConfirmationService
.buildSubmitResponse(caseReference, persistenceResult, defendantParty);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package uk.gov.hmcts.reform.pcs.ccd.event.respondpossessionclaim.strategy;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.ccd.sdk.api.EventPayload;
import uk.gov.hmcts.ccd.sdk.api.callback.SubmitResponse;
import uk.gov.hmcts.reform.pcs.ccd.accesscontrol.UserRole;
import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase;
import uk.gov.hmcts.reform.pcs.ccd.domain.State;
import uk.gov.hmcts.reform.pcs.ccd.domain.respondpossessionclaim.PossessionClaimResponse;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
import uk.gov.hmcts.reform.pcs.ccd.service.DraftCaseDataService;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.ClaimResponseService;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.DefendantResponseService;
import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.CounterClaimSubmitConfirmationService;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.RespondPossessionClaimSubmitPersistenceResult;
import uk.gov.hmcts.reform.pcs.ccd.service.respondpossessionclaim.RespondPossessionClaimSubmitService;
import uk.gov.hmcts.reform.pcs.ccd.util.SelectedPartyRetriever;
import uk.gov.hmcts.reform.pcs.exception.DraftNotFoundException;
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;
import uk.gov.hmcts.reform.pcs.model.JourneyType;

import java.util.List;
import java.util.Optional;
Expand All @@ -23,22 +28,29 @@

@Component
@RequiredArgsConstructor
@Slf4j
public class LegalRepSubmissionEventStrategy implements RespondPossessionClaimSubmissionEventStrategy {

private final DraftCaseDataService draftCaseDataService;
private final ClaimResponseService claimResponseService;
private final DefendantResponseService defendantResponseService;
private final SelectedPartyRetriever selectedPartyRetriever;
private final SubmitResponseFactory submitResponseFactory;
private final PartyService partyService;
private final RespondPossessionClaimSubmitService respondPossessionClaimSubmitService;
private final CounterClaimSubmitConfirmationService counterClaimSubmitConfirmationService;
private final SecurityContextService securityContextService;

@Override
public boolean supports(List<String> roles) {
return !roles.contains(UserRole.CITIZEN.getRole());
}

@Transactional
@Override
public SubmitResponse<State> process(EventPayload<PCSCase, State> eventPayload) {
if (securityContextService.getCurrentUserId() == null) {
log.error("Current user IDAM ID is null");
throw new IllegalStateException("Current user IDAM ID is null");
}

Long caseReference = eventPayload.caseReference();
UUID representedPartyId = selectedPartyRetriever
.getCurrentRepresentedPartyId(eventPayload.caseData())
Expand All @@ -57,10 +69,13 @@ public SubmitResponse<State> process(EventPayload<PCSCase, State> eventPayload)
return validationResult.get();
}

claimResponseService.saveDraftDataForParty(responseDraftData, caseReference, representedPartyId);
defendantResponseService.saveDefendantResponse(caseReference, responseDraftData, representedPartyId);
draftCaseDataService.deleteUnsubmittedCaseData(caseReference, respondPossessionClaim, representedPartyId);
PartyEntity defendantParty = partyService.getPartyEntityById(representedPartyId, caseReference);

return submitResponseFactory.success();
RespondPossessionClaimSubmitPersistenceResult persistenceResult = respondPossessionClaimSubmitService
.persistFinalSubmit(caseReference, responseDraftData, defendantParty, JourneyType.LEGAL_REPRESENTATIVE);

return counterClaimSubmitConfirmationService
.buildSubmitResponse(caseReference, persistenceResult, defendantParty);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
import uk.gov.hmcts.reform.pcs.ccd.entity.AddressEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.ContactPreferencesEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService;
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;

import java.util.Optional;
import java.util.UUID;
import java.util.function.Supplier;

/**
* Service for managing defendant contact preferences.
Expand All @@ -29,46 +25,27 @@
@RequiredArgsConstructor
public class ClaimResponseService {

private final PartyService partyService;
private final SecurityContextService securityContextService;
private final ModelMapper modelMapper;

/**
* Saves defendant's contact preferences and contact details.
* Finds the defendant party by the current user's IDAM ID and case reference updates their information.
* Saves defendant's contact preferences and contact details for the given defendant party.
*
* @throws IllegalStateException if no party found for the current user's IDAM ID
* @throws IllegalStateException if no party is found
*/
public void saveDraftData(PossessionClaimResponse dataFromDraftTable, long caseReference) {
UUID currentUserIdamId = securityContextService.getCurrentUserId();
public void saveDraftDataForParty(PossessionClaimResponse dataFromDraftTable, PartyEntity defendantParty) {
Comment thread
jonathanditcher-solirius marked this conversation as resolved.

if (currentUserIdamId == null) {
log.error("Cannot save contact preferences: current user IDAM ID is null");
throw new IllegalStateException("Current user IDAM ID is null");
if (defendantParty == null) {
throw new IllegalStateException("defendant party is null");
}

saveDraftDataForPartyInternal(dataFromDraftTable, () -> partyService.getPartyEntityByIdamId(currentUserIdamId,
caseReference));
log.debug("Successfully saved contact preferences for defendant with IDAM ID: {}", currentUserIdamId);
}

public void saveDraftDataForParty(PossessionClaimResponse dataFromDraftTable, long caseReference, UUID partyId) {
saveDraftDataForPartyInternal(dataFromDraftTable, () -> partyService.getPartyEntityById(partyId,
caseReference));
}

private void saveDraftDataForPartyInternal(PossessionClaimResponse dataFromDraftTable, Supplier<PartyEntity>
partyEntitySupplier) {
PartyEntity defendant = partyEntitySupplier.get();

saveContactPreferences(defendant, dataFromDraftTable.getDefendantResponses());
updatePartyContactDetails(defendant, dataFromDraftTable.getDefendantContactDetails(), dataFromDraftTable
saveContactPreferences(defendantParty, dataFromDraftTable.getDefendantResponses());
updatePartyContactDetails(defendantParty, dataFromDraftTable.getDefendantContactDetails(), dataFromDraftTable
.getDefendantResponses());

if (dataFromDraftTable.getDefendantResponses() != null
&& dataFromDraftTable.getDefendantResponses().getDateOfBirth() != null) {
defendant.setDateOfBirth(dataFromDraftTable.getDefendantResponses().getDateOfBirth());
log.debug("Updated date of birth from defendantResponses for party ID: {}", defendant.getId());
defendantParty.setDateOfBirth(dataFromDraftTable.getDefendantResponses().getDateOfBirth());
log.debug("Updated date of birth from defendantResponses for party ID: {}", defendantParty.getId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import uk.gov.hmcts.reform.pcs.ccd.repository.ClaimRepository;
import uk.gov.hmcts.reform.pcs.ccd.repository.CounterClaimRepository;
import uk.gov.hmcts.reform.pcs.ccd.repository.PartyRepository;
import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService;
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;

import java.time.Clock;
import java.time.LocalDateTime;
Expand All @@ -28,41 +26,34 @@
@Transactional
public class CounterClaimService {

private final PartyService partyService;
private final PartyRepository partyRepository;
private final ClaimRepository claimRepository;
private final CounterClaimRepository counterClaimRepository;
private final SecurityContextService securityContextService;
private final Clock utcClock;

public CounterClaimService(PartyService partyService,
PartyRepository partyRepository,
public CounterClaimService(PartyRepository partyRepository,
ClaimRepository claimRepository,
CounterClaimRepository counterClaimRepository,
SecurityContextService securityContextService,
@Qualifier("utcClock") Clock utcClock) {
this.partyService = partyService;
this.partyRepository = partyRepository;
this.claimRepository = claimRepository;
this.counterClaimRepository = counterClaimRepository;
this.securityContextService = securityContextService;
this.utcClock = utcClock;
}

public Optional<CounterClaimEntity> saveCounterClaim(long caseReference, CounterClaim counterClaim) {
if (counterClaim == null) {
return Optional.empty();
public Optional<CounterClaimEntity> saveCounterClaim(
long caseReference,
CounterClaim counterClaim,
PartyEntity partyRef
) {
if (partyRef == null) {
throw new IllegalStateException("party is null for case: " + caseReference);
}

UUID userId = securityContextService.getCurrentUserId();
if (userId == null) {
throw new IllegalStateException("Current user IDAM ID is null");
if (counterClaim == null) {
return Optional.empty();
}

PartyEntity partyRef = partyRepository.getReferenceById(
partyService.getPartyEntityByIdamId(userId, caseReference).getId()
);

UUID claimId = claimRepository.findIdByCaseReference(caseReference)
.orElseThrow(() -> new IllegalStateException("No claim found for case: " + caseReference));
ClaimEntity claimRef = claimRepository.getReferenceById(claimId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
import uk.gov.hmcts.reform.pcs.feesandpay.service.FeeService;
import uk.gov.hmcts.reform.pcs.feesandpay.service.PaymentService;
import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService;
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;
import uk.gov.hmcts.reform.payments.response.PaymentServiceResponse;

import java.math.BigDecimal;
import java.util.UUID;

import static uk.gov.hmcts.reform.pcs.feesandpay.model.PaymentCallbackHandlerType.COUNTER_CLAIM_ISSUE;

Expand All @@ -35,18 +33,22 @@ public class CounterClaimSubmitConfirmationService {
private final FeeService feeService;
private final PaymentService paymentService;
private final CounterClaimFeeCalculator counterClaimFeeCalculator;
private final SecurityContextService securityContextService;
private final ObjectMapper objectMapper;

public SubmitResponse<State> buildSubmitResponse(
long caseReference,
RespondPossessionClaimSubmitPersistenceResult persistenceResult
RespondPossessionClaimSubmitPersistenceResult persistenceResult,
PartyEntity responsibleParty
) {
CounterClaimEntity counterClaimEntity = persistenceResult.counterClaimEntity();
if (counterClaimEntity == null) {
return SubmitResponse.defaultResponse();
}

if (responsibleParty == null) {
throw new IllegalStateException("Responsible party entity not provided");
}

if (persistenceResult.issuedWithoutPayment()) {
return buildCounterClaimConfirmationResponse(
persistenceResult.counterClaimEntity().getStatus(),
Expand All @@ -66,6 +68,7 @@ public SubmitResponse<State> buildSubmitResponse(
);
String serviceRequestReference = createPaymentServiceRequest(
counterClaimEntity,
responsibleParty,
feeDetails,
caseReference
);
Expand All @@ -79,9 +82,9 @@ public SubmitResponse<State> buildSubmitResponse(
}

private String createPaymentServiceRequest(CounterClaimEntity counterClaimEntity,
PartyEntity responsibleParty,
FeeDetails feeDetails,
long caseReference) {
PartyEntity responsibleParty = getCurrentUserParty(caseReference);

FeesAndPayTaskData taskData = FeesAndPayTaskData.builder()
.feeDetails(feeDetails)
Expand Down Expand Up @@ -124,14 +127,6 @@ private SubmitResponse<State> buildCounterClaimConfirmationResponse(
.build();
}

private PartyEntity getCurrentUserParty(long caseReference) {
UUID currentUserId = securityContextService.getCurrentUserId();
if (currentUserId == null) {
throw new IllegalStateException("Current user IDAM ID is null");
}
return partyService.getPartyEntityByIdamId(currentUserId, caseReference);
}

private String writeAsString(RespondPossessionClaimSubmitResponse submitResponse) {
try {
return objectMapper.writeValueAsString(submitResponse);
Expand Down
Loading
Loading