Commit d9023482d906df834a6133aea0dd304f1433269c

Authored by Igor Kulikov
1 parent ae4a7134

TB-73: Make Rule plugin and action optional. Fix rule deletion.

... ... @@ -72,16 +72,19 @@ public abstract class RuleManager {
72 72 }
73 73
74 74 public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) {
75   - RuleMetaData rule = null;
  75 + RuleMetaData rule;
76 76 if (event != ComponentLifecycleEvent.DELETED) {
77 77 rule = systemContext.getRuleService().findRuleById(ruleId);
78   - }
79   - if (rule == null) {
  78 + } else {
80 79 rule = ruleMap.keySet().stream()
81 80 .filter(r -> r.getId().equals(ruleId))
82 81 .peek(r -> r.setState(ComponentLifecycleState.SUSPENDED))
83 82 .findFirst()
84 83 .orElse(null);
  84 + if (rule != null) {
  85 + ruleMap.remove(rule);
  86 + ruleActors.remove(ruleId);
  87 + }
85 88 }
86 89 if (rule != null) {
87 90 RuleActorMetaData actorMd = ruleMap.get(rule);
... ...
... ... @@ -176,7 +176,7 @@ actors:
176 176 statistics:
177 177 # Enable/disable actor statistics
178 178 enabled: "${ACTORS_STATISTICS_ENABLED:true}"
179   - persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:60000}"
  179 + persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:3600000}"
180 180
181 181 # Cache parameters
182 182 cache:
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.common.data.rule;
17 17
18 18 import com.fasterxml.jackson.databind.JsonNode;
19 19 import lombok.Data;
  20 +import lombok.EqualsAndHashCode;
20 21 import org.thingsboard.server.common.data.HasName;
21 22 import org.thingsboard.server.common.data.SearchTextBased;
22 23 import org.thingsboard.server.common.data.id.RuleId;
... ... @@ -24,6 +25,7 @@ import org.thingsboard.server.common.data.id.TenantId;
24 25 import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
25 26
26 27 @Data
  28 +@EqualsAndHashCode(callSuper = true)
27 29 public class RuleMetaData extends SearchTextBased<RuleId> implements HasName {
28 30
29 31 private static final long serialVersionUID = -5656679015122935465L;
... ...
... ... @@ -165,11 +165,11 @@
165 165 <fieldset ng-disabled="loading || !isEdit || isReadOnly">
166 166 <md-input-container ng-if="!isEdit || isReadOnly" flex class="md-block">
167 167 <label translate>plugin.plugin</label>
168   - <input required name="name" ng-model="plugin.name">
  168 + <input name="name" ng-model="plugin.name">
169 169 </md-input-container>
170 170 <tb-plugin-select ng-show="isEdit && !isReadOnly" flex
171 171 ng-model="plugin"
172   - tb-required="true"
  172 + tb-required="false"
173 173 the-form="theForm"
174 174 plugins-scope="action">
175 175 </tb-plugin-select>
... ...
... ... @@ -85,10 +85,11 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu
85 85 if (scope.rule) {
86 86 var valid = scope.rule.filters && scope.rule.filters.length > 0;
87 87 scope.theForm.$setValidity('filters', valid);
88   - valid = angular.isDefined(scope.rule.pluginToken) && scope.rule.pluginToken != null;
89   - scope.theForm.$setValidity('plugin', valid);
90   - valid = angular.isDefined(scope.rule.action) && scope.rule.action != null;
91   - scope.theForm.$setValidity('action', valid);
  88 + var processorDefined = angular.isDefined(scope.rule.processor) && scope.rule.processor != null;
  89 + var pluginDefined = angular.isDefined(scope.rule.pluginToken) && scope.rule.pluginToken != null;
  90 + var pluginActionDefined = angular.isDefined(scope.rule.action) && scope.rule.action != null;
  91 + valid = processorDefined && !pluginDefined || (pluginDefined && pluginActionDefined);
  92 + scope.theForm.$setValidity('processorOrPlugin', valid);
92 93 }
93 94 };
94 95
... ... @@ -160,6 +161,7 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu
160 161 scope.$watch('rule.processor', function(newVal, prevVal) {
161 162 if (scope.rule && scope.isEdit && !angular.equals(newVal, prevVal)) {
162 163 scope.theForm.$setDirty();
  164 + scope.updateValidity();
163 165 }
164 166 }, true);
165 167
... ...