feat(manager-api-notifications): Allow notification subsystem to be disabled
New config option that allows dispatcher to drop any generated
notifications.
We could consider putting this on the production side if this proves
troublesome.
Closes:
MODIFY
manager/api/core/src/main/java/io/apiman/manager/api/core/config/ApiManagerConfig.java
manager/api/core/src/main/java/io/apiman/manager/api/core/config/ApiManagerConfig.java
@@ -52,6 +52,8 @@ public abstract class ApiManagerConfig {
public static final String APIMAN_MANAGER_FEATURES_ORG_CREATE_ADMIN_ONLY = "apiman-manager.config.features.org-create-admin-only"; //$NON-NLS-1$
+ public static final String APIMAN_MANAGER_CONFIG_NOTIFICATIONS = "apiman-manager.config.notifications";
+
/*
* Database/hibernate properties
*/
@@ -149,6 +151,10 @@ public abstract class ApiManagerConfig {
return rval;
}
+ public Map<String, String> getNotificationsConfig() {
+ return getPrefixedProperties(APIMAN_MANAGER_CONFIG_NOTIFICATIONS);
+ }
+
public boolean isAdminOnlyOrgCreationEnabled() {
return config.getBoolean(APIMAN_MANAGER_FEATURES_ORG_CREATE_ADMIN_ONLY, false);
}

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/NotificationService.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/NotificationService.java
package io.apiman.manager.api.service;
+import io.apiman.common.config.options.GenericOptionsParser;
import io.apiman.common.logging.ApimanLoggerFactory;
import io.apiman.common.logging.IApimanLogger;
import io.apiman.common.util.JsonUtil;
@@ -19,12 +20,14 @@ import io.apiman.manager.api.beans.search.SearchCriteriaBean;
import io.apiman.manager.api.beans.search.SearchResultsBean;
import io.apiman.manager.api.core.INotificationRepository;
import io.apiman.manager.api.core.IStorage;
+import io.apiman.manager.api.core.config.ApiManagerConfig;
import io.apiman.manager.api.notifications.mappers.NotificationMapper;
import io.apiman.manager.api.rest.impl.util.DataAccessUtilMixin;
import io.apiman.manager.api.security.ISecurityContext;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.enterprise.context.ApplicationScoped;
@@ -47,7 +50,7 @@ import org.jetbrains.annotations.Nullable;
public class NotificationService implements DataAccessUtilMixin {
private static final IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(NotificationService.class);
-
+ private NotificationServiceConfig config;
private IStorage storage;
private INotificationRepository notificationRepository;
private NotificationMapper notificationMapper;
@@ -56,6 +59,7 @@ public class NotificationService implements DataAccessUtilMixin {
@Inject
public NotificationService(
+ ApiManagerConfig config,
IStorage storage,
INotificationRepository notificationRepository,
NotificationMapper notificationMapper,
@@ -66,6 +70,7 @@ public class NotificationService implements DataAccessUtilMixin {
this.notificationMapper = notificationMapper;
this.notificationDispatcher = notificationDispatcher;
this.securityContext = securityContext;
+ this.config = new NotificationServiceConfig(config.getNotificationsConfig());
}
public NotificationService() {
@@ -133,6 +138,11 @@ public class NotificationService implements DataAccessUtilMixin {
* @param newNotification the new notification.
*/
public void sendNotification(@NotNull CreateNotificationDto newNotification) {
+ if (!config.isEnabled()) {
+ LOGGER.trace("Notifications subsystem is disabled. Notification {0} will not be sent", newNotification);
+ return;
+ }
+
LOGGER.debug("Creating new notification(s): {0}", newNotification);
List<UserDto> resolvedRecipients = calculateRecipients(newNotification.getRecipient());
@@ -249,4 +259,22 @@ public class NotificationService implements DataAccessUtilMixin {
.setPayload(event);
}
+ private static final class NotificationServiceConfig extends GenericOptionsParser {
+ static final boolean DEFAULT_NOTIFICATIONS_ENABLED = true;
+ private boolean enabled;
+
+ public NotificationServiceConfig(Map<String, String> options) {
+ super(options);
+ parseOptions();
+ }
+
+ private void parseOptions() {
+ this.enabled = getBool(keys("enable"), DEFAULT_NOTIFICATIONS_ENABLED);
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+ }
+
}

MODIFY
manager/ui/war/src/main/java/io/apiman/manager/ui/server/IUIConfig.java
manager/ui/war/src/main/java/io/apiman/manager/ui/server/IUIConfig.java
@@ -24,6 +24,11 @@ import io.apiman.manager.ui.server.beans.ApiAuthType;
*/
public interface IUIConfig {
+ /**
+ * @return true if the notifications UI elements should be enabled.
+ */
+ boolean isNotificationsEnabled();
+
/**
* Returns true if the metrics UI should be enabled.
*/

MODIFY
manager/ui/war/src/main/java/io/apiman/manager/ui/server/UIConfig.java
manager/ui/war/src/main/java/io/apiman/manager/ui/server/UIConfig.java
@@ -34,6 +34,7 @@ public class UIConfig implements IUIConfig {
public static final String APIMAN_MANAGER_UI_API_AUTH_TOKEN_GENERATOR = "apiman-manager-ui.api.authentication.token.generator"; //$NON-NLS-1$
public static final String APIMAN_MANAGER_UI_ENABLE_METRICS = "apiman-manager-ui.metrics.enable"; //$NON-NLS-1$
+ public static final String APIMAN_MANAGER_UI_ENABLE_NOTIFICATIONS = "apiman-manager.config.notifications.enable"; //$NON-NLS-1$
public static final String APIMAN_MANAGER_UI_PLATFORM = "apiman-manager-ui.platform"; //$NON-NLS-1$
public static final String APIMAN_MANAGER_UI_ORG_CREATE_ADMIN_ONLY = "apiman-manager-ui.org-create-admin-only"; //$NON-NLS-1$
@@ -50,6 +51,14 @@ public class UIConfig implements IUIConfig {
public UIConfig() {
}
+ /**
+ * @return true if notifications UI elements should be shown, else false.
+ */
+ @Override
+ public boolean isNotificationsEnabled() {
+ return config.getBoolean(UIConfig.APIMAN_MANAGER_UI_ENABLE_NOTIFICATIONS, true);
+ }
+
/**
* @see io.apiman.manager.ui.server.IUIConfig#isMetricsEnabled()
*/

MODIFY
manager/ui/war/src/main/java/io/apiman/manager/ui/server/beans/UiConfigurationBean.java
manager/ui/war/src/main/java/io/apiman/manager/ui/server/beans/UiConfigurationBean.java
@@ -25,6 +25,7 @@ public class UiConfigurationBean {
private String header;
private Boolean metrics;
+ private Boolean notifications;
private String platform = "community"; //$NON-NLS-1$
private String backToConsole;
private Boolean adminOnlyOrgCreation;
@@ -49,6 +50,22 @@ public class UiConfigurationBean {
this.header = header;
}
+ /**
+ * @return true if notifications subsystem enabled, else false
+ */
+ public Boolean getNotifications() {
+ return notifications;
+ }
+
+ /**
+ * Indicate whether the notification system is enabled/disabled to UI
+ *
+ * @param notifications status of notification system
+ */
+ public void setNotifications(Boolean notifications) {
+ this.notifications = notifications;
+ }
+
/**
* @return the metrics
*/

MODIFY
manager/ui/war/src/main/java/io/apiman/manager/ui/server/servlets/ConfigurationServlet.java
manager/ui/war/src/main/java/io/apiman/manager/ui/server/servlets/ConfigurationServlet.java
@@ -98,6 +98,7 @@ public class ConfigurationServlet extends AbstractUIServlet {
configBean.setApi(new ApiConfigurationBean());
configBean.getUi().setHeader("community"); //$NON-NLS-1$
configBean.getUi().setMetrics(getConfig().isMetricsEnabled());
+ configBean.getUi().setNotifications(getConfig().isNotificationsEnabled());
configBean.getUi().setPlatform(getConfig().getPlatform());
configBean.getUi().setAdminOnlyOrgCreation(getConfig().isAdminOnlyOrgCreationEnabled());
configBean.getApiman().setVersion(version.getVersionString());

feat(manager-api-notifications): Allow notification subsystem to be disabled

New config option that allows dispatcher to drop any generated
notifications.

We could consider putting this on the production side if this proves
troublesome.

Closes: #1558