Skip to content

Commit

Permalink
MGR-81 limit number of users for event filter (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Sep 16, 2019
1 parent 1b0a3c6 commit b93bd81
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions application-home/application.xml
Expand Up @@ -321,6 +321,7 @@
<properties>
<property id="clusterInterfaceName"
description="the name of the network interface who's first assigned IP address is used as system property appng.node.id in case it was not set an JVM startup">eth0</property>
<property id="eventFilterMaxUsers" description="The maximum number of users shown when filtering platform events">100</property>
<property id="eventReportReceivers"
description="a semicolon separted list of receviers for PlatformEventReportJob, additional to all users with role 'Event report receiver'"></property>
<property id="eventReportSender" description="the sender for the event report email">report@example.com</property>
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -73,36 +76,47 @@ public DataContainer getData(Site site, Application application, Environment env
SelectionGroup group = new SelectionGroup();
List<Selection> 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<String> 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<String>(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<String> applications = platformEventEventService.getApplications();
Selection applicationSelection = getStringSelection("eAp", applications, filter.getEAp(),
Selection applicationSelection = getStringSelection(EventFilter.APP, applications, filter.getEAp(),
MessageConstants.APPLICATION);
selections.add(applicationSelection);

List<String> 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<String> 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<PlatformEvent> events = platformEventEventService.getEvents(fieldProcessor.getPageable(), filter);
dataContainer.setPage(events);
return dataContainer;
Expand All @@ -115,9 +129,19 @@ private Selection getStringSelection(String id, List<String> 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 */
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PlatformEvent> events = platformEventEventService.getEvents(filter);
try {
try (ByteArrayOutputStream out = getEventReport(events, messageSource)) {
Expand Down
Expand Up @@ -46,7 +46,7 @@ public Page<PlatformEvent> 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());
Expand Down

0 comments on commit b93bd81

Please sign in to comment.