Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
be244b5
[SNI-8773] update bundle logic for further documents
oleon23 Mar 27, 2026
564db19
Merge branch 'master' into SNI-8773
oleon23 Mar 27, 2026
2372296
[SNI-8773] fix checkstyle test
oleon23 Mar 27, 2026
6478065
Merge remote-tracking branch 'origin/SNI-8773' into SNI-8773
oleon23 Mar 27, 2026
6b9b2c4
[SNI-8773] temporarily ignore IT
oleon23 Mar 27, 2026
92b1bf4
add label check for ccd diff
oleon23 Mar 27, 2026
f795f25
[SNI-8773] fix checkstyle IT
oleon23 Mar 27, 2026
3d5d688
[SNI-8773] fix tests
oleon23 Mar 27, 2026
85c31c8
[SNI-8773] fix checkstyle test
oleon23 Mar 27, 2026
eb09ae2
edit ccd-diff.yml
oleon23 Mar 27, 2026
ed79664
[SNI-8773] temp fix tests
oleon23 Mar 27, 2026
ed1a137
Merge branch 'master' into SNI-8773
oleon23 Mar 27, 2026
dddadf9
[SNI-8773] update unit tests for further docs uploaded
oleon23 Mar 27, 2026
f032517
Merge remote-tracking branch 'origin/SNI-8773' into SNI-8773
oleon23 Mar 27, 2026
8ccc27a
[SNI-8773] test minor updates
oleon23 Mar 27, 2026
a377f80
[SNI-8773] fix checkstyle test
oleon23 Mar 27, 2026
bb28d22
Merge branch 'refs/heads/master' into SNI-8773
oleon23 Apr 2, 2026
3153ed4
[SNI-8773] revert back to document lists instead of dates
oleon23 Apr 2, 2026
eb753ca
[SNI-8773] update tests
oleon23 Apr 7, 2026
1b0666d
Merge branch 'master' into SNI-8773
oleon23 Apr 8, 2026
8668765
[SNI-8773] ensure further documents are sorted
oleon23 Apr 8, 2026
5d56732
Merge remote-tracking branch 'origin/SNI-8773' into SNI-8773
oleon23 Apr 8, 2026
48d93a7
[SNI-8773] update comments
oleon23 Apr 8, 2026
297861b
[SNI-8773] add task for cron to migrate data, revert field rename
oleon23 Apr 10, 2026
bb48462
[SNI-8773] add new tests for CaseEventRepository
oleon23 Apr 13, 2026
eacb9d6
[SNI-8773] fix checkstyleTest
oleon23 Apr 13, 2026
60b37d8
[SNI-8773] add system task/event tests
oleon23 Apr 13, 2026
a3bee3a
Merge branch 'master' into SNI-8773
oleon23 Apr 13, 2026
3069cb5
Merge branch 'master' into SNI-8773
oleon23 Apr 14, 2026
be27284
Merge branch 'master' into SNI-8773
oleon23 Apr 16, 2026
eff6f1a
[SNI-8773] Update event to be component and adjust naming (less than …
oleon23 Apr 20, 2026
85850de
[SNI-8773] Update event migration query to use date range
oleon23 Apr 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
Expand Up @@ -6,13 +6,13 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import uk.gov.hmcts.ccd.sdk.api.CCDConfig;
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.ccd.sdk.type.ListValue;
import uk.gov.hmcts.sptribs.caseworker.util.DocumentListUtil;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.State;
import uk.gov.hmcts.sptribs.ciccase.model.UserRole;
Expand All @@ -38,7 +38,8 @@
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
import static uk.gov.hmcts.sptribs.caseworker.util.DocumentListUtil.getAllCaseDocumentsExcludingInitialCicaUpload;
import static uk.gov.hmcts.sptribs.caseworker.util.DocumentListUtil.extractDocumentsFromListValues;
import static uk.gov.hmcts.sptribs.caseworker.util.DocumentListUtil.getAllCaseDocuments;
import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CREATE_BUNDLE;
import static uk.gov.hmcts.sptribs.ciccase.model.State.AwaitingHearing;
import static uk.gov.hmcts.sptribs.ciccase.model.State.CaseClosed;
Expand Down Expand Up @@ -92,13 +93,12 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<C
CaseDetails<CaseData, State> beforeDetails) {

final CaseData caseData = details.getData();
final List<ListValue<CaseworkerCICDocument>> documentListValues = DocumentListUtil.getAllCaseDocuments(caseData);
final List<CaseworkerCICDocument> allCaseDocuments = extractDocumentsFromListValues(getAllCaseDocuments(caseData));

if (caseData.isBundleOrderEnabled()) {
caseData.setCaseDocuments(getInitialCicaUpload(caseData, details.getId()));
caseData.setFurtherCaseDocuments(getFurtherDocuments(caseData));
setCaseBundleRequestDocuments(caseData, allCaseDocuments);
} else {
var cicDocumentList = convertToBundleDocumentType(documentListValues);
var cicDocumentList = convertToBundleDocumentType(allCaseDocuments);
caseData.setCaseDocuments(cicDocumentList);
}

Expand All @@ -124,43 +124,36 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<C
.build();
}

private List<AbstractCaseworkerCICDocument<CaseworkerCICDocument>> getInitialCicaUpload(CaseData caseData, long caseId) {
var initialDocs = Optional.ofNullable(caseData.getInitialCicaDocuments()).orElse(emptyList());
private void setCaseBundleRequestDocuments(CaseData caseData, List<CaseworkerCICDocument> allDocuments) {
List<CaseworkerCICDocument> initialDocuments = extractDocumentsFromListValues(caseData.getInitialCicaDocuments());

if (initialDocs.isEmpty()) {
log.warn("Initial Cica doc upload was empty for case {}", caseId);
return emptyList();
if (!CollectionUtils.isEmpty(initialDocuments)) {
caseData.setCaseDocuments(convertToBundleDocumentType(initialDocuments));
caseData.setFurtherCaseDocuments(convertToBundleDocumentType(getFurtherDocuments(allDocuments, initialDocuments)));
} else {
caseData.setCaseDocuments(convertToBundleDocumentType(allDocuments));
}

return convertToBundleDocumentType(initialDocs);
}

private List<AbstractCaseworkerCICDocument<CaseworkerCICDocument>> getFurtherDocuments(CaseData caseData) {
var docs = getAllCaseDocumentsExcludingInitialCicaUpload(caseData);

var bundleDocuments = convertToBundleDocumentType(docs);

bundleDocuments.sort(
Comparator.comparing(
doc -> doc.getValue().getDate(),
private static List<CaseworkerCICDocument> getFurtherDocuments(List<CaseworkerCICDocument> allDocuments,
List<CaseworkerCICDocument> initialDocuments) {
if (CollectionUtils.isEmpty(allDocuments)) {
return new ArrayList<>();
}
if (CollectionUtils.isEmpty(initialDocuments)) {
return new ArrayList<>(allDocuments);
}
return allDocuments.stream().filter(doc -> !initialDocuments.contains(doc))
.sorted(Comparator.comparing(
CaseworkerCICDocument::getDate,
Comparator.nullsLast(Comparator.naturalOrder())
)
);
return bundleDocuments;
))
.collect(Collectors.toCollection(ArrayList::new));
}

private List<AbstractCaseworkerCICDocument<CaseworkerCICDocument>> convertToBundleDocumentType(
List<ListValue<CaseworkerCICDocument>> docs) {
List<AbstractCaseworkerCICDocument<CaseworkerCICDocument>> abstractCaseworkerCICDocumentList = new ArrayList<>();

for (ListValue<CaseworkerCICDocument> caseworkerCICDocumentListValue : docs) {
CaseworkerCICDocument document = caseworkerCICDocumentListValue.getValue();
if (document.isValidBundleDocument()) {
abstractCaseworkerCICDocumentList.add(new AbstractCaseworkerCICDocument<>(document));
}
}
private List<AbstractCaseworkerCICDocument<CaseworkerCICDocument>> convertToBundleDocumentType(List<CaseworkerCICDocument> docs) {

return abstractCaseworkerCICDocumentList;
return docs.stream().filter(CaseworkerCICDocument::isValidBundleDocument).map(AbstractCaseworkerCICDocument::new).toList();
}

private List<ListValue<Bundle>> getExistingBundles(CaseDetails<CaseData, State> beforeDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.List;

import static uk.gov.hmcts.sptribs.caseworker.util.DocumentListUtil.addToExistingDocumentList;
import static uk.gov.hmcts.sptribs.caseworker.util.DocumentListUtil.getAllCaseDocuments;
import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.RESPONDENT_DOCUMENT_MANAGEMENT;
import static uk.gov.hmcts.sptribs.ciccase.model.State.AwaitingHearing;
import static uk.gov.hmcts.sptribs.ciccase.model.State.AwaitingOutcome;
Expand Down Expand Up @@ -103,13 +105,10 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(final CaseDet

if (caseData.isBundleOrderEnabled()) {
if (auditEventService.hasCaseEvent(String.valueOf(details.getId()), RESPONDENT_DOCUMENT_MANAGEMENT)) {
if (caseData.getFurtherUploadedDocuments() == null) {
caseData.setFurtherUploadedDocuments(documents);
} else {
caseData.getFurtherUploadedDocuments().addAll(documents);
}
caseData.setFurtherUploadedDocuments(addToExistingDocumentList(caseData.getFurtherUploadedDocuments(), documents));
} else {
caseData.setInitialCicaDocuments(documents);
documents = getAllCaseDocuments(caseData);
caseData.setInitialCicaDocuments(addToExistingDocumentList(caseData.getInitialCicaDocuments(), documents));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static List<CaseworkerCICDocument> prepareListExcludingInitialCicaUpload

private static void prepareOtherCaseDocuments(CaseData data, List<CaseworkerCICDocument> docList) {
docList.addAll(getOrderDocuments(data.getCicCase()));
docList.addAll(getCaseDocs(data.getCicCase()));
docList.addAll(getApplicantCaseDocs(data.getCicCase()));
docList.addAll(getReinstateDocuments(data.getCicCase()));
docList.addAll(getDecisionDocs(data));
docList.addAll(getFinalDecisionDocs(data));
Expand All @@ -78,7 +78,7 @@ public static List<ListValue<CaseworkerCICDocument>> getAllCaseDocuments(final C
public static DynamicList prepareCICDocumentListWithAllDocuments(final CaseData data) {
List<DynamicListElement> dynamicListElements = new ArrayList<>();

dynamicListElements.addAll(getDynamicListElements(getCaseDocs(data.getCicCase()), CASE_TYPE));
dynamicListElements.addAll(getDynamicListElements(getApplicantCaseDocs(data.getCicCase()), CASE_TYPE));
dynamicListElements.addAll(getDynamicListElements(getReinstateDocuments(data.getCicCase()), REINSTATE_TYPE));
dynamicListElements.addAll(getDynamicListElements(getDocumentManagementDocs(data), DOC_MGMT_TYPE));
dynamicListElements.addAll(getDynamicListElements(getCloseCaseDocuments(data), CLOSE_CASE_TYPE));
Expand All @@ -90,6 +90,12 @@ public static DynamicList prepareCICDocumentListWithAllDocuments(final CaseData
.build();
}

public static List<CaseworkerCICDocument> extractDocumentsFromListValues(List<ListValue<CaseworkerCICDocument>> listValues) {
return CollectionUtils.isEmpty(listValues)
? new ArrayList<>()
: listValues.stream().map(ListValue::getValue).toList();
}

private static List<DynamicListElement> getDynamicListElements(List<CaseworkerCICDocument> docList, String fileType) {
return docList
.stream()
Expand Down Expand Up @@ -161,6 +167,15 @@ public static DynamicMultiSelectList prepareContactPartiesDocumentList(final Cas
.build();
}

public static List<ListValue<CaseworkerCICDocument>> addToExistingDocumentList(
List<ListValue<CaseworkerCICDocument>> existing,
List<ListValue<CaseworkerCICDocument>> toAdd) {
if (CollectionUtils.isEmpty(existing)) {
return toAdd;
}
existing.addAll(toAdd);
return existing;
}

private static void createDocumentList(String apiUrl, List<DynamicListElement> dynamicListElements, CaseworkerCICDocument doc) {
String documentId = StringUtils.substringAfterLast(doc.getDocumentLink().getUrl(),
Expand All @@ -183,7 +198,7 @@ private static List<CaseworkerCICDocument> getReinstateDocuments(CicCase cicCase
return reinstateDocList;
}

private static List<CaseworkerCICDocument> getCaseDocs(CicCase cicCase) {
private static List<CaseworkerCICDocument> getApplicantCaseDocs(CicCase cicCase) {
List<CaseworkerCICDocument> caseDocs = new ArrayList<>();
if (!CollectionUtils.isEmpty(cicCase.getApplicantDocumentsUploaded())) {
for (ListValue<CaseworkerCICDocument> document : cicCase.getApplicantDocumentsUploaded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ public class CaseData {
label = "Initial CICA Documents",
typeOverride = Collection,
typeParameterOverride = "CaseworkerCICDocument",
hint = "Initial case documents up to and including CICA initial submission",
access = {CollectionCreateUpdateOnlyAccess.class}
)
private List<ListValue<CaseworkerCICDocument>> initialCicaDocuments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ public class CaseEventRepository {
+ ")"
+ "SELECT * FROM events_with_context WHERE event_id = :caseEventId AND created_date >= :startDate AND created_date < :endDate";

private static final String SELECT_FIRST_EVENT_DATA_FOR_CASE =
"SELECT ce.data FROM ccd.case_event ce "
+ "WHERE ce.case_data_id = (SELECT id FROM ccd.case_data WHERE reference = :reference)"
+ "AND ce.event_id = :caseEventId "
+ "ORDER BY ce.created_date ASC "
+ "LIMIT 1";

public List<CaseData> getFirstEventDataForCase(Long reference, String caseEventId) {
Comment thread
oleon23 marked this conversation as resolved.
try {
return namedParameterJdbcTemplate.query(
SELECT_FIRST_EVENT_DATA_FOR_CASE,
Map.of(REFERENCE, reference, CASE_EVENT_ID, caseEventId),
(rs, rowNum) -> parseEventData(rs.getString("data"), reference)
);
} catch (DataAccessException e) {
log.error("Failed to retrieve first event data for reference={}", reference, e);
throw new CaseEventRepositoryException(
"Failed to retrieve first event data for reference=" + reference, e);
}
}

public List<Long> getListOfCasesByEventTypeAndDate(String caseEventId, LocalDate createdDate) {

List<Long> results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uk.gov.hmcts.ccd.sdk.type.Document;
import uk.gov.hmcts.ccd.sdk.type.ListValue;
import uk.gov.hmcts.sptribs.caseworker.model.Order;
import uk.gov.hmcts.sptribs.caseworker.util.DocumentListUtil;
import uk.gov.hmcts.sptribs.caseworker.util.DocumentRemoveListUtil;
import uk.gov.hmcts.sptribs.caseworker.util.SendOrderUtil;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
Expand All @@ -21,11 +22,12 @@
import java.util.stream.Collectors;

import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CASEWORKER_DOCUMENT_MANAGEMENT_REMOVE;
import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.RESPONDENT_DOCUMENT_MANAGEMENT;

@Slf4j
@Service
@RequiredArgsConstructor
public class OrdersListRestoreService {
public class CaseDataRestoreService {

private final CaseEventRepository caseEventRepository;

Expand Down Expand Up @@ -63,6 +65,19 @@ public void restoreOrdersList(Long reference, CaseData currentData, LocalDate st
restoredOrdersList.stream().map(ListValue::getValue).forEach(order -> SendOrderUtil.updateCicCaseOrderList(currentData, order));
}

public void updateInitialCaseDocuments(Long reference, CaseData currentCaseData) {
List<CaseData> caseDataFromEventList = caseEventRepository.getFirstEventDataForCase(reference, RESPONDENT_DOCUMENT_MANAGEMENT);
if (caseDataFromEventList.isEmpty()) {
log.warn("No event data found for reference={}, skipping", reference);
return;
}
CaseData caseDataBefore = caseDataFromEventList.getFirst();
var caseDocumentsAtRespondentUpload = DocumentListUtil.getAllCaseDocuments(caseDataBefore);
log.info("Updating initial case documents at respondent upload. Total number of case documents at respondent upload: {}",
caseDocumentsAtRespondentUpload.size());
currentCaseData.setInitialCicaDocuments(caseDocumentsAtRespondentUpload);
}

private List<ListValue<Order>> findRemovedEntries(RemoveEventWithPrecedingData event) {
List<ListValue<Order>> before = event.getPrecedingEventData().getCicCase().getOrderList();
List<ListValue<Order>> after = event.getCurrentEventData().getCicCase().getOrderList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package uk.gov.hmcts.sptribs.systemupdate.event;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.api.CCDConfig;
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.State;
import uk.gov.hmcts.sptribs.ciccase.model.UserRole;
import uk.gov.hmcts.sptribs.common.service.CaseDataRestoreService;

import static uk.gov.hmcts.sptribs.ciccase.model.UserRole.SYSTEM_UPDATE;
import static uk.gov.hmcts.sptribs.ciccase.model.access.Permissions.CREATE_READ_UPDATE_DELETE;

@RequiredArgsConstructor
@Component
public class SystemMigrateInitialCaseDocuments implements CCDConfig<CaseData, State, UserRole> {
public static final String SYSTEM_MIGRATE_INITIAL_CASE_DOCUMENTS = "migrate-initial-case-documents";

private final CaseDataRestoreService caseDataRestoreService;

@Override
public void configure(ConfigBuilder<CaseData, State, UserRole> configBuilder) {
configBuilder
.event(SYSTEM_MIGRATE_INITIAL_CASE_DOCUMENTS)
.forAllStates()
.name("System: Migrate initial docs")
.description("Migrate ")
.aboutToSubmitCallback(this::aboutToSubmit)
.grant(CREATE_READ_UPDATE_DELETE, SYSTEM_UPDATE);
}

public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<CaseData, State> caseDetails,
CaseDetails<CaseData, State> beforeDetails) {
CaseData caseData = caseDetails.getData();
Long reference = caseDetails.getId();

caseDataRestoreService.updateInitialCaseDocuments(reference, caseData);

return AboutToStartOrSubmitResponse.<CaseData, State>builder()
.data(caseData)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import uk.gov.hmcts.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.ciccase.model.State;
import uk.gov.hmcts.sptribs.ciccase.model.UserRole;
import uk.gov.hmcts.sptribs.common.service.OrdersListRestoreService;
import uk.gov.hmcts.sptribs.common.service.CaseDataRestoreService;

import java.time.LocalDate;

Expand All @@ -28,7 +28,7 @@ public class SystemRestoreOrders implements CCDConfig<CaseData, State, UserRole>

private static final LocalDate END_TO_DATE = LocalDate.of(2026, 3, 6);

private final OrdersListRestoreService ordersListRestoreService;
private final CaseDataRestoreService caseDataRestoreService;

@Override
public void configure(ConfigBuilder<CaseData, State, UserRole> configBuilder) {
Expand All @@ -46,7 +46,7 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<C
CaseData caseData = caseDetails.getData();
Long reference = caseDetails.getId();

ordersListRestoreService.restoreOrdersList(reference, caseData, START_FROM_DATE, END_TO_DATE);
caseDataRestoreService.restoreOrdersList(reference, caseData, START_FROM_DATE, END_TO_DATE);

return AboutToStartOrSubmitResponse.<CaseData, State>builder()
.data(caseData)
Expand Down
Loading
Loading