100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Send notifications to user from manager admin
Christian Bauer01688be4d428
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.java b/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.javaindex 4268c0b37..bacf983e8 100644--- a/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.java+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.java@@ -53,6 +53,8 @@ public class AdminModule extends AbstractGinModule {bind(AdminUsersActivity.class);bind(AdminUser.class).to(AdminUserImpl.class).in(Singleton.class);bind(AdminUserActivity.class);++ bind(AdminUserNotificationEditor.class).to(AdminUserNotificationEditorImpl.class).in(Singleton.class);}@Providesdiff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/AlertNotificationMapper.java b/manager/client/src/main/java/org/openremote/manager/client/admin/AlertNotificationMapper.javanew file mode 100644index 000000000..357adc633--- /dev/null+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/AlertNotificationMapper.java@@ -0,0 +1,32 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.manager.client.admin;++import com.github.nmorel.gwtjackson.client.ObjectMapper;+import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;+import org.openremote.manager.client.interop.jackson.DefaultJsonMixin;+import org.openremote.manager.shared.http.EntityWriter;+import org.openremote.model.notification.AlertNotification;++@JsonMixIns({@JsonMixIns.JsonMixIn(target = AlertNotification.class, mixIn = DefaultJsonMixin.class)})+public interface AlertNotificationMapper+ extends ObjectMapper<AlertNotification>,+ EntityWriter<AlertNotification> {+}diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUser.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUser.javaindex 48d54a5a9..8539ae4ec 100644--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUser.java@@ -29,6 +29,8 @@ public interface AdminUser extends AdminContent, FormView {interface Presenter {+ void onSendNotification();+void onRoleAssigned(String id, boolean assigned);void onDeviceRegistrationDelete(DeviceNotificationToken.Id id);diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.javaindex 54764a4b9..30781d191 100644--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java@@ -34,6 +34,9 @@ import org.openremote.manager.shared.security.UserResource;import org.openremote.manager.shared.validation.ConstraintViolation;import org.openremote.model.event.bus.EventBus;import org.openremote.model.event.bus.EventRegistration;+import org.openremote.model.notification.ActionType;+import org.openremote.model.notification.AlertAction;+import org.openremote.model.notification.AlertNotification;import javax.inject.Inject;import java.util.ArrayList;@@ -56,7 +59,9 @@ public class AdminUserActivityfinal protected UserMapper userMapper;final protected CredentialMapper credentialMapper;final protected RoleArrayMapper roleArrayMapper;+ final protected AdminUserNotificationEditor notificationEditor;final protected NotificationResource notificationResource;+ final protected AlertNotificationMapper alertNotificationMapper;final protected DeviceNotificationTokenMapper deviceNotificationTokenMapper;final protected Consumer<ConstraintViolation[]> validationErrorHandler = violations -> {@@ -90,6 +95,7 @@ public class AdminUserActivityprotected String userId;protected User user;protected Role[] roles = new Role[0];+ protected AlertNotification alertNotification;@Injectpublic AdminUserActivity(Environment environment,@@ -100,7 +106,9 @@ public class AdminUserActivityUserMapper userMapper,CredentialMapper credentialMapper,RoleArrayMapper roleArrayMapper,+ AdminUserNotificationEditor notificationEditor,NotificationResource notificationResource,+ AlertNotificationMapper alertNotificationMapper,DeviceNotificationTokenMapper deviceNotificationTokenMapper) {super(adminView, adminNavigationPresenter, view);this.environment = environment;@@ -108,7 +116,9 @@ public class AdminUserActivitythis.userMapper = userMapper;this.credentialMapper = credentialMapper;this.roleArrayMapper = roleArrayMapper;+ this.notificationEditor = notificationEditor;this.notificationResource = notificationResource;+ this.alertNotificationMapper = alertNotificationMapper;this.deviceNotificationTokenMapper = deviceNotificationTokenMapper;}@@ -154,6 +164,7 @@ public class AdminUserActivity@Overridepublic void onStop() {super.onStop();+ notificationEditor.reset();adminContent.setPresenter(null);adminContent.clearRoles();adminContent.clearFormMessages();@@ -269,9 +280,45 @@ public class AdminUserActivity);}+ @Override+ public void onSendNotification() {+ // Keep it so we can send it again later+ if (this.alertNotification == null)+ this.alertNotification = createDefaultNotification();++ notificationEditor.setAlertNotification(this.alertNotification);+ notificationEditor.setOnSend(updatedNotification -> {+ this.alertNotification = updatedNotification;+ environment.getRequestService().execute(+ alertNotificationMapper,+ requestParams -> notificationResource.storeAlertNotificationForUser(requestParams, userId, this.alertNotification),+ 204,+ () -> environment.getEventBus().dispatch(new ShowSuccessEvent(+ environment.getMessages().notificationSentToUser()+ )),+ ex -> handleRequestException(ex, environment)+ );+ });+ notificationEditor.show();+ }++ protected AlertNotification createDefaultNotification() {+ AlertNotification alertNotification = new AlertNotification(+ "Hello User",+ "This is a test message.",+ "/#"+ );+ AlertAction alertAction = new AlertAction();+ alertAction.setTitle(environment.getMessages().notificationOpenApplicationDetails());+ alertAction.setActionType(ActionType.LINK);+ alertNotification.addAction(alertAction);+ return alertNotification;+ }+@Overridepublic void onDeviceRegistrationDelete(DeviceNotificationToken.Id id) {environment.getRequestService().execute(+requestParams -> notificationResource.deleteDeviceToken(requestParams, id.getUserId(), id.getDeviceId()),204,() -> {diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.javaindex d5ef725c6..bd9f53fba 100644--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java@@ -53,6 +53,9 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {interface UI extends UiBinder<HTMLPanel, AdminUserImpl> {}+ @UiField+ PushButton sendNotificationButton;+@UiFieldFormGroup usernameGroup;@UiField@@ -125,6 +128,12 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {UI ui = GWT.create(UI.class);initWidget(ui.createAndBindUi(this));+ sendNotificationButton.addClickHandler(event -> {+ if (presenter != null) {+ presenter.onSendNotification();+ }+ });+clearRegisteredDevices(false);}@@ -132,6 +141,7 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {public void setPresenter(Presenter presenter) {this.presenter = presenter;if (presenter == null) {+ sendNotificationButton.setVisible(false);usernameInput.setValue(null);firstNameInput.setValue(null);lastNameInput.setValue(null);@@ -305,6 +315,7 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {@Overridepublic void setDeviceRegistrations(List<DeviceNotificationToken> deviceNotificationTokens) {clearRegisteredDevices(deviceNotificationTokens.size() == 0);+ sendNotificationButton.setVisible(deviceNotificationTokens.size() > 0);for (DeviceNotificationToken deviceNotificationToken : deviceNotificationTokens) {registeredDevicesContainer.add(new DeviceRegistrationItem(deviceNotificationToken));}@@ -319,6 +330,7 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {registeredDevicesContainer.remove(i);}}+ sendNotificationButton.setVisible(registeredDevicesContainer.getWidgetCount() > 0);clearRegisteredDevices(registeredDevicesContainer.getWidgetCount() == 0);}@@ -362,7 +374,7 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {}protected void clearRegisteredDevices(boolean addEmptyMessage) {- registeredDevicesContainer.clear();+ registeredDevicesContainer.clear();if (addEmptyMessage) {Label emptyLabel = new Label(managerMessages.noRegisteredDevices());emptyLabel.addStyleName(widgetStyle.FormListEmptyMessage());diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.ui.xmlindex 2f837aadb..710373006 100644--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.ui.xml+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.ui.xml@@ -6,6 +6,10 @@<ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/><ui:style>+ .navItem {+ margin: 0 1em;+ }+.formMessages {max-width: 30em;}@@ -16,6 +20,13 @@<g:HTMLPanelstyleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">+ <w:PushButton+ ui:field="sendNotificationButton"+ addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"+ icon="send"+ visible="false"+ text="{managerMessages.sendNotification}"/>+</g:HTMLPanel><w:Form ui:field="form" addStyleNames="flex">diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditor.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditor.javanew file mode 100644index 000000000..31820ddfc--- /dev/null+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditor.java@@ -0,0 +1,37 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.manager.client.admin.users;++import org.openremote.model.notification.AlertNotification;++import java.util.function.Consumer;++public interface AdminUserNotificationEditor {++ void reset();++ void setAlertNotification(AlertNotification notification);++ void setOnSend(Consumer<AlertNotification> onSend);++ void setOnClose(Runnable onClose);++ void show();+}\ No newline at end of filediff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditorImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditorImpl.javanew file mode 100644index 000000000..fe78f7cfb--- /dev/null+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditorImpl.java@@ -0,0 +1,187 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.manager.client.admin.users;++import com.google.gwt.user.client.ui.FlowPanel;+import com.google.gwt.user.client.ui.InlineLabel;+import com.google.gwt.user.client.ui.TextArea;+import org.openremote.manager.client.app.dialog.Dialog;+import org.openremote.manager.client.i18n.ManagerMessages;+import org.openremote.manager.client.style.WidgetStyle;+import org.openremote.manager.client.widget.*;+import org.openremote.model.notification.AlertNotification;++import javax.inject.Inject;+import java.util.function.Consumer;++import static org.openremote.model.util.TextUtil.isNullOrEmpty;++public class AdminUserNotificationEditorImpl implements AdminUserNotificationEditor {++ final protected Dialog dialog;+ final protected WidgetStyle widgetStyle;+ final protected ManagerMessages managerMessages;++ final protected FlowPanel errorPanel = new FlowPanel();+ final protected FormInputText notificationTitleInput = new FormInputText();+ final protected TextArea notificationMessageInput = new TextArea();+ final protected FormInputText notificationAppUrlInput = new FormInputText();++ AlertNotification alertNotification;++ Consumer<AlertNotification> onSend;+ Runnable onClose;++ @Inject+ public AdminUserNotificationEditorImpl(Dialog dialog,+ WidgetStyle widgetStyle,+ ManagerMessages managerMessages) {+ this.dialog = dialog;+ this.widgetStyle = widgetStyle;+ this.managerMessages = managerMessages;++ dialog.setHeaderLabel(managerMessages.sendNotification());++ dialog.setModal(true);+ dialog.setAutoHideOnHistoryEvents(true);+ dialog.addStyleName(widgetStyle.AdminNotificationEditor());++ PushButton sendButton = new PushButton();+ sendButton.setFocus(true);+ sendButton.setText(managerMessages.sendNotification());+ sendButton.setIcon("send");+ sendButton.addStyleName(widgetStyle.FormControl());+ sendButton.addStyleName(widgetStyle.PushButton());+ sendButton.addStyleName(widgetStyle.FormButtonPrimary());+ sendButton.addClickHandler(event -> {+ AlertNotification notification = buildAlertNotification();+ if (notification != null) {+ if (onSend != null)+ onSend.accept(notification);+ dialog.hide();+ }+ });+ dialog.getFooterPanel().add(sendButton);++ PushButton cancelButton = new PushButton();+ cancelButton.setText(managerMessages.cancel());+ cancelButton.setIcon("close");+ cancelButton.addStyleName(widgetStyle.FormControl());+ cancelButton.addStyleName(widgetStyle.PushButton());+ cancelButton.addStyleName(widgetStyle.FormButton());+ cancelButton.addClickHandler(event -> {+ dialog.hide();+ if (onClose != null)+ onClose.run();+ });+ dialog.getFooterPanel().add(cancelButton);++ errorPanel.setStyleName("flex-none layout horizontal error");+ errorPanel.addStyleName(widgetStyle.FormMessages());+ errorPanel.setVisible(false);+ dialog.getContentPanel().add(errorPanel);++ FormGroup titleGroup = new FormGroup();+ FormLabel titleLabel = new FormLabel(managerMessages.title());+ titleGroup.setFormLabel(titleLabel);+ FormField titleField = new FormField();+ titleGroup.setFormField(titleField);+ notificationTitleInput.addStyleName("flex");+ titleField.add(notificationTitleInput);+ dialog.getContentPanel().add(titleGroup);++ FormGroup messageGroup = new FormGroup();+ FormLabel messageLabel = new FormLabel(managerMessages.message());+ messageGroup.setFormLabel(messageLabel);+ FormField messageField = new FormField();+ messageGroup.setFormField(messageField);+ notificationMessageInput.addStyleName("flex");+ notificationMessageInput.setHeight("5em");+ notificationMessageInput.getElement().getStyle().setProperty("resize", "none");+ messageField.add(notificationMessageInput);+ dialog.getContentPanel().add(messageGroup);++ FormGroup appUrlGroup = new FormGroup();+ FormLabel appUrlLabel = new FormLabel(managerMessages.notificationAppUrl());+ appUrlGroup.setFormLabel(appUrlLabel);+ FormField appUrlField = new FormField();+ appUrlGroup.setFormField(appUrlField);+ notificationAppUrlInput.addStyleName("flex");+ appUrlField.add(notificationAppUrlInput);+ dialog.getContentPanel().add(appUrlGroup);+ }++ @Override+ public void reset() {+ alertNotification = null;+ onSend = null;+ onClose = null;+ errorPanel.clear();+ notificationTitleInput.setValue(null);+ notificationMessageInput.setValue(null);+ notificationAppUrlInput.setValue(null);+ }++ @Override+ public void setAlertNotification(AlertNotification notification) {+ this.alertNotification = notification;+ errorPanel.clear();+ errorPanel.setVisible(false);+ notificationTitleInput.setText(notification.getTitle());+ notificationMessageInput.setText(notification.getMessage());+ notificationAppUrlInput.setText(notification.getAppUrl());+ }++ public void setOnSend(Consumer<AlertNotification> onSend) {+ this.onSend = onSend;+ }++ public void setOnClose(Runnable onClose) {+ this.onClose = onClose;+ }++ public void show() {+ dialog.showCenter();+ }++ protected AlertNotification buildAlertNotification() {+ errorPanel.clear();+ String notificationTitle = notificationTitleInput.getText();+ String notificationMessage = notificationMessageInput.getText();+ String notificationAppUrl = notificationAppUrlInput.getText();+ if (isNullOrEmpty(notificationTitle)+ || isNullOrEmpty(notificationMessage)+ || isNullOrEmpty(notificationAppUrl)) {+ IconLabel warningLabel = new IconLabel();+ warningLabel.setIcon("warning");+ warningLabel.addStyleName(widgetStyle.MessagesIcon());+ errorPanel.add(warningLabel);+ InlineLabel errorMessage = new InlineLabel(managerMessages.enterTitleMessageAppurlForNotification());+ errorPanel.add(errorMessage);+ errorPanel.setVisible(true);+ return null;+ }+ errorPanel.setVisible(false);+ alertNotification.setTitle(notificationTitle);+ alertNotification.setMessage(notificationMessage);+ alertNotification.setAppUrl(notificationAppUrl);+ return alertNotification;+ }+}\ No newline at end of filediff --git a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.javaindex 1d974cf15..4efcf386b 100644--- a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java+++ b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java@@ -462,4 +462,18 @@ public interface ManagerMessages extends Messages {String registeredDeviceNotificationToken();String registeredDeviceDeleted(String deviceId);++ String sendNotification();++ String title();++ String message();++ String notificationAppUrl();++ String enterTitleMessageAppurlForNotification();++ String notificationSentToUser();++ String notificationOpenApplicationDetails();}diff --git a/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java b/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.javaindex 4e2c109b6..dda3d7ca4 100644--- a/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java+++ b/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java@@ -401,6 +401,10 @@ public class WidgetStyle {return "or-JsonEditor";}+ public String AdminNotificationEditor() {+ return "or-AdminNotificationEditor";+ }+public String BorderRed() {return "or-BorderRed";}diff --git a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.propertiesindex 3623f8406..d515a6569 100644--- a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties+++ b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties@@ -378,4 +378,11 @@ deleteRegistration=Delete device registrationregisteredDeviceType=Device typeregisteredDeviceLastLogin=Last loginregisteredDeviceNotificationToken=Notification token-registeredDeviceDeleted=Device registration deleted: {0}\ No newline at end of file+registeredDeviceDeleted=Device registration deleted: {0}+sendNotification=Send notification+title=Title+message=Message+notificationAppUrl=Details URL/anchor+enterTitleMessageAppurlForNotification=Enter title, message, and App URL of notification.+notificationSentToUser=Alert notification sent to user.+notificationOpenApplicationDetails=Detailsdiff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.htmlindex e742e2bb2..25b1c7be2 100644--- a/manager/client/src/main/webapp/css/style.html+++ b/manager/client/src/main/webapp/css/style.html@@ -612,6 +612,11 @@height: 30em;}+ .or-AdminNotificationEditor {+ width: 50em;+ height: 20em;+ }+.or-SimulatorElement {}diff --git a/manager/client/src/main/webapp/css/theme.html b/manager/client/src/main/webapp/css/theme.htmlindex e1e3a29a1..7c4bb8226 100644--- a/manager/client/src/main/webapp/css/theme.html+++ b/manager/client/src/main/webapp/css/theme.html@@ -148,6 +148,11 @@background-image: -moz-linear-gradient(45deg, var(--theme-brightgrey) 0%, var(--theme-white) 100%);}+ .or-PopupPanelContent .or-FormGroup {+ background-image: -webkit-linear-gradient(45deg, var(--theme-lightergrey) 0%, var(--theme-brightgrey) 100%);+ background-image: -moz-linear-gradient(45deg, var(--theme-lightergrey) 0%, var(--theme-brightgrey) 100%);+ }+.or-FormGroup.expanded {}diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationResourceImpl.javaindex eb46f2e28..cb0137499 100644--- a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationResourceImpl.java+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationResourceImpl.java@@ -70,13 +70,21 @@ public class NotificationResourceImpl extends WebResource implements Notificatio}@Override- public void storeAlertNotification(AlertNotification alertNotification) {+ public void storeAlertNotification(RequestParams requestParams, AlertNotification alertNotification) {if (alertNotification == null) {throw new WebApplicationException("Missing alertNotification", BAD_REQUEST);}notificationService.storeAndNotify(getUserId(), alertNotification);}+ @Override+ public void storeAlertNotificationForUser(RequestParams requestParams, String userId, AlertNotification alertNotification) {+ if (alertNotification == null) {+ throw new WebApplicationException("Missing alertNotification", BAD_REQUEST);+ }+ notificationService.storeAndNotify(userId, alertNotification);+ }+@Overridepublic List<AlertNotification> getAlertNotification() {return notificationService.getPendingAlertForUserId(getUserId());diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.javaindex 2e8c462f4..c03b82d52 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.java@@ -27,7 +27,6 @@ import org.openremote.model.notification.AlertNotification;import javax.annotation.security.RolesAllowed;import javax.ws.rs.*;import javax.ws.rs.core.MediaType;-import java.util.List;import static javax.ws.rs.core.MediaType.APPLICATION_JSON;@@ -75,7 +74,20 @@ public interface NotificationResource {@SuccessStatusCode(204)@Consumes(APPLICATION_JSON)@RolesAllowed({"write:user"})- void storeAlertNotification(AlertNotification alertNotification);+ void storeAlertNotification(@BeanParam RequestParams requestParams,+ AlertNotification alertNotification);++ /**+ * Only the superuser can call this operation.+ */+ @POST+ @Path("alert/{userId}")+ @SuccessStatusCode(204)+ @Consumes(APPLICATION_JSON)+ @RolesAllowed({"write:admin"})+ void storeAlertNotificationForUser(@BeanParam RequestParams requestParams,+ @PathParam("userId") String userId,+ AlertNotification alertNotification);@GET@Path("alert")diff --git a/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovyindex d1b2c9cf5..229d4817a 100644--- a/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy@@ -26,6 +26,7 @@ import org.openremote.manager.shared.security.*import org.openremote.manager.shared.validation.ConstraintViolationReportimport org.openremote.model.event.Eventimport org.openremote.model.event.bus.EventListener+import org.openremote.model.notification.AlertNotificationimport org.openremote.test.ClientObjectMapperimport org.openremote.test.ClientSecurityServiceimport org.openremote.test.GwtClientTrait@@ -162,10 +163,12 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTrAdminUsersActivity adminUsersActivitydef adminUserView = Mock(AdminUser)+ def notificationEditor = Mock(AdminUserNotificationEditor)def userMapper = new ClientObjectMapper(container.JSON, User.class) as UserMapperdef credentialMapper = new ClientObjectMapper(container.JSON, Credential.class) as CredentialMapperdef roleArrayMapper = new ClientObjectMapper(container.JSON, Role[].class) as RoleArrayMapperdef notificationTokenMapper = new ClientObjectMapper(container.JSON, List.class) as DeviceNotificationTokenMapper+ def alertNotificationMapper = new ClientObjectMapper(container.JSON, AlertNotification.class) as AlertNotificationMapperAdminUserActivity adminUserActivityand: "An activity management configuration"@@ -198,7 +201,7 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr},{adminUserActivity = new AdminUserActivity(- environment, adminView, adminNavigationPresenter, adminUserView, userResource, userMapper, credentialMapper, roleArrayMapper, notificationResource, notificationTokenMapper+ environment, adminView, adminNavigationPresenter, adminUserView, userResource, userMapper, credentialMapper, roleArrayMapper, notificationEditor, notificationResource, alertNotificationMapper, notificationTokenMapper)return adminUserActivity},diff --git a/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy b/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovyindex c0005971e..a27d5a9ba 100644--- a/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy@@ -117,7 +117,7 @@ class NotificationServiceTest extends Specification implements ManagerContainerTnotificationService.findAllTokenForUser(keycloakDemoSetup.testuser3Id).size() == 2when: "the Alert Notification is stored"- notificationResource.storeAlertNotification(notificationAlert)+ notificationResource.storeAlertNotification(null, notificationAlert)def alerts = notificationResource.getAlertNotification()then: "it should be one alert notification pending"diff --git a/model/src/main/java/org/openremote/model/notification/AlertNotification.java b/model/src/main/java/org/openremote/model/notification/AlertNotification.javaindex aeb857be4..8e44ca134 100644--- a/model/src/main/java/org/openremote/model/notification/AlertNotification.java+++ b/model/src/main/java/org/openremote/model/notification/AlertNotification.java@@ -70,6 +70,12 @@ public class AlertNotification {this.message = message;}+ public AlertNotification(String title, String message, String appUrl) {+ this.title = title;+ this.message = message;+ this.appUrl = appUrl;+ }+/* Actuator */public Long getId() {@@ -145,4 +151,17 @@ public class AlertNotification {public void setDeliveryStatus(DeliveryStatus deliveryStatus) {this.deliveryStatus = deliveryStatus;}++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "id=" + id ++ ", title='" + title + '\'' ++ ", message='" + message + '\'' ++ ", actions=" + actions ++ ", appUrl='" + appUrl + '\'' ++ ", userId='" + userId + '\'' ++ ", deliveryStatus=" + deliveryStatus ++ '}';+ }}