Commit c32a2ac06476aae36c15a8b36fcbae9078d8c14d
Committed by
Andrew Shvayka
1 parent
e19bd433
load demo rule chains improvements
Showing
4 changed files
with
9 additions
and
286 deletions
application/src/main/data/json/demo/rule_chains/root_rule_chain.json
deleted
100644 → 0
1 | -{ | |
2 | - "ruleChain": { | |
3 | - "additionalInfo": null, | |
4 | - "name": "Root Rule Chain", | |
5 | - "firstRuleNodeId": null, | |
6 | - "root": true, | |
7 | - "debugMode": false, | |
8 | - "configuration": null | |
9 | - }, | |
10 | - "metadata": { | |
11 | - "firstNodeIndex": 6, | |
12 | - "nodes": [ | |
13 | - { | |
14 | - "additionalInfo": { | |
15 | - "layoutX": 824, | |
16 | - "layoutY": 156 | |
17 | - }, | |
18 | - "type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode", | |
19 | - "name": "Save Timeseries", | |
20 | - "debugMode": false, | |
21 | - "configuration": { | |
22 | - "defaultTTL": 0 | |
23 | - } | |
24 | - }, | |
25 | - { | |
26 | - "additionalInfo": { | |
27 | - "layoutX": 825, | |
28 | - "layoutY": 52 | |
29 | - }, | |
30 | - "type": "org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode", | |
31 | - "name": "Save Client Attributes", | |
32 | - "debugMode": false, | |
33 | - "configuration": { | |
34 | - "scope": "CLIENT_SCOPE", | |
35 | - "notifyDevice": "false" | |
36 | - } | |
37 | - }, | |
38 | - { | |
39 | - "additionalInfo": { | |
40 | - "layoutX": 347, | |
41 | - "layoutY": 149 | |
42 | - }, | |
43 | - "type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode", | |
44 | - "name": "Message Type Switch", | |
45 | - "debugMode": false, | |
46 | - "configuration": { | |
47 | - "version": 0 | |
48 | - } | |
49 | - }, | |
50 | - { | |
51 | - "additionalInfo": { | |
52 | - "layoutX": 825, | |
53 | - "layoutY": 266 | |
54 | - }, | |
55 | - "type": "org.thingsboard.rule.engine.action.TbLogNode", | |
56 | - "name": "Log RPC from Device", | |
57 | - "debugMode": false, | |
58 | - "configuration": { | |
59 | - "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);" | |
60 | - } | |
61 | - }, | |
62 | - { | |
63 | - "additionalInfo": { | |
64 | - "layoutX": 825, | |
65 | - "layoutY": 379 | |
66 | - }, | |
67 | - "type": "org.thingsboard.rule.engine.action.TbLogNode", | |
68 | - "name": "Log Other", | |
69 | - "debugMode": false, | |
70 | - "configuration": { | |
71 | - "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);" | |
72 | - } | |
73 | - }, | |
74 | - { | |
75 | - "additionalInfo": { | |
76 | - "layoutX": 825, | |
77 | - "layoutY": 468 | |
78 | - }, | |
79 | - "type": "org.thingsboard.rule.engine.rpc.TbSendRPCRequestNode", | |
80 | - "name": "RPC Call Request", | |
81 | - "debugMode": false, | |
82 | - "configuration": { | |
83 | - "timeoutInSeconds": 60 | |
84 | - } | |
85 | - }, | |
86 | - { | |
87 | - "additionalInfo": { | |
88 | - "description": "Process incoming messages from devices with the alarm rules defined in the device profile. Dispatch all incoming messages with \"Success\" relation type.", | |
89 | - "layoutX": 204, | |
90 | - "layoutY": 240 | |
91 | - }, | |
92 | - "type": "org.thingsboard.rule.engine.profile.TbDeviceProfileNode", | |
93 | - "name": "Device Profile Node", | |
94 | - "debugMode": false, | |
95 | - "configuration": { | |
96 | - "persistAlarmRulesState": false, | |
97 | - "fetchAlarmRulesStateOnStart": false | |
98 | - } | |
99 | - } | |
100 | - ], | |
101 | - "connections": [ | |
102 | - { | |
103 | - "fromIndex": 6, | |
104 | - "toIndex": 2, | |
105 | - "type": "Success" | |
106 | - }, | |
107 | - { | |
108 | - "fromIndex": 2, | |
109 | - "toIndex": 4, | |
110 | - "type": "Other" | |
111 | - }, | |
112 | - { | |
113 | - "fromIndex": 2, | |
114 | - "toIndex": 1, | |
115 | - "type": "Post attributes" | |
116 | - }, | |
117 | - { | |
118 | - "fromIndex": 2, | |
119 | - "toIndex": 0, | |
120 | - "type": "Post telemetry" | |
121 | - }, | |
122 | - { | |
123 | - "fromIndex": 2, | |
124 | - "toIndex": 3, | |
125 | - "type": "RPC Request from Device" | |
126 | - }, | |
127 | - { | |
128 | - "fromIndex": 2, | |
129 | - "toIndex": 5, | |
130 | - "type": "RPC Request to Device" | |
131 | - } | |
132 | - ], | |
133 | - "ruleChainConnections": null | |
134 | - } | |
135 | -} | |
\ No newline at end of file |
application/src/main/data/json/demo/rule_chains/thermostat_rule_chain.json
deleted
100644 → 0
1 | -{ | |
2 | - "ruleChain": { | |
3 | - "additionalInfo": null, | |
4 | - "name": "Thermostat", | |
5 | - "firstRuleNodeId": null, | |
6 | - "root": false, | |
7 | - "debugMode": false, | |
8 | - "configuration": null | |
9 | - }, | |
10 | - "metadata": { | |
11 | - "firstNodeIndex": 6, | |
12 | - "nodes": [ | |
13 | - { | |
14 | - "additionalInfo": { | |
15 | - "layoutX": 824, | |
16 | - "layoutY": 156 | |
17 | - }, | |
18 | - "type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode", | |
19 | - "name": "Save Timeseries", | |
20 | - "debugMode": false, | |
21 | - "configuration": { | |
22 | - "defaultTTL": 0 | |
23 | - } | |
24 | - }, | |
25 | - { | |
26 | - "additionalInfo": { | |
27 | - "layoutX": 825, | |
28 | - "layoutY": 52 | |
29 | - }, | |
30 | - "type": "org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode", | |
31 | - "name": "Save Client Attributes", | |
32 | - "debugMode": false, | |
33 | - "configuration": { | |
34 | - "scope": "CLIENT_SCOPE", | |
35 | - "notifyDevice": "false" | |
36 | - } | |
37 | - }, | |
38 | - { | |
39 | - "additionalInfo": { | |
40 | - "layoutX": 347, | |
41 | - "layoutY": 149 | |
42 | - }, | |
43 | - "type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode", | |
44 | - "name": "Message Type Switch", | |
45 | - "debugMode": false, | |
46 | - "configuration": { | |
47 | - "version": 0 | |
48 | - } | |
49 | - }, | |
50 | - { | |
51 | - "additionalInfo": { | |
52 | - "layoutX": 825, | |
53 | - "layoutY": 266 | |
54 | - }, | |
55 | - "type": "org.thingsboard.rule.engine.action.TbLogNode", | |
56 | - "name": "Log RPC from Device", | |
57 | - "debugMode": false, | |
58 | - "configuration": { | |
59 | - "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);" | |
60 | - } | |
61 | - }, | |
62 | - { | |
63 | - "additionalInfo": { | |
64 | - "layoutX": 825, | |
65 | - "layoutY": 379 | |
66 | - }, | |
67 | - "type": "org.thingsboard.rule.engine.action.TbLogNode", | |
68 | - "name": "Log Other", | |
69 | - "debugMode": false, | |
70 | - "configuration": { | |
71 | - "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);" | |
72 | - } | |
73 | - }, | |
74 | - { | |
75 | - "additionalInfo": { | |
76 | - "layoutX": 825, | |
77 | - "layoutY": 468 | |
78 | - }, | |
79 | - "type": "org.thingsboard.rule.engine.rpc.TbSendRPCRequestNode", | |
80 | - "name": "RPC Call Request", | |
81 | - "debugMode": false, | |
82 | - "configuration": { | |
83 | - "timeoutInSeconds": 60 | |
84 | - } | |
85 | - }, | |
86 | - { | |
87 | - "additionalInfo": { | |
88 | - "description": "Process incoming messages from devices with the alarm rules defined in the device profile. Dispatch all incoming messages with \"Success\" relation type.", | |
89 | - "layoutX": 204, | |
90 | - "layoutY": 240 | |
91 | - }, | |
92 | - "type": "org.thingsboard.rule.engine.profile.TbDeviceProfileNode", | |
93 | - "name": "Device Profile Node", | |
94 | - "debugMode": false, | |
95 | - "configuration": { | |
96 | - "persistAlarmRulesState": false, | |
97 | - "fetchAlarmRulesStateOnStart": false | |
98 | - } | |
99 | - } | |
100 | - ], | |
101 | - "connections": [ | |
102 | - { | |
103 | - "fromIndex": 6, | |
104 | - "toIndex": 2, | |
105 | - "type": "Success" | |
106 | - }, | |
107 | - { | |
108 | - "fromIndex": 2, | |
109 | - "toIndex": 4, | |
110 | - "type": "Other" | |
111 | - }, | |
112 | - { | |
113 | - "fromIndex": 2, | |
114 | - "toIndex": 1, | |
115 | - "type": "Post attributes" | |
116 | - }, | |
117 | - { | |
118 | - "fromIndex": 2, | |
119 | - "toIndex": 0, | |
120 | - "type": "Post telemetry" | |
121 | - }, | |
122 | - { | |
123 | - "fromIndex": 2, | |
124 | - "toIndex": 3, | |
125 | - "type": "RPC Request from Device" | |
126 | - }, | |
127 | - { | |
128 | - "fromIndex": 2, | |
129 | - "toIndex": 5, | |
130 | - "type": "RPC Request to Device" | |
131 | - } | |
132 | - ], | |
133 | - "ruleChainConnections": null | |
134 | - } | |
135 | -} | |
\ No newline at end of file |
... | ... | @@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.asset.Asset; |
33 | 33 | import org.thingsboard.server.common.data.asset.AssetInfo; |
34 | 34 | import org.thingsboard.server.common.data.asset.AssetSearchQuery; |
35 | 35 | import org.thingsboard.server.common.data.audit.ActionType; |
36 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | |
36 | 37 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
37 | 38 | import org.thingsboard.server.common.data.id.AssetId; |
38 | 39 | import org.thingsboard.server.common.data.id.CustomerId; |
... | ... | @@ -51,6 +52,8 @@ import java.util.ArrayList; |
51 | 52 | import java.util.List; |
52 | 53 | import java.util.stream.Collectors; |
53 | 54 | |
55 | +import static org.thingsboard.server.dao.asset.BaseAssetService.TB_SERVICE_QUEUE; | |
56 | + | |
54 | 57 | @RestController |
55 | 58 | @TbCoreComponent |
56 | 59 | @RequestMapping("/api") |
... | ... | @@ -89,6 +92,10 @@ public class AssetController extends BaseController { |
89 | 92 | @ResponseBody |
90 | 93 | public Asset saveAsset(@RequestBody Asset asset) throws ThingsboardException { |
91 | 94 | try { |
95 | + if (TB_SERVICE_QUEUE.equals(asset.getType())) { | |
96 | + throw new ThingsboardException("Unable to save asset with type " + TB_SERVICE_QUEUE, ThingsboardErrorCode.BAD_REQUEST_PARAMS); | |
97 | + } | |
98 | + | |
92 | 99 | asset.setTenantId(getCurrentUser().getTenantId()); |
93 | 100 | |
94 | 101 | checkEntity(asset.getId(), asset, Resource.ASSET); | ... | ... |
... | ... | @@ -210,23 +210,9 @@ public class InstallScripts { |
210 | 210 | |
211 | 211 | |
212 | 212 | public void loadDemoRuleChains(TenantId tenantId) throws Exception { |
213 | - Path ruleChainsDir = Paths.get(getDataDir(), JSON_DIR, DEMO_DIR, RULE_CHAINS_DIR); | |
214 | 213 | try { |
215 | - JsonNode thermostatRuleChainJson = objectMapper.readTree(ruleChainsDir.resolve("thermostat_rule_chain.json").toFile()); | |
216 | - RuleChain thermostatRuleChain = objectMapper.treeToValue(thermostatRuleChainJson.get("ruleChain"), RuleChain.class); | |
217 | - RuleChainMetaData ruleChainMetaData = objectMapper.treeToValue(thermostatRuleChainJson.get("metadata"), RuleChainMetaData.class); | |
218 | - thermostatRuleChain.setTenantId(tenantId); | |
219 | - thermostatRuleChain = ruleChainService.saveRuleChain(thermostatRuleChain); | |
220 | - ruleChainMetaData.setRuleChainId(thermostatRuleChain.getId()); | |
221 | - ruleChainService.saveRuleChainMetaData(new TenantId(EntityId.NULL_UUID), ruleChainMetaData); | |
222 | - | |
223 | - JsonNode rootChainJson = objectMapper.readTree(ruleChainsDir.resolve("root_rule_chain.json").toFile()); | |
224 | - RuleChain rootChain = objectMapper.treeToValue(rootChainJson.get("ruleChain"), RuleChain.class); | |
225 | - RuleChainMetaData rootChainMetaData = objectMapper.treeToValue(rootChainJson.get("metadata"), RuleChainMetaData.class); | |
226 | - rootChain.setTenantId(tenantId); | |
227 | - rootChain = ruleChainService.saveRuleChain(rootChain); | |
228 | - rootChainMetaData.setRuleChainId(rootChain.getId()); | |
229 | - ruleChainService.saveRuleChainMetaData(new TenantId(EntityId.NULL_UUID), rootChainMetaData); | |
214 | + createDefaultRuleChains(tenantId); | |
215 | + createDefaultRuleChain(tenantId, "Thermostat"); | |
230 | 216 | } catch (Exception e) { |
231 | 217 | log.error("Unable to load dashboard from json", e); |
232 | 218 | throw new RuntimeException("Unable to load dashboard from json", e); | ... | ... |