Revert "Fix TbSubscriptionUtils order for matching KeyValueType and DataType"
This reverts commit d9669c9391146b402821f6fc872418ecbe0f3686.
This commit is contained in:
parent
79803292b6
commit
e1bac1bf79
@ -36,6 +36,7 @@ import org.thingsboard.server.common.data.kv.TsKvEntry;
|
||||
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.KeyValueProto;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.KeyValueType;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.SubscriptionMgrMsgProto;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.TbAlarmDeleteProto;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.TbAlarmUpdateProto;
|
||||
@ -53,7 +54,6 @@ import org.thingsboard.server.service.ws.notification.sub.NotificationsSubscript
|
||||
import org.thingsboard.server.service.ws.telemetry.sub.AlarmSubscriptionUpdate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -62,14 +62,6 @@ import java.util.UUID;
|
||||
|
||||
public class TbSubscriptionUtils {
|
||||
|
||||
private static final DataType[] dataTypeByProtoNumber;
|
||||
|
||||
static {
|
||||
int arraySize = Arrays.stream(DataType.values()).mapToInt(DataType::getProtoNumber).max().orElse(0);
|
||||
dataTypeByProtoNumber = new DataType[arraySize + 1];
|
||||
Arrays.stream(DataType.values()).forEach(dataType -> dataTypeByProtoNumber[dataType.getProtoNumber()] = dataType);
|
||||
}
|
||||
|
||||
public static ToCoreMsg toSubEventProto(String serviceId, TbEntitySubEvent event) {
|
||||
SubscriptionMgrMsgProto.Builder msgBuilder = SubscriptionMgrMsgProto.newBuilder();
|
||||
var builder = TbEntitySubEventProto.newBuilder()
|
||||
@ -243,7 +235,7 @@ public class TbSubscriptionUtils {
|
||||
private static TsKvProto.Builder toKeyValueProto(long ts, KvEntry attr) {
|
||||
KeyValueProto.Builder dataBuilder = KeyValueProto.newBuilder();
|
||||
dataBuilder.setKey(attr.getKey());
|
||||
dataBuilder.setType(toProto(attr.getDataType()));
|
||||
dataBuilder.setType(KeyValueType.forNumber(attr.getDataType().ordinal()));
|
||||
switch (attr.getDataType()) {
|
||||
case BOOLEAN:
|
||||
attr.getBooleanValue().ifPresent(dataBuilder::setBoolV);
|
||||
@ -267,7 +259,7 @@ public class TbSubscriptionUtils {
|
||||
private static TransportProtos.TsValueProto toTsValueProto(long ts, KvEntry attr) {
|
||||
TransportProtos.TsValueProto.Builder dataBuilder = TransportProtos.TsValueProto.newBuilder();
|
||||
dataBuilder.setTs(ts);
|
||||
dataBuilder.setType(toProto(attr.getDataType()));
|
||||
dataBuilder.setType(KeyValueType.forNumber(attr.getDataType().ordinal()));
|
||||
switch (attr.getDataType()) {
|
||||
case BOOLEAN:
|
||||
attr.getBooleanValue().ifPresent(dataBuilder::setBoolV);
|
||||
@ -307,7 +299,8 @@ public class TbSubscriptionUtils {
|
||||
|
||||
private static KvEntry getKvEntry(KeyValueProto proto) {
|
||||
KvEntry entry = null;
|
||||
switch (fromProto(proto.getType())) {
|
||||
DataType type = DataType.values()[proto.getType().getNumber()];
|
||||
switch (type) {
|
||||
case BOOLEAN:
|
||||
entry = new BooleanDataEntry(proto.getKey(), proto.getBoolV());
|
||||
break;
|
||||
@ -335,7 +328,8 @@ public class TbSubscriptionUtils {
|
||||
|
||||
private static KvEntry getKvEntry(String key, TransportProtos.TsValueProto proto) {
|
||||
KvEntry entry = null;
|
||||
switch (fromProto(proto.getType())) {
|
||||
DataType type = DataType.values()[proto.getType().getNumber()];
|
||||
switch (type) {
|
||||
case BOOLEAN:
|
||||
entry = new BooleanDataEntry(key, proto.getBoolV());
|
||||
break;
|
||||
@ -454,12 +448,4 @@ public class TbSubscriptionUtils {
|
||||
return ToCoreNotificationMsg.newBuilder().setToLocalSubscriptionServiceMsg(result).build();
|
||||
}
|
||||
|
||||
public static TransportProtos.KeyValueType toProto(DataType dataType) {
|
||||
return TransportProtos.KeyValueType.forNumber(dataType.getProtoNumber());
|
||||
}
|
||||
|
||||
public static DataType fromProto(TransportProtos.KeyValueType keyValueType) {
|
||||
return dataTypeByProtoNumber[keyValueType.getNumber()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2024 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.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.kv.DataType;
|
||||
import org.thingsboard.server.service.subscription.TbSubscriptionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TbSubscriptionUtilsTest {
|
||||
|
||||
@Test
|
||||
public void protoDataTypeSerialization() {
|
||||
for (DataType dataType : DataType.values()) {
|
||||
assertThat(TbSubscriptionUtils.fromProto(TbSubscriptionUtils.toProto(dataType))).as(dataType.name()).isEqualTo(dataType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,7 +26,6 @@ import java.util.stream.Collectors;
|
||||
* @author Andrew Shvayka
|
||||
*/
|
||||
public enum EntityType {
|
||||
|
||||
TENANT(1),
|
||||
CUSTOMER(2),
|
||||
USER(3),
|
||||
@ -64,7 +63,7 @@ public enum EntityType {
|
||||
@Getter
|
||||
private final int protoNumber; // Corresponds to EntityTypeProto
|
||||
|
||||
EntityType(int protoNumber) {
|
||||
private EntityType(int protoNumber) {
|
||||
this.protoNumber = protoNumber;
|
||||
}
|
||||
|
||||
|
||||
@ -15,21 +15,8 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data.kv;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum DataType {
|
||||
|
||||
BOOLEAN(0),
|
||||
LONG(1),
|
||||
DOUBLE(2),
|
||||
STRING(3),
|
||||
JSON(4);
|
||||
|
||||
@Getter
|
||||
private final int protoNumber; // Corresponds to KeyValueType
|
||||
|
||||
DataType(int protoNumber) {
|
||||
this.protoNumber = protoNumber;
|
||||
}
|
||||
STRING, LONG, BOOLEAN, DOUBLE, JSON;
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user