From 56d1c8838d73ef24c57d68b4406f4453fc982b61 Mon Sep 17 00:00:00 2001 From: fudge88 Date: Mon, 30 Mar 2026 16:32:18 +0100 Subject: [PATCH 1/4] dashboard event configured - hardcoded case issued --- .../reform/pcs/ccd/event/DashboardView.java | 37 +++++++++ .../hmcts/reform/pcs/ccd/event/EventId.java | 3 +- .../dashboard/StartDashboardViewHandler.java | 75 +++++++++++++++++++ .../dashboard/SubmitDashboardViewHandler.java | 23 ++++++ .../dashboard/DashboardJourneyService.java | 56 ++++++++++++++ 5 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java create mode 100644 src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java create mode 100644 src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java create mode 100644 src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java new file mode 100644 index 0000000000..0b6997adca --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.reform.pcs.ccd.event; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import uk.gov.hmcts.ccd.sdk.api.CCDConfig; +import uk.gov.hmcts.ccd.sdk.api.DecentralisedConfigBuilder; +import uk.gov.hmcts.ccd.sdk.api.Permission; +import uk.gov.hmcts.reform.pcs.ccd.ShowConditions; +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.event.dashboard.StartDashboardViewHandler; +import uk.gov.hmcts.reform.pcs.ccd.event.dashboard.SubmitDashboardViewHandler; + +import static uk.gov.hmcts.reform.pcs.ccd.event.EventId.dashboardView; + +@Component +@Slf4j +@RequiredArgsConstructor +public class DashboardView implements CCDConfig { + + private final StartDashboardViewHandler startDashboardViewHandler; + private final SubmitDashboardViewHandler submitDashboardViewHandler; + + @Override + public void configureDecentralised(final DecentralisedConfigBuilder configBuilder) { + configBuilder + .decentralisedEvent(dashboardView.name(), submitDashboardViewHandler, startDashboardViewHandler) + .forState(State.CASE_ISSUED) + .showCondition(ShowConditions.NEVER_SHOW) + .name("Dashboard view") + .description("Compute dashboard notifications for case journey") + .grant(Permission.CRU, UserRole.DEFENDANT); + } +} + diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/EventId.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/EventId.java index 3a84e15878..903d63e465 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/EventId.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/EventId.java @@ -7,5 +7,6 @@ public enum EventId { enforceTheOrder, respondPossessionClaim, submitDefendantResponse, - createTestCase + createTestCase, + dashboardView } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java new file mode 100644 index 0000000000..01eb9d96a1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java @@ -0,0 +1,75 @@ +package uk.gov.hmcts.reform.pcs.ccd.event.dashboard; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +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.Start; +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.event.EventId; +import uk.gov.hmcts.reform.pcs.ccd.service.DraftCaseDataService; +import uk.gov.hmcts.reform.pcs.ccd.service.dashboard.DashboardJourneyService; +import uk.gov.hmcts.reform.pcs.dashboard.model.DashboardNotification; + +import java.util.List; +import java.util.Optional; + +import static uk.gov.hmcts.reform.pcs.ccd.event.EventId.respondPossessionClaim; + +@Component +@Slf4j +@RequiredArgsConstructor +public class StartDashboardViewHandler implements Start { + + private final DraftCaseDataService draftCaseDataService; + private final DashboardJourneyService dashboardJourneyService; + private final ObjectMapper objectMapper; + + @Override + public PCSCase start(EventPayload eventPayload) { + long caseReference = eventPayload.caseReference(); + State state = State.CASE_ISSUED; + + PCSCase submittedCaseData = eventPayload.caseData(); + + Optional draftForRespondPossession = getDraft(caseReference, respondPossessionClaim); + + List notifications = dashboardJourneyService.computeNotifications( + caseReference, + state, + submittedCaseData, + draftForRespondPossession + ); + + String payloadJson = toPayloadJson(caseReference, notifications); + + submittedCaseData.setCaseTitleMarkdown(payloadJson); + return submittedCaseData; + } + + private Optional getDraft(long caseReference, EventId eventId) { + try { + return draftCaseDataService.getUnsubmittedCaseData(caseReference, eventId); + } catch (Exception e) { + log.warn("Failed to load draft case data for caseReference={} eventId={}", caseReference, eventId, e); + return Optional.empty(); + } + } + + private String toPayloadJson(long caseReference, List notifications) { + DashboardPayload payload = new DashboardPayload(notifications); + try { + return objectMapper.writeValueAsString(payload); + } catch (JsonProcessingException e) { + log.error("Failed to serialise dashboard payload for caseReference={}", caseReference, e); + return "{\"notifications\":[]}"; + } + } + + private record DashboardPayload(List notifications) { + } +} + diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java new file mode 100644 index 0000000000..9d8f643eb8 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java @@ -0,0 +1,23 @@ +package uk.gov.hmcts.reform.pcs.ccd.event.dashboard; + +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.Submit; +import uk.gov.hmcts.ccd.sdk.api.callback.SubmitResponse; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.State; + +@Component +@Slf4j +@RequiredArgsConstructor +public class SubmitDashboardViewHandler implements Submit { + + @Override + public SubmitResponse submit(EventPayload eventPayload) { + // READ-ONLY: the dashboard view event should not persist changes. + return SubmitResponse.defaultResponse(); + } +} + diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java new file mode 100644 index 0000000000..4c8de29018 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java @@ -0,0 +1,56 @@ +package uk.gov.hmcts.reform.pcs.ccd.service.dashboard; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.State; +import uk.gov.hmcts.reform.pcs.dashboard.model.DashboardNotification; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * Computes dashboard notifications (template IDs + values) from submitted and draft case data. + * + *

READ-ONLY: callers are responsible for loading any data needed and passing it in.

+ */ +@Service +@Slf4j +@RequiredArgsConstructor +public class DashboardJourneyService { + + public List computeNotifications(long caseReference, + State state, + PCSCase submittedCaseData, + Optional draftCaseData) { + + boolean hasDraft = draftCaseData.isPresent(); + + if (state == State.CASE_ISSUED) { + DashboardNotification journeyNotification = DashboardNotification.builder() + .templateId("Notice.PCS.Dashboard.CaseIssued") + .templateValues(Map.of( + "caseReference", caseReference, + "hasDraft", hasDraft + )) + .build(); + + return List.of(journeyNotification); + } + + if (state == State.AWAITING_SUBMISSION_TO_HMCTS && hasDraft) { + DashboardNotification resumeNotification = DashboardNotification.builder() + .templateId("Notice.PCS.Dashboard.DraftInProgress") + .templateValues(Map.of( + "caseReference", caseReference + )) + .build(); + return List.of(resumeNotification); + } + + return List.of(); + } +} + From 7c257dccf9a4bbab5123b346c43112f9a315c723 Mon Sep 17 00:00:00 2001 From: fudge88 Date: Tue, 31 Mar 2026 10:24:10 +0100 Subject: [PATCH 2/4] console.logs --- build.gradle | 8 +++++++- .../event/dashboard/StartDashboardViewHandler.java | 14 ++++++++++++++ .../dashboard/SubmitDashboardViewHandler.java | 2 ++ .../service/dashboard/DashboardJourneyService.java | 9 +++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index fad90c64f8..85ccd378e9 100644 --- a/build.gradle +++ b/build.gradle @@ -326,7 +326,13 @@ sonarqube { "**/uk/gov/hmcts/reform/pcs/ccd/domain/**/*.java," + "**/uk/gov/hmcts/reform/pcs/ccd/page/**/*.java," + "**/uk/gov/hmcts/reform/pcs/ccd/entity/**/*.java," + - "**/entities/**," + "**/model/**," + "**/uk/gov/hmcts/reform/pcs/testingsupport/**/*.java" + "**/entities/**," + + "**/model/**," + + "**/uk/gov/hmcts/reform/pcs/testingsupport/**/*.java," + + "**/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java," + + "**/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java," + + "**/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java," + + "**/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java" property "sonar.cpd.exclusions", "**/uk/gov/hmcts/reform/pcs/ccd/domain/enforcetheorder/warrant/StatementOfTruthDetails.java" } } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java index 01eb9d96a1..d008a6435c 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/StartDashboardViewHandler.java @@ -33,10 +33,16 @@ public PCSCase start(EventPayload eventPayload) { long caseReference = eventPayload.caseReference(); State state = State.CASE_ISSUED; + log.info("DashboardView START invoked for caseReference={}, assumedState={}", caseReference, state); + PCSCase submittedCaseData = eventPayload.caseData(); Optional draftForRespondPossession = getDraft(caseReference, respondPossessionClaim); + boolean hasDraft = draftForRespondPossession.isPresent(); + log.info("DashboardView START loaded data for caseReference={}, hasRespondPossessionDraft={}", + caseReference, hasDraft); + List notifications = dashboardJourneyService.computeNotifications( caseReference, state, @@ -44,14 +50,22 @@ public PCSCase start(EventPayload eventPayload) { draftForRespondPossession ); + log.info("DashboardView START computed {} dashboard notification(s) for caseReference={}", + notifications.size(), caseReference); + String payloadJson = toPayloadJson(caseReference, notifications); + log.info("DashboardView START serialised dashboard payload for caseReference={} (length={} chars)", + caseReference, payloadJson.length()); + submittedCaseData.setCaseTitleMarkdown(payloadJson); return submittedCaseData; } private Optional getDraft(long caseReference, EventId eventId) { try { + log.info("DashboardView START attempting to load draft for caseReference={}, eventId={}", + caseReference, eventId); return draftCaseDataService.getUnsubmittedCaseData(caseReference, eventId); } catch (Exception e) { log.warn("Failed to load draft case data for caseReference={} eventId={}", caseReference, eventId, e); diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java index 9d8f643eb8..f42f914fd2 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/dashboard/SubmitDashboardViewHandler.java @@ -16,6 +16,8 @@ public class SubmitDashboardViewHandler implements Submit { @Override public SubmitResponse submit(EventPayload eventPayload) { + long caseReference = eventPayload.caseReference(); + log.info("DashboardView SUBMIT invoked for caseReference={} (no-op submit, read-only event)", caseReference); // READ-ONLY: the dashboard view event should not persist changes. return SubmitResponse.defaultResponse(); } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java index 4c8de29018..c3bdef9f2f 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java @@ -28,6 +28,9 @@ public List computeNotifications(long caseReference, boolean hasDraft = draftCaseData.isPresent(); + log.info("DashboardJourneyService.computeNotifications called for caseReference={}, state={}, hasDraft={}", + caseReference, state, hasDraft); + if (state == State.CASE_ISSUED) { DashboardNotification journeyNotification = DashboardNotification.builder() .templateId("Notice.PCS.Dashboard.CaseIssued") @@ -37,6 +40,8 @@ public List computeNotifications(long caseReference, )) .build(); + log.info("DashboardJourneyService selected templateId={} for caseReference={}, state={}", + journeyNotification.getTemplateId(), caseReference, state); return List.of(journeyNotification); } @@ -47,9 +52,13 @@ public List computeNotifications(long caseReference, "caseReference", caseReference )) .build(); + log.info("DashboardJourneyService selected templateId={} for caseReference={}, state={}", + resumeNotification.getTemplateId(), caseReference, state); return List.of(resumeNotification); } + log.info("DashboardJourneyService found no matching dashboard notification rules for caseReference={}, state={}", + caseReference, state); return List.of(); } } From 09909b1b689d57104f4b08f42de9dc3f97af3ce2 Mon Sep 17 00:00:00 2001 From: fudge88 Date: Tue, 31 Mar 2026 11:59:26 +0100 Subject: [PATCH 3/4] checksum lien break issue fix --- .../pcs/ccd/service/dashboard/DashboardJourneyService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java index c3bdef9f2f..ef28766e68 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/dashboard/DashboardJourneyService.java @@ -57,8 +57,9 @@ public List computeNotifications(long caseReference, return List.of(resumeNotification); } - log.info("DashboardJourneyService found no matching dashboard notification rules for caseReference={}, state={}", - caseReference, state); + log.info( + "DashboardJourneyService no matching dashboard notification rules for caseReference={}, state={}", + caseReference, state); return List.of(); } } From e064b50545fed9f4196e93981ac4f903e91fde88 Mon Sep 17 00:00:00 2001 From: fudge88 Date: Wed, 1 Apr 2026 10:18:52 +0100 Subject: [PATCH 4/4] all states for testing --- .../java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java index 0b6997adca..8b00a66a57 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/DashboardView.java @@ -27,7 +27,8 @@ public class DashboardView implements CCDConfig { public void configureDecentralised(final DecentralisedConfigBuilder configBuilder) { configBuilder .decentralisedEvent(dashboardView.name(), submitDashboardViewHandler, startDashboardViewHandler) - .forState(State.CASE_ISSUED) + // TODO: HDPI-5421 - Revist this once we have clarification on the states we need + .forAllStates() .showCondition(ShowConditions.NEVER_SHOW) .name("Dashboard view") .description("Compute dashboard notifications for case journey")