Add new Filter Rule Node 'originator type'
This commit is contained in:
parent
4616823c3b
commit
10e588aaf4
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright © 2016-2018 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.filter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.rule.engine.api.util.TbNodeUtils;
|
||||
import org.thingsboard.rule.engine.api.*;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.plugin.ComponentType;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
|
||||
@Slf4j
|
||||
@RuleNode(
|
||||
type = ComponentType.FILTER,
|
||||
name = "originator type",
|
||||
configClazz = TbOriginatorTypeFilterNodeConfiguration.class,
|
||||
relationTypes = {"True", "False"},
|
||||
nodeDescription = "Filter incoming messages by message Originator Type",
|
||||
nodeDetails = "If Originator Type of incoming message is expected - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.",
|
||||
uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
|
||||
configDirective = "tbFilterNodeOriginatorTypeConfig")
|
||||
public class TbOriginatorTypeFilterNode implements TbNode {
|
||||
|
||||
TbOriginatorTypeFilterNodeConfiguration config;
|
||||
|
||||
@Override
|
||||
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
|
||||
this.config = TbNodeUtils.convert(configuration, TbOriginatorTypeFilterNodeConfiguration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMsg(TbContext ctx, TbMsg msg) throws TbNodeException {
|
||||
EntityType originatorType = msg.getOriginator().getEntityType();
|
||||
ctx.tellNext(msg, config.getOriginatorTypes().contains(originatorType) ? "True" : "False");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright © 2016-2018 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.filter;
|
||||
|
||||
import lombok.Data;
|
||||
import org.thingsboard.rule.engine.api.NodeConfiguration;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TbOriginatorTypeFilterNodeConfiguration implements NodeConfiguration<TbOriginatorTypeFilterNodeConfiguration> {
|
||||
|
||||
private List<EntityType> originatorTypes;
|
||||
|
||||
@Override
|
||||
public TbOriginatorTypeFilterNodeConfiguration defaultConfiguration() {
|
||||
TbOriginatorTypeFilterNodeConfiguration configuration = new TbOriginatorTypeFilterNodeConfiguration();
|
||||
configuration.setOriginatorTypes(Arrays.asList(
|
||||
EntityType.DEVICE
|
||||
));
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -366,6 +366,12 @@ export default angular.module('thingsboard.types', [])
|
||||
list: 'entity.list-of-rulechains',
|
||||
nameStartsWith: 'entity.rulechain-name-starts-with'
|
||||
},
|
||||
"RULE_NODE": {
|
||||
type: 'entity.type-rulenode',
|
||||
typePlural: 'entity.type-rulenodes',
|
||||
list: 'entity.list-of-rulenodes',
|
||||
nameStartsWith: 'entity.rulenode-name-starts-with'
|
||||
},
|
||||
"CURRENT_CUSTOMER": {
|
||||
type: 'entity.type-current-customer',
|
||||
list: 'entity.type-current-customer'
|
||||
|
||||
@ -35,7 +35,30 @@ export default function EntityTypeListDirective($compile, $templateCache, $q, $m
|
||||
: $translate.instant('entity.any-entity');
|
||||
scope.secondaryPlaceholder = '+' + $translate.instant('entity.entity-type');
|
||||
|
||||
var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes);
|
||||
var entityTypes;
|
||||
|
||||
if (scope.ignoreAuthorityFilter && scope.allowedEntityTypes
|
||||
&& scope.allowedEntityTypes.length) {
|
||||
entityTypes = {};
|
||||
scope.allowedEntityTypes.forEach((entityTypeValue) => {
|
||||
var entityType = entityTypeFromValue(entityTypeValue);
|
||||
if (entityType) {
|
||||
entityTypes[entityType] = entityTypeValue;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes);
|
||||
}
|
||||
|
||||
function entityTypeFromValue(entityTypeValue) {
|
||||
for (var entityType in types.entityType) {
|
||||
if (types.entityType[entityType] === entityTypeValue) {
|
||||
return entityType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
scope.entityTypesList = [];
|
||||
for (var type in entityTypes) {
|
||||
var entityTypeInfo = {};
|
||||
@ -118,7 +141,8 @@ export default function EntityTypeListDirective($compile, $templateCache, $q, $m
|
||||
scope: {
|
||||
disabled:'=ngDisabled',
|
||||
tbRequired: '=?',
|
||||
allowedEntityTypes: '=?'
|
||||
allowedEntityTypes: '=?',
|
||||
ignoreAuthorityFilter: '=?'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -755,6 +755,10 @@ export default angular.module('thingsboard.locale', [])
|
||||
"type-rulechains": "Rule chains",
|
||||
"list-of-rulechains": "{ count, select, 1 {One rule chain} other {List of # rule chains} }",
|
||||
"rulechain-name-starts-with": "Rule chains whose names start with '{{prefix}}'",
|
||||
"type-rulenode": "Rule node",
|
||||
"type-rulenodes": "Rule nodes",
|
||||
"list-of-rulenodes": "{ count, select, 1 {One rule node} other {List of # rule nodes} }",
|
||||
"rulenode-name-starts-with": "Rule nodes whose names start with '{{prefix}}'",
|
||||
"type-current-customer": "Current Customer",
|
||||
"search": "Search entities",
|
||||
"selected-entities": "{ count, select, 1 {1 entity} other {# entities} } selected",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user