Browse Source

changed checkType and checkTypeOneOf to isTypeOf and isTypeOneOf

pull/8786/head
ShvaykaD 3 years ago
parent
commit
ad847ff40c
  1. 6
      common/message/src/main/java/org/thingsboard/server/common/msg/TbMsg.java
  2. 6
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbCopyAttributesToEntityViewNode.java
  3. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbMsgCountNode.java
  4. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/debug/TbMsgGeneratorNode.java
  5. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/deduplication/TbMsgDeduplicationNode.java
  6. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/delay/TbMsgDelayNode.java
  7. 14
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/edge/AbstractTbMsgPushNode.java
  8. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/mail/TbSendEmailNode.java
  9. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/metadata/CalculateDeltaNode.java
  10. 18
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/profile/DeviceState.java
  11. 10
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/profile/TbDeviceProfileNode.java
  12. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/rpc/TbSendRPCRequestNode.java
  13. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java
  14. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgTimeseriesNode.java

6
common/message/src/main/java/org/thingsboard/server/common/msg/TbMsg.java

@ -468,13 +468,13 @@ public final class TbMsg implements Serializable {
return ts;
}
public boolean checkType(TbMsgType tbMsgType) {
public boolean isTypeOf(TbMsgType tbMsgType) {
return tbMsgType != null && tbMsgType.name().equals(this.type);
}
public boolean checkTypeOneOf(TbMsgType... types) {
public boolean isTypeOneOf(TbMsgType... types) {
for (TbMsgType type : types) {
if (checkType(type)) {
if (isTypeOf(type)) {
return true;
}
}

6
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbCopyAttributesToEntityViewNode.java

@ -75,11 +75,11 @@ public class TbCopyAttributesToEntityViewNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
if (msg.checkTypeOneOf(ATTRIBUTES_UPDATED, ATTRIBUTES_DELETED,
if (msg.isTypeOneOf(ATTRIBUTES_UPDATED, ATTRIBUTES_DELETED,
ACTIVITY_EVENT, INACTIVITY_EVENT, POST_ATTRIBUTES_REQUEST)) {
if (!msg.getMetaData().getData().isEmpty()) {
long now = System.currentTimeMillis();
String scope = msg.checkType(POST_ATTRIBUTES_REQUEST) ?
String scope = msg.isTypeOf(POST_ATTRIBUTES_REQUEST) ?
DataConstants.CLIENT_SCOPE : msg.getMetaData().getValue(DataConstants.SCOPE);
ListenableFuture<List<EntityView>> entityViewsFuture =
@ -91,7 +91,7 @@ public class TbCopyAttributesToEntityViewNode implements TbNode {
long startTime = entityView.getStartTimeMs();
long endTime = entityView.getEndTimeMs();
if ((endTime != 0 && endTime > now && startTime < now) || (endTime == 0 && startTime < now)) {
if (msg.checkType(ATTRIBUTES_DELETED)) {
if (msg.isTypeOf(ATTRIBUTES_DELETED)) {
List<String> attributes = new ArrayList<>();
for (JsonElement element : JsonParser.parseString(msg.getData()).getAsJsonObject().get("attributes").getAsJsonArray()) {
if (element.isJsonPrimitive()) {

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbMsgCountNode.java

@ -65,7 +65,7 @@ public class TbMsgCountNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
if (msg.checkType(TbMsgType.MSG_COUNT_SELF_MSG) && msg.getId().equals(nextTickId)) {
if (msg.isTypeOf(TbMsgType.MSG_COUNT_SELF_MSG) && msg.getId().equals(nextTickId)) {
JsonObject telemetryJson = new JsonObject();
telemetryJson.addProperty(this.telemetryPrefix + "_" + ctx.getServiceId(), messagesProcessed.longValue());

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/debug/TbMsgGeneratorNode.java

@ -107,7 +107,7 @@ public class TbMsgGeneratorNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
log.trace("onMsg, config {}, msg {}", config, msg);
if (initialized.get() && msg.checkType(TbMsgType.GENERATOR_NODE_SELF_MSG) && msg.getId().equals(nextTickId)) {
if (initialized.get() && msg.isTypeOf(TbMsgType.GENERATOR_NODE_SELF_MSG) && msg.getId().equals(nextTickId)) {
TbStopWatch sw = TbStopWatch.create();
withCallback(generate(ctx, msg),
m -> {

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/deduplication/TbMsgDeduplicationNode.java

@ -80,7 +80,7 @@ public class TbMsgDeduplicationNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException, TbNodeException {
if (msg.checkType(TbMsgType.DEDUPLICATION_TIMEOUT_SELF_MSG)) {
if (msg.isTypeOf(TbMsgType.DEDUPLICATION_TIMEOUT_SELF_MSG)) {
processDeduplication(ctx, msg.getOriginator());
} else {
processOnRegularMsg(ctx, msg);

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/delay/TbMsgDelayNode.java

@ -61,7 +61,7 @@ public class TbMsgDelayNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
if (msg.checkType(TbMsgType.DELAY_TIMEOUT_SELF_MSG)) {
if (msg.isTypeOf(TbMsgType.DELAY_TIMEOUT_SELF_MSG)) {
TbMsg pendingMsg = pendingMsgs.remove(UUID.fromString(msg.getData()));
if (pendingMsg != null) {
ctx.enqueueForTellNext(

14
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/edge/AbstractTbMsgPushNode.java

@ -82,7 +82,7 @@ public abstract class AbstractTbMsgPushNode<T extends BaseTbMsgPushNodeConfigura
}
protected S buildEvent(TbMsg msg, TbContext ctx) {
if (msg.checkType(ALARM)) {
if (msg.isTypeOf(ALARM)) {
EdgeEventActionType actionType = getAlarmActionType(msg);
return buildEvent(ctx.getTenantId(), actionType, getUUIDFromMsgData(msg), getAlarmEventType(), null);
} else {
@ -159,15 +159,15 @@ public abstract class AbstractTbMsgPushNode<T extends BaseTbMsgPushNodeConfigura
protected EdgeEventActionType getEdgeEventActionTypeByMsgType(TbMsg msg) {
EdgeEventActionType actionType;
if (msg.checkTypeOneOf(POST_TELEMETRY_REQUEST, TIMESERIES_UPDATED)) {
if (msg.isTypeOneOf(POST_TELEMETRY_REQUEST, TIMESERIES_UPDATED)) {
actionType = EdgeEventActionType.TIMESERIES_UPDATED;
} else if (msg.checkType(ATTRIBUTES_UPDATED)) {
} else if (msg.isTypeOf(ATTRIBUTES_UPDATED)) {
actionType = EdgeEventActionType.ATTRIBUTES_UPDATED;
} else if (msg.checkType(POST_ATTRIBUTES_REQUEST)) {
} else if (msg.isTypeOf(POST_ATTRIBUTES_REQUEST)) {
actionType = EdgeEventActionType.POST_ATTRIBUTES;
} else if (msg.checkType(ATTRIBUTES_DELETED)) {
} else if (msg.isTypeOf(ATTRIBUTES_DELETED)) {
actionType = EdgeEventActionType.ATTRIBUTES_DELETED;
} else if (msg.checkTypeOneOf(CONNECT_EVENT, DISCONNECT_EVENT, ACTIVITY_EVENT, INACTIVITY_EVENT)) {
} else if (msg.isTypeOneOf(CONNECT_EVENT, DISCONNECT_EVENT, ACTIVITY_EVENT, INACTIVITY_EVENT)) {
String scope = msg.getMetaData().getValue(SCOPE);
actionType = StringUtils.isEmpty(scope) ?
EdgeEventActionType.TIMESERIES_UPDATED : EdgeEventActionType.ATTRIBUTES_UPDATED;
@ -180,7 +180,7 @@ public abstract class AbstractTbMsgPushNode<T extends BaseTbMsgPushNodeConfigura
}
protected boolean isSupportedMsgType(TbMsg msg) {
return msg.checkTypeOneOf(POST_TELEMETRY_REQUEST, POST_ATTRIBUTES_REQUEST, ATTRIBUTES_UPDATED,
return msg.isTypeOneOf(POST_TELEMETRY_REQUEST, POST_ATTRIBUTES_REQUEST, ATTRIBUTES_UPDATED,
ATTRIBUTES_DELETED, TIMESERIES_UPDATED, ALARM, CONNECT_EVENT, DISCONNECT_EVENT, ACTIVITY_EVENT, INACTIVITY_EVENT);
}

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/mail/TbSendEmailNode.java

@ -101,7 +101,7 @@ public class TbSendEmailNode extends TbAbstractExternalNode {
}
private void validateType(TbMsg msg) {
if (!msg.checkType(TbMsgType.SEND_EMAIL)) {
if (!msg.isTypeOf(TbMsgType.SEND_EMAIL)) {
String type = msg.getType();
log.warn("Not expected msg type [{}] for SendEmail Node", type);
throw new IllegalStateException("Not expected msg type " + type + " for SendEmail Node");

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/metadata/CalculateDeltaNode.java

@ -75,7 +75,7 @@ public class CalculateDeltaNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
if (!msg.checkType(TbMsgType.POST_TELEMETRY_REQUEST)) {
if (!msg.isTypeOf(TbMsgType.POST_TELEMETRY_REQUEST)) {
ctx.tellNext(msg, TbNodeConnectionType.OTHER);
return;
}

18
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/profile/DeviceState.java

@ -147,24 +147,24 @@ class DeviceState {
latestValues = fetchLatestValues(ctx, deviceId);
}
boolean stateChanged = false;
if (msg.checkType(POST_TELEMETRY_REQUEST)) {
if (msg.isTypeOf(POST_TELEMETRY_REQUEST)) {
stateChanged = processTelemetry(ctx, msg);
} else if (msg.checkType(POST_ATTRIBUTES_REQUEST)) {
} else if (msg.isTypeOf(POST_ATTRIBUTES_REQUEST)) {
stateChanged = processAttributesUpdateRequest(ctx, msg);
} else if (msg.checkTypeOneOf(ACTIVITY_EVENT, INACTIVITY_EVENT)) {
} else if (msg.isTypeOneOf(ACTIVITY_EVENT, INACTIVITY_EVENT)) {
stateChanged = processDeviceActivityEvent(ctx, msg);
} else if (msg.checkType(ATTRIBUTES_UPDATED)) {
} else if (msg.isTypeOf(ATTRIBUTES_UPDATED)) {
stateChanged = processAttributesUpdateNotification(ctx, msg);
} else if (msg.checkType(ATTRIBUTES_DELETED)) {
} else if (msg.isTypeOf(ATTRIBUTES_DELETED)) {
stateChanged = processAttributesDeleteNotification(ctx, msg);
} else if (msg.checkType(ALARM_CLEAR)) {
} else if (msg.isTypeOf(ALARM_CLEAR)) {
stateChanged = processAlarmClearNotification(ctx, msg);
} else if (msg.checkType(ALARM_ACK)) {
} else if (msg.isTypeOf(ALARM_ACK)) {
processAlarmAckNotification(ctx, msg);
} else if (msg.checkType(ALARM_DELETE)) {
} else if (msg.isTypeOf(ALARM_DELETE)) {
processAlarmDeleteNotification(ctx, msg);
} else {
if (msg.checkTypeOneOf(ENTITY_ASSIGNED, ENTITY_UNASSIGNED)) {
if (msg.isTypeOneOf(ENTITY_ASSIGNED, ENTITY_UNASSIGNED)) {
dynamicPredicateValueCtx.resetCustomer();
}
ctx.tellSuccess(msg);

10
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/profile/TbDeviceProfileNode.java

@ -108,12 +108,12 @@ public class TbDeviceProfileNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException {
EntityType originatorType = msg.getOriginator().getEntityType();
if (msg.checkType(TbMsgType.DEVICE_PROFILE_PERIODIC_SELF_MSG)) {
if (msg.isTypeOf(TbMsgType.DEVICE_PROFILE_PERIODIC_SELF_MSG)) {
scheduleAlarmHarvesting(ctx, msg);
harvestAlarms(ctx, System.currentTimeMillis());
} else if (msg.checkType(TbMsgType.DEVICE_PROFILE_UPDATE_SELF_MSG)) {
} else if (msg.isTypeOf(TbMsgType.DEVICE_PROFILE_UPDATE_SELF_MSG)) {
updateProfile(ctx, new DeviceProfileId(UUID.fromString(msg.getData())));
} else if (msg.checkType(TbMsgType.DEVICE_UPDATE_SELF_MSG)) {
} else if (msg.isTypeOf(TbMsgType.DEVICE_UPDATE_SELF_MSG)) {
JsonNode data = JacksonUtil.toJsonNode(msg.getData());
DeviceId deviceId = new DeviceId(UUID.fromString(data.get("deviceId").asText()));
if (data.has("profileId")) {
@ -124,10 +124,10 @@ public class TbDeviceProfileNode implements TbNode {
} else {
if (EntityType.DEVICE.equals(originatorType)) {
DeviceId deviceId = new DeviceId(msg.getOriginator().getId());
if (msg.checkType(TbMsgType.ENTITY_UPDATED)) {
if (msg.isTypeOf(TbMsgType.ENTITY_UPDATED)) {
invalidateDeviceProfileCache(deviceId, msg.getData());
ctx.tellSuccess(msg);
} else if (msg.checkType(TbMsgType.ENTITY_DELETED)) {
} else if (msg.isTypeOf(TbMsgType.ENTITY_DELETED)) {
removeDeviceState(deviceId);
ctx.tellSuccess(msg);
} else {

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/rpc/TbSendRPCRequestNode.java

@ -76,7 +76,7 @@ public class TbSendRPCRequestNode implements TbNode {
ctx.tellFailure(msg, new RuntimeException("Params are not present in the message!"));
} else {
int requestId = json.has("requestId") ? json.get("requestId").getAsInt() : random.nextInt();
boolean restApiCall = msg.checkType(TbMsgType.RPC_CALL_FROM_SERVER_TO_DEVICE);
boolean restApiCall = msg.isTypeOf(TbMsgType.RPC_CALL_FROM_SERVER_TO_DEVICE);
tmp = msg.getMetaData().getValue("oneway");
boolean oneway = !StringUtils.isEmpty(tmp) && Boolean.parseBoolean(tmp);

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java

@ -65,7 +65,7 @@ public class TbMsgAttributesNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
if (!msg.checkType(POST_ATTRIBUTES_REQUEST)) {
if (!msg.isTypeOf(POST_ATTRIBUTES_REQUEST)) {
ctx.tellFailure(msg, new IllegalArgumentException("Unsupported msg type: " + msg.getType()));
return;
}

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgTimeseriesNode.java

@ -82,7 +82,7 @@ public class TbMsgTimeseriesNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
if (!msg.checkType(POST_TELEMETRY_REQUEST)) {
if (!msg.isTypeOf(POST_TELEMETRY_REQUEST)) {
ctx.tellFailure(msg, new IllegalArgumentException("Unsupported msg type: " + msg.getType()));
return;
}

Loading…
Cancel
Save