From 259a734a4b882343efd7c660fda829dcfffedc0c Mon Sep 17 00:00:00 2001 From: exceptionfactory Date: Fri, 19 Apr 2024 10:12:19 -0500 Subject: [PATCH] NIFI-12858 Corrected Order of Previous Property Values - Reversed default order of previous values to return oldest entries before newest entries Signed-off-by: Pierre Villard This closes #8673. --- .../service/EntityStoreAuditService.java | 3 ++- .../service/EntityStoreAuditServiceTest.java | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/EntityStoreAuditService.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/EntityStoreAuditService.java index eab8798312..097f099d65 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/EntityStoreAuditService.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/EntityStoreAuditService.java @@ -135,7 +135,8 @@ public class EntityStoreAuditService implements AuditService, Closeable { final Map> previousValuesFound = new LinkedHashMap<>(); final EntityIterable actionEntities = storeTransaction.find(EntityType.ACTION.getEntityType(), ActionEntity.SOURCE_ID.getProperty(), componentId); - for (Entity actionEntity : actionEntities) { + // Reverse default ordering to return oldest entries before newest entries + for (Entity actionEntity : actionEntities.reverse()) { final Entity configureDetails = actionEntity.getLink(ActionLink.CONFIGURE_DETAILS.getProperty()); if (configureDetails != null) { final String name = getProperty(configureDetails, ConfigureDetailsEntity.NAME); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/EntityStoreAuditServiceTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/EntityStoreAuditServiceTest.java index 2df1fabe6a..62492b9f34 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/EntityStoreAuditServiceTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/EntityStoreAuditServiceTest.java @@ -95,6 +95,8 @@ class EntityStoreAuditServiceTest { private static final String SECOND_VALUE = "SecondValue"; + private static final String THIRD_VALUE = "ThirdValue"; + private static final String DATABASE_FILE_EXTENSION = ".xd"; @TempDir @@ -331,7 +333,14 @@ class EntityStoreAuditServiceTest { secondConfigureDetails.setValue(SECOND_VALUE); secondAction.setActionDetails(secondConfigureDetails); - final Collection actions = Arrays.asList(firstAction, secondAction); + final FlowChangeAction thirdAction = newAction(); + thirdAction.setOperation(Operation.Configure); + final FlowChangeConfigureDetails thirdConfigureDetails = new FlowChangeConfigureDetails(); + thirdConfigureDetails.setName(SECOND_PROPERTY_NAME); + thirdConfigureDetails.setValue(THIRD_VALUE); + thirdAction.setActionDetails(thirdConfigureDetails); + + final Collection actions = Arrays.asList(firstAction, secondAction, thirdAction); service.addActions(actions); final Map> previousValues = service.getPreviousValues(SOURCE_ID); @@ -348,7 +357,14 @@ class EntityStoreAuditServiceTest { final List secondPreviousValues = previousValues.get(SECOND_PROPERTY_NAME); assertNotNull(secondPreviousValues); - final PreviousValue secondPreviousValue = secondPreviousValues.get(0); + + final PreviousValue thirdPreviousValue = secondPreviousValues.get(0); + assertNotNull(thirdPreviousValue); + assertEquals(THIRD_VALUE, thirdPreviousValue.getPreviousValue()); + assertNotNull(thirdPreviousValue.getTimestamp()); + assertEquals(USER_IDENTITY, thirdPreviousValue.getUserIdentity()); + + final PreviousValue secondPreviousValue = secondPreviousValues.get(1); assertNotNull(secondPreviousValue); assertEquals(SECOND_VALUE, secondPreviousValue.getPreviousValue()); assertNotNull(secondPreviousValue.getTimestamp());