From b93bd81f4931adbd54eb781ba7a0081bf8c7d276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=BCller?= Date: Mon, 16 Sep 2019 10:16:31 +0200 Subject: [PATCH] MGR-81 limit number of users for event filter (#19) --- application-home/application.xml | 1 + .../manager/business/PlatformEvents.java | 46 ++++++++++++++----- .../webservice/PlatformEventExport.java | 3 +- .../manager/service/PlatformEventService.java | 2 +- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/application-home/application.xml b/application-home/application.xml index cdc4961..27c386f 100644 --- a/application-home/application.xml +++ b/application-home/application.xml @@ -321,6 +321,7 @@ eth0 + 100 report@example.com diff --git a/src/main/java/org/appng/application/manager/business/PlatformEvents.java b/src/main/java/org/appng/application/manager/business/PlatformEvents.java index 533b64a..085f4b3 100644 --- a/src/main/java/org/appng/application/manager/business/PlatformEvents.java +++ b/src/main/java/org/appng/application/manager/business/PlatformEvents.java @@ -17,6 +17,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -36,6 +37,7 @@ import org.appng.api.model.Site; import org.appng.api.support.SelectionBuilder; import org.appng.api.support.SelectionFactory; +import org.appng.application.manager.ManagerSettings; import org.appng.application.manager.MessageConstants; import org.appng.application.manager.service.PlatformEventService; import org.appng.core.domain.PlatformEvent; @@ -54,6 +56,7 @@ @Service public class PlatformEvents implements DataProvider { + public static final String EVENT_FILTER = "eventFilter"; private static final FastDateFormat FDF = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); private PlatformEventService platformEventEventService; @@ -73,36 +76,47 @@ public DataContainer getData(Site site, Application application, Environment env SelectionGroup group = new SelectionGroup(); List selections = group.getSelections(); - Selection typeFilter = selectionFactory.fromEnum("eT", MessageConstants.TYPE, PlatformEvent.Type.values(), - filter.eventTypes()); + Selection typeFilter = selectionFactory.fromEnum(EventFilter.TYPE, MessageConstants.TYPE, + PlatformEvent.Type.values(), filter.eventTypes()); typeFilter.setType(SelectionType.CHECKBOX); selections.add(typeFilter); - selections.add(selectionFactory.getTextSelection("eX", MessageConstants.EVENT, filter.getEX())); + selections.add(selectionFactory.getTextSelection(EventFilter.EVENT, MessageConstants.EVENT, filter.getEX())); List users = platformEventEventService.getUsers(); - Selection userSelection = getStringSelection("eU", users, filter.getEU(), MessageConstants.USER); + Selection userSelection; + if (users.size() > application.getProperties().getInteger(ManagerSettings.EVENT_FILTER_MAX_USERS)) { + String username = StringUtils.trimToEmpty(filter.getEU()); + userSelection = new SelectionBuilder(EventFilter.USER).title(MessageConstants.USER) + .options(Arrays.asList(username)).select(username).type(SelectionType.TEXT).build(); + } else { + userSelection = getStringSelection(EventFilter.USER, users, filter.getEU(), MessageConstants.USER); + } selections.add(userSelection); List applications = platformEventEventService.getApplications(); - Selection applicationSelection = getStringSelection("eAp", applications, filter.getEAp(), + Selection applicationSelection = getStringSelection(EventFilter.APP, applications, filter.getEAp(), MessageConstants.APPLICATION); selections.add(applicationSelection); List hostNames = platformEventEventService.getOrigins(); - Selection hostSelection = getStringSelection("eH", hostNames, filter.getEH(), MessageConstants.HOST); + Selection hostSelection = getStringSelection(EventFilter.HOST, hostNames, filter.getEH(), + MessageConstants.HOST); selections.add(hostSelection); List hosts = platformEventEventService.getHostNames(); - Selection hostNameSelection = getStringSelection("eN", hosts, filter.getEN(), MessageConstants.HOST_NAME); + Selection hostNameSelection = getStringSelection(EventFilter.HOSTNAME, hosts, filter.getEN(), + MessageConstants.HOST_NAME); selections.add(hostNameSelection); - selections.add(selectionFactory.getDateSelection("eA", MessageConstants.CREATED_AFTER, filter.getEA(), FDF)); - selections.add(selectionFactory.getDateSelection("eB", MessageConstants.CREATED_BEFORE, filter.getEB(), FDF)); + selections.add(selectionFactory.getDateSelection(EventFilter.AFTER, MessageConstants.CREATED_AFTER, + filter.getEA(), FDF)); + selections.add(selectionFactory.getDateSelection(EventFilter.BEFORE, MessageConstants.CREATED_BEFORE, + filter.getEB(), FDF)); DataContainer dataContainer = new DataContainer(fieldProcessor); dataContainer.getSelectionGroups().add(group); - environment.setAttribute(Scope.SESSION, "eventFilter", filter.copy()); + environment.setAttribute(Scope.SESSION, EVENT_FILTER, filter.copy()); Page events = platformEventEventService.getEvents(fieldProcessor.getPageable(), filter); dataContainer.setPage(events); return dataContainer; @@ -115,9 +129,19 @@ private Selection getStringSelection(String id, List values, String sele } @Data - @Component("eventFilter") + @Component(EVENT_FILTER) @RequestScope(proxyMode = ScopedProxyMode.TARGET_CLASS) public static class EventFilter implements DataProvider, Serializable { + + static final String BEFORE = "eB"; + static final String AFTER = "eA"; + static final String EVENT = "eX"; + static final String USER = "eU"; + static final String HOST = "eH"; + static final String HOSTNAME = "eN"; + static final String APP = "eAp"; + static final String TYPE = "eT"; + /** before */ private Date eB; /** after */ diff --git a/src/main/java/org/appng/application/manager/business/webservice/PlatformEventExport.java b/src/main/java/org/appng/application/manager/business/webservice/PlatformEventExport.java index b0ef8c6..050bd1d 100644 --- a/src/main/java/org/appng/application/manager/business/webservice/PlatformEventExport.java +++ b/src/main/java/org/appng/application/manager/business/webservice/PlatformEventExport.java @@ -22,6 +22,7 @@ import org.appng.api.model.Application; import org.appng.api.model.Site; import org.appng.application.manager.MessageConstants; +import org.appng.application.manager.business.PlatformEvents; import org.appng.application.manager.business.PlatformEvents.EventFilter; import org.appng.application.manager.service.PlatformEventService; import org.appng.core.domain.PlatformEvent; @@ -51,7 +52,7 @@ public byte[] processRequest(Site site, Application application, Environment env throws BusinessException { if (environment.isSubjectAuthenticated() && request.getPermissionProcessor().hasPermission("platform.events")) { - EventFilter filter = environment.getAttribute(Scope.SESSION, "eventFilter"); + EventFilter filter = environment.getAttribute(Scope.SESSION, PlatformEvents.EVENT_FILTER); List events = platformEventEventService.getEvents(filter); try { try (ByteArrayOutputStream out = getEventReport(events, messageSource)) { diff --git a/src/main/java/org/appng/application/manager/service/PlatformEventService.java b/src/main/java/org/appng/application/manager/service/PlatformEventService.java index cfee365..4851b76 100644 --- a/src/main/java/org/appng/application/manager/service/PlatformEventService.java +++ b/src/main/java/org/appng/application/manager/service/PlatformEventService.java @@ -46,7 +46,7 @@ public Page getEvents(Pageable pageable, EventFilter eventFilter) query.equals("origin", StringUtils.trimToNull(eventFilter.getEH())); query.equals("hostName", StringUtils.trimToNull(eventFilter.getEN())); if (StringUtils.isNotBlank(eventFilter.getEU())) { - query.equals("user", eventFilter.getEU()); + query.contains("user", eventFilter.getEU()); } query.equals("application", StringUtils.trimToNull(eventFilter.getEAp())); query.in("type", eventFilter.eventTypes());