Skip to content

Commit

Permalink
MGR-123
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Sep 1, 2021
1 parent 7dcb597 commit bfe28ed
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions application-home/application.xml
Expand Up @@ -344,6 +344,7 @@
<property id="databaseReportSender" description="the sender for the database report email">report@example.com</property>
<property id="databaseReportSubject" description="the subject for the database report email">appNG database report</property>
<property id="databaseReportText" description="the text for the database report email">See attached file for a report of the database related platform events.</property>
<property id="maxFilterableCacheEntries" description="The maximum number of cache entries that can be filtered/sorted">5000</property>
</properties>

</application>
65 changes: 42 additions & 23 deletions src/main/java/org/appng/application/manager/business/Cache.java
Expand Up @@ -37,13 +37,16 @@
import org.appng.api.model.Site;
import org.appng.api.support.SelectionFactory;
import org.appng.api.support.SelectionFactory.Selection;
import org.appng.application.manager.ManagerSettings;
import org.appng.application.manager.MessageConstants;
import org.appng.application.manager.service.ServiceAware;
import org.appng.core.controller.CachedResponse;
import org.appng.core.controller.filter.PageCacheFilter;
import org.appng.core.service.CacheService;
import org.appng.xml.platform.SelectionGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

/**
Expand All @@ -66,10 +69,10 @@ public class Cache extends ServiceAware implements ActionProvider<Void>, DataPro
private SelectionFactory selectionFactory;

public DataContainer getData(Site site, Application application, Environment environment, Options options,
Request request, FieldProcessor fieldProcessor) {
Request request, FieldProcessor fp) {
String mode = options.getString("mode", ID);
Integer siteId = options.getInteger("site", ID);
DataContainer dataContainer = new DataContainer(fieldProcessor);
DataContainer dataContainer = new DataContainer(fp);
if (STATISTICS.equals(mode)) {
List<Entry<String, String>> result = new ArrayList<>();
Map<String, String> cacheStatistics = getService().getCacheStatistics(siteId);
Expand All @@ -87,31 +90,47 @@ public DataContainer getData(Site site, Application application, Environment env
result.add(getStatEntry(request, cacheStatistics, CacheService.STATS_AVG_REMOVAL_TIME));
dataContainer.setItems(result);
} else if (ENTRIES.equals(mode)) {
Integer maxCacheEntries = application.getProperties()
.getInteger(ManagerSettings.MAX_FILTERABLE_CACHE_ENTRIES);

List<CachedResponse> allCacheEntries = getService().getCacheEntries(siteId);
List<CacheEntry> cacheEntries = new ArrayList<>();
String entryName = request.getParameter(F_ETR);
String entryType = request.getParameter(F_CTYPE);
boolean filterName = StringUtils.isNotBlank(entryName);
boolean filterType = StringUtils.isNotBlank(entryType);

for (CachedResponse entry : allCacheEntries) {
String entryId = entry.getId();
boolean nameMatches = !filterName || FilenameUtils
.wildcardMatch(entryId.substring(entryId.indexOf('/')), entryName, IOCase.INSENSITIVE);
boolean typeMatches = !filterType
|| FilenameUtils.wildcardMatch(entry.getContentType(), entryType, IOCase.INSENSITIVE);
if (nameMatches && typeMatches) {
cacheEntries.add(new CacheEntry(entry));
Pageable pageable = fp.getPageable();

int cacheSize = allCacheEntries.size();
if (cacheSize > maxCacheEntries) {
fp.getFields().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)));
}
}
dataContainer.setPage(new PageImpl<>(cacheEntries, pageable, cacheSize));
} else {
String entryName = request.getParameter(F_ETR);
String entryType = request.getParameter(F_CTYPE);
boolean filterName = StringUtils.isNotBlank(entryName);
boolean filterType = StringUtils.isNotBlank(entryType);

for (CachedResponse entry : allCacheEntries) {
String entryId = entry.getId();
boolean nameMatches = !filterName || FilenameUtils
.wildcardMatch(entryId.substring(entryId.indexOf('/')), entryName, IOCase.INSENSITIVE);
boolean typeMatches = !filterType
|| FilenameUtils.wildcardMatch(entry.getContentType(), entryType, IOCase.INSENSITIVE);
if (nameMatches && typeMatches) {
cacheEntries.add(new CacheEntry(entry));
}
}
}

Selection nameSelection = selectionFactory.getTextSelection(F_ETR, MessageConstants.NAME, entryName);
Selection typeSelection = selectionFactory.getTextSelection(F_CTYPE, MessageConstants.TYPE, entryType);
SelectionGroup selectionGroup = new SelectionGroup();
selectionGroup.getSelections().add(nameSelection);
selectionGroup.getSelections().add(typeSelection);
dataContainer.getSelectionGroups().add(selectionGroup);
dataContainer.setPage(cacheEntries, fieldProcessor.getPageable());
Selection nameSelection = selectionFactory.getTextSelection(F_ETR, MessageConstants.NAME, entryName);
Selection typeSelection = selectionFactory.getTextSelection(F_CTYPE, MessageConstants.TYPE, entryType);
SelectionGroup selectionGroup = new SelectionGroup();
selectionGroup.getSelections().add(nameSelection);
selectionGroup.getSelections().add(typeSelection);
dataContainer.getSelectionGroups().add(selectionGroup);
dataContainer.setPage(cacheEntries, pageable);
}
}
return dataContainer;
}
Expand Down

0 comments on commit bfe28ed

Please sign in to comment.