From 70be3c3c0b598546e83609440f74274eecd4ab6e Mon Sep 17 00:00:00 2001 From: Zlatin Todorinski Date: Thu, 19 Dec 2024 15:29:28 +0100 Subject: [PATCH] Fix bug that used an empty list of transactions to check for nodes --- CHANGELOG.md | 9 +++++++-- .../indexing/Alfresco7TrackingComponent.java | 8 ++++++-- .../indexing/Alfresco7TrackingComponentTest.java | 9 ++++++++- .../indexing/AlfrescoTrackingComponent.java | 8 ++++++-- .../indexing/AlfrescoTrackingComponentTest.java | 9 ++++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc73ba90..5477f552 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ --- title: Changelog - Alfred Health Processor -date: 31 May 2021 +date: 19 December 2024 report: true colorlinks: true --- @@ -22,7 +22,12 @@ Version template: # Alfresco Health Processor Changelog -## [0.5.6] - UNRELEASED +## [0.5.6] - 2024-12-19 + +### Fixed + +*[[#60](https://github.com/xenit-eu/alfresco-health-processor/pull/60)] Fix exception when searching for an empty list of transactions for nodes in Solr + ## [0.5.5] - 2024-12-16 diff --git a/alfresco-health-processor-platform/alfresco-7-upwards/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponent.java b/alfresco-health-processor-platform/alfresco-7-upwards/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponent.java index 17703529..5fa2ed85 100644 --- a/alfresco-health-processor-platform/alfresco-7-upwards/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponent.java +++ b/alfresco-health-processor-platform/alfresco-7-upwards/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponent.java @@ -5,6 +5,7 @@ import java.util.Set; import lombok.AllArgsConstructor; import org.alfresco.repo.search.SearchTrackingComponent; +import org.alfresco.repo.solr.NodeParameters; @AllArgsConstructor public class Alfresco7TrackingComponent implements TrackingComponent { @@ -18,9 +19,12 @@ public long getMaxTxnId() { @Override public Set getNodesForTxnIds(List txnIds) { + if(txnIds.isEmpty()) { + return new HashSet<>(); + } Set ret = new HashSet<>(); - - trackingComponent.getNodes(toNodeParameters(txnIds), node -> { + NodeParameters parameters = toNodeParameters(txnIds); + trackingComponent.getNodes(parameters, node -> { // TODO filter out deleted nodes? ret.add(new NodeInfo(node.getTransaction().getId(), node.getId(), node.getNodeRef())); return true; diff --git a/alfresco-health-processor-platform/alfresco-7-upwards/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponentTest.java b/alfresco-health-processor-platform/alfresco-7-upwards/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponentTest.java index f0ecf29f..fd8ddab9 100644 --- a/alfresco-health-processor-platform/alfresco-7-upwards/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponentTest.java +++ b/alfresco-health-processor-platform/alfresco-7-upwards/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/Alfresco7TrackingComponentTest.java @@ -8,6 +8,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import eu.xenit.alfresco.healthprocessor.indexing.TrackingComponent.NodeInfo; @@ -61,6 +63,11 @@ void getNodesForTxnIds() { new NodeInfo(1L, 102L, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "xyz-987")))); } + @Test + void getNodesForEmptyTxnIdList() { + trackingComponent.getNodesForTxnIds(Collections.emptyList()); + verify(searchTrackingComponent, never()).getNodes(any(), any()); + } private Node nodeEntity(long txnId, long nodeId, String uuid) { Node ret = mock(Node.class); @@ -73,4 +80,4 @@ private Node nodeEntity(long txnId, long nodeId, String uuid) { } -} \ No newline at end of file +} diff --git a/alfresco-health-processor-platform/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponent.java b/alfresco-health-processor-platform/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponent.java index cb24788e..d7244827 100644 --- a/alfresco-health-processor-platform/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponent.java +++ b/alfresco-health-processor-platform/src/main/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponent.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Set; import lombok.RequiredArgsConstructor; +import org.alfresco.repo.solr.NodeParameters; import org.alfresco.repo.solr.SOLRTrackingComponent; @RequiredArgsConstructor @@ -18,9 +19,12 @@ public long getMaxTxnId() { @Override public Set getNodesForTxnIds(List txnIds) { + if(txnIds.isEmpty()) { + return new HashSet<>(); + } Set ret = new HashSet<>(); - - trackingComponent.getNodes(toNodeParameters(txnIds), node -> { + NodeParameters parameters = toNodeParameters(txnIds); + trackingComponent.getNodes(parameters, node -> { // TODO filter out deleted nodes? ret.add(new NodeInfo(node.getTransaction().getId(), node.getId(), node.getNodeRef())); return true; diff --git a/alfresco-health-processor-platform/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponentTest.java b/alfresco-health-processor-platform/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponentTest.java index da3b3003..641ad4ad 100644 --- a/alfresco-health-processor-platform/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponentTest.java +++ b/alfresco-health-processor-platform/src/test/java/eu/xenit/alfresco/healthprocessor/indexing/AlfrescoTrackingComponentTest.java @@ -7,6 +7,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import eu.xenit.alfresco.healthprocessor.indexing.TrackingComponent.NodeInfo; @@ -60,6 +62,11 @@ void getNodesForTxnIds() { new NodeInfo(1L, 102L, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "xyz-987")))); } + @Test + void getNodesForEmptyTxnIdList() { + trackingComponent.getNodesForTxnIds(Collections.emptyList()); + verify(solrTrackingComponent, never()).getNodes(any(), any()); + } private Node nodeEntity(long txnId, long nodeId, String uuid) { Node ret = mock(Node.class); @@ -72,4 +79,4 @@ private Node nodeEntity(long txnId, long nodeId, String uuid) { } -} \ No newline at end of file +}