Fix issue with recent activity sorting

This commit is contained in:
George Kalampokis 2021-10-12 15:41:20 +03:00
parent 7fe84d7de5
commit 29919f981a
1 changed files with 17 additions and 2 deletions

View File

@ -38,6 +38,7 @@ import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@ -338,7 +339,7 @@ public class DashBoardManager {
}/*);*/
//GK: Shuffle the deck otherwise we will summon the DMPodia when sorting with status
int pos = -1;
/*int pos = -1;
for (int i = (recentActivityModels.size() / 2); i < recentActivityModels.size(); i++) {
RecentActivityModel recentActivityModel = recentActivityModels.remove(i);
while (pos < recentActivityModels.size()) {
@ -348,7 +349,21 @@ public class DashBoardManager {
}
}
recentActivityModels.add(pos, recentActivityModel);
}
}*/
//GK: No one likes to play shuffle with the recent activities. So just re-sort them based on how they have been sorted already
recentActivityModels = recentActivityModels.stream().sorted((o1, o2) -> {
try {
String order = tableRequest.getOrderings().getFields().get(0).toCharArray()[0] + "";
String field = tableRequest.getOrderings().getFields().get(0).substring(1);
field = field.equals("label") ? "title" : field;
field = field.substring(0, 1).toUpperCase() + field.substring(1);
return (order.equals("+") ? 1 : -1 ) * ((Comparable)o1.getClass().getMethod("get" + field).invoke(o1)).compareTo(o2.getClass().getMethod("get" + field).invoke(o2));
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
logger.error(e.getLocalizedMessage(), e);
}
return 0;
}).collect(Collectors.toList());
//CompletableFuture.allOf(future).join();
// CompletableFuture.allOf(dmps, datasets).join();