Skip to content

Commit

Permalink
NIFI-13532 Fixed Flow Configuration History Sorting when Filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
exceptionfactory committed Aug 15, 2024
1 parent 30e8df6 commit ebdd500
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,7 @@ private EntityIterable findActionEntities(final HistoryQuery actionQuery, final
endTimestamp = endDate.getTime();
}

final ActionEntity sortEntityProperty = getSortEntityProperty(actionQuery);
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 entities = storeTransaction.find(EntityType.ACTION.getEntityType(), ActionEntity.TIMESTAMP.getProperty(), startTimestamp, endTimestamp);

final EntityIterable sourceEntities;
final String sourceId = actionQuery.getSourceId();
Expand All @@ -359,7 +356,9 @@ private EntityIterable findActionEntities(final HistoryQuery actionQuery, final
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class EntityStoreAuditServiceTest {

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 String USER_IDENTITY = "admin";
Expand Down Expand Up @@ -99,6 +101,8 @@ class EntityStoreAuditServiceTest {

private static final String DATABASE_FILE_EXTENSION = ".xd";

private static final String SORT_ASCENDING = "ASC";

@TempDir
File directory;

Expand Down Expand Up @@ -248,6 +252,42 @@ void testAddActionsGetActionsQueryStartDateFiltered() {
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
void testAddActionsPurgeActionsGetAction() {
final Action action = newAction();
Expand Down Expand Up @@ -349,7 +389,7 @@ void testAddActionsGetPreviousValues() {

final List<PreviousValue> firstPreviousValues = previousValues.get(FIRST_PROPERTY_NAME);
assertNotNull(firstPreviousValues);
final PreviousValue firstPreviousValue = firstPreviousValues.get(0);
final PreviousValue firstPreviousValue = firstPreviousValues.getFirst();
assertNotNull(firstPreviousValue);
assertEquals(FIRST_VALUE, firstPreviousValue.getPreviousValue());
assertNotNull(firstPreviousValue.getTimestamp());
Expand All @@ -358,7 +398,7 @@ void testAddActionsGetPreviousValues() {
final List<PreviousValue> secondPreviousValues = previousValues.get(SECOND_PROPERTY_NAME);
assertNotNull(secondPreviousValues);

final PreviousValue thirdPreviousValue = secondPreviousValues.get(0);
final PreviousValue thirdPreviousValue = secondPreviousValues.getFirst();
assertNotNull(thirdPreviousValue);
assertEquals(THIRD_VALUE, thirdPreviousValue.getPreviousValue());
assertNotNull(thirdPreviousValue.getTimestamp());
Expand Down

0 comments on commit ebdd500

Please sign in to comment.