Added scope to push to cloud and push to edge rule nodes configuration
This commit is contained in:
parent
3d1f0c61f7
commit
d79ab8880d
@ -16,7 +16,6 @@
|
||||
package org.thingsboard.rule.engine.edge;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.rule.engine.api.EmptyNodeConfiguration;
|
||||
import org.thingsboard.rule.engine.api.RuleNode;
|
||||
import org.thingsboard.rule.engine.api.TbContext;
|
||||
import org.thingsboard.rule.engine.api.TbNode;
|
||||
@ -31,7 +30,7 @@ import org.thingsboard.server.common.msg.TbMsg;
|
||||
@RuleNode(
|
||||
type = ComponentType.ACTION,
|
||||
name = "push to cloud",
|
||||
configClazz = EmptyNodeConfiguration.class,
|
||||
configClazz = TbMsgPushToCloudNodeConfiguration.class,
|
||||
nodeDescription = "Pushes messages from edge to cloud",
|
||||
nodeDetails = "Push messages from edge to cloud. " +
|
||||
"This node used only on edge to push messages from edge to cloud. " +
|
||||
@ -60,11 +59,11 @@ import org.thingsboard.server.common.msg.TbMsg;
|
||||
)
|
||||
public class TbMsgPushToCloudNode implements TbNode {
|
||||
|
||||
private EmptyNodeConfiguration config;
|
||||
private TbMsgPushToCloudNodeConfiguration config;
|
||||
|
||||
@Override
|
||||
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
|
||||
this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class);
|
||||
this.config = TbNodeUtils.convert(configuration, TbMsgPushToCloudNodeConfiguration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright © 2016-2021 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.edge;
|
||||
|
||||
import lombok.Data;
|
||||
import org.thingsboard.rule.engine.api.NodeConfiguration;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
|
||||
@Data
|
||||
public class TbMsgPushToCloudNodeConfiguration implements NodeConfiguration<TbMsgPushToCloudNodeConfiguration> {
|
||||
|
||||
private String scope;
|
||||
|
||||
@Override
|
||||
public TbMsgPushToCloudNodeConfiguration defaultConfiguration() {
|
||||
TbMsgPushToCloudNodeConfiguration configuration = new TbMsgPushToCloudNodeConfiguration();
|
||||
configuration.setScope(DataConstants.SERVER_SCOPE);
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.rule.engine.api.EmptyNodeConfiguration;
|
||||
import org.thingsboard.rule.engine.api.RuleNode;
|
||||
import org.thingsboard.rule.engine.api.TbContext;
|
||||
import org.thingsboard.rule.engine.api.TbNode;
|
||||
@ -57,7 +56,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
|
||||
@RuleNode(
|
||||
type = ComponentType.ACTION,
|
||||
name = "push to edge",
|
||||
configClazz = EmptyNodeConfiguration.class,
|
||||
configClazz = TbMsgPushToEdgeNodeConfiguration.class,
|
||||
nodeDescription = "Push messages from cloud to edge",
|
||||
nodeDetails = "Push messages from cloud to edge. " +
|
||||
"Message originator must be assigned to particular edge or message originator is <b>EDGE</b> entity itself. " +
|
||||
@ -87,7 +86,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
|
||||
)
|
||||
public class TbMsgPushToEdgeNode implements TbNode {
|
||||
|
||||
private EmptyNodeConfiguration config;
|
||||
private TbMsgPushToEdgeNodeConfiguration config;
|
||||
|
||||
private static final String SCOPE = "scope";
|
||||
|
||||
@ -95,7 +94,7 @@ public class TbMsgPushToEdgeNode implements TbNode {
|
||||
|
||||
@Override
|
||||
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
|
||||
this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class);
|
||||
this.config = TbNodeUtils.convert(configuration, TbMsgPushToEdgeNodeConfiguration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -186,7 +185,8 @@ public class TbMsgPushToEdgeNode implements TbNode {
|
||||
entityBody.put(SCOPE, getScope(metadata));
|
||||
break;
|
||||
case ATTRIBUTES_DELETED:
|
||||
List<String> keys = JacksonUtil.convertValue(dataJson.get("attributes"), new TypeReference<>() {});
|
||||
List<String> keys = JacksonUtil.convertValue(dataJson.get("attributes"), new TypeReference<>() {
|
||||
});
|
||||
entityBody.put("keys", keys);
|
||||
entityBody.put(SCOPE, getScope(metadata));
|
||||
break;
|
||||
@ -202,8 +202,7 @@ public class TbMsgPushToEdgeNode implements TbNode {
|
||||
private String getScope(Map<String, String> metadata) {
|
||||
String scope = metadata.get(SCOPE);
|
||||
if (StringUtils.isEmpty(scope)) {
|
||||
// TODO: @voba - move this to configuration of the node UI or some other place
|
||||
scope = DataConstants.SERVER_SCOPE;
|
||||
scope = config.getScope();
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright © 2016-2021 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.edge;
|
||||
|
||||
import lombok.Data;
|
||||
import org.thingsboard.rule.engine.api.NodeConfiguration;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
|
||||
@Data
|
||||
public class TbMsgPushToEdgeNodeConfiguration implements NodeConfiguration<TbMsgPushToEdgeNodeConfiguration> {
|
||||
|
||||
private String scope;
|
||||
|
||||
@Override
|
||||
public TbMsgPushToEdgeNodeConfiguration defaultConfiguration() {
|
||||
TbMsgPushToEdgeNodeConfiguration configuration = new TbMsgPushToEdgeNodeConfiguration();
|
||||
configuration.setScope(DataConstants.SERVER_SCOPE);
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user