Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Notification management UI and improvements, #52

Christian Bauerac6905249742
diff --git a/agent/build.gradle b/agent/build.gradle
index 65e9c009d..3444caede 100644
--- a/agent/build.gradle
+++ b/agent/build.gradle
@@ -9,7 +9,9 @@ dependencies {
compile "org.drools:drools-decisiontables:$droolsVersion"
compile "com.luckycatlabs:SunriseSunsetCalculator:$sunriseSunsetCalculatorVersion"
- compile "org.quartz-scheduler:quartz:$quartzVersion"
+ compile("org.quartz-scheduler:quartz:$quartzVersion") {
+ exclude group: "c3p0"
+ }
compile("com.github.calimero:calimero-core:$calimeroVersion") {
// Libraries should not depend on a logging implementation and/or alpha versions!
diff --git a/console/android/src/main/java/org/openremote/android/service/AlertNotification.java b/console/android/src/main/java/org/openremote/android/service/AlertNotification.java
index a56538e07..c7c3d2108 100644
--- a/console/android/src/main/java/org/openremote/android/service/AlertNotification.java
+++ b/console/android/src/main/java/org/openremote/android/service/AlertNotification.java
@@ -2,6 +2,7 @@ package org.openremote.android.service;
import java.io.Serializable;
+import java.util.Date;
import java.util.List;
public class AlertNotification implements Serializable {
@@ -9,6 +10,8 @@ public class AlertNotification implements Serializable {
private String title;
+ private Date createdOn;
+
private String message;
private List<AlertAction> actions;
@@ -19,7 +22,6 @@ public class AlertNotification implements Serializable {
private DeliveryStatus deliveryStatus;
-
public Long getId() {
return id;
}
@@ -36,6 +38,14 @@ public class AlertNotification implements Serializable {
this.title = title;
}
+ public Date getCreatedOn() {
+ return createdOn;
+ }
+
+ public void setCreatedOn(Date createdOn) {
+ this.createdOn = createdOn;
+ }
+
public String getMessage() {
return message;
}
@@ -81,6 +91,7 @@ public class AlertNotification implements Serializable {
return "AlertNotification{" +
"id=" + id +
", title='" + title + '\'' +
+ ", createdOn='" + createdOn + '\'' +
", message='" + message + '\'' +
", actions=" + actions +
", appUrl='" + appUrl + '\'' +
diff --git a/console/android/src/main/java/org/openremote/android/service/DeliveryStatus.java b/console/android/src/main/java/org/openremote/android/service/DeliveryStatus.java
index 1c785cb3c..68eb56162 100644
--- a/console/android/src/main/java/org/openremote/android/service/DeliveryStatus.java
+++ b/console/android/src/main/java/org/openremote/android/service/DeliveryStatus.java
@@ -2,6 +2,18 @@ package org.openremote.android.service;
enum DeliveryStatus {
+ /**
+ * Not delivered to queue.
+ */
PENDING,
- DELIVERED
+
+ /**
+ * Delivered to queue for at least one device, device should soon pick it up.
+ */
+ QUEUED,
+
+ /**
+ * Picked up by receiving device and dismissed by user.
+ */
+ ACKNOWLEDGED
}
diff --git a/gradle.properties b/gradle.properties
index 885a7a21d..5d4710992 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,7 +4,7 @@ jaxrsSpecVersion = 1.0.0.Final
javaxAnnotationsVersion = 1.0.0.Final
javaxPersistenceVersion = 1.0.0.Final
javaxELVersion = 2.2.6
-slf4jVersion = 1.8.0-alpha2
+slf4jVersion = 1.7.25
guavaVersion = 19.0
undertowVersion = 1.4.12.Final
resteasyVersion = 3.0.21.Final
diff --git a/keycloak/theme/account/template.ftl b/keycloak/theme/account/template.ftl
index b0296c96f..563431541 100644
--- a/keycloak/theme/account/template.ftl
+++ b/keycloak/theme/account/template.ftl
@@ -49,7 +49,7 @@
<div class="flex layout vertical">
- <div class="layout horizontal center end-justified or-SecondaryNavHorizontal">
+ <div class="layout horizontal center end-justified or-SecondaryNav">
</div>
<#if message?has_content>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
index b8d94f4c7..e6da839c1 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
@@ -28,15 +28,20 @@ import org.openremote.manager.client.admin.tenant.AdminTenantActivity;
import org.openremote.manager.client.admin.tenant.AdminTenantPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantsActivity;
import org.openremote.manager.client.admin.tenant.AdminTenantsPlace;
-import org.openremote.manager.client.admin.users.AdminUserActivity;
-import org.openremote.manager.client.admin.users.AdminUserPlace;
import org.openremote.manager.client.admin.users.AdminUsersActivity;
import org.openremote.manager.client.admin.users.AdminUsersPlace;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditActivity;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditPlace;
+import org.openremote.manager.client.admin.users.notifications.AdminUserNotificationsActivity;
+import org.openremote.manager.client.admin.users.notifications.AdminUserNotificationsPlace;
import org.openremote.manager.client.apps.AppsActivity;
import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.assets.AssetsDashboardActivity;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
-import org.openremote.manager.client.assets.asset.*;
+import org.openremote.manager.client.assets.asset.AssetEditActivity;
+import org.openremote.manager.client.assets.asset.AssetEditPlace;
+import org.openremote.manager.client.assets.asset.AssetViewActivity;
+import org.openremote.manager.client.assets.asset.AssetViewPlace;
import org.openremote.manager.client.assets.tenant.AssetsTenantActivity;
import org.openremote.manager.client.assets.tenant.AssetsTenantPlace;
import org.openremote.manager.client.event.ShowFailureEvent;
@@ -88,7 +93,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
protected final Provider<AdminTenantsActivity> adminTenantsActivityProvider;
protected final Provider<AdminTenantActivity> adminTenantActivityProvider;
protected final Provider<AdminUsersActivity> adminUsersActivityProvider;
- protected final Provider<AdminUserActivity> adminUserActivityProvider;
+ protected final Provider<AdminUserEditActivity> adminUserActivityProvider;
+ protected final Provider<AdminUserNotificationsActivity> adminUserNotificationsActivityProvider;
protected final Provider<UserAccountActivity> userProfileActivityProvider;
@Inject
@@ -111,7 +117,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
Provider<AdminTenantsActivity> adminTenantsActivityProvider,
Provider<AdminTenantActivity> adminTenantActivityProvider,
Provider<AdminUsersActivity> adminUsersActivityProvider,
- Provider<AdminUserActivity> adminUserActivityProvider,
+ Provider<AdminUserEditActivity> adminUserActivityProvider,
+ Provider<AdminUserNotificationsActivity> adminUserNotificationsActivityProvider,
Provider<UserAccountActivity> userProfileActivityProvider) {
this.securityService = securityService;
this.eventBus = eventBus;
@@ -133,6 +140,7 @@ public class ManagerActivityMapper implements AppActivityMapper {
this.adminTenantActivityProvider = adminTenantActivityProvider;
this.adminUsersActivityProvider = adminUsersActivityProvider;
this.adminUserActivityProvider = adminUserActivityProvider;
+ this.adminUserNotificationsActivityProvider = adminUserNotificationsActivityProvider;
this.userProfileActivityProvider = userProfileActivityProvider;
}
@@ -186,8 +194,11 @@ public class ManagerActivityMapper implements AppActivityMapper {
if (place instanceof AdminUsersPlace) {
return adminUsersActivityProvider.get().init(securityService, (AdminUsersPlace) place);
}
- if (place instanceof AdminUserPlace) {
- return adminUserActivityProvider.get().init(securityService, (AdminUserPlace) place);
+ if (place instanceof AdminUserEditPlace) {
+ return adminUserActivityProvider.get().init(securityService, (AdminUserEditPlace) place);
+ }
+ if (place instanceof AdminUserNotificationsPlace) {
+ return adminUserNotificationsActivityProvider.get().init(securityService, (AdminUserNotificationsPlace) place);
}
if (place instanceof UserAccountPlace) {
return userProfileActivityProvider.get().init(securityService, (UserAccountPlace) place);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
index efd6613e1..5cb96f29d 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
@@ -24,8 +24,9 @@ import com.google.gwt.place.shared.WithTokenizers;
import org.openremote.manager.client.admin.syslog.AdminSyslogPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantsPlace;
-import org.openremote.manager.client.admin.users.AdminUserPlace;
import org.openremote.manager.client.admin.users.AdminUsersPlace;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditPlace;
+import org.openremote.manager.client.admin.users.notifications.AdminUserNotificationsPlace;
import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
import org.openremote.manager.client.assets.asset.AssetEditPlace;
@@ -60,7 +61,8 @@ import org.openremote.manager.client.user.UserAccountPlace;
AdminTenantsPlace.Tokenizer.class,
AdminTenantPlace.Tokenizer.class,
AdminUsersPlace.Tokenizer.class,
- AdminUserPlace.Tokenizer.class,
+ AdminUserEditPlace.Tokenizer.class,
+ AdminUserNotificationsPlace.Tokenizer.class,
UserAccountPlace.Tokenizer.class
}
)
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.java
index bacf983e8..3e9d19ee1 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
@@ -25,9 +25,15 @@ import com.google.inject.Singleton;
import org.openremote.manager.client.admin.navigation.AdminNavigation;
import org.openremote.manager.client.admin.navigation.AdminNavigationImpl;
import org.openremote.manager.client.admin.navigation.AdminNavigationPresenter;
-import org.openremote.manager.client.admin.syslog.*;
+import org.openremote.manager.client.admin.syslog.AdminSyslog;
+import org.openremote.manager.client.admin.syslog.AdminSyslogActivity;
+import org.openremote.manager.client.admin.syslog.AdminSyslogImpl;
import org.openremote.manager.client.admin.tenant.*;
import org.openremote.manager.client.admin.users.*;
+import org.openremote.manager.client.admin.users.edit.AdminUserEdit;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditActivity;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditImpl;
+import org.openremote.manager.client.admin.users.notifications.*;
import org.openremote.manager.shared.notification.NotificationResource;
import org.openremote.manager.shared.security.UserResource;
import org.openremote.manager.shared.syslog.SyslogResource;
@@ -51,9 +57,12 @@ public class AdminModule extends AbstractGinModule {
bind(AdminUsers.class).to(AdminUsersImpl.class).in(Singleton.class);
bind(AdminUsersActivity.class);
- bind(AdminUser.class).to(AdminUserImpl.class).in(Singleton.class);
- bind(AdminUserActivity.class);
+ bind(AdminUserEdit.class).to(AdminUserEditImpl.class).in(Singleton.class);
+ bind(AdminUserEditActivity.class);
+
+ bind(AdminUserNotifications.class).to(AdminUserNotificationsImpl.class).in(Singleton.class);
+ bind(AdminUserNotificationsActivity.class);
bind(AdminUserNotificationEditor.class).to(AdminUserNotificationEditorImpl.class).in(Singleton.class);
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java
index 466a386ce..67a0fd0cc 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java
@@ -28,7 +28,7 @@ import com.google.gwt.user.client.ui.Hyperlink;
import org.openremote.manager.client.admin.AdminPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantsPlace;
-import org.openremote.manager.client.admin.users.AdminUserPlace;
+import org.openremote.manager.client.admin.users.AbstractAdminUsersPlace;
import org.openremote.manager.client.admin.users.AdminUsersPlace;
import javax.inject.Inject;
@@ -76,7 +76,7 @@ public class AdminNavigationImpl extends Composite implements AdminNavigation {
tenantsLink.addStyleName("active");
} else if (adminPlace instanceof AdminUsersPlace) {
usersLink.addStyleName("active");
- } else if (adminPlace instanceof AdminUserPlace) {
+ } else if (adminPlace instanceof AbstractAdminUsersPlace) {
usersLink.addStyleName("active");
} else {
syslogLink.addStyleName("active");
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/syslog/AdminSyslogImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/syslog/AdminSyslogImpl.ui.xml
index 73bd7f81b..fc6955bf8 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/syslog/AdminSyslogImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/syslog/AdminSyslogImpl.ui.xml
@@ -19,7 +19,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="flex-none layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="flex-none layout horizontal center end-justified {widgetStyle.SecondaryNav}">
</g:HTMLPanel>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.ui.xml
index 460d412b4..ed4939409 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.ui.xml
@@ -8,7 +8,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
</g:HTMLPanel>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantsImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantsImpl.ui.xml
index 9de168080..9edd674fc 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantsImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantsImpl.ui.xml
@@ -32,7 +32,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
<w:Hyperlink
ui:field="createLink"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AbstractAdminUsersPlace.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AbstractAdminUsersPlace.java
new file mode 100644
index 000000000..20eb66e73
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AbstractAdminUsersPlace.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016, 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.manager.client.admin.AdminPlace;
+
+public abstract class AbstractAdminUsersPlace extends AdminPlace {
+
+ final String realm;
+ final String userId;
+
+ public AbstractAdminUsersPlace() {
+ this(null);
+ }
+
+ protected AbstractAdminUsersPlace(String realm) {
+ this.realm = realm;
+ this.userId = null;
+ }
+
+ protected AbstractAdminUsersPlace(String realm, String userId) {
+ this.realm = realm;
+ this.userId = userId;
+ }
+
+ public String getRealm() {
+ return realm;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{" +
+ "realm='" + realm + '\'' +
+ ", userId='" + userId + '\'' +
+ "}";
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsers.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsers.java
index 56c00d0e4..98af70638 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsers.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsers.java
@@ -27,6 +27,8 @@ public interface AdminUsers extends AdminContent {
interface Presenter {
+ AbstractAdminUsersPlace getPlace();
+
void onTenantSelected(String realm);
void onUserSelected(User user);
@@ -37,8 +39,6 @@ public interface AdminUsers extends AdminContent {
void setTenants(Tenant[] tenants, String selectedRealm);
- void setCreateUserHistoryToken(String token);
-
void setUsers(User[] users);
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersActivity.java
index c7916c829..1d94439d7 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersActivity.java
@@ -26,6 +26,7 @@ import org.openremote.manager.client.admin.AdminView;
import org.openremote.manager.client.admin.TenantArrayMapper;
import org.openremote.manager.client.admin.UserArrayMapper;
import org.openremote.manager.client.admin.navigation.AdminNavigation;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditPlace;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.manager.client.mvp.AppActivity;
@@ -104,9 +105,6 @@ public class AdminUsersActivity
200,
users -> {
adminContent.setUsers(users);
- adminContent.setCreateUserHistoryToken(
- environment.getPlaceHistoryMapper().getToken(new AdminUserPlace(realm))
- );
adminContent.setFormBusy(false);
},
ex -> handleRequestException(ex, environment)
@@ -127,6 +125,6 @@ public class AdminUsersActivity
@Override
public void onUserSelected(User user) {
- environment.getPlaceController().goTo(new AdminUserPlace(realm, user.getId()));
+ environment.getPlaceController().goTo(new AdminUserEditPlace(realm, user.getId()));
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.java
index 9fc6679b9..955600aea 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.java
@@ -30,7 +30,6 @@ import org.openremote.manager.client.app.dialog.Confirmation;
import org.openremote.manager.client.style.FormTableStyle;
import org.openremote.manager.client.style.WidgetStyle;
import org.openremote.manager.client.widget.FormViewImpl;
-import org.openremote.manager.client.widget.Hyperlink;
import org.openremote.manager.shared.security.Tenant;
import org.openremote.manager.shared.security.User;
@@ -46,8 +45,8 @@ public class AdminUsersImpl extends FormViewImpl implements AdminUsers {
@UiField
AdminUsersTable.Style usersTableStyle;
- @UiField
- Hyperlink createLink;
+ @UiField(provided = true)
+ AdminUsersNavigation adminUsersNavigation;
@UiField
HTMLPanel mainContent;
@@ -64,8 +63,12 @@ public class AdminUsersImpl extends FormViewImpl implements AdminUsers {
@Inject
public AdminUsersImpl(Provider<Confirmation> confirmationDialogProvider,
WidgetStyle widgetStyle,
- FormTableStyle formTableStyle) {
+ FormTableStyle formTableStyle,
+ AdminUsersNavigation adminUsersNavigation) {
super(confirmationDialogProvider, widgetStyle);
+
+ this.adminUsersNavigation = adminUsersNavigation;
+
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
@@ -98,7 +101,13 @@ public class AdminUsersImpl extends FormViewImpl implements AdminUsers {
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
- setCreateUserHistoryToken("");
+ if (presenter == null) {
+ adminUsersNavigation.setVisible(false);
+ adminUsersNavigation.reset();
+ } else {
+ adminUsersNavigation.setActive(presenter.getPlace());
+ adminUsersNavigation.setVisible(true);
+ }
noUsersLabel.setVisible(false);
tenantListBox.clear();
tenantListBox.addItem(managerMessages.loadingDotdotdot());
@@ -133,9 +142,4 @@ public class AdminUsersImpl extends FormViewImpl implements AdminUsers {
table.flush();
}
- @Override
- public void setCreateUserHistoryToken(String token) {
- createLink.setTargetHistoryToken(token);
- createLink.setVisible(token != null && token.length() > 0);
- }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.ui.xml
index d7dc29782..b3d16c527 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersImpl.ui.xml
@@ -1,15 +1,12 @@
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
- xmlns:w="urn:import:org.openremote.manager.client.widget">
+ xmlns:w="urn:import:org.openremote.manager.client.widget"
+ xmlns:adminUsers="urn:import:org.openremote.manager.client.admin.users">
<ui:with field="managerMessages" type="org.openremote.manager.client.i18n.ManagerMessages"/>
<ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/>
<ui:style>
- .navItem {
- margin: 0 1em;
- }
-
.noUsersLabel {
max-width: 30em;
}
@@ -32,17 +29,7 @@
<g:HTMLPanel styleName="flex layout vertical">
- <g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
-
- <w:Hyperlink
- ui:field="createLink"
- addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
- icon="plus-square"
- visible="false"
- text="{managerMessages.newUser}"/>
-
- </g:HTMLPanel>
+ <adminUsers:AdminUsersNavigation ui:field="adminUsersNavigation"/>
<w:Form ui:field="form" addStyleNames="flex">
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersNavigation.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersNavigation.java
new file mode 100644
index 000000000..cbd81aa43
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersNavigation.java
@@ -0,0 +1,110 @@
+/*
+ * 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.place.shared.PlaceHistoryMapper;
+import com.google.inject.Inject;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditPlace;
+import org.openremote.manager.client.admin.users.notifications.AdminUserNotificationsPlace;
+import org.openremote.manager.client.i18n.ManagerMessages;
+import org.openremote.manager.client.widget.Hyperlink;
+import org.openremote.manager.client.widget.SecondaryNavigation;
+
+public class AdminUsersNavigation extends SecondaryNavigation {
+
+ final PlaceHistoryMapper placeHistoryMapper;
+
+ final Hyperlink allUsersLink;
+ final Hyperlink editUserLink;
+ final Hyperlink notificationsLink;
+ final Hyperlink createUserLink;
+
+ @Inject
+ public AdminUsersNavigation(ManagerMessages managerMessages, PlaceHistoryMapper placeHistoryMapper) {
+ this.placeHistoryMapper = placeHistoryMapper;
+
+ allUsersLink = new Hyperlink("users", managerMessages.allUsers());
+ add(allUsersLink);
+
+ createUserLink = new Hyperlink("plus-square", managerMessages.newUser());
+ add(createUserLink);
+
+ editUserLink = new Hyperlink("edit", managerMessages.editUser());
+ add(editUserLink);
+
+ notificationsLink = new Hyperlink("send", managerMessages.manageNotifications());
+ add(notificationsLink);
+ }
+
+ public void reset() {
+ reset(allUsersLink);
+ reset(createUserLink);
+ reset(editUserLink);
+ reset(notificationsLink);
+ }
+
+ public void setActive(AbstractAdminUsersPlace place) {
+ reset();
+
+ if (place.getRealm() != null) {
+ allUsersLink.setTargetHistoryToken(
+ placeHistoryMapper.getToken(new AdminUsersPlace(place.getRealm()))
+ );
+ allUsersLink.setVisible(true);
+
+ createUserLink.setTargetHistoryToken(
+ placeHistoryMapper.getToken(new AdminUserEditPlace(place.getRealm()))
+ );
+ createUserLink.setVisible(true);
+
+ } else {
+ allUsersLink.setVisible(false);
+ createUserLink.setVisible(false);
+ }
+
+ editUserLink.setTargetHistoryToken(
+ placeHistoryMapper.getToken(new AdminUserEditPlace(place))
+ );
+
+ if (place instanceof AdminUserEditPlace) {
+ AdminUserEditPlace adminUserEditPlace = (AdminUserEditPlace) place;
+ if (adminUserEditPlace.getUserId() == null) {
+ createUserLink.addStyleName("active");
+ createUserLink.setVisible(true);
+ } else {
+ editUserLink.addStyleName("active");
+ editUserLink.setVisible(true);
+
+ notificationsLink.setTargetHistoryToken(
+ placeHistoryMapper.getToken(new AdminUserNotificationsPlace(place))
+ );
+ notificationsLink.setVisible(true);
+
+ }
+ } else if (place instanceof AdminUserNotificationsPlace) {
+ createUserLink.setVisible(true);
+ editUserLink.setVisible(true);
+ notificationsLink.addStyleName("active");
+ notificationsLink.setVisible(true);
+ } else if (place instanceof AdminUsersPlace) {
+ allUsersLink.setVisible(false);
+ }
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersPlace.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersPlace.java
index e889a8edd..47e71f7db 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersPlace.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUsersPlace.java
@@ -21,22 +21,14 @@ package org.openremote.manager.client.admin.users;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
-import org.openremote.manager.client.admin.AdminPlace;
-public class AdminUsersPlace extends AdminPlace {
-
- final String realm;
+public class AdminUsersPlace extends AbstractAdminUsersPlace {
public AdminUsersPlace() {
- this.realm = null;
}
public AdminUsersPlace(String realm) {
- this.realm = realm;
- }
-
- public String getRealm() {
- return realm;
+ super(realm);
}
@Prefix("users")
@@ -53,10 +45,4 @@ public class AdminUsersPlace extends AdminPlace {
}
}
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "realm='" + realm + '\'' +
- "}";
- }
}
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/edit/AdminUserEdit.java
similarity index 90%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUser.java
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/edit/AdminUserEdit.java
index d8c2e73b9..0a4dacea9 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/edit/AdminUserEdit.java
@@ -17,30 +17,31 @@
* 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;
+package org.openremote.manager.client.admin.users.edit;
import org.openremote.manager.client.admin.AdminContent;
+import org.openremote.manager.client.admin.users.AbstractAdminUsersPlace;
import org.openremote.manager.shared.notification.DeviceNotificationToken;
import java.util.List;
-public interface AdminUser extends AdminContent {
+public interface AdminUserEdit extends AdminContent {
interface Presenter {
- void onSendNotification();
+ AbstractAdminUsersPlace getPlace();
void onRoleAssigned(String id, boolean assigned);
void onDeviceRegistrationDelete(DeviceNotificationToken.Id id);
+ void onDeviceRegistrationsRefresh();
+
void create();
void update();
void delete();
-
- void cancel();
}
void setPresenter(Presenter presenter);
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/edit/AdminUserEditActivity.java
similarity index 82%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/edit/AdminUserEditActivity.java
index 3d1b11810..efd34ccee 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/edit/AdminUserEditActivity.java
@@ -17,12 +17,13 @@
* 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;
+package org.openremote.manager.client.admin.users.edit;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.admin.*;
import org.openremote.manager.client.admin.navigation.AdminNavigation;
+import org.openremote.manager.client.admin.users.AdminUsersPlace;
import org.openremote.manager.client.event.ShowSuccessEvent;
import org.openremote.manager.client.mvp.AppActivity;
import org.openremote.manager.shared.notification.DeviceNotificationToken;
@@ -34,9 +35,6 @@ 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;
@@ -47,18 +45,16 @@ import java.util.function.Consumer;
import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
-public class AdminUserActivity
- extends AbstractAdminActivity<AdminUserPlace, AdminUser>
- implements AdminUser.Presenter {
+public class AdminUserEditActivity
+ extends AbstractAdminActivity<AdminUserEditPlace, AdminUserEdit>
+ implements AdminUserEdit.Presenter {
final protected Environment environment;
final protected UserResource userResource;
final 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 -> {
@@ -88,34 +84,30 @@ public class AdminUserActivity
adminContent.setFormBusy(false);
};
+ protected AdminUserEditPlace place;
protected String realm;
protected String userId;
protected User user;
protected Role[] roles = new Role[0];
- protected AlertNotification alertNotification;
@Inject
- public AdminUserActivity(Environment environment,
- AdminView adminView,
- AdminNavigation.Presenter adminNavigationPresenter,
- AdminUser view,
- UserResource userResource,
- UserMapper userMapper,
- CredentialMapper credentialMapper,
- RoleArrayMapper roleArrayMapper,
- AdminUserNotificationEditor notificationEditor,
- NotificationResource notificationResource,
- AlertNotificationMapper alertNotificationMapper,
- DeviceNotificationTokenMapper deviceNotificationTokenMapper) {
+ public AdminUserEditActivity(Environment environment,
+ AdminView adminView,
+ AdminNavigation.Presenter adminNavigationPresenter,
+ AdminUserEdit view,
+ UserResource userResource,
+ UserMapper userMapper,
+ CredentialMapper credentialMapper,
+ RoleArrayMapper roleArrayMapper,
+ NotificationResource notificationResource,
+ DeviceNotificationTokenMapper deviceNotificationTokenMapper) {
super(adminView, adminNavigationPresenter, view);
this.environment = environment;
this.userResource = userResource;
this.userMapper = userMapper;
this.credentialMapper = credentialMapper;
this.roleArrayMapper = roleArrayMapper;
- this.notificationEditor = notificationEditor;
this.notificationResource = notificationResource;
- this.alertNotificationMapper = alertNotificationMapper;
this.deviceNotificationTokenMapper = deviceNotificationTokenMapper;
}
@@ -125,7 +117,7 @@ public class AdminUserActivity
}
@Override
- protected AppActivity<AdminUserPlace> init(AdminUserPlace place) {
+ protected AppActivity<AdminUserEditPlace> init(AdminUserEditPlace place) {
realm = place.getRealm();
userId = place.getUserId();
return super.init(place);
@@ -161,7 +153,6 @@ public class AdminUserActivity
@Override
public void onStop() {
super.onStop();
- notificationEditor.reset();
adminContent.setPresenter(null);
adminContent.clearRoles();
adminContent.clearFormMessages();
@@ -277,45 +268,9 @@ 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.storeNotificationForUser(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;
- }
-
@Override
public void onDeviceRegistrationDelete(DeviceNotificationToken.Id id) {
environment.getRequestService().execute(
-
requestParams -> notificationResource.deleteDeviceToken(requestParams, id.getUserId(), id.getDeviceId()),
204,
() -> {
@@ -328,6 +283,11 @@ public class AdminUserActivity
);
}
+ @Override
+ public void onDeviceRegistrationsRefresh() {
+ loadDeviceRegistrations(() -> {});
+ }
+
@Override
public void delete() {
adminContent.showConfirmation(
@@ -353,11 +313,6 @@ public class AdminUserActivity
);
}
- @Override
- public void cancel() {
- environment.getPlaceController().goTo(new AdminUsersPlace(realm));
- }
-
protected void loadUser() {
adminContent.setFormBusy(true);
environment.getRequestService().execute(
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/edit/AdminUserEditImpl.java
similarity index 91%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/edit/AdminUserEditImpl.java
index 45fef4824..0e1a8e66d 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/edit/AdminUserEditImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016, OpenRemote Inc.
+ * Copyright 2017, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
@@ -17,7 +17,7 @@
* 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;
+package org.openremote.manager.client.admin.users.edit;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
@@ -29,6 +29,7 @@ import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.*;
import com.google.inject.Provider;
import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.admin.users.AdminUsersNavigation;
import org.openremote.manager.client.app.dialog.Confirmation;
import org.openremote.manager.client.widget.*;
import org.openremote.manager.client.widget.PushButton;
@@ -40,13 +41,13 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-public class AdminUserImpl extends FormViewImpl implements AdminUser {
+public class AdminUserEditImpl extends FormViewImpl implements AdminUserEdit {
- interface UI extends UiBinder<HTMLPanel, AdminUserImpl> {
+ interface UI extends UiBinder<HTMLPanel, AdminUserEditImpl> {
}
- @UiField
- PushButton sendNotificationButton;
+ @UiField(provided = true)
+ AdminUsersNavigation adminUsersNavigation;
@UiField
FormGroup usernameGroup;
@@ -107,25 +108,23 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
PushButton deleteButton;
@UiField
- PushButton cancelButton;
+ FormButton refreshDeviceRegistrations;
final protected Map<String, FormCheckBox> roles = new LinkedHashMap<>();
protected Presenter presenter;
@Inject
- public AdminUserImpl(Environment environment,
- Provider<Confirmation> confirmationDialogProvider) {
+ public AdminUserEditImpl(Environment environment,
+ Provider<Confirmation> confirmationDialogProvider,
+ AdminUsersNavigation adminUsersNavigation) {
super(confirmationDialogProvider, environment.getWidgetStyle());
+
+ this.adminUsersNavigation = adminUsersNavigation;
+
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
- sendNotificationButton.addClickHandler(event -> {
- if (presenter != null) {
- presenter.onSendNotification();
- }
- });
-
clearRegisteredDevices(false);
}
@@ -133,7 +132,8 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
if (presenter == null) {
- sendNotificationButton.setVisible(false);
+ adminUsersNavigation.setVisible(false);
+ adminUsersNavigation.reset();
usernameInput.setValue(null);
firstNameInput.setValue(null);
lastNameInput.setValue(null);
@@ -142,6 +142,9 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
resetPasswordInput.setValue(null);
resetPasswordControlInput.setValue(null);
clearRegisteredDevices(false);
+ } else {
+ adminUsersNavigation.setActive(presenter.getPlace());
+ adminUsersNavigation.setVisible(true);
}
}
@@ -307,7 +310,6 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
@Override
public void setDeviceRegistrations(List<DeviceNotificationToken> deviceNotificationTokens) {
clearRegisteredDevices(deviceNotificationTokens.size() == 0);
- sendNotificationButton.setVisible(deviceNotificationTokens.size() > 0);
for (DeviceNotificationToken deviceNotificationToken : deviceNotificationTokens) {
registeredDevicesContainer.add(new DeviceRegistrationItem(deviceNotificationToken));
}
@@ -322,8 +324,9 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
registeredDevicesContainer.remove(i);
}
}
- sendNotificationButton.setVisible(registeredDevicesContainer.getWidgetCount() > 0);
- clearRegisteredDevices(registeredDevicesContainer.getWidgetCount() == 0);
+ if (registeredDevicesContainer.getWidgetCount() == 0) {
+ clearRegisteredDevices(true);
+ }
}
@Override
@@ -359,10 +362,10 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
presenter.delete();
}
- @UiHandler("cancelButton")
- void cancelClicked(ClickEvent e) {
+ @UiHandler("refreshDeviceRegistrations")
+ void refreshDeviceRegistrationsClicked(ClickEvent e) {
if (presenter != null)
- presenter.cancel();
+ presenter.onDeviceRegistrationsRefresh();
}
protected void clearRegisteredDevices(boolean addEmptyMessage) {
@@ -420,6 +423,7 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
deviceTypeField.add(deviceTypeOutput);
typeLoginPanel.add(deviceTypeGroup);
+ // TODO The label says "first login" because we still don't capture last login on service/from consoles
FormGroup lastLoginGroup = new FormGroup();
FormField lastLoginField = new FormField();
FormLabel lastLoginLabel = new FormLabel(managerMessages.registeredDeviceLastLogin());
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/edit/AdminUserEditImpl.ui.xml
similarity index 90%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.ui.xml
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/edit/AdminUserEditImpl.ui.xml
index 42645fdb2..2e810e9e6 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/edit/AdminUserEditImpl.ui.xml
@@ -1,33 +1,14 @@
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
- xmlns:w="urn:import:org.openremote.manager.client.widget">
+ xmlns:w="urn:import:org.openremote.manager.client.widget"
+ xmlns:adminUsers="urn:import:org.openremote.manager.client.admin.users">
<ui:with field="managerMessages" type="org.openremote.manager.client.i18n.ManagerMessages"/>
<ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/>
- <ui:style>
- .navItem {
- margin: 0 1em;
- }
-
- .formMessages {
- max-width: 30em;
- }
- </ui:style>
-
<g:HTMLPanel styleName="flex layout vertical">
- <g:HTMLPanel
- styleName="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>
+ <adminUsers:AdminUsersNavigation ui:field="adminUsersNavigation"/>
<w:Form ui:field="form" addStyleNames="flex">
@@ -37,17 +18,6 @@
<w:Headline icon="edit"
text="{managerMessages.editUser}"/>
- <w:FormGroup ui:field="enabledGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.enabled}" addStyleNames="larger"/>
- </w:label>
- <w:field>
- <w:FormField>
- <w:FormCheckBox ui:field="enabledCheckBox"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
<div class="layout horizontal center wrap">
<w:FormGroup ui:field="usernameGroup" addStyleNames="flex">
<w:label>
@@ -94,6 +64,17 @@
</w:FormGroup>
</div>
+ <w:FormGroup ui:field="enabledGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.enabled}" addStyleNames="larger"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormCheckBox ui:field="enabledCheckBox"/>
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
<g:Label ui:field="resetPasswordNote"
styleName="{widgetStyle.FormMessages} info"
text="{managerMessages.notePasswordAfterCreate}"/>
@@ -155,7 +136,9 @@
visible="false" icon="save"/>
<w:FormButton ui:field="deleteButton" danger="true" text="{managerMessages.deleteUser}"
visible="false" icon="trash"/>
- <w:FormButton ui:field="cancelButton" text="{managerMessages.cancel}" icon="close"/>
+ <w:FormButton ui:field="refreshDeviceRegistrations"
+ text="{managerMessages.refreshDeviceRegistrations}"
+ icon="refresh"/>
</w:FormField>
</w:field>
</w:FormGroup>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserPlace.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/edit/AdminUserEditPlace.java
similarity index 61%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserPlace.java
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/edit/AdminUserEditPlace.java
index 3c57d8756..6ab46037b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserPlace.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/edit/AdminUserEditPlace.java
@@ -17,55 +17,46 @@
* 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;
+package org.openremote.manager.client.admin.users.edit;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
-import org.openremote.manager.client.admin.AdminPlace;
+import org.openremote.manager.client.admin.users.AbstractAdminUsersPlace;
-public class AdminUserPlace extends AdminPlace {
+public class AdminUserEditPlace extends AbstractAdminUsersPlace {
- final String realm;
- final String userId;
-
- public AdminUserPlace(String realm) {
- this.realm = realm;
- this.userId = null;
- }
-
- public AdminUserPlace(String realm, String userId) {
- this.realm = realm;
- this.userId = userId;
+ public AdminUserEditPlace(AbstractAdminUsersPlace place) {
+ this(place.getRealm(), place.getUserId());
}
- public String getRealm() {
- return realm;
+ public AdminUserEditPlace(String realm) {
+ super(realm);
}
- public String getUserId() {
- return userId;
+ public AdminUserEditPlace(String realm, String userId) {
+ super(realm, userId);
}
- @Prefix("user")
- public static class Tokenizer implements PlaceTokenizer<AdminUserPlace> {
+ @Prefix("adminUserEdit")
+ public static class Tokenizer implements PlaceTokenizer<AdminUserEditPlace> {
@Override
- public AdminUserPlace getPlace(String token) {
+ public AdminUserEditPlace getPlace(String token) {
if (token == null) {
throw new IllegalArgumentException("Invalid empty token");
}
String[] fields = token.split(":");
if (fields.length == 1) {
- return new AdminUserPlace(fields[0]);
+ return new AdminUserEditPlace(fields[0]);
} else if (fields.length == 2) {
- return new AdminUserPlace(fields[0], fields[1]);
+ return new AdminUserEditPlace(fields[0], fields[1]);
} else {
throw new IllegalArgumentException("Invalid token: " + token);
}
}
@Override
- public String getToken(AdminUserPlace place) {
+ public String getToken(AdminUserEditPlace place) {
if (place.getRealm() == null) {
return "";
}
@@ -73,11 +64,4 @@ public class AdminUserPlace extends AdminPlace {
}
}
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "realm='" + realm + '\'' +
- ", userId='" + userId + '\'' +
- "}";
- }
}
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/notifications/AdminUserNotificationEditor.java
similarity index 94%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditor.java
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationEditor.java
index 31820ddfc..6082793fd 100644
--- 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/notifications/AdminUserNotificationEditor.java
@@ -17,7 +17,7 @@
* 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;
+package org.openremote.manager.client.admin.users.notifications;
import org.openremote.model.notification.AlertNotification;
diff --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/notifications/AdminUserNotificationEditorImpl.java
similarity index 97%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserNotificationEditorImpl.java
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationEditorImpl.java
index fe78f7cfb..d9ec1deaf 100644
--- 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/notifications/AdminUserNotificationEditorImpl.java
@@ -17,11 +17,10 @@
* 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;
+package org.openremote.manager.client.admin.users.notifications;
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;
@@ -41,7 +40,7 @@ public class AdminUserNotificationEditorImpl implements AdminUserNotificationEdi
final protected FlowPanel errorPanel = new FlowPanel();
final protected FormInputText notificationTitleInput = new FormInputText();
- final protected TextArea notificationMessageInput = new TextArea();
+ final protected FormTextArea notificationMessageInput = new FormTextArea();
final protected FormInputText notificationAppUrlInput = new FormInputText();
AlertNotification alertNotification;
@@ -112,7 +111,7 @@ public class AdminUserNotificationEditorImpl implements AdminUserNotificationEdi
messageGroup.setFormLabel(messageLabel);
FormField messageField = new FormField();
messageGroup.setFormField(messageField);
- notificationMessageInput.addStyleName("flex");
+ notificationMessageInput.addStyleName("flex border");
notificationMessageInput.setHeight("5em");
notificationMessageInput.getElement().getStyle().setProperty("resize", "none");
messageField.add(notificationMessageInput);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotifications.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotifications.java
new file mode 100644
index 000000000..32c41a04f
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotifications.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016, 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.notifications;
+
+import org.openremote.manager.client.admin.AdminContent;
+import org.openremote.manager.client.admin.users.AbstractAdminUsersPlace;
+import org.openremote.model.notification.AlertNotification;
+
+public interface AdminUserNotifications extends AdminContent {
+
+ interface Presenter {
+
+ AbstractAdminUsersPlace getPlace();
+
+ void onRefresh();
+
+ void onSendNotification();
+
+ void onNotificationDelete(Long id);
+
+ void onNotificationsDelete();
+
+ }
+
+ void setPresenter(Presenter presenter);
+
+ void setUsername(String username);
+
+ void setNotifications(AlertNotification[] notifications);
+
+ void removeNotification(Long id);
+
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsActivity.java
new file mode 100644
index 000000000..b99d15c4e
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsActivity.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2016, 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.notifications;
+
+import com.google.gwt.user.client.ui.AcceptsOneWidget;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.admin.*;
+import org.openremote.manager.client.admin.navigation.AdminNavigation;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditPlace;
+import org.openremote.manager.client.event.ShowSuccessEvent;
+import org.openremote.manager.client.mvp.AppActivity;
+import org.openremote.manager.shared.notification.NotificationResource;
+import org.openremote.manager.shared.security.User;
+import org.openremote.manager.shared.security.UserResource;
+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.Collection;
+
+import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
+
+public class AdminUserNotificationsActivity
+ extends AbstractAdminActivity<AdminUserNotificationsPlace, AdminUserNotifications>
+ implements AdminUserNotifications.Presenter {
+
+ final protected Environment environment;
+ final protected UserResource userResource;
+ final 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 AlertNotificationArrayMapper alertNotificationArrayMapper;
+
+ protected AdminUserEditPlace place;
+ protected String realm;
+ protected String userId;
+ protected User user;
+ protected AlertNotification alertNotification;
+
+ @Inject
+ public AdminUserNotificationsActivity(Environment environment,
+ AdminView adminView,
+ AdminNavigation.Presenter adminNavigationPresenter,
+ AdminUserNotifications view,
+ UserResource userResource,
+ UserMapper userMapper,
+ CredentialMapper credentialMapper,
+ RoleArrayMapper roleArrayMapper,
+ AdminUserNotificationEditor notificationEditor,
+ NotificationResource notificationResource,
+ AlertNotificationMapper alertNotificationMapper,
+ AlertNotificationArrayMapper alertNotificationArrayMapper) {
+ super(adminView, adminNavigationPresenter, view);
+ this.environment = environment;
+ this.userResource = userResource;
+ this.userMapper = userMapper;
+ this.credentialMapper = credentialMapper;
+ this.roleArrayMapper = roleArrayMapper;
+ this.notificationEditor = notificationEditor;
+ this.notificationResource = notificationResource;
+ this.alertNotificationMapper = alertNotificationMapper;
+ this.alertNotificationArrayMapper = alertNotificationArrayMapper;
+ }
+
+ @Override
+ protected String[] getRequiredRoles() {
+ return new String[]{"read:admin", "write:admin"};
+ }
+
+ @Override
+ protected AppActivity<AdminUserNotificationsPlace> init(AdminUserNotificationsPlace place) {
+ realm = place.getRealm();
+ userId = place.getUserId();
+ return super.init(place);
+ }
+
+ @Override
+ public void start(AcceptsOneWidget container, EventBus eventBus, Collection<EventRegistration> registrations) {
+ super.start(container, eventBus, registrations);
+
+ adminContent.setPresenter(this);
+
+ adminContent.clearFormMessages();
+
+ if (userId != null) {
+ loadUser();
+ }
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ notificationEditor.reset();
+ adminContent.setPresenter(null);
+ adminContent.clearFormMessages();
+ }
+
+ @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 -> {
+ adminContent.setFormBusy(true);
+ this.alertNotification = updatedNotification;
+ environment.getRequestService().execute(
+ alertNotificationMapper,
+ requestParams -> notificationResource.storeNotificationForUser(requestParams, userId, this.alertNotification),
+ 204,
+ () -> {
+ environment.getEventBus().dispatch(new ShowSuccessEvent(
+ environment.getMessages().notificationSentToUser()
+ ));
+ loadNotifications(() -> adminContent.setFormBusy(false));
+ },
+ ex -> handleRequestException(ex, environment)
+ );
+ });
+ notificationEditor.show();
+ }
+
+ @Override
+ public void onRefresh() {
+ loadNotifications(() -> {});
+ }
+
+ @Override
+ public void onNotificationsDelete() {
+ adminContent.setFormBusy(true);
+ environment.getRequestService().execute(
+ requestParams -> notificationResource.removeNotificationsOfUser(requestParams, userId),
+ 204,
+ () -> {
+ environment.getEventBus().dispatch(new ShowSuccessEvent(
+ environment.getMessages().notificationsDeleted())
+ );
+ loadNotifications(() -> adminContent.setFormBusy(false));
+ },
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+
+ @Override
+ public void onNotificationDelete(Long id) {
+ adminContent.setFormBusy(true);
+ environment.getRequestService().execute(
+ requestParams -> notificationResource.removeNotification(requestParams, userId, id),
+ 204,
+ () -> {
+ adminContent.setFormBusy(false);
+ adminContent.removeNotification(id);
+ environment.getEventBus().dispatch(new ShowSuccessEvent(
+ environment.getMessages().notificationDeleted(id))
+ );
+ },
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+
+ 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;
+ }
+
+ protected void loadUser() {
+ adminContent.setFormBusy(true);
+ environment.getRequestService().execute(
+ userMapper,
+ requestParams -> userResource.get(requestParams, realm, userId),
+ 200,
+ user -> {
+ this.user = user;
+ this.realm = user.getRealm();
+ adminContent.setUsername(user.getFullName());
+ loadNotifications(() -> {
+ adminContent.setFormBusy(false);
+ });
+ },
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+
+ protected void loadNotifications(Runnable onComplete) {
+ environment.getRequestService().execute(
+ alertNotificationArrayMapper,
+ requestParams -> notificationResource.getNotificationsOfUser(requestParams, userId),
+ 200,
+ notifications -> {
+ adminContent.setNotifications(notifications);
+ onComplete.run();
+ },
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsImpl.java
new file mode 100644
index 000000000..a035eece4
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsImpl.java
@@ -0,0 +1,248 @@
+/*
+ * 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.notifications;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.gwt.user.client.ui.Label;
+import com.google.inject.Provider;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.admin.users.AdminUsersNavigation;
+import org.openremote.manager.client.app.dialog.Confirmation;
+import org.openremote.manager.client.widget.*;
+import org.openremote.model.Constants;
+import org.openremote.model.notification.AlertNotification;
+
+import javax.inject.Inject;
+
+public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUserNotifications {
+
+ interface UI extends UiBinder<HTMLPanel, AdminUserNotificationsImpl> {
+ }
+
+ @UiField(provided = true)
+ AdminUsersNavigation adminUsersNavigation;
+
+ @UiField
+ FormOutputText usernameOutput;
+
+ @UiField
+ FormButton sendNotificationButton;
+
+ @UiField
+ FormButton refreshNotificationsButton;
+
+ @UiField
+ FormButton deleteNotificationsButton;
+
+ @UiField
+ FlowPanel notificationsContainer;
+
+ protected Presenter presenter;
+
+ @Inject
+ public AdminUserNotificationsImpl(Environment environment,
+ Provider<Confirmation> confirmationDialogProvider,
+ AdminUsersNavigation adminUsersNavigation) {
+ super(confirmationDialogProvider, environment.getWidgetStyle());
+
+ this.adminUsersNavigation = adminUsersNavigation;
+
+ UI ui = GWT.create(UI.class);
+ initWidget(ui.createAndBindUi(this));
+
+ sendNotificationButton.addClickHandler(event -> {
+ if (presenter != null) {
+ presenter.onSendNotification();
+ }
+ });
+
+ refreshNotificationsButton.addClickHandler(event -> {
+ if (presenter != null) {
+ presenter.onRefresh();
+ }
+ });
+
+ deleteNotificationsButton.addClickHandler(event -> {
+ if (presenter != null) {
+ presenter.onNotificationsDelete();
+ }
+ });
+ }
+
+ @Override
+ public void setPresenter(Presenter presenter) {
+ this.presenter = presenter;
+ if (presenter == null) {
+ deleteNotificationsButton.setEnabled(false);
+ adminUsersNavigation.setVisible(false);
+ adminUsersNavigation.reset();
+ usernameOutput.setText(null);
+ } else {
+ adminUsersNavigation.setActive(presenter.getPlace());
+ adminUsersNavigation.setVisible(true);
+ }
+ }
+
+ @Override
+ public void setUsername(String username) {
+ usernameOutput.setText(username);
+ }
+
+ @Override
+ public void setNotifications(AlertNotification[] notifications) {
+ clearNotifications(notifications.length == 0);
+ for (AlertNotification notification : notifications) {
+ notificationsContainer.add(new NotificationItem(notification));
+ }
+ }
+
+ @Override
+ public void removeNotification(Long id) {
+ for (int i = 0; i < notificationsContainer.getWidgetCount(); i++) {
+ if (notificationsContainer.getWidget(i) instanceof NotificationItem) {
+ NotificationItem item = (NotificationItem) notificationsContainer.getWidget(i);
+ if (item.getNotification().getId().equals(id))
+ notificationsContainer.remove(i);
+ }
+ }
+ if (notificationsContainer.getWidgetCount() == 0) {
+ clearNotifications(true);
+ }
+ }
+
+
+ protected void clearNotifications(boolean addEmptyMessage) {
+ deleteNotificationsButton.setEnabled(!addEmptyMessage);
+ notificationsContainer.clear();
+ if (addEmptyMessage) {
+ Label emptyLabel = new Label(managerMessages.noNotifications());
+ emptyLabel.addStyleName(widgetStyle.FormListEmptyMessage());
+ notificationsContainer.add(emptyLabel);
+ }
+ }
+
+ protected class NotificationItem extends FlowPanel {
+
+ private final AlertNotification notification;
+
+ public NotificationItem(AlertNotification notification) {
+ this.notification = notification;
+ setStyleName("flex-none layout vertical or-FormListItem");
+
+ FormGroup statusGroup = new FormGroup();
+ statusGroup.setFormGroupActions(new FormGroupActions());
+ FormField statusField = new FormField();
+ FormLabel statusLabel = new FormLabel(managerMessages.deliveryStatus());
+ statusGroup.setFormLabel(statusLabel);
+ statusGroup.setFormField(statusField);
+ FormOutputText statusTxt = new FormOutputText(notification.getDeliveryStatus().toString());
+ statusField.add(statusTxt);
+
+ FormGroup createdOnGroup = new FormGroup();
+ createdOnGroup.addStyleName("flex");
+ createdOnGroup.setFormGroupActions(new FormGroupActions());
+ FormField createdOnField = new FormField();
+ FormLabel createdOnLabel = new FormLabel(managerMessages.createdOn());
+ createdOnGroup.setFormLabel(createdOnLabel);
+ createdOnGroup.setFormField(createdOnField);
+ FormOutputText createdOnTxt = new FormOutputText(
+ DateTimeFormat.getFormat(Constants.DEFAULT_DATETIME_FORMAT).format(notification.getCreatedOn())
+ );
+ createdOnTxt.addStyleName("flex");
+ createdOnField.add(createdOnTxt);
+
+ FormButton deleteButton = new FormButton();
+ deleteButton.setDanger(true);
+ deleteButton.setIcon("trash-o");
+ deleteButton.setText(managerMessages.deleteNotification());
+ deleteButton.addClickHandler(event -> {
+ if (presenter != null)
+ presenter.onNotificationDelete(notification.getId());
+ });
+ statusGroup.getFormGroupActions().add(deleteButton);
+
+ FlowPanel createdStatusPanel = new FlowPanel();
+ createdStatusPanel.setStyleName("layout horizontal wrap");
+ createdStatusPanel.add(createdOnGroup);
+ createdStatusPanel.add(statusGroup);
+ add(createdStatusPanel);
+
+ FormGroup titleGroup = new FormGroup();
+ FormField titleField = new FormField();
+ FormLabel titleLabel = new FormLabel(managerMessages.title());
+ titleGroup.setFormLabel(titleLabel);
+ titleGroup.setFormField(titleField);
+ FormOutputText titleTxt = new FormOutputText(notification.getTitle());
+ titleField.add(titleTxt);
+ add(titleGroup);
+
+ FormGroup messageGroup = new FormGroup();
+ FormField messageField = new FormField();
+ FormLabel messageLabel = new FormLabel(managerMessages.message());
+ messageGroup.setFormLabel(messageLabel);
+ messageGroup.setFormField(messageField);
+ FormTextArea messageTxt = new FormTextArea();
+ messageTxt.setReadOnly(true);
+ messageTxt.addStyleName("flex border");
+ messageTxt.setHeight("3em");
+ messageTxt.getElement().getStyle().setProperty("resize", "none");
+ messageTxt.setText(notification.getMessage());
+ messageField.add(messageTxt);
+ add(messageGroup);
+
+ for (int i = 0; i < notification.getActions().length(); i++) {
+ notification.getActions().get(i).ifPresent(action -> {
+ FormGroup actionGroup = new FormGroup();
+ FormField actionField = new FormField();
+ FormLabel actionLabel = new FormLabel(managerMessages.action());
+ actionGroup.setFormLabel(actionLabel);
+ actionGroup.setFormField(actionField);
+ FormTextArea actionTxt = new FormTextArea();
+ actionTxt.setReadOnly(true);
+ actionTxt.addStyleName("flex border");
+ actionTxt.setHeight("3em");
+ actionTxt.getElement().getStyle().setProperty("resize", "none");
+ actionTxt.setText(action.toJson());
+ actionField.add(actionTxt);
+ add(actionGroup);
+ });
+ }
+
+ FormGroup appUrlGroup = new FormGroup();
+ FormField appUrlField = new FormField();
+ FormLabel appUrlLabel = new FormLabel(managerMessages.notificationAppUrl());
+ appUrlGroup.setFormLabel(appUrlLabel);
+ appUrlGroup.setFormField(appUrlField);
+ FormOutputText appUrlTxt = new FormOutputText(notification.getAppUrl());
+ appUrlField.add(appUrlTxt);
+ add(appUrlGroup);
+ }
+
+ public AlertNotification getNotification() {
+ return notification;
+ }
+ }
+
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsImpl.ui.xml
new file mode 100644
index 000000000..e43041a48
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsImpl.ui.xml
@@ -0,0 +1,56 @@
+<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
+ xmlns:g="urn:import:com.google.gwt.user.client.ui"
+ xmlns:w="urn:import:org.openremote.manager.client.widget"
+ xmlns:adminUsers="urn:import:org.openremote.manager.client.admin.users">
+
+ <ui:with field="managerMessages" type="org.openremote.manager.client.i18n.ManagerMessages"/>
+ <ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/>
+
+ <g:HTMLPanel styleName="flex layout vertical">
+
+ <adminUsers:AdminUsersNavigation ui:field="adminUsersNavigation"/>
+
+ <w:Form ui:field="form" addStyleNames="flex">
+
+ <g:HTMLPanel ui:field="mainContent"
+ styleName="flex-none layout vertical {widgetStyle.MainContent}">
+
+ <w:Headline icon="send"
+ text="{managerMessages.notifications}"/>
+
+ <w:FormGroup>
+ <w:label>
+ <w:FormLabel text="{managerMessages.username}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormOutputText ui:field="usernameOutput" addStyleNames="flex"/>
+ </w:FormField>
+ </w:field>
+ <w:actions>
+ <w:FormGroupActions>
+ <w:FormButton ui:field="refreshNotificationsButton"
+ text="{managerMessages.refresh}"
+ icon="refresh"/>
+ <w:FormButton ui:field="deleteNotificationsButton"
+ danger="true"
+ text="{managerMessages.deleteNotifications}"
+ icon="trash"/>
+ <w:FormButton ui:field="sendNotificationButton"
+ primary="true"
+ text="{managerMessages.sendNotification}"
+ icon="send"/>
+ </w:FormGroupActions>
+ </w:actions>
+ </w:FormGroup>
+
+ </g:HTMLPanel>
+
+ <g:FlowPanel ui:field="notificationsContainer"
+ styleName="flex layout vertical {widgetStyle.MainContent} {widgetStyle.FormList}"/>
+
+ </w:Form>
+
+ </g:HTMLPanel>
+
+</ui:UiBinder>
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsPlace.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsPlace.java
new file mode 100644
index 000000000..432c07f20
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AdminUserNotificationsPlace.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016, 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.notifications;
+
+import com.google.gwt.place.shared.PlaceTokenizer;
+import com.google.gwt.place.shared.Prefix;
+import org.openremote.manager.client.admin.users.AbstractAdminUsersPlace;
+
+public class AdminUserNotificationsPlace extends AbstractAdminUsersPlace {
+
+ public AdminUserNotificationsPlace(AbstractAdminUsersPlace place) {
+ super(place.getRealm(), place.getUserId());
+ }
+
+ public AdminUserNotificationsPlace(String realm, String userId) {
+ super(realm, userId);
+ }
+
+ @Prefix("adminUserNotifications")
+ public static class Tokenizer implements PlaceTokenizer<AdminUserNotificationsPlace> {
+
+ @Override
+ public AdminUserNotificationsPlace getPlace(String token) {
+ if (token == null) {
+ throw new IllegalArgumentException("Invalid empty token");
+ }
+ String[] fields = token.split(":");
+ if (fields.length == 2) {
+ return new AdminUserNotificationsPlace(fields[0], fields[1]);
+ } else {
+ throw new IllegalArgumentException("Invalid token: " + token);
+ }
+ }
+
+ @Override
+ public String getToken(AdminUserNotificationsPlace place) {
+ if (place.getRealm() == null) {
+ return "";
+ }
+ return place.getRealm() + ":" + (place.getUserId() != null ? place.getUserId() : "");
+ }
+ }
+
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AlertNotificationArrayMapper.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AlertNotificationArrayMapper.java
new file mode 100644
index 000000000..cd3c48ff9
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AlertNotificationArrayMapper.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.users.notifications;
+
+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.EntityReader;
+import org.openremote.model.notification.AlertNotification;
+
+@JsonMixIns({@JsonMixIns.JsonMixIn(target = AlertNotification.class, mixIn = DefaultJsonMixin.class)})
+public interface AlertNotificationArrayMapper
+ extends ObjectMapper<AlertNotification[]>,
+ EntityReader<AlertNotification[]> {
+}
diff --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/users/notifications/AlertNotificationMapper.java
similarity index 95%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/AlertNotificationMapper.java
rename to manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AlertNotificationMapper.java
index 357adc633..e4ccbcb5b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/AlertNotificationMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/notifications/AlertNotificationMapper.java
@@ -17,7 +17,7 @@
* 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;
+package org.openremote.manager.client.admin.users.notifications;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.ui.xml
index a5cfcaee0..f01cee931 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.ui.xml
@@ -24,7 +24,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
</g:HTMLPanel>
<g:HTMLPanel styleName="flex layout vertical {widgetStyle.MainContent}"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml
index 1777a3269..6578dcfe7 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml
@@ -25,7 +25,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
</g:HTMLPanel>
<g:HTMLPanel styleName="flex {widgetStyle.MainContent}">
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml
index 0aea8d4ac..4bcb0950b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml
@@ -36,7 +36,7 @@
addStyleNames="{style.view}">
<g:HTMLPanel
- styleName="layout horizontal center {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center {widgetStyle.SecondaryNav}">
<!-- TODO Depends on AssetQuery/Rules Designer work
<w:FormInputText ui:field="searchInput"
@@ -61,7 +61,7 @@
</g:HTMLPanel>
<g:HTMLPanel
- styleName="layout horizontal center {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center {widgetStyle.SecondaryNav}">
<w:Hyperlink
ui:field="createAssetLink"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/navigation/AssetNavigationImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/navigation/AssetNavigationImpl.ui.xml
index 8e4e156f7..67f133517 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/navigation/AssetNavigationImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/navigation/AssetNavigationImpl.ui.xml
@@ -12,7 +12,7 @@
</ui:style>
- <g:HTMLPanel styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ <g:HTMLPanel styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
<g:FlowPanel ui:field="navItemContainer"
styleName="layout horizontal center"/>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java
index 27a35ad7b..f3d65d69f 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java
@@ -23,7 +23,7 @@ import com.google.gwt.user.client.ui.AcceptsOneWidget;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.TenantMapper;
import org.openremote.manager.client.admin.UserArrayMapper;
-import org.openremote.manager.client.admin.users.AdminUserPlace;
+import org.openremote.manager.client.admin.users.edit.AdminUserEditPlace;
import org.openremote.manager.client.assets.AssetBrowsingActivity;
import org.openremote.manager.client.assets.asset.AssetViewPlace;
import org.openremote.manager.client.assets.browser.*;
@@ -44,7 +44,6 @@ import java.util.Arrays;
import java.util.Collection;
import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
-import static org.openremote.model.util.TextUtil.isNullOrEmpty;
public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlace> implements AssetsTenant.Presenter {
@@ -197,7 +196,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
@Override
public void onEditUser(UserAsset.Id id) {
environment.getPlaceController().goTo(
- new AdminUserPlace(tenant.getRealm(), id.getUserId())
+ new AdminUserEditPlace(tenant.getRealm(), id.getUserId())
);
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml
index 095545d4b..f3a6bc1ec 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml
@@ -18,7 +18,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
</g:HTMLPanel>
<w:Form ui:field="form" addStyleNames="flex">
diff --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.java
index 41bbc2db7..ed26dece6 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
@@ -496,4 +496,28 @@ public interface ManagerMessages extends Messages {
String userAssetLinkDeleted();
String assetNotInTenant(String displayName);
+
+ String notifications();
+
+ String manageNotifications();
+
+ String allUsers();
+
+ String noNotifications();
+
+ String notificationDeleted(Long id);
+
+ String deleteNotification();
+
+ String deliveryStatus();
+
+ String action();
+
+ String notificationsDeleted();
+
+ String refresh();
+
+ String deleteNotifications();
+
+ String refreshDeviceRegistrations();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
index 3406952ff..004da50e1 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
@@ -26,7 +26,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
<w:Hyperlink
ui:field="viewAssetLink"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/mvp/AppActivity.java b/manager/client/src/main/java/org/openremote/manager/client/mvp/AppActivity.java
index 722cde8da..bac435c62 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/mvp/AppActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/mvp/AppActivity.java
@@ -33,6 +33,8 @@ import java.util.Collection;
*/
public abstract class AppActivity<P extends Place> {
+ protected P place;
+
public String mayStop() {
return null;
}
@@ -49,9 +51,14 @@ public abstract class AppActivity<P extends Place> {
throw new RoleRequiredException(requiredRole);
}
}
+ this.place = place;
return init(place);
}
+ public P getPlace() {
+ return place;
+ }
+
protected abstract AppActivity<P> init(P place);
/**
diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml
index 215baaade..782ede290 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml
@@ -36,7 +36,7 @@
<w:second>
<g:HTMLPanel styleName="flex layout vertical">
- <div class="layout horizontal center end-justified {style.rulesControls} {widgetStyle.SecondaryNavHorizontal}">
+ <div class="layout horizontal center end-justified {style.rulesControls} {widgetStyle.SecondaryNav}">
<w:Hyperlink
addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesListImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesListImpl.ui.xml
index e7b484cbb..f8976ed5d 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesListImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesListImpl.ui.xml
@@ -41,7 +41,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
<w:Hyperlink
ui:field="createLink"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesListImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesListImpl.ui.xml
index 831e54cbd..13573631e 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesListImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesListImpl.ui.xml
@@ -45,7 +45,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
<w:Hyperlink
ui:field="createLink"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesListImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesListImpl.ui.xml
index 52f05b7c3..2893cfdd2 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesListImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesListImpl.ui.xml
@@ -46,7 +46,7 @@
<g:HTMLPanel styleName="flex layout vertical">
<g:HTMLPanel
- styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
<w:Hyperlink
ui:field="createLink"
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.java
index b0cdd0efe..cdb576ba9 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
@@ -41,10 +41,6 @@ public class WidgetStyle {
return "or-SecondaryNav";
}
- public String SecondaryNavHorizontal() {
- return "or-SecondaryNavHorizontal";
- }
-
public String SecondaryNavItem() {
return "or-SecondaryNavItem";
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.java b/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.java
index 562744ef1..b9cafc4f5 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.java
@@ -35,12 +35,19 @@ public class Hyperlink extends com.google.gwt.user.client.ui.Hyperlink {
protected Runnable simpleClickHandler;
public Hyperlink() {
+ this(null, null);
+ }
+
+ public Hyperlink(String icon, String text) {
super();
getElement().addClassName("or-Hyperlink");
Element anchor = getElement().getFirstChildElement();
// TODO Clickable icon?!
DOM.insertBefore(getElement(), iconLabel.getElement(), anchor);
+
+ setIcon(icon);
+ setText(text);
}
public String getIcon() {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/SecondaryNavigation.java b/manager/client/src/main/java/org/openremote/manager/client/widget/SecondaryNavigation.java
new file mode 100644
index 000000000..cd0d07c5e
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/SecondaryNavigation.java
@@ -0,0 +1,54 @@
+/*
+ * 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.widget;
+
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+public class SecondaryNavigation extends FlowPanel {
+
+ public SecondaryNavigation() {
+ setHorizontal();
+ }
+
+ protected void setHorizontal() {
+ setStyleName("layout horizontal center end-justified or-SecondaryNav");
+ }
+
+ public void setVertical(boolean vertical) {
+ if (vertical) {
+ setStyleName("layout vertical or-SecondaryNav");
+ } else {
+ setHorizontal();
+ }
+ }
+
+ @Override
+ public void add(Widget w) {
+ super.add(w);
+ w.addStyleName("or-SecondaryNavItem");
+ }
+
+ protected void reset(Hyperlink hyperlink) {
+ hyperlink.removeStyleName("active");
+ hyperlink.setVisible(false);
+ hyperlink.setTargetHistoryToken("");
+ }
+}
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.properties
index dbb0ecf26..bf2e0ecfe 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
@@ -376,7 +376,7 @@ noRegisteredDevices=The user never logged in on any console device.
registeredDeviceId=Registered console device ID
deleteRegistration=Delete device registration
registeredDeviceType=Device type
-registeredDeviceLastLogin=Last login
+registeredDeviceLastLogin=First login
registeredDeviceNotificationToken=Notification token
registeredDeviceDeleted=Device registration deleted: {0}
sendNotification=Send notification
@@ -397,3 +397,15 @@ linkedToUser=Linked to user
userAssetLinkCreated=Asset/user link created.
userAssetLinkDeleted=Asset/user link deleted.
assetNotInTenant=Asset not in tenant: {0}
+notifications=Notifications
+manageNotifications=Manage notifications
+allUsers=All users
+noNotifications=This user has no stored notifications.
+notificationDeleted=Notification deleted: {0}
+deleteNotification=Delete notification
+deliveryStatus=Delivery status
+action=Action
+notificationsDeleted=Notifications deleted.
+refresh=Refresh
+deleteNotifications=Delete all notifications
+refreshDeviceRegistrations=Refresh device registrations
diff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.html
index f39d5ebf9..ea6c96fb9 100644
--- a/manager/client/src/main/webapp/css/style.html
+++ b/manager/client/src/main/webapp/css/style.html
@@ -47,7 +47,11 @@
min-width: 12em;
}
- .or-SecondaryNavHorizontal {
+ .or-SecondaryNav.vertical {
+ padding-top: 2.8em !important;
+ }
+
+ .or-SecondaryNav.horizontal {
padding: 0.4em;
height: 2em;
min-height: 2em;
@@ -64,6 +68,7 @@
border-radius: 0.15em;
font-weight: 600;
display: inline-block;
+ margin: 0 1em;
}
.or-SecondaryNavItem a {
@@ -91,9 +96,9 @@
}
.or-LeftGradient::before {
- background: -moz-linear-gradient(right, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0) 100%);
- background: -webkit-linear-gradient(right, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%);
- background: linear-gradient(to left, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%);
+ background: -moz-linear-gradient(right, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
+ background: -webkit-linear-gradient(right, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
+ background: linear-gradient(to left, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
content: "\00a0";
height: 100%;
position: absolute;
@@ -111,8 +116,8 @@
}
.or-MainContent.scrollable div {
- -webkit-flex-shrink:0;
- flex-shrink:0;
+ -webkit-flex-shrink: 0;
+ flex-shrink: 0;
}
.or-MainContent:first-child {
@@ -203,16 +208,13 @@
text-decoration: underline;
}
- .or-SecondaryNav .or-Hyperlink,
- .or-SecondaryNavHorizontal .or-Hyperlink {
+ .or-SecondaryNav .or-Hyperlink {
padding: 0;
border-radius: 0
}
.or-SecondaryNav .or-Hyperlink a:hover,
- .or-SecondaryNav .or-Hyperlink a:focus,
- .or-SecondaryNavHorizontal .or-Hyperlink a:hover,
- .or-SecondaryNavHorizontal .or-Hyperlink a:focus {
+ .or-SecondaryNav .or-Hyperlink a:focus {
text-decoration: none;
}
@@ -416,6 +418,12 @@
resize: none;
}
+ .or-FormTextArea.border {
+ border-width: 1px;
+ border-style: solid;
+ padding: 0.4em 0.4em !important;
+ }
+
.or-FormFileUploadLabel input[type="file"] {
position: fixed;
top: -10000px;
@@ -563,7 +571,7 @@
padding: 0.4em;
}
- .or-FormListItem .or-FormGroup:last-child {
+ .or-FormListItem > .or-FormGroup:last-of-type {
margin-bottom: 0;
}
diff --git a/manager/client/src/main/webapp/css/theme.html b/manager/client/src/main/webapp/css/theme.html
index 7c4bb8226..4a4456c4f 100644
--- a/manager/client/src/main/webapp/css/theme.html
+++ b/manager/client/src/main/webapp/css/theme.html
@@ -58,8 +58,7 @@
border-top-color: var(--theme-lightgreen) !important;
}
- .or-SecondaryNav,
- .or-SecondaryNavHorizontal {
+ .or-SecondaryNav {
background-color: var(--theme-black);
color: var(--theme-white);
}
@@ -233,6 +232,10 @@
background-color: var(--theme-brightgrey);
}
+ .or-FormTextArea.border {
+ border-color: var(--theme-darkgrey);
+ }
+
.or-FormButton {
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.java b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.java
index 250b579b3..464fe9e3f 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.java
@@ -34,4 +34,11 @@ public class FCMBaseMessage {
public void setTo(String to) {
this.to = to;
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{" +
+ "to='" + to + '\'' +
+ '}';
+ }
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMDeliveryService.java b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMDeliveryService.java
new file mode 100644
index 000000000..3085ba31f
--- /dev/null
+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMDeliveryService.java
@@ -0,0 +1,140 @@
+/*
+ * 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.server.notification;
+
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.openremote.container.Container;
+import org.openremote.manager.shared.notification.DeviceNotificationToken;
+import org.openremote.model.notification.AlertNotification;
+import org.openremote.model.notification.DeliveryStatus;
+
+import javax.persistence.EntityManager;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
+
+public class FCMDeliveryService {
+
+ private static final Logger LOG = Logger.getLogger(FCMDeliveryService.class.getName());
+
+ public static final String NOTIFICATION_FIREBASE_API_KEY = "NOTIFICATION_FIREBASE_API_KEY";
+ public static final String NOTIFICATION_FIREBASE_URL = "NOTIFICATION_FIREBASE_URL";
+ public static final String NOTIFICATION_FIREBASE_URL_DEFAULT = "https://fcm.googleapis.com/fcm/send";
+
+ final protected String fcmKey;
+ final protected ResteasyWebTarget firebaseTarget;
+
+ public FCMDeliveryService(Container container) {
+ this(
+ container.getConfig().get(NOTIFICATION_FIREBASE_API_KEY),
+ container.getConfig().getOrDefault(NOTIFICATION_FIREBASE_URL, NOTIFICATION_FIREBASE_URL_DEFAULT)
+ );
+ }
+
+ public FCMDeliveryService(String fcmKey, String firebaseUrl) {
+ if (fcmKey == null) {
+ LOG.info(NOTIFICATION_FIREBASE_API_KEY + " not defined, can not send notifications to user devices");
+ }
+ this.fcmKey = fcmKey;
+
+ ResteasyClient client = new ResteasyClientBuilder()
+ .socketTimeout(30, TimeUnit.SECONDS)
+ .establishConnectionTimeout(10, TimeUnit.SECONDS)
+ .build();
+ firebaseTarget = client.target(firebaseUrl);
+ }
+
+ public Consumer<EntityManager> deliverPendingToFCM(String userId, List<DeviceNotificationToken> deviceTokens) {
+ return entityManager -> {
+ List<AlertNotification> pendingNotifications = entityManager.createQuery(
+ "SELECT an FROM AlertNotification an WHERE an.userId =:userId and an.deliveryStatus = :deliveryStatus",
+ AlertNotification.class
+ ).setParameter("userId", userId).setParameter("deliveryStatus", DeliveryStatus.PENDING).getResultList();
+
+ // If there are any pending notifications for the user
+ if (pendingNotifications.size() > 0) {
+ // If at least one of the user's devices received the pickup signal, it's queued
+ if (sendPickupSignalThroughFCM(userId, deviceTokens)) {
+ for (AlertNotification notification : pendingNotifications) {
+ notification.setDeliveryStatus(DeliveryStatus.QUEUED);
+ }
+ }
+ }
+ };
+ }
+
+ /**
+ * @return <code>true</code> if a signal was delivered to at least one device of the user.
+ */
+ protected boolean sendPickupSignalThroughFCM(String userId, List<DeviceNotificationToken> deviceTokens) {
+ if (fcmKey == null) {
+ LOG.warning("No " + NOTIFICATION_FIREBASE_API_KEY + " configured, can't deliver pending notifications of: " + userId);
+ return false;
+ }
+
+ if (deviceTokens.size() == 0) {
+ LOG.fine("No registered devices, can't deliver pending notifications of: " + userId);
+ return false;
+ }
+
+ boolean success = false;
+ for (DeviceNotificationToken deviceToken : deviceTokens) {
+ try {
+ Invocation.Builder builder = firebaseTarget.request().header("Authorization", "key=" + fcmKey);
+ FCMBaseMessage message;
+ if ("ANDROID".equals(deviceToken.getDeviceType())) {
+ message = new FCMBaseMessage(deviceToken.getToken());
+ } else {
+ message = new FCMMessage(new FCMNotification("_"), true, true, "high", deviceToken.getToken());
+ }
+ LOG.fine("Sending FCM notification pickup message to: " + deviceToken);
+ Response response = builder.post(Entity.entity(message, "application/json"));
+ if (response.getStatus() != 200) {
+ LOG.warning("Error sending FCM notification pickup message, status=[" + response.getStatus() + "], statusInformation=[" + response.getStatusInfo() + "]");
+ } else {
+ LOG.fine("Pickup message delivered successfully delivered to FCM: " + deviceToken);
+ }
+ response.close();
+
+ success = true;
+ } catch (Exception e) {
+ if (success) {
+ LOG.log(Level.WARNING, "Error sending FCM notification pickup message: " + getRootCause(e), e);
+ }
+ }
+ }
+ if (success) {
+ LOG.fine("Successfully delivered FCM pickup message for at least one device of: " + userId);
+ } else {
+ LOG.warning("Unsuccessful sending FCM pickup message for any device of: " + userId);
+ }
+ return success;
+ }
+
+}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.java b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.java
index 8ddb9adcc..fdabf2be3 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.java
@@ -23,12 +23,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class FCMMessage extends FCMBaseMessage {
- protected Notification notification;
+ protected FCMNotification notification;
protected boolean contentAvailable;
protected boolean mutableContent;
protected String priority;
- public FCMMessage(Notification notification, boolean contentAvailable, boolean mutableContent, String priority, String to) {
+ public FCMMessage(FCMNotification notification, boolean contentAvailable, boolean mutableContent, String priority, String to) {
super(to);
this.notification = notification;
this.contentAvailable = contentAvailable;
@@ -36,11 +36,11 @@ public class FCMMessage extends FCMBaseMessage {
this.priority = priority;
}
- public Notification getNotification() {
+ public FCMNotification getNotification() {
return notification;
}
- public void setNotification(Notification notification) {
+ public void setNotification(FCMNotification notification) {
this.notification = notification;
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/Notification.java b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMNotification.java
similarity index 92%
rename from manager/server/src/main/java/org/openremote/manager/server/notification/Notification.java
rename to manager/server/src/main/java/org/openremote/manager/server/notification/FCMNotification.java
index 1eb06b01d..e97c3f093 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/notification/Notification.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMNotification.java
@@ -19,14 +19,12 @@
*/
package org.openremote.manager.server.notification;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class Notification {
+public class FCMNotification {
protected String body;
protected String clickAction = "openremoteNotification";
- public Notification(String body) {
+ public FCMNotification(String body) {
super();
this.body = body;
}
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.java
index a955c77df..500665b1f 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
@@ -24,6 +24,7 @@ import org.openremote.manager.shared.http.RequestParams;
import org.openremote.manager.shared.notification.DeviceNotificationToken;
import org.openremote.manager.shared.notification.NotificationResource;
import org.openremote.model.notification.AlertNotification;
+import org.openremote.model.notification.DeliveryStatus;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
@@ -79,36 +80,56 @@ public class NotificationResourceImpl extends WebResource implements Notificatio
@Override
public void storeNotificationForUser(RequestParams requestParams, String userId, AlertNotification alertNotification) {
+ if (!isSuperUser()) {
+ LOG.fine("Forbidden access for user '" + getUsername() + "', can't store notification for user: " + userId);
+ throw new WebApplicationException(Response.Status.FORBIDDEN);
+ }
if (alertNotification == null) {
- throw new WebApplicationException("Missing alertNotification", BAD_REQUEST);
+ throw new WebApplicationException("Missing AlertNotification entity", BAD_REQUEST);
}
notificationService.storeAndNotify(userId, alertNotification);
}
@Override
- public List<AlertNotification> getNotificationsOfUser(RequestParams requestParams, String userId) {
- return null;
- // TODO
+ public AlertNotification[] getNotificationsOfUser(RequestParams requestParams, String userId) {
+ if (!isSuperUser()) {
+ LOG.fine("Forbidden access for user '" + getUsername() + "', can't get notifications of user: " + userId);
+ throw new WebApplicationException(Response.Status.FORBIDDEN);
+ }
+ return notificationService.getNotificationsOfUser(userId).toArray(new AlertNotification[0]);
+ }
+
+ @Override
+ public void removeNotificationsOfUser(RequestParams requestParams, String userId) {
+ if (!isSuperUser()) {
+ LOG.fine("Forbidden access for user '" + getUsername() + "', can't remove notifications of user: " + userId);
+ throw new WebApplicationException(Response.Status.FORBIDDEN);
+ }
+ notificationService.removeNotificationsOfUser(userId);
}
@Override
- public void removeNotificationOfUser(RequestParams requestParams, String userId) {
- // TODO
+ public void removeNotification(RequestParams requestParams, String userId, Long id) {
+ if (!isSuperUser()) {
+ LOG.fine("Forbidden access for user '" + getUsername() + "', can't remove notification of user: " + userId);
+ throw new WebApplicationException(Response.Status.FORBIDDEN);
+ }
+ notificationService.removeNotification(userId, id);
}
@Override
- public List<AlertNotification> getPendingNotificationsOfCurrentUser(RequestParams requestParams) {
- return notificationService.getPendingAlertForUserId(getUserId());
+ public List<AlertNotification> getQueuedNotificationsOfCurrentUser(RequestParams requestParams) {
+ return notificationService.getNotificationsOfUser(getUserId(), DeliveryStatus.QUEUED);
}
@Override
- public void ackPendingNotificationOfCurrentUser(RequestParams requestParams, Long id) {
+ public void ackNotificationOfCurrentUser(RequestParams requestParams, Long id) {
if (id == null) {
throw new WebApplicationException("Missing alert id", BAD_REQUEST);
}
- if (!notificationService.isPendingAlertForUserId(id, getUserId())) {
+ if (!isSuperUser() && !notificationService.isQueuedNotificationForUser(id, getUserId())) {
throw new WebApplicationException(FORBIDDEN);
}
- notificationService.removeAlertNotification(id);
+ notificationService.setAcknowledged(id);
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java
index 3694392dc..18ff69d4d 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java
@@ -19,9 +19,6 @@
*/
package org.openremote.manager.server.notification;
-import org.jboss.resteasy.client.jaxrs.ResteasyClient;
-import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
-import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.persistence.PersistenceService;
@@ -32,49 +29,27 @@ import org.openremote.model.notification.AlertNotification;
import org.openremote.model.notification.DeliveryStatus;
import org.openremote.model.user.UserQuery;
-import javax.persistence.EntityManager;
import javax.persistence.Query;
-import javax.persistence.TypedQuery;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.Response;
import java.util.Date;
import java.util.List;
import java.util.Optional;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
public class NotificationService implements ContainerService {
- private static final Logger LOG = Logger.getLogger(NotificationService.class.getName());
-
- public static final String NOTIFICATION_FIREBASE_API_KEY = "NOTIFICATION_FIREBASE_API_KEY";
- public static final String NOTIFICATION_FIREBASE_URL = "NOTIFICATION_FIREBASE_URL";
- public static final String NOTIFICATION_FIREBASE_URL_DEFAULT = "https://fcm.googleapis.com/fcm/send";
-
protected TimerService timerService;
protected PersistenceService persistenceService;
- protected ResteasyWebTarget firebaseTarget;
- private String fcmKey;
+ protected FCMDeliveryService fcmDeliveryService;
@Override
public void init(Container container) throws Exception {
this.timerService = container.getService(TimerService.class);
this.persistenceService = container.getService(PersistenceService.class);
- fcmKey = container.getConfig().get(NOTIFICATION_FIREBASE_API_KEY);
- if (fcmKey == null) {
- LOG.info(NOTIFICATION_FIREBASE_API_KEY + " not defined, can not send notifications to user devices");
- }
+ this.fcmDeliveryService = new FCMDeliveryService(container);
container.getService(WebService.class).getApiSingletons().add(
new NotificationResourceImpl(this)
);
-
- ResteasyClient client = new ResteasyClientBuilder().build();
- firebaseTarget = client.target(container.getConfig().getOrDefault(NOTIFICATION_FIREBASE_URL, NOTIFICATION_FIREBASE_URL_DEFAULT));
}
@Override
@@ -113,89 +88,71 @@ public class NotificationService implements ContainerService {
}
public List<DeviceNotificationToken> findAllTokenForUser(String userId) {
- return persistenceService.doReturningTransaction(entityManager -> {
- Query query = entityManager.createQuery(
- "SELECT dnt FROM DeviceNotificationToken dnt WHERE dnt.id.userId =:userId order by dnt.updatedOn desc"
- );
- query.setParameter("userId", userId);
- return query.getResultList();
- });
+ return persistenceService.doReturningTransaction(entityManager -> entityManager.createQuery(
+ "SELECT dnt FROM DeviceNotificationToken dnt WHERE dnt.id.userId =:userId order by dnt.updatedOn desc", DeviceNotificationToken.class
+ ).setParameter("userId", userId).getResultList());
}
+ public void storeAndNotify(String userId, AlertNotification notification) {
+ notification.setUserId(userId);
+ notification.setDeliveryStatus(DeliveryStatus.PENDING);
+ persistenceService.doTransaction(entityManager -> entityManager.merge(notification));
- public void storeAndNotify(String userId, AlertNotification alertNotification) {
- alertNotification.setUserId(userId);
- alertNotification.setDeliveryStatus(DeliveryStatus.PENDING);
- persistenceService.doTransaction((EntityManager entityManager) -> {
- entityManager.merge(alertNotification);
- if (fcmKey == null) {
- LOG.info("No " + NOTIFICATION_FIREBASE_API_KEY + " configured, not sending to '" + userId + "': " + alertNotification);
- return;
- }
- List<DeviceNotificationToken> allTokenForUser = findAllTokenForUser(userId);
- if (allTokenForUser.size() == 0) {
- LOG.fine("User has no registered devices/notification tokens: " + userId);
- }
- for (DeviceNotificationToken notificationToken : allTokenForUser) {
- try {
- Invocation.Builder builder = firebaseTarget.request().header("Authorization", "key=" + fcmKey);
- Notification notification = new Notification("_");
-
- FCMBaseMessage message;
- if ("ANDROID".equals(notificationToken.getDeviceType())) {
- message = new FCMBaseMessage(notificationToken.getToken());
- } else {
- message = new FCMMessage(notification, true, true, "high", notificationToken.getToken());
- }
- LOG.fine("Sending notification message to device of user '" + userId + "': " + message);
- Response response = builder.post(Entity.entity(message, "application/json"));
- if (response.getStatus() != 200) {
- LOG.severe("Error send FCM notification status=[" + response.getStatus() + "], statusInformation=[" + response.getStatusInfo() + "]");
- }
- response.close();
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Error sending notification to FCM: " + getRootCause(e), e);
- }
- }
- });
+ // Try to queue through FCM in a separate transaction
+ persistenceService.doTransaction(fcmDeliveryService.deliverPendingToFCM(userId, findAllTokenForUser(userId)));
}
- public List<AlertNotification> getPendingAlertForUserId(String userId) {
- return persistenceService.doReturningTransaction(entityManager -> {
- Query query = entityManager.createQuery("SELECT an FROM AlertNotification an WHERE an.userId =:userId and an.deliveryStatus =:deliveryStatus");
- query.setParameter("userId", userId);
- query.setParameter("deliveryStatus", DeliveryStatus.PENDING);
- return query.getResultList();
- });
+ public List<AlertNotification> getNotificationsOfUser(String userId, DeliveryStatus deliveryStatus) {
+ return persistenceService.doReturningTransaction(entityManager -> entityManager.createQuery(
+ "SELECT an FROM AlertNotification an WHERE an.userId =:userId and an.deliveryStatus = :deliveryStatus order by an.createdOn desc",
+ AlertNotification.class
+ ).setParameter("userId", userId).setParameter("deliveryStatus", deliveryStatus).getResultList());
}
- public boolean isPendingAlertForUserId(Long alertId, String userId) {
- return persistenceService.doReturningTransaction(entityManager -> {
- TypedQuery<Long> query = entityManager.createQuery(
- "SELECT count(an) FROM AlertNotification an WHERE an.id = :alertId and an.userId =:userId and an.deliveryStatus = :deliveryStatus"
- , Long.class);
- query.setParameter("alertId", alertId);
- query.setParameter("userId", userId);
- query.setParameter("deliveryStatus", DeliveryStatus.PENDING);
- return query.getSingleResult() > 0;
- });
+ public List<AlertNotification> getNotificationsOfUser(String userId) {
+ return persistenceService.doReturningTransaction(entityManager -> entityManager.createQuery(
+ "SELECT an FROM AlertNotification an WHERE an.userId = :userId order by an.createdOn desc",
+ AlertNotification.class
+ ).setParameter("userId", userId).getResultList());
}
- public void removeAlertNotification(Long id) {
+ public boolean isQueuedNotificationForUser(Long id, String userId) {
+ return persistenceService.doReturningTransaction(entityManager -> entityManager.createQuery(
+ "SELECT count(an) FROM AlertNotification an WHERE an.id = :alertId and an.userId =:userId and an.deliveryStatus = :deliveryStatus"
+ , Long.class
+ ).setParameter("alertId", id).setParameter("userId", userId).setParameter("deliveryStatus", DeliveryStatus.QUEUED).getSingleResult() > 0);
+ }
+
+ public void setAcknowledged(Long id) {
persistenceService.doTransaction(entityManager -> {
- Query query = entityManager.createQuery("UPDATE AlertNotification SET deliveryStatus=:status WHERE id =:id");
+ Query query = entityManager.createQuery("UPDATE AlertNotification SET deliveryStatus=:status WHERE id =:id");
query.setParameter("id", id);
- query.setParameter("status", DeliveryStatus.DELIVERED);
+ query.setParameter("status", DeliveryStatus.ACKNOWLEDGED);
query.executeUpdate();
- // TODO Who is cleaning up the delivered notifications?
+ // TODO Who is cleaning up the acknowledged notifications?
});
}
+ public void removeNotificationsOfUser(String userId) {
+ persistenceService.doTransaction(entityManager -> entityManager
+ .createQuery("delete AlertNotification an where an.userId = :userId")
+ .setParameter("userId", userId)
+ .executeUpdate()
+ );
+ }
+
+ public void removeNotification(String userId, Long id) {
+ persistenceService.doTransaction(entityManager -> entityManager
+ .createQuery("delete AlertNotification an where an.userId = :userId and an.id = :id")
+ .setParameter("userId", userId).setParameter("id", id)
+ .executeUpdate()
+ );
+ }
+
public List<String> findAllUsersWithToken() {
- return persistenceService.doReturningTransaction(entityManager -> {
- Query query = entityManager.createQuery("SELECT DISTINCT dnt.id.userId FROM DeviceNotificationToken dnt");
- return query.getResultList();
- });
+ return persistenceService.doReturningTransaction(entityManager ->
+ entityManager.createQuery("SELECT DISTINCT dnt.id.userId FROM DeviceNotificationToken dnt", String.class).getResultList()
+ );
}
public List<String> findAllUsersWithToken(UserQuery userQuery) {
@@ -214,11 +171,6 @@ public class NotificationService implements ContainerService {
});
}
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{}";
- }
-
protected String buildFromString(UserQuery query) {
StringBuilder sb = new StringBuilder();
@@ -249,4 +201,9 @@ public class NotificationService implements ContainerService {
return sb.toString();
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{}";
+ }
+
}
\ No newline at end of file
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.java
index 99af82425..1bb13b82e 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
@@ -97,8 +97,8 @@ public interface NotificationResource {
@SuccessStatusCode(200)
@Produces(APPLICATION_JSON)
@RolesAllowed({"read:admin"})
- List<AlertNotification> getNotificationsOfUser(@BeanParam RequestParams requestParams,
- @PathParam("userId") String userId);
+ AlertNotification[] getNotificationsOfUser(@BeanParam RequestParams requestParams,
+ @PathParam("userId") String userId);
/**
* Only the superuser can call this operation.
@@ -107,19 +107,30 @@ public interface NotificationResource {
@Path("alert/user/{userId}")
@SuccessStatusCode(204)
@RolesAllowed({"write:admin"})
- void removeNotificationOfUser(@BeanParam RequestParams requestParams,
- @PathParam("userId") String userId);
+ void removeNotificationsOfUser(@BeanParam RequestParams requestParams,
+ @PathParam("userId") String userId);
+
+ /**
+ * Only the superuser can call this operation.
+ */
+ @DELETE
+ @Path("alert/user/{userId}/{alertId}")
+ @SuccessStatusCode(204)
+ @RolesAllowed({"write:admin"})
+ void removeNotification(@BeanParam RequestParams requestParams,
+ @PathParam("userId") String userId,
+ @PathParam("alertId") Long id);
@GET
@Path("alert")
@Produces(APPLICATION_JSON)
@RolesAllowed({"write:user"})
- List<AlertNotification> getPendingNotificationsOfCurrentUser(@BeanParam RequestParams requestParams);
+ List<AlertNotification> getQueuedNotificationsOfCurrentUser(@BeanParam RequestParams requestParams);
@DELETE
@Path("alert/{alertId}")
@SuccessStatusCode(204)
@RolesAllowed({"write:user"})
- void ackPendingNotificationOfCurrentUser(@BeanParam RequestParams requestParams,
- @PathParam("alertId") Long id);
+ void ackNotificationOfCurrentUser(@BeanParam RequestParams requestParams,
+ @PathParam("alertId") Long id);
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/security/User.java b/manager/shared/src/main/java/org/openremote/manager/shared/security/User.java
index dec423426..8aae49f19 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/security/User.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/security/User.java
@@ -134,6 +134,10 @@ public class User {
this.enabled = enabled;
}
+ public String getFullName() {
+ return getUsername() + " (" + getFirstName() + " " + getLastName() + ")";
+ }
+
@Override
public String toString() {
return getClass().getName() + "{" +
diff --git a/manager/test/build.gradle b/manager/test/build.gradle
index 52923f02e..25807e5d6 100644
--- a/manager/test/build.gradle
+++ b/manager/test/build.gradle
@@ -26,7 +26,10 @@ dependencies {
compile "junit:junit:$junitVersion"
compile "org.spockframework:spock-core:$spockVersion"
- compile "com.github.calimero:calimero-server:$calimeroVersion"
+ compile("com.github.calimero:calimero-server:$calimeroVersion") {
+ // Libraries should not depend on a logging implementation and/or alpha versions!
+ exclude group: "org.slf4j"
+ }
}
test {
diff --git a/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
index 6499b5ea4..34b6ba8b0 100644
--- a/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
@@ -177,6 +177,7 @@ class AdminTenantsActivityTest extends Specification implements ManagerContainer
{},
{},
{},
+ {},
)
startActivityManager(activityDisplay, activityMapper, eventBus)
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.groovy
index dfab05087..9e293b3ed 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
@@ -10,7 +10,13 @@ import org.openremote.manager.client.ManagerHistoryMapper
import org.openremote.manager.client.admin.*
import org.openremote.manager.client.admin.navigation.AdminNavigation
import org.openremote.manager.client.admin.navigation.AdminNavigationPresenter
-import org.openremote.manager.client.admin.users.*
+import org.openremote.manager.client.admin.users.AbstractAdminUsersPlace
+import org.openremote.manager.client.admin.users.AdminUsers
+import org.openremote.manager.client.admin.users.AdminUsersActivity
+import org.openremote.manager.client.admin.users.AdminUsersPlace
+import org.openremote.manager.client.admin.users.edit.AdminUserEdit
+import org.openremote.manager.client.admin.users.edit.AdminUserEditActivity
+import org.openremote.manager.client.admin.users.edit.AdminUserEditPlace
import org.openremote.manager.client.event.GoToPlaceEvent
import org.openremote.manager.client.event.ShowSuccessEvent
import org.openremote.manager.client.event.WillGoToPlaceEvent
@@ -26,7 +32,6 @@ import org.openremote.manager.shared.security.*
import org.openremote.manager.shared.validation.ConstraintViolationReport
import org.openremote.model.event.Event
import org.openremote.model.event.bus.EventListener
-import org.openremote.model.notification.AlertNotification
import org.openremote.test.ClientObjectMapper
import org.openremote.test.ClientSecurityService
import org.openremote.test.GwtClientTrait
@@ -56,7 +61,6 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
def resultTenants = []
def resultUsers = []
def resultSelectedRealm = null
- def resultCreateUserHistoryToken = null
and: "An authenticated user and client security service"
def realm = MASTER_REALM
@@ -154,22 +158,17 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
setUsers(_) >> {
resultUsers = it[0]
}
- setCreateUserHistoryToken(_) >> {
- resultCreateUserHistoryToken = it[0]
- }
}
def tenantArrayMapper = new ClientObjectMapper(container.JSON, Tenant[].class) as TenantArrayMapper
def userArrayMapper = new ClientObjectMapper(container.JSON, User[].class) as UserArrayMapper
AdminUsersActivity adminUsersActivity
- def adminUserView = Mock(AdminUser)
- def notificationEditor = Mock(AdminUserNotificationEditor)
+ def adminUserView = Mock(AdminUserEdit)
def userMapper = new ClientObjectMapper(container.JSON, User.class) as UserMapper
def credentialMapper = new ClientObjectMapper(container.JSON, Credential.class) as CredentialMapper
def roleArrayMapper = new ClientObjectMapper(container.JSON, Role[].class) as RoleArrayMapper
- def notificationTokenMapper = new ClientObjectMapper(container.JSON, List.class) as DeviceNotificationTokenMapper
- def alertNotificationMapper = new ClientObjectMapper(container.JSON, AlertNotification.class) as AlertNotificationMapper
- AdminUserActivity adminUserActivity
+ def deviceTokenMapper = new ClientObjectMapper(container.JSON, List.class) as DeviceNotificationTokenMapper
+ AdminUserEditActivity adminUserActivity
and: "An activity management configuration"
def activityDisplay = Mock(AcceptsOneWidget)
@@ -199,11 +198,12 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
return adminUsersActivity
},
{
- adminUserActivity = new AdminUserActivity(
- environment, adminView, adminNavigationPresenter, adminUserView, userResource, userMapper, credentialMapper, roleArrayMapper, notificationEditor, notificationResource, alertNotificationMapper, notificationTokenMapper
+ adminUserActivity = new AdminUserEditActivity(
+ environment, adminView, adminNavigationPresenter, adminUserView, userResource, userMapper, credentialMapper, roleArrayMapper, notificationResource, deviceTokenMapper
)
return adminUserActivity
},
+ {},
{}
)
startActivityManager(activityDisplay, activityMapper, eventBus)
@@ -234,7 +234,6 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
resultEvents = []
resultTenants = []
resultUsers = []
- resultCreateUserHistoryToken = null
resultSelectedRealm = null
adminUsersActivity != null
adminUsersActivity.onTenantSelected(MASTER_REALM)
@@ -258,11 +257,12 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
}
when: "The user clicks Create User"
+ def place = new AdminUserEditPlace(resultEvents[1].place)
resultEvents = []
resultTenants = []
resultUsers = []
resultSelectedRealm = null
- placeController.goTo(placeHistoryMapper.getPlace(resultCreateUserHistoryToken))
+ placeController.goTo(place)
then: "The activity should be stopped"
1 * adminUsersView.setPresenter(null)
@@ -271,14 +271,14 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
and: "The admin user activity should be shown with the selected realm"
conditions.eventually {
assert resultEvents[0] instanceof WillGoToPlaceEvent
- assert resultEvents[0].place instanceof AdminUserPlace
+ assert resultEvents[0].place instanceof AdminUserEditPlace
assert resultEvents[1] instanceof GoToPlaceEvent
- assert resultEvents[1].place instanceof AdminUserPlace
+ assert resultEvents[1].place instanceof AdminUserEditPlace
assert resultEvents[1].place.realm == MASTER_REALM
}
and: "The admin navigation view should have the right place set"
- 1 * adminNavigationView.onPlaceChange(_ as AdminUserPlace)
+ 1 * adminNavigationView.onPlaceChange(_ as AdminUserEditPlace)
and: "The activity display should be set to admin view"
1 * activityDisplay.setWidget(adminViewWidget)
@@ -287,7 +287,7 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
1 * adminView.setContent(adminUserView)
and: "The admin user view should have the right activity set as presenter"
- 1 * adminUserView.setPresenter(_ as AdminUserActivity)
+ 1 * adminUserView.setPresenter(_ as AdminUserEditActivity)
and: "The admin user form should be cleared"
1 * adminUserView.clearRoles()
@@ -430,9 +430,9 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
then: "The admin user activity should be shown"
conditions.eventually {
assert resultEvents[0] instanceof WillGoToPlaceEvent
- assert resultEvents[0].place instanceof AdminUserPlace
+ assert resultEvents[0].place instanceof AbstractAdminUsersPlace
assert resultEvents[1] instanceof GoToPlaceEvent
- assert resultEvents[1].place instanceof AdminUserPlace
+ assert resultEvents[1].place instanceof AbstractAdminUsersPlace
assert resultEvents[1].place.realm == MASTER_REALM
assert resultEvents[1].place.userId == selectedUser.id
}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotifyAlarmTriggerTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotifyAlarmTriggerTest.groovy
index 3ccbbed8e..23d7f9e3c 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotifyAlarmTriggerTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotifyAlarmTriggerTest.groovy
@@ -2,6 +2,7 @@ package org.openremote.test.rules.apartment
import org.openremote.manager.server.asset.AssetProcessingService
import org.openremote.manager.server.asset.AssetStorageService
+import org.openremote.manager.server.notification.FCMDeliveryService
import org.openremote.manager.server.notification.NotificationService
import org.openremote.manager.server.rules.RulesEngine
import org.openremote.manager.server.rules.RulesService
@@ -38,10 +39,19 @@ class ApartmentNotifyAlarmTriggerTest extends Specification implements ManagerCo
def rulesService = container.getService(RulesService.class)
def assetProcessingService = container.getService(AssetProcessingService.class)
def assetStorageService = container.getService(AssetStorageService.class)
- def notificationService = container.getService(NotificationService.class)
def rulesetStorageService = container.getService(RulesetStorageService.class)
RulesEngine apartment1Engine
+ and: "a mock FCM delivery service"
+ def mockFCMDeliveryService = Spy(FCMDeliveryService, constructorArgs: [container]) {
+ // Always "deliver" to FCM
+ sendPickupSignalThroughFCM(*_) >> {
+ return true
+ }
+ }
+ def notificationService = container.getService(NotificationService)
+ notificationService.fcmDeliveryService = mockFCMDeliveryService
+
and: "some rules"
Ruleset ruleset = new AssetRuleset(
"Demo Apartment - Notify Alarm Trigger",
@@ -109,7 +119,7 @@ class ApartmentNotifyAlarmTriggerTest extends Specification implements ManagerCo
and: "the user should be notified"
conditions.eventually {
- def alerts = notificationResource.getPendingNotificationsOfCurrentUser()
+ def alerts = notificationResource.getQueuedNotificationsOfCurrentUser(null)
assert alerts.size() == 1
assert alerts[0].title == "Apartment Alarm"
assert alerts[0].message.startsWith("Aanwezigheid in Living Room")
@@ -129,7 +139,7 @@ class ApartmentNotifyAlarmTriggerTest extends Specification implements ManagerCo
conditions.eventually {
def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
assert asset.getAttribute("co2Level").get().valueAsInteger.orElse(null) == 444
- def alerts = notificationResource.getPendingNotificationsOfCurrentUser()
+ def alerts = notificationResource.getQueuedNotificationsOfCurrentUser(null)
assert alerts.size() == 1
}
@@ -138,7 +148,7 @@ class ApartmentNotifyAlarmTriggerTest extends Specification implements ManagerCo
then: "we notify again and now have two notifications pending"
conditions.eventually {
- def alerts = notificationResource.getPendingNotificationsOfCurrentUser()
+ def alerts = notificationResource.getQueuedNotificationsOfCurrentUser(null)
assert alerts.size() == 2
}
@@ -159,7 +169,7 @@ class ApartmentNotifyAlarmTriggerTest extends Specification implements ManagerCo
then: "we have still only two notifications pending"
conditions.eventually {
- def alerts = notificationResource.getPendingNotificationsOfCurrentUser()
+ def alerts = notificationResource.getQueuedNotificationsOfCurrentUser(null)
assert alerts.size() == 2
}
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.groovy
index f544624dc..485f0d837 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
@@ -1,6 +1,7 @@
package org.openremote.test.user
import org.openremote.container.timer.TimerService
+import org.openremote.manager.server.notification.FCMDeliveryService
import org.openremote.manager.server.notification.NotificationService
import org.openremote.manager.server.setup.SetupService
import org.openremote.manager.server.setup.builtin.KeycloakDemoSetup
@@ -9,6 +10,7 @@ import org.openremote.manager.shared.notification.NotificationResource
import org.openremote.model.notification.ActionType
import org.openremote.model.notification.AlertAction
import org.openremote.model.notification.AlertNotification
+import org.openremote.model.notification.DeliveryStatus
import org.openremote.model.user.UserQuery
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -31,7 +33,16 @@ class NotificationServiceTest extends Specification implements ManagerContainerT
def container = startContainer(defaultConfig(serverPort), defaultServices())
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
- def notificationService = container.getService(NotificationService.class)
+
+ and: "a mock FCM delivery service"
+ def mockFCMDeliveryService = Spy(FCMDeliveryService, constructorArgs: [container]) {
+ // Always "deliver" to FCM
+ sendPickupSignalThroughFCM(*_) >> {
+ return true
+ }
+ }
+ def notificationService = container.getService(NotificationService)
+ notificationService.fcmDeliveryService = mockFCMDeliveryService
and: "an authenticated test user"
def realm = "customerA"
@@ -59,7 +70,7 @@ class NotificationServiceTest extends Specification implements ManagerContainerT
getString(container.getConfig(), SETUP_KEYCLOAK_ADMIN_PASSWORD, SETUP_KEYCLOAK_ADMIN_PASSWORD_DEFAULT)
).token
- def notificationAlert = new AlertNotification(
+ def notification = new AlertNotification(
title: "The Title",
appUrl: '#test',
message: "Message",
@@ -69,7 +80,7 @@ class NotificationServiceTest extends Specification implements ManagerContainerT
alertAction.setTitle("TEST_ACTION")
alertAction.setActionType(ActionType.ACTUATOR)
- notificationAlert.addAction(alertAction)
+ notification.addAction(alertAction)
and: "the notification resource"
// For user operations
@@ -127,25 +138,51 @@ class NotificationServiceTest extends Specification implements ManagerContainerT
thirdToken.get().token == "token789"
notificationService.findAllTokenForUser(keycloakDemoSetup.testuser3Id).size() == 2
- when: "the Alert Notification is stored"
- testuser3NotificationResource.storeNotificationForCurrentUser(null, notificationAlert)
- def alerts = testuser3NotificationResource.getPendingNotificationsOfCurrentUser(null)
+ when: "the notification is stored"
+ testuser3NotificationResource.storeNotificationForCurrentUser(null, notification)
+ def alerts = testuser3NotificationResource.getQueuedNotificationsOfCurrentUser(null)
- then: "it should be one alert notification pending"
+ then: "it should be one notification pending"
alerts.size() == 1
- when: "a user tries to acknowledge an alert notification she doesn't own"
- testuser2NotificationResource.ackPendingNotificationOfCurrentUser(null, alerts.get(0).id)
+ when: "a user tries to store a notification for another user"
+ testuser2NotificationResource.storeNotificationForUser(null, keycloakDemoSetup.testuser3Id, notification)
then: "an exception should be thrown"
WebApplicationException ex = thrown()
ex.response.status == 403
- when: "the alert Notification is acknowledged"
- testuser3NotificationResource.ackPendingNotificationOfCurrentUser(null, alerts.get(0).id)
+ when: "a user tries to acknowledge a notification she doesn't own"
+ testuser2NotificationResource.ackNotificationOfCurrentUser(null, alerts.get(0).id)
+
+ then: "an exception should be thrown"
+ ex = thrown()
+ ex.response.status == 403
+
+ when: "the notification is acknowledged"
+ testuser3NotificationResource.ackNotificationOfCurrentUser(null, alerts.get(0).id)
+
+ then: "there should be no alert"
+ testuser3NotificationResource.getQueuedNotificationsOfCurrentUser(null).size() == 0
+
+ when: "the notification is stored"
+ testuser3NotificationResource.storeNotificationForCurrentUser(null, notification)
+ alerts = adminNotificationResource.getNotificationsOfUser(null, keycloakDemoSetup.testuser3Id)
+
+ then: "it should be one notification queued"
+ alerts.size() == 2
+ alerts.any {
+ it.deliveryStatus == DeliveryStatus.ACKNOWLEDGED
+ }
+ alerts.any {
+ it.deliveryStatus == DeliveryStatus.QUEUED
+ }
+
+ when: "all notifications of the user are removed"
+ adminNotificationResource.removeNotificationsOfUser(null, keycloakDemoSetup.testuser3Id)
then: "there should be no alert"
- testuser3NotificationResource.getPendingNotificationsOfCurrentUser(null).size() == 0
+ testuser3NotificationResource.getQueuedNotificationsOfCurrentUser(null).size() == 0
when: "a device registration is removed"
adminNotificationResource.deleteDeviceToken(null, keycloakDemoSetup.testuser3Id, "device456")
diff --git a/model/build.gradle b/model/build.gradle
index d254f1f4a..b069556d0 100644
--- a/model/build.gradle
+++ b/model/build.gradle
@@ -9,7 +9,9 @@ dependencies {
compile "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:$javaxPersistenceVersion"
compile "org.hibernate:hibernate-core:$hibernateVersion"
compile "org.jboss.logging:jboss-logging-annotations:$jbossLoggingAnnotationsVersion"
- compile "org.kie:kie-api:$droolsVersion"
+ compile("org.kie:kie-api:$droolsVersion") {
+ exclude group: "org.slf4j"
+ }
}
jar {
diff --git a/model/src/main/java/org/openremote/model/notification/AlertNotification.java b/model/src/main/java/org/openremote/model/notification/AlertNotification.java
index 8e44ca134..d36d87e0c 100644
--- a/model/src/main/java/org/openremote/model/notification/AlertNotification.java
+++ b/model/src/main/java/org/openremote/model/notification/AlertNotification.java
@@ -25,6 +25,8 @@ import org.openremote.model.value.Values;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
+import java.util.Date;
+
import static org.openremote.model.Constants.PERSISTENCE_JSON_ARRAY_TYPE;
import static org.openremote.model.Constants.PERSISTENCE_SEQUENCE_ID_GENERATOR;
@@ -41,6 +43,11 @@ public class AlertNotification {
@Column(name = "TITLE", nullable = false)
private String title;
+ @Temporal(TemporalType.TIMESTAMP)
+ @Column(name = "CREATED_ON", updatable = false, nullable = false, columnDefinition = "TIMESTAMP WITH TIME ZONE")
+ @org.hibernate.annotations.CreationTimestamp
+ protected Date createdOn;
+
@NotNull
@Column(name = "MESSAGE", nullable = false)
private String message;
@@ -94,6 +101,10 @@ public class AlertNotification {
this.title = title;
}
+ public Date getCreatedOn() {
+ return createdOn;
+ }
+
public String getMessage() {
return message;
}
@@ -157,6 +168,7 @@ public class AlertNotification {
return getClass().getSimpleName() + "{" +
"id=" + id +
", title='" + title + '\'' +
+ ", createdOn=" + createdOn +
", message='" + message + '\'' +
", actions=" + actions +
", appUrl='" + appUrl + '\'' +
diff --git a/model/src/main/java/org/openremote/model/notification/DeliveryStatus.java b/model/src/main/java/org/openremote/model/notification/DeliveryStatus.java
index 5ccc5b62e..396ce4f36 100644
--- a/model/src/main/java/org/openremote/model/notification/DeliveryStatus.java
+++ b/model/src/main/java/org/openremote/model/notification/DeliveryStatus.java
@@ -22,12 +22,17 @@ package org.openremote.model.notification;
public enum DeliveryStatus {
/**
- * To be picked up by receiving device.
+ * Not delivered to queue.
*/
PENDING,
/**
- * Picked up by receiving device.
+ * Delivered to queue for at least one device, device should soon pick it up.
*/
- DELIVERED
+ QUEUED,
+
+ /**
+ * Picked up by receiving device and dismissed by user.
+ */
+ ACKNOWLEDGED
}