Skip to content

Commit

Permalink
MGR-123 keep id sort
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Oct 1, 2021
1 parent 61be9b1 commit fdd4129
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/org/appng/application/manager/business/Cache.java
Expand Up @@ -16,6 +16,7 @@
package org.appng.application.manager.business;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -44,6 +45,7 @@
import org.appng.core.controller.filter.PageCacheFilter;
import org.appng.core.service.CacheService;
import org.appng.xml.platform.SelectionGroup;
import org.appng.xml.platform.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -99,12 +101,21 @@ public DataContainer getData(Site site, Application application, Environment env

int cacheSize = allCacheEntries.size();
if (cacheSize > maxCacheEntries) {
fp.getFields().forEach(f -> f.setSort(null));
fp.getFields().stream().filter(f -> !"id".equals(f.getBinding())).forEach(f -> f.setSort(null));
for (int i = pageable.getOffset(); i < pageable.getOffset() + pageable.getPageSize(); i++) {
if (i < cacheSize) {
cacheEntries.add(new CacheEntry(allCacheEntries.get(i)));
}
}

SortOrder idOrder = fp.getField("id").getSort().getOrder();
if (null != idOrder) {
Collections.sort(cacheEntries, (e1, e2) -> StringUtils.compare(e1.getId(), e2.getId()));
if (SortOrder.DESC.equals(idOrder)) {
Collections.reverse(cacheEntries);
}
}

dataContainer.setPage(new PageImpl<>(cacheEntries, pageable, cacheSize));
} else {
String entryName = request.getParameter(F_ETR);
Expand Down

0 comments on commit fdd4129

Please sign in to comment.