Browse Source
Filter nodes improvements && fixes for enrichment rule nodes && added TbMsgType enum and enforced use of it in corresponding places.pull/9044/head
committed by
GitHub
193 changed files with 3687 additions and 1710 deletions
@ -0,0 +1,115 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.server.common.data.msg; |
|||
|
|||
import lombok.Getter; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.EnumSet; |
|||
import java.util.List; |
|||
import java.util.Objects; |
|||
import java.util.stream.Collectors; |
|||
|
|||
public enum TbMsgType { |
|||
|
|||
POST_ATTRIBUTES_REQUEST("Post attributes"), |
|||
POST_TELEMETRY_REQUEST("Post telemetry"), |
|||
TO_SERVER_RPC_REQUEST("RPC Request from Device"), |
|||
ACTIVITY_EVENT("Activity Event"), |
|||
INACTIVITY_EVENT("Inactivity Event"), |
|||
CONNECT_EVENT("Connect Event"), |
|||
DISCONNECT_EVENT("Disconnect Event"), |
|||
ENTITY_CREATED("Entity Created"), |
|||
ENTITY_UPDATED("Entity Updated"), |
|||
ENTITY_DELETED("Entity Deleted"), |
|||
ENTITY_ASSIGNED("Entity Assigned"), |
|||
ENTITY_UNASSIGNED("Entity Unassigned"), |
|||
ATTRIBUTES_UPDATED("Attributes Updated"), |
|||
ATTRIBUTES_DELETED("Attributes Deleted"), |
|||
ALARM(null), |
|||
ALARM_ACK("Alarm Acknowledged"), |
|||
ALARM_CLEAR("Alarm Cleared"), |
|||
ALARM_DELETE(null), |
|||
ALARM_ASSIGNED("Alarm Assigned"), |
|||
ALARM_UNASSIGNED("Alarm Unassigned"), |
|||
COMMENT_CREATED("Comment Created"), |
|||
COMMENT_UPDATED("Comment Updated"), |
|||
RPC_CALL_FROM_SERVER_TO_DEVICE("RPC Request to Device"), |
|||
ENTITY_ASSIGNED_FROM_TENANT("Entity Assigned From Tenant"), |
|||
ENTITY_ASSIGNED_TO_TENANT("Entity Assigned To Tenant"), |
|||
ENTITY_ASSIGNED_TO_EDGE(null), |
|||
ENTITY_UNASSIGNED_FROM_EDGE(null), |
|||
TIMESERIES_UPDATED("Timeseries Updated"), |
|||
TIMESERIES_DELETED("Timeseries Deleted"), |
|||
RPC_QUEUED("RPC Queued"), |
|||
RPC_SENT("RPC Sent"), |
|||
RPC_DELIVERED("RPC Delivered"), |
|||
RPC_SUCCESSFUL("RPC Successful"), |
|||
RPC_TIMEOUT("RPC Timeout"), |
|||
RPC_EXPIRED("RPC Expired"), |
|||
RPC_FAILED("RPC Failed"), |
|||
RPC_DELETED("RPC Deleted"), |
|||
RELATION_ADD_OR_UPDATE("Relation Added or Updated"), |
|||
RELATION_DELETED("Relation Deleted"), |
|||
RELATIONS_DELETED("All Relations Deleted"), |
|||
PROVISION_SUCCESS(null), |
|||
PROVISION_FAILURE(null), |
|||
SEND_EMAIL(null), |
|||
|
|||
// tellSelfOnly types
|
|||
GENERATOR_NODE_SELF_MSG(null, true), |
|||
DEVICE_PROFILE_PERIODIC_SELF_MSG(null, true), |
|||
DEVICE_PROFILE_UPDATE_SELF_MSG(null, true), |
|||
DEVICE_UPDATE_SELF_MSG(null, true), |
|||
DEDUPLICATION_TIMEOUT_SELF_MSG(null, true), |
|||
DELAY_TIMEOUT_SELF_MSG(null, true), |
|||
MSG_COUNT_SELF_MSG(null, true); |
|||
|
|||
public static final List<String> NODE_CONNECTIONS = EnumSet.allOf(TbMsgType.class).stream() |
|||
.filter(tbMsgType -> !tbMsgType.isTellSelfOnly()) |
|||
.map(TbMsgType::getRuleNodeConnection) |
|||
.filter(Objects::nonNull) |
|||
.collect(Collectors.toUnmodifiableList()); |
|||
|
|||
@Getter |
|||
private final String ruleNodeConnection; |
|||
|
|||
@Getter |
|||
private final boolean tellSelfOnly; |
|||
|
|||
TbMsgType(String ruleNodeConnection, boolean tellSelfOnly) { |
|||
this.ruleNodeConnection = ruleNodeConnection; |
|||
this.tellSelfOnly = tellSelfOnly; |
|||
} |
|||
|
|||
TbMsgType(String ruleNodeConnection) { |
|||
this.ruleNodeConnection = ruleNodeConnection; |
|||
this.tellSelfOnly = false; |
|||
} |
|||
|
|||
public static String getRuleNodeConnectionOrElseOther(String msgType) { |
|||
if (msgType == null) { |
|||
return TbNodeConnectionType.OTHER; |
|||
} else { |
|||
return Arrays.stream(TbMsgType.values()) |
|||
.filter(type -> type.name().equals(msgType)) |
|||
.findFirst() |
|||
.map(TbMsgType::getRuleNodeConnection) |
|||
.orElse(TbNodeConnectionType.OTHER); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.server.common.data; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
|
|||
class EntityTypeTest { |
|||
|
|||
// backward-compatibility test
|
|||
@Test |
|||
void getNormalNameTest() { |
|||
assertThat(EntityType.ENTITY_VIEW.getNormalName()).isEqualTo("Entity View"); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.server.common.data.audit; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.util.List; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.ACTIVATED; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.ATTRIBUTES_READ; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.CREDENTIALS_READ; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.CREDENTIALS_UPDATED; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.DELETED_COMMENT; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.LOCKOUT; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.LOGIN; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.LOGOUT; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.RPC_CALL; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.SMS_SENT; |
|||
import static org.thingsboard.server.common.data.audit.ActionType.SUSPENDED; |
|||
|
|||
class ActionTypeTest { |
|||
|
|||
private static final List<ActionType> typesWithNullRuleEngineMsgType = List.of( |
|||
RPC_CALL, |
|||
CREDENTIALS_UPDATED, |
|||
ACTIVATED, |
|||
SUSPENDED, |
|||
CREDENTIALS_READ, |
|||
ATTRIBUTES_READ, |
|||
LOGIN, |
|||
LOGOUT, |
|||
LOCKOUT, |
|||
DELETED_COMMENT, |
|||
SMS_SENT |
|||
); |
|||
|
|||
// backward-compatibility tests
|
|||
|
|||
@Test |
|||
void getRuleEngineMsgTypeTest() { |
|||
var types = ActionType.values(); |
|||
for (var type : types) { |
|||
if (typesWithNullRuleEngineMsgType.contains(type)) { |
|||
assertThat(type.getRuleEngineMsgType()).isEmpty(); |
|||
} else { |
|||
assertThat(type.getRuleEngineMsgType()).isPresent(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.server.common.data.msg; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.util.List; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.ALARM; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.ALARM_DELETE; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.DEDUPLICATION_TIMEOUT_SELF_MSG; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.DELAY_TIMEOUT_SELF_MSG; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.ENTITY_ASSIGNED_TO_EDGE; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.ENTITY_UNASSIGNED_FROM_EDGE; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.MSG_COUNT_SELF_MSG; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.PROVISION_FAILURE; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.PROVISION_SUCCESS; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.DEVICE_PROFILE_PERIODIC_SELF_MSG; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.DEVICE_PROFILE_UPDATE_SELF_MSG; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.DEVICE_UPDATE_SELF_MSG; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.GENERATOR_NODE_SELF_MSG; |
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.SEND_EMAIL; |
|||
|
|||
class TbMsgTypeTest { |
|||
|
|||
private static final List<TbMsgType> typesWithNullRuleNodeConnection = List.of( |
|||
ALARM, |
|||
ALARM_DELETE, |
|||
ENTITY_ASSIGNED_TO_EDGE, |
|||
ENTITY_UNASSIGNED_FROM_EDGE, |
|||
PROVISION_FAILURE, |
|||
PROVISION_SUCCESS, |
|||
SEND_EMAIL, |
|||
GENERATOR_NODE_SELF_MSG, |
|||
DEVICE_PROFILE_PERIODIC_SELF_MSG, |
|||
DEVICE_PROFILE_UPDATE_SELF_MSG, |
|||
DEVICE_UPDATE_SELF_MSG, |
|||
DEDUPLICATION_TIMEOUT_SELF_MSG, |
|||
DELAY_TIMEOUT_SELF_MSG, |
|||
MSG_COUNT_SELF_MSG |
|||
); |
|||
|
|||
// backward-compatibility tests
|
|||
|
|||
@Test |
|||
void getRuleNodeConnectionsTest() { |
|||
var tbMsgTypes = TbMsgType.values(); |
|||
for (var type : tbMsgTypes) { |
|||
if (typesWithNullRuleNodeConnection.contains(type)) { |
|||
assertThat(type.getRuleNodeConnection()).isNull(); |
|||
} else { |
|||
assertThat(type.getRuleNodeConnection()).isNotNull(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Test |
|||
void getRuleNodeConnectionOrElseOtherTest() { |
|||
assertThat(TbMsgType.getRuleNodeConnectionOrElseOther(null)) |
|||
.isEqualTo(TbNodeConnectionType.OTHER); |
|||
var tbMsgTypes = TbMsgType.values(); |
|||
for (var type : tbMsgTypes) { |
|||
if (typesWithNullRuleNodeConnection.contains(type)) { |
|||
assertThat(TbMsgType.getRuleNodeConnectionOrElseOther(type.name())) |
|||
.isEqualTo(TbNodeConnectionType.OTHER); |
|||
} else { |
|||
assertThat(TbMsgType.getRuleNodeConnectionOrElseOther(type.name())).isNotNull() |
|||
.isNotEqualTo(TbNodeConnectionType.OTHER); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.server.transport.coap; |
|||
|
|||
public enum CoapSessionMsgType { |
|||
|
|||
GET_ATTRIBUTES_REQUEST, |
|||
POST_ATTRIBUTES_REQUEST, |
|||
SUBSCRIBE_ATTRIBUTES_REQUEST, |
|||
UNSUBSCRIBE_ATTRIBUTES_REQUEST, |
|||
POST_TELEMETRY_REQUEST, |
|||
SUBSCRIBE_RPC_COMMANDS_REQUEST, |
|||
UNSUBSCRIBE_RPC_COMMANDS_REQUEST, |
|||
TO_DEVICE_RPC_RESPONSE, |
|||
TO_SERVER_RPC_REQUEST, |
|||
CLAIM_REQUEST; |
|||
|
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue