Permalink
Browse files

Simplify and delegate HTTP request error handling of manager UI to or…

…-app web component
  • Loading branch information...
christianbauer committed Jan 11, 2018
1 parent 910a124 commit 5e561a44b8ce112a21d112929a1c7495e7a9ca2f
Showing with 316 additions and 508 deletions.
  1. +1 −0 client/src/main/java/org/openremote/app/client/ManagerActivityMapper.java
  2. +6 −12 client/src/main/java/org/openremote/app/client/admin/syslog/AdminSyslogActivity.java
  3. +30 −37 client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantActivity.java
  4. +2 −5 client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantsActivity.java
  5. +2 −6 client/src/main/java/org/openremote/app/client/admin/users/AdminUsersActivity.java
  6. +41 −47 client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditActivity.java
  7. +9 −14 ...main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsActivity.java
  8. +1 −4 client/src/main/java/org/openremote/app/client/apps/ConsoleAppsActivity.java
  9. +3 −5 client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
  10. +11 −24 client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
  11. +7 −10 client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
  12. +3 −8 client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java
  13. +5 −12 client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantActivity.java
  14. +0 −32 client/src/main/java/org/openremote/app/client/http/ConstraintViolationReportMapper.java
  15. +0 −90 client/src/main/java/org/openremote/app/client/http/RequestExceptionHandler.java
  16. +0 −12 client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java
  17. +4 −9 client/src/main/java/org/openremote/app/client/map/MapActivity.java
  18. +82 −83 client/src/main/java/org/openremote/app/client/rest/RequestService.java
  19. +7 −11 client/src/main/java/org/openremote/app/client/rules/AbstractRulesEditorActivity.java
  20. +4 −7 client/src/main/java/org/openremote/app/client/rules/asset/AssetRulesEditorActivity.java
  21. +3 −6 client/src/main/java/org/openremote/app/client/rules/asset/AssetRulesListActivity.java
  22. +2 −5 client/src/main/java/org/openremote/app/client/rules/global/GlobalRulesListActivity.java
  23. +4 −7 client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorActivity.java
  24. +3 −7 client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListActivity.java
  25. +0 −6 client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
  26. +5 −1 client/src/main/webapp/src/or-app/or-app.html
  27. +0 −3 client/src/main/webapp/src/or-asset-list/or-asset-list.html
  28. +1 −1 manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java
  29. +1 −1 manager/src/main/java/org/openremote/manager/security/UserResourceImpl.java
  30. +10 −3 model/src/main/java/org/openremote/model/http/{BadRequestException.java → BadRequestError.java}
  31. +2 −2 ...c/main/java/org/openremote/model/http/{ConflictRequestException.java → ConflictRequestError.java}
  32. +1 −1 model/src/main/java/org/openremote/model/http/ConstraintViolation.java
  33. +2 −2 ...enremote/model/http/{EntityMarshallingRequestException.java → EntityMarshallingRequestError.java}
  34. +2 −2 model/src/main/java/org/openremote/model/http/{NoResponseException.java → NoResponseError.java}
  35. +32 −0 model/src/main/java/org/openremote/model/http/NotFoundRequestError.java
  36. +13 −20 model/src/main/java/org/openremote/model/http/{RequestException.java → RequestError.java}
  37. +2 −2 ...ava/org/openremote/model/http/{UnauthorizedRequestException.java → UnauthorizedRequestError.java}
  38. +3 −3 ...openremote/model/http/{UnexpectedStatusRequestException.java → UnexpectedStatusRequestError.java}
  39. +7 −2 test/src/main/groovy/org/openremote/test/TestOpenRemoteApp.java
  40. +5 −6 test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
@@ -208,6 +208,7 @@ public AppActivity getActivity(Place place) {
LOG.severe("No activity available for place: " + place);
} catch (RoleRequiredException ex) {
// TODO Delegate to or-app error handling!
LOG.warning("Access denied, missing required role '" + ex.getRequiredRole() + "': " + place);
eventBus.dispatch(new ShowFailureEvent(managerMessages.accessDenied(), 5000));
}
@@ -26,21 +26,19 @@
import org.openremote.app.client.event.SharedEventArrayMapper;
import org.openremote.app.client.event.ShowSuccessEvent;
import org.openremote.app.client.mvp.AcceptsView;
import org.openremote.model.syslog.SyslogConfig;
import org.openremote.model.syslog.SyslogResource;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.event.shared.SharedEvent;
import org.openremote.model.syslog.SyslogConfig;
import org.openremote.model.syslog.SyslogEvent;
import org.openremote.model.syslog.SyslogLevel;
import org.openremote.model.syslog.SyslogResource;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.openremote.app.client.http.RequestExceptionHandler.handleRequestException;
public class AdminSyslogActivity
extends AbstractAdminActivity<AdminSyslogPlace, AdminSyslog>
implements AdminSyslog.Presenter {
@@ -144,8 +142,7 @@ public void saveSettings() {
environment.getMessages().settingsSaved()
));
adminContent.setFormBusy(false);
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages())
}
);
}
@@ -161,8 +158,7 @@ public void removeAll() {
environment.getEventBus().dispatch(new ShowSuccessEvent(
environment.getMessages().eventsRemoved()
));
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages())
}
);
}
@@ -187,8 +183,7 @@ protected void fetchEvents() {
SyslogEvent.class,
new SyslogEvent.LevelCategoryFilter(filterLevel)
);
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages())
}
);
}
@@ -203,8 +198,7 @@ protected void loadConfig() {
adminContent.setStoredLevel(config.getStoredLevel());
adminContent.setStoredMinutes(config.getStoredMaxAgeMinutes());
adminContent.setFormBusy(false);
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages())
}
);
}
@@ -27,43 +27,24 @@
import org.openremote.app.client.event.ShowSuccessEvent;
import org.openremote.app.client.mvp.AcceptsView;
import org.openremote.app.client.mvp.AppActivity;
import org.openremote.model.security.Tenant;
import org.openremote.model.http.ConstraintViolation;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.http.ConstraintViolation;
import org.openremote.model.interop.Consumer;
import org.openremote.model.security.Tenant;
import org.openremote.model.security.TenantResource;
import javax.inject.Inject;
import java.util.Collection;
import static org.openremote.app.client.http.RequestExceptionHandler.handleRequestException;
public class AdminTenantActivity
extends AbstractAdminActivity<AdminTenantPlace, AdminTenant>
implements AdminTenant.Presenter {
final protected Environment environment;
final protected TenantResource tenantResource;
final protected TenantMapper tenantMapper;
final protected Consumer<ConstraintViolation[]> validationErrorHandler = violations -> {
for (ConstraintViolation violation : violations) {
if (violation.getPath() != null) {
if (violation.getPath().endsWith("displayName")) {
adminContent.setTenantDisplayNameError(true);
}
if (violation.getPath().endsWith("realm")) {
adminContent.setTenantRealmError(true);
}
if (violation.getPath().endsWith("enabled")) {
adminContent.setTenantEnabledError(true);
}
}
adminContent.addFormMessageError(violation.getMessage());
}
adminContent.setFormBusy(false);
};
final protected Consumer<ConstraintViolation[]> validationErrorHandler;
protected String realm;
protected Tenant tenant;
@@ -79,6 +60,26 @@ public AdminTenantActivity(Environment environment,
this.environment = environment;
this.tenantResource = tenantResource;
this.tenantMapper = tenantMapper;
this.validationErrorHandler = violations -> {
for (ConstraintViolation violation : violations) {
if (violation.getConstraintType() == ConstraintViolation.Type.CONFLICT) {
adminContent.addFormMessageError(environment.getMessages().conflictRequest());
adminContent.setTenantRealmError(true);
} else if (violation.getPath() != null) {
if (violation.getPath().endsWith("displayName")) {
adminContent.setTenantDisplayNameError(true);
}
if (violation.getPath().endsWith("realm")) {
adminContent.setTenantRealmError(true);
}
if (violation.getPath().endsWith("enabled")) {
adminContent.setTenantEnabledError(true);
}
adminContent.addFormMessageError(violation.getMessage());
}
}
adminContent.setFormBusy(false);
};
}
@Override
@@ -129,9 +130,7 @@ public void create() {
readFromView();
environment.getApp().getRequestService().sendWith(
tenantMapper,
requestParams -> {
tenantResource.create(requestParams, tenant);
},
requestParams -> tenantResource.create(requestParams, tenant),
204,
() -> {
adminContent.setFormBusy(false);
@@ -140,7 +139,7 @@ public void create() {
));
environment.getPlaceController().goTo(new AdminTenantsPlace());
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages(), validationErrorHandler)
validationErrorHandler
);
}
@@ -152,9 +151,7 @@ public void update() {
readFromView();
environment.getApp().getRequestService().sendWith(
tenantMapper,
requestParams -> {
tenantResource.update(requestParams, realm, tenant);
},
requestParams -> tenantResource.update(requestParams, realm, tenant),
204,
() -> {
adminContent.setFormBusy(false);
@@ -163,7 +160,7 @@ public void update() {
));
this.realm = tenant.getRealm();
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages(), validationErrorHandler)
validationErrorHandler
);
}
@@ -177,18 +174,15 @@ public void delete() {
adminContent.clearFormMessages();
clearViewFieldErrors();
environment.getApp().getRequestService().send(
requestParams -> {
tenantResource.delete(requestParams, this.realm);
},
requestParams -> tenantResource.delete(requestParams, this.realm),
204,
() -> {
adminContent.setFormBusy(false);
environment.getEventBus().dispatch(new ShowSuccessEvent(
environment.getMessages().tenantDeleted(tenant.getDisplayName())
));
environment.getPlaceController().goTo(new AdminTenantsPlace());
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages(), validationErrorHandler)
}
);
}
);
@@ -213,8 +207,7 @@ protected void loadTenant() {
adminContent.enableCreate(false);
adminContent.enableUpdate(true);
adminContent.enableDelete(true);
},
ex -> handleRequestException(ex, environment)
}
);
}
@@ -25,16 +25,14 @@
import org.openremote.app.client.admin.TenantArrayMapper;
import org.openremote.app.client.admin.navigation.AdminNavigation;
import org.openremote.app.client.mvp.AcceptsView;
import org.openremote.model.security.Tenant;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.security.Tenant;
import org.openremote.model.security.TenantResource;
import javax.inject.Inject;
import java.util.Collection;
import static org.openremote.app.client.http.RequestExceptionHandler.handleRequestException;
public class AdminTenantsActivity
extends AbstractAdminActivity<AdminTenantsPlace, AdminTenants>
implements AdminTenants.Presenter {
@@ -74,8 +72,7 @@ public void start(AcceptsView container, EventBus eventBus, Collection<EventRegi
tenants -> {
adminContent.setTenants(tenants);
adminContent.setFormBusy(false);
},
ex -> handleRequestException(ex, environment)
}
);
adminContent.setCreateTenantHistoryToken(
@@ -37,8 +37,6 @@
import javax.inject.Inject;
import java.util.Collection;
import static org.openremote.app.client.http.RequestExceptionHandler.handleRequestException;
public class AdminUsersActivity
extends AbstractAdminActivity<AdminUsersPlace, AdminUsers>
implements AdminUsers.Presenter {
@@ -93,8 +91,7 @@ public void start(AcceptsView container, EventBus eventBus, Collection<EventRegi
tenants -> {
adminContent.setTenants(tenants, realm);
adminContent.setFormBusy(false);
},
ex -> handleRequestException(ex, environment)
}
);
if (realm != null) {
@@ -106,8 +103,7 @@ public void start(AcceptsView container, EventBus eventBus, Collection<EventRegi
users -> {
adminContent.setUsers(users);
adminContent.setFormBusy(false);
},
ex -> handleRequestException(ex, environment)
}
);
}
}
Oops, something went wrong.

0 comments on commit 5e561a4

Please sign in to comment.