NIFI-13532 Fixed Flow Configuration History Sorting when Filtered

This closes #9179

Signed-off-by: Joseph Witt <joewitt@apache.org>
This commit is contained in:
exceptionfactory 2024-08-14 21:03:42 -05:00 committed by Joseph Witt
parent 9d51c675cb
commit 98f55b21b8
No known key found for this signature in database
GPG Key ID: 9093BF854F811A1A
2 changed files with 46 additions and 7 deletions

View File

@ -336,10 +336,7 @@ public class EntityStoreAuditService implements AuditService, Closeable {
endTimestamp = endDate.getTime(); endTimestamp = endDate.getTime();
} }
final ActionEntity sortEntityProperty = getSortEntityProperty(actionQuery); final EntityIterable entities = storeTransaction.find(EntityType.ACTION.getEntityType(), ActionEntity.TIMESTAMP.getProperty(), startTimestamp, endTimestamp);
final boolean ascending = isAscending(actionQuery);
final EntityIterable sorted = storeTransaction.sort(EntityType.ACTION.getEntityType(), sortEntityProperty.getProperty(), ascending);
final EntityIterable entities = sorted.intersect(storeTransaction.find(EntityType.ACTION.getEntityType(), ActionEntity.TIMESTAMP.getProperty(), startTimestamp, endTimestamp));
final EntityIterable sourceEntities; final EntityIterable sourceEntities;
final String sourceId = actionQuery.getSourceId(); final String sourceId = actionQuery.getSourceId();
@ -359,7 +356,9 @@ public class EntityStoreAuditService implements AuditService, Closeable {
filteredEntities = sourceEntities.intersect(identityFiltered); filteredEntities = sourceEntities.intersect(identityFiltered);
} }
return filteredEntities; final ActionEntity sortEntityProperty = getSortEntityProperty(actionQuery);
final boolean ascending = isAscending(actionQuery);
return storeTransaction.sort(EntityType.ACTION.getEntityType(), sortEntityProperty.getProperty(), filteredEntities, ascending);
} }
private boolean isAscending(final HistoryQuery historyQuery) { private boolean isAscending(final HistoryQuery historyQuery) {

View File

@ -63,6 +63,8 @@ class EntityStoreAuditServiceTest {
private static final Date SECOND_ACTION_TIMESTAMP = new Date(97500); private static final Date SECOND_ACTION_TIMESTAMP = new Date(97500);
private static final Date THIRD_ACTION_TIMESTAMP = new Date(172800);
private static final Date PURGE_END_DATE = new Date(43200); private static final Date PURGE_END_DATE = new Date(43200);
private static final String USER_IDENTITY = "admin"; private static final String USER_IDENTITY = "admin";
@ -99,6 +101,8 @@ class EntityStoreAuditServiceTest {
private static final String DATABASE_FILE_EXTENSION = ".xd"; private static final String DATABASE_FILE_EXTENSION = ".xd";
private static final String SORT_ASCENDING = "ASC";
@TempDir @TempDir
File directory; File directory;
@ -248,6 +252,42 @@ class EntityStoreAuditServiceTest {
assertFalse(actionsFiltered.hasNext()); assertFalse(actionsFiltered.hasNext());
} }
@Test
void testAddActionsGetActionsQueryTimestampSortedSourceIdFiltered() {
final FlowChangeAction firstAction = newAction();
final FlowChangeAction secondAction = newAction();
secondAction.setTimestamp(SECOND_ACTION_TIMESTAMP);
final FlowChangeAction thirdAction = newAction();
thirdAction.setTimestamp(THIRD_ACTION_TIMESTAMP);
final Collection<Action> actions = Arrays.asList(firstAction, secondAction, thirdAction);
service.addActions(actions);
final HistoryQuery historyQuery = new HistoryQuery();
historyQuery.setSourceId(SOURCE_ID);
historyQuery.setSortOrder(SORT_ASCENDING);
final History actionsHistory = service.getActions(historyQuery);
assertNotNull(actionsHistory);
assertEquals(actionsHistory.getTotal(), actions.size());
assertNotNull(actionsHistory.getLastRefreshed());
final Collection<Action> actionsFound = actionsHistory.getActions();
assertNotNull(actionsFound);
final Iterator<Action> actionsFiltered = actionsFound.iterator();
assertTrue(actionsFiltered.hasNext());
final Action firstActionFound = actionsFiltered.next();
assertEquals(ACTION_TIMESTAMP, firstActionFound.getTimestamp());
final Action secondActionFound = actionsFiltered.next();
assertEquals(SECOND_ACTION_TIMESTAMP, secondActionFound.getTimestamp());
final Action thirdActionFound = actionsFiltered.next();
assertEquals(THIRD_ACTION_TIMESTAMP, thirdActionFound.getTimestamp());
}
@Test @Test
void testAddActionsPurgeActionsGetAction() { void testAddActionsPurgeActionsGetAction() {
final Action action = newAction(); final Action action = newAction();
@ -349,7 +389,7 @@ class EntityStoreAuditServiceTest {
final List<PreviousValue> firstPreviousValues = previousValues.get(FIRST_PROPERTY_NAME); final List<PreviousValue> firstPreviousValues = previousValues.get(FIRST_PROPERTY_NAME);
assertNotNull(firstPreviousValues); assertNotNull(firstPreviousValues);
final PreviousValue firstPreviousValue = firstPreviousValues.get(0); final PreviousValue firstPreviousValue = firstPreviousValues.getFirst();
assertNotNull(firstPreviousValue); assertNotNull(firstPreviousValue);
assertEquals(FIRST_VALUE, firstPreviousValue.getPreviousValue()); assertEquals(FIRST_VALUE, firstPreviousValue.getPreviousValue());
assertNotNull(firstPreviousValue.getTimestamp()); assertNotNull(firstPreviousValue.getTimestamp());
@ -358,7 +398,7 @@ class EntityStoreAuditServiceTest {
final List<PreviousValue> secondPreviousValues = previousValues.get(SECOND_PROPERTY_NAME); final List<PreviousValue> secondPreviousValues = previousValues.get(SECOND_PROPERTY_NAME);
assertNotNull(secondPreviousValues); assertNotNull(secondPreviousValues);
final PreviousValue thirdPreviousValue = secondPreviousValues.get(0); final PreviousValue thirdPreviousValue = secondPreviousValues.getFirst();
assertNotNull(thirdPreviousValue); assertNotNull(thirdPreviousValue);
assertEquals(THIRD_VALUE, thirdPreviousValue.getPreviousValue()); assertEquals(THIRD_VALUE, thirdPreviousValue.getPreviousValue());
assertNotNull(thirdPreviousValue.getTimestamp()); assertNotNull(thirdPreviousValue.getTimestamp());