Skip to content

Commit

Permalink
MGR-71 fix possible NPEs when building filters (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Sep 16, 2019
1 parent be5c578 commit 0eb866c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Expand Up @@ -17,6 +17,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -83,7 +84,7 @@ public DataContainer getData(Site site, Application application, Environment env

selections.add(selectionFactory.getTextSelection(EventFilter.EVENT, MessageConstants.EVENT, filter.getEX()));

List<String> users = platformEventEventService.getUsers();
Collection<String> users = platformEventEventService.getUsers();
Selection userSelection;
if (users.size() > application.getProperties().getInteger(ManagerSettings.EVENT_FILTER_MAX_USERS)) {
String username = StringUtils.trimToEmpty(filter.getEU());
Expand All @@ -94,17 +95,17 @@ public DataContainer getData(Site site, Application application, Environment env
}
selections.add(userSelection);

List<String> applications = platformEventEventService.getApplications();
Collection<String> applications = platformEventEventService.getApplications();
Selection applicationSelection = getStringSelection(EventFilter.APP, applications, filter.getEAp(),
MessageConstants.APPLICATION);
selections.add(applicationSelection);

List<String> hostNames = platformEventEventService.getOrigins();
Collection<String> hostNames = platformEventEventService.getOrigins();
Selection hostSelection = getStringSelection(EventFilter.HOST, hostNames, filter.getEH(),
MessageConstants.HOST);
selections.add(hostSelection);

List<String> hosts = platformEventEventService.getHostNames();
Collection<String> hosts = platformEventEventService.getHostNames();
Selection hostNameSelection = getStringSelection(EventFilter.HOSTNAME, hosts, filter.getEN(),
MessageConstants.HOST_NAME);
selections.add(hostNameSelection);
Expand All @@ -122,7 +123,7 @@ public DataContainer getData(Site site, Application application, Environment env
return dataContainer;
}

private Selection getStringSelection(String id, List<String> values, String selected, String label) {
private Selection getStringSelection(String id, Collection<String> values, String selected, String label) {
SelectionBuilder<String> builder = new SelectionBuilder<String>(id);
return builder.title(label).options(values).select(selected).type(SelectionType.SELECT)
.defaultOption(StringUtils.EMPTY, StringUtils.EMPTY).build();
Expand Down
Expand Up @@ -15,7 +15,10 @@
*/
package org.appng.application.manager.service;

import java.util.Collection;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import org.apache.commons.lang3.StringUtils;
import org.appng.application.manager.business.PlatformEvents.EventFilter;
Expand Down Expand Up @@ -58,19 +61,25 @@ public List<PlatformEvent> getEvents(EventFilter eventFilter) {
return getEvents(new PageRequest(0, Integer.MAX_VALUE), eventFilter).getContent();
}

public List<String> getUsers() {
return platformEventRepository.findDistinctUsers();
public Collection<String> getUsers() {
return removeNulls(platformEventRepository.findDistinctUsers());
}

public List<String> getApplications() {
return platformEventRepository.findDistinctApplications();
public Collection<String> getApplications() {
return removeNulls(platformEventRepository.findDistinctApplications());
}

public List<String> getHostNames() {
return platformEventRepository.findDistinctHostNames();
public Collection<String> getHostNames() {
return removeNulls(platformEventRepository.findDistinctHostNames());
}

public List<String> getOrigins() {
return platformEventRepository.findDistinctOrigins();
public Collection<String> getOrigins() {
return removeNulls(platformEventRepository.findDistinctOrigins());
}

private Collection<String> removeNulls(List<String> items) {
SortedSet<String> set = new TreeSet<>(items);
set.remove(null);
return set;
}
}

0 comments on commit 0eb866c

Please sign in to comment.