Showing
2 changed files
with
0 additions
and
125 deletions
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbCreateRelationNode.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2018 The Thingsboard Authors | |
3 | - * | |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
7 | - * | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
15 | - */ | |
16 | -package org.thingsboard.rule.engine.action; | |
17 | - | |
18 | -import com.google.common.util.concurrent.ListenableFuture; | |
19 | -import lombok.extern.slf4j.Slf4j; | |
20 | -import org.thingsboard.rule.engine.api.*; | |
21 | -import org.thingsboard.rule.engine.api.util.DonAsynchron; | |
22 | -import org.thingsboard.rule.engine.api.util.TbNodeUtils; | |
23 | -import org.thingsboard.server.common.data.id.EntityId; | |
24 | -import org.thingsboard.server.common.data.id.EntityIdFactory; | |
25 | -import org.thingsboard.server.common.data.plugin.ComponentType; | |
26 | -import org.thingsboard.server.common.data.relation.EntityRelation; | |
27 | -import org.thingsboard.server.common.data.relation.EntitySearchDirection; | |
28 | -import org.thingsboard.server.common.data.relation.RelationTypeGroup; | |
29 | -import org.thingsboard.server.common.msg.TbMsg; | |
30 | - | |
31 | -import static org.thingsboard.rule.engine.api.TbRelationTypes.FAILURE; | |
32 | -import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; | |
33 | -import static org.thingsboard.rule.engine.api.util.DonAsynchron.withCallback; | |
34 | - | |
35 | -@Slf4j | |
36 | -@RuleNode( | |
37 | - type = ComponentType.ACTION, | |
38 | - name = "create relation", | |
39 | - configClazz = TbCreateRelationNodeConfiguration.class, | |
40 | - nodeDescription = "Create the relation from the selected entity to originator of the message by type and direction", | |
41 | - nodeDetails = "If relation is already exists - send Message via <b>Success</b> chain with error message, otherwise is also used <b>Success</b> chain without error message.", | |
42 | - uiResources = {"static/rulenode/rulenode-core-config.js"}, | |
43 | - configDirective = "tbFilterNodeCheckRelationConfig") | |
44 | -public class TbCreateRelationNode implements TbNode { | |
45 | - | |
46 | - private TbCreateRelationNodeConfiguration config; | |
47 | - private EntityId fromId; | |
48 | - private EntityId toId; | |
49 | - | |
50 | - @Override | |
51 | - public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { | |
52 | - this.config = TbNodeUtils.convert(configuration, TbCreateRelationNodeConfiguration.class); | |
53 | - } | |
54 | - | |
55 | - @Override | |
56 | - public void onMsg(TbContext ctx, TbMsg msg) { | |
57 | - DonAsynchron.withCallback(checkRelation(ctx, msg), result -> { | |
58 | - if (result) { | |
59 | - ctx.tellNext(msg, SUCCESS, new Throwable("Relation between message originator and Entity: " + config.getEntityId() + " is already exist")); | |
60 | - } else { | |
61 | - processCreateRelation(ctx, msg); | |
62 | - } | |
63 | - }, error -> ctx.tellFailure(msg, error), ctx.getDbCallbackExecutor()); | |
64 | - } | |
65 | - | |
66 | - @Override | |
67 | - public void destroy() { | |
68 | - } | |
69 | - | |
70 | - private ListenableFuture<Boolean> checkRelation(TbContext ctx, TbMsg msg) { | |
71 | - if (EntitySearchDirection.TO.name().equals(config.getDirection())) { | |
72 | - fromId = EntityIdFactory.getByTypeAndId(config.getEntityType(), config.getEntityId()); | |
73 | - toId = msg.getOriginator(); | |
74 | - } else { | |
75 | - fromId = EntityIdFactory.getByTypeAndId(config.getEntityType(), config.getEntityId()); | |
76 | - toId = msg.getOriginator(); | |
77 | - } | |
78 | - return ctx.getRelationService().checkRelation(ctx.getTenantId(), fromId, toId, config.getRelationType(), RelationTypeGroup.COMMON); | |
79 | - } | |
80 | - | |
81 | - private void processCreateRelation(TbContext ctx, TbMsg msg) { | |
82 | - EntityRelation entityRelation = new EntityRelation(fromId, toId, config.getRelationType(), RelationTypeGroup.COMMON); | |
83 | - withCallback(ctx.getRelationService().saveRelationAsync(ctx.getTenantId(), entityRelation), | |
84 | - filterResult -> ctx.tellNext(msg, filterResult ? SUCCESS : FAILURE), t -> ctx.tellFailure(msg, t), ctx.getDbCallbackExecutor()); | |
85 | - } | |
86 | - | |
87 | -} |
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbCreateRelationNodeConfiguration.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2018 The Thingsboard Authors | |
3 | - * | |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
7 | - * | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
15 | - */ | |
16 | -package org.thingsboard.rule.engine.action; | |
17 | - | |
18 | -import lombok.Data; | |
19 | -import org.thingsboard.rule.engine.api.NodeConfiguration; | |
20 | -import org.thingsboard.server.common.data.relation.EntitySearchDirection; | |
21 | - | |
22 | -@Data | |
23 | -public class TbCreateRelationNodeConfiguration implements NodeConfiguration<TbCreateRelationNodeConfiguration> { | |
24 | - | |
25 | - private String direction; | |
26 | - private String entityId; | |
27 | - private String entityType; | |
28 | - private String relationType; | |
29 | - | |
30 | - | |
31 | - @Override | |
32 | - public TbCreateRelationNodeConfiguration defaultConfiguration() { | |
33 | - TbCreateRelationNodeConfiguration configuration = new TbCreateRelationNodeConfiguration(); | |
34 | - configuration.setDirection(EntitySearchDirection.FROM.name()); | |
35 | - configuration.setRelationType("Contains"); | |
36 | - return configuration; | |
37 | - } | |
38 | -} |