Permalink
Browse files

Added rules engine and ruleset status event support and implemented f…

…unctionality in manager UI
  • Loading branch information...
richturner committed Sep 6, 2018
1 parent 3afe1d5 commit f80ac7ce3e9dc4d71afcf22d3bde029d21b00fde
Showing with 993 additions and 120 deletions.
  1. +9 −0 client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java
  2. +8 −0 client/src/main/java/org/openremote/app/client/rest/Requests.java
  3. +78 −5 client/src/main/java/org/openremote/app/client/rules/AbstractRulesList.java
  4. +35 −0 client/src/main/java/org/openremote/app/client/rules/RulesEngineInfoMapper.java
  5. +7 −2 client/src/main/java/org/openremote/app/client/rules/RulesList.java
  6. +19 −0 client/src/main/java/org/openremote/app/client/rules/RulesetTable.java
  7. +51 −5 client/src/main/java/org/openremote/app/client/rules/asset/AssetRulesListActivity.java
  8. +38 −0 client/src/main/java/org/openremote/app/client/rules/asset/AssetRulesListImpl.ui.xml
  9. +50 −7 client/src/main/java/org/openremote/app/client/rules/global/GlobalRulesListActivity.java
  10. +38 −0 client/src/main/java/org/openremote/app/client/rules/global/GlobalRulesListImpl.ui.xml
  11. +52 −5 client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListActivity.java
  12. +38 −0 client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListImpl.ui.xml
  13. +8 −1 client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
  14. +1 −3 console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt
  15. +108 −12 manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
  16. +89 −7 manager/src/main/java/org/openremote/manager/rules/RulesResourceImpl.java
  17. +51 −0 manager/src/main/java/org/openremote/manager/rules/RulesService.java
  18. +21 −38 manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java
  19. +5 −3 model/src/main/java/org/openremote/model/event/shared/SharedEvent.java
  20. +1 −3 model/src/main/java/org/openremote/model/event/shared/TenantScopedEvent.java
  21. +2 −0 model/src/main/java/org/openremote/model/rules/AssetRuleset.java
  22. +2 −0 model/src/main/java/org/openremote/model/rules/GlobalRuleset.java
  23. +56 −0 model/src/main/java/org/openremote/model/rules/RulesEngineInfo.java
  24. +26 −0 model/src/main/java/org/openremote/model/rules/RulesEngineStatus.java
  25. +56 −0 model/src/main/java/org/openremote/model/rules/RulesEngineStatusEvent.java
  26. +30 −0 model/src/main/java/org/openremote/model/rules/RulesResource.java
  27. +37 −1 model/src/main/java/org/openremote/model/rules/Ruleset.java
  28. +12 −17 model/src/main/java/org/openremote/model/rules/{RulesetStatusEvent.java → RulesetChangedEvent.java}
  29. +52 −0 model/src/main/java/org/openremote/model/rules/RulesetStatus.java
  30. +2 −0 model/src/main/java/org/openremote/model/rules/TenantRuleset.java
  31. +1 −1 test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
  32. +7 −7 test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy
  33. +1 −1 test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
  34. +1 −1 test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
  35. +1 −1 test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -24,6 +24,7 @@
import jsinterop.annotations.JsType;
import org.openremote.app.client.notifications.FilterOptions;
import org.openremote.app.client.notifications.NotificationEditorImpl;
import org.openremote.model.rules.RulesEngineStatus;
@LocalizableResource.DefaultLocale
@JsType
@@ -556,4 +557,12 @@
String none();
String notificationBuildError();
String engineStatusLabel();
String engineStatus(@Select RulesEngineStatus status);
String compilationErrorCount();
String executionErrorCount();
}
@@ -89,6 +89,14 @@ public void send(Consumer<RequestParams<Void, Void>> onRequest,
execute(null, null, onRequest, new double[]{expectedStatusCode}, out -> onResponse.run(), null);
}
@JsIgnore
public <OUT> void sendAndReturn(EntityReader<OUT> entityReader,
Consumer<RequestParams<Void, OUT>> onRequest,
double[] expectedStatusCodes,
Consumer<OUT> onResponse) {
execute(entityReader::read, null, onRequest, expectedStatusCodes, onResponse, null);
}
@JsIgnore
public <OUT> void sendAndReturn(EntityReader<OUT> entityReader,
Consumer<RequestParams<Void, OUT>> onRequest,
@@ -26,12 +26,19 @@
import org.openremote.app.client.assets.browser.AssetBrowser;
import org.openremote.app.client.i18n.ManagerMessages;
import org.openremote.app.client.style.FormTableStyle;
import org.openremote.app.client.widget.Form;
import org.openremote.app.client.widget.FormOutputText;
import org.openremote.app.client.widget.Headline;
import org.openremote.app.client.widget.Hyperlink;
import org.openremote.model.asset.agent.AgentStatusEvent;
import org.openremote.model.event.shared.TenantFilter;
import org.openremote.model.rules.RulesEngineInfo;
import org.openremote.model.rules.Ruleset;
import org.openremote.model.rules.RulesetStatus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public abstract class AbstractRulesList<P extends RulesList.Presenter<R>, R extends Ruleset>
extends Composite
@@ -49,6 +56,18 @@
@UiField
public Headline headline;
@UiField
public Form engineStatusForm;
@UiField
public FormOutputText engineStatusOutput;
@UiField
public FormOutputText compilationErrorCountOutput;
@UiField
public FormOutputText executionErrorCountOutput;
@UiField
public Hyperlink createLink;
@@ -59,9 +78,13 @@
public RulesetTable.Style tableStyle;
final protected RulesetTable<R> table;
final AssetBrowser assetBrowser;
P presenter;
List<R> rulesets;
public AbstractRulesList(AssetBrowser assetBrowser, FormTableStyle formTableStyle) {
this.assetBrowser = assetBrowser;
@@ -98,6 +121,7 @@ protected void onPresenterReset() {
headline.setText(managerMessages.loadingDotdotdot());
setCreateRulesetHistoryToken("");
noRulesetsLabel.setVisible(false);
engineStatusForm.setVisible(false);
table.setVisible(false);
table.setRowData(new ArrayList<>());
table.flush();
@@ -110,10 +134,59 @@ public void setCreateRulesetHistoryToken(String token) {
}
@Override
public void setRulesets(R[] rulesets) {
noRulesetsLabel.setVisible(rulesets.length == 0);
table.setVisible(rulesets.length > 0);
table.setRowData(Arrays.asList(rulesets));
public void setRulesets(List<R> rulesets) {
noRulesetsLabel.setVisible(rulesets.isEmpty());
engineStatusForm.setVisible(!rulesets.isEmpty());
this.rulesets = rulesets;
table.setVisible(!rulesets.isEmpty());
table.setRowData(this.rulesets);
table.flush();
}
@Override
public void onEngineStatusChanged(RulesEngineInfo engineInfo) {
if (engineInfo == null) {
engineStatusForm.setVisible(false);
return;
}
engineStatusOutput.setText(managerMessages.engineStatus(engineInfo.getStatus()));
compilationErrorCountOutput.setText(Integer.toString(engineInfo.getCompilationErrorCount()));
executionErrorCountOutput.setText(Integer.toString(engineInfo.getExecutionErrorCount()));
engineStatusForm.setVisible(true);
}
@Override
public void onRulesetStatusChanged(R ruleset) {
if (rulesets == null) {
rulesets = new ArrayList<>();
}
if (ruleset.getStatus() == RulesetStatus.REMOVED) {
if (!rulesets.removeIf(r -> Objects.equals(r.getId(), ruleset.getId()))) {
return;
}
} else {
boolean matchFound = false;
for (Ruleset existingRuleset : rulesets) {
if (Objects.equals(existingRuleset.getId(), ruleset.getId())) {
matchFound = true;
existingRuleset.setName(ruleset.getName());
existingRuleset.setEnabled(ruleset.isEnabled());
existingRuleset.setLang(ruleset.getLang());
existingRuleset.setLastModified(ruleset.getLastModified());
existingRuleset.setStatus(ruleset.getStatus());
existingRuleset.setError(ruleset.getError());
break;
}
}
if (!matchFound) {
rulesets.add(ruleset);
}
}
setRulesets(rulesets);
}
}
@@ -0,0 +1,35 @@
/*
* 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.app.client.rules;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.app.client.interop.jackson.DefaultJsonMixin;
import org.openremote.app.client.rest.EntityReader;
import org.openremote.app.client.rest.EntityWriter;
import org.openremote.model.rules.RulesEngineInfo;
import org.openremote.model.security.Tenant;
@JsonMixIns({@JsonMixIns.JsonMixIn(target = RulesEngineInfo.class, mixIn = DefaultJsonMixin.class)})
public interface RulesEngineInfoMapper
extends ObjectMapper<RulesEngineInfo>,
EntityReader<RulesEngineInfo>,
EntityWriter<RulesEngineInfo> {
}
@@ -19,7 +19,9 @@
*/
package org.openremote.app.client.rules;
import org.openremote.model.rules.Ruleset;
import org.openremote.model.rules.*;
import java.util.List;
public interface RulesList<P extends RulesList.Presenter<R>, R extends Ruleset> extends RulesView {
@@ -33,6 +35,9 @@
void setCreateRulesetHistoryToken(String token);
void setRulesets(R[] rulesets);
void setRulesets(List<R> rulesets);
void onEngineStatusChanged(RulesEngineInfo engineInfo);
void onRulesetStatusChanged(R ruleset);
}
@@ -32,6 +32,7 @@
import org.openremote.app.client.widget.IconCell;
import org.openremote.model.Constants;
import org.openremote.model.rules.Ruleset;
import org.openremote.model.rules.RulesetStatus;
public class RulesetTable<R extends Ruleset> extends FormTable<R> {
@@ -47,6 +48,8 @@
String createOnColumn();
String lastModifiedColumn();
String statusColumn();
}
final protected Style style;
@@ -103,6 +106,18 @@ public String getValue(R ruleset) {
}
};
final protected TextColumn<R> statusColumn = new TextColumn<R>() {
@Override
public String getValue(R ruleset) {
return !ruleset.isEnabled() ? RulesetStatus.DISABLED.name() : ruleset.getStatus() != null ? ruleset.getStatus().name() : "";
}
@Override
public String getCellStyleNames(Cell.Context context, R object) {
return "nowrap";
}
};
public RulesetTable(ManagerMessages managerMessages,
Style style,
FormTableStyle formTableStyle) {
@@ -118,6 +133,10 @@ public RulesetTable(ManagerMessages managerMessages,
addColumn(nameColumn, createHeader(managerMessages.rulesetName()));
addColumnStyleName(i++, style.nameColumn());
addColumn(statusColumn, createHeader(managerMessages.status()));
addColumnStyleName(i++, style.statusColumn());
statusColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
applyStyleCellText(createOnColumn);
addColumn(createOnColumn, createHeader(managerMessages.createdOn()));
addColumnStyleName(i++, style.createOnColumn());
@@ -26,15 +26,20 @@
import org.openremote.app.client.assets.browser.AssetBrowserSelection;
import org.openremote.app.client.mvp.AcceptsView;
import org.openremote.app.client.mvp.AppActivity;
import org.openremote.app.client.rules.RulesEngineInfoMapper;
import org.openremote.app.client.rules.RulesModule;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetResource;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.rules.AssetRuleset;
import org.openremote.model.rules.RulesEngineStatusEvent;
import org.openremote.model.rules.RulesResource;
import org.openremote.model.rules.RulesetChangedEvent;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
public class AssetRulesListActivity
@@ -45,7 +50,8 @@
final AssetResource assetResource;
final AssetMapper assetMapper;
final AssetRulesetArrayMapper assetRulesetArrayMapper;
final RulesResource rulesetResource;
final RulesEngineInfoMapper rulesEngineInfoMapper;
final RulesResource rulesResource;
String assetId;
Asset asset;
@@ -57,13 +63,15 @@ public AssetRulesListActivity(Environment environment,
AssetResource assetResource,
AssetMapper assetMapper,
AssetRulesetArrayMapper assetRulesetArrayMapper,
RulesResource rulesetResource) {
RulesEngineInfoMapper rulesEngineInfoMapper,
RulesResource rulesResource) {
super(environment, assetBrowserPresenter);
this.view = view;
this.assetResource = assetResource;
this.assetMapper = assetMapper;
this.assetRulesetArrayMapper = assetRulesetArrayMapper;
this.rulesetResource = rulesetResource;
this.rulesEngineInfoMapper = rulesEngineInfoMapper;
this.rulesResource = rulesResource;
}
@Override
@@ -84,6 +92,8 @@ public void start(AcceptsView container, EventBus eventBus, Collection<EventRegi
if (assetId != null) {
subscribeStatusEvents(true, registrations);
assetBrowserPresenter.loadAsset(assetId, loadedAsset -> {
this.asset = loadedAsset;
if (asset != null) {
@@ -95,17 +105,25 @@ public void start(AcceptsView container, EventBus eventBus, Collection<EventRegi
}
});
environment.getApp().getRequests().sendAndReturn(
rulesEngineInfoMapper,
params -> rulesResource.getTenantEngineInfo(params, assetId),
new double[] {200, 204},
view::onEngineStatusChanged
);
environment.getApp().getRequests().sendAndReturn(
assetRulesetArrayMapper,
params -> rulesetResource.getAssetRulesets(params, assetId),
params -> rulesResource.getAssetRulesets(params, assetId),
200,
view::setRulesets
results -> view.setRulesets(new ArrayList<>(Arrays.asList(results)))
);
}
}
@Override
public void onStop() {
subscribeStatusEvents(false, null);
super.onStop();
view.setPresenter(null);
}
@@ -114,4 +132,32 @@ public void onStop() {
public void onRulesetSelected(AssetRuleset ruleset) {
environment.getPlaceController().goTo(new AssetRulesEditorPlace(assetId, ruleset.getId()));
}
protected void subscribeStatusEvents(boolean subscribe, Collection<EventRegistration> registrations) {
if (subscribe) {
environment.getEventService().subscribe(RulesEngineStatusEvent.class);
environment.getEventService().subscribe(RulesetChangedEvent.class);
registrations.add(environment.getEventBus().register(
RulesEngineStatusEvent.class,
e -> {
if (assetId.equals(e.getEngineId())) {
view.onEngineStatusChanged(e.getEngineInfo());
}
}
));
registrations.add(environment.getEventBus().register(
RulesetChangedEvent.class,
e -> {
if (assetId.equals(e.getEngineId())) {
view.onRulesetStatusChanged((AssetRuleset)e.getRuleset());
}
}
));
} else {
environment.getEventService().unsubscribe(RulesetChangedEvent.class);
environment.getEventService().unsubscribe(RulesEngineStatusEvent.class);
}
}
}
Oops, something went wrong.

0 comments on commit f80ac7c

Please sign in to comment.