EDQS: optimize serialization, fix api usage fields
This commit is contained in:
parent
0115ac231b
commit
506ec363eb
@ -43,8 +43,9 @@ public class ApiUsageStateFields extends AbstractEntityFields {
|
||||
|
||||
public ApiUsageStateFields(UUID id, long createdTime, UUID tenantId, UUID entityId, String entityType, ApiUsageStateValue transportState, ApiUsageStateValue dbStorageState,
|
||||
ApiUsageStateValue reExecState, ApiUsageStateValue jsExecState, ApiUsageStateValue tbelExecState,
|
||||
ApiUsageStateValue emailExecState, ApiUsageStateValue smsExecState, ApiUsageStateValue alarmExecState) {
|
||||
super(id, createdTime, tenantId);
|
||||
ApiUsageStateValue emailExecState, ApiUsageStateValue smsExecState, ApiUsageStateValue alarmExecState,
|
||||
Long version) {
|
||||
super(id, createdTime, tenantId, null, null, version);
|
||||
this.entityId = (entityType != null && entityId != null) ? EntityIdFactory.getByTypeAndUuid(entityType, entityId) : null;
|
||||
this.transportState = transportState;
|
||||
this.dbStorageState = dbStorageState;
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data.edqs.fields;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -23,6 +24,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public interface EntityFields {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(EntityFields.class);
|
||||
|
||||
@ -284,6 +284,7 @@ public class FieldsUtil {
|
||||
.emailExecState(entity.getEmailExecState())
|
||||
.smsExecState(entity.getSmsExecState())
|
||||
.alarmExecState(entity.getAlarmExecState())
|
||||
.version(entity.getVersion())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@ -219,7 +219,9 @@ public class TenantRepo {
|
||||
EntityType entityType = entity.getType();
|
||||
EntityData<?> removed = getEntityMap(entityType).remove(entityId);
|
||||
if (removed != null) {
|
||||
getEntitySet(entityType).remove(removed);
|
||||
if (removed.getFields() != null) {
|
||||
getEntitySet(entityType).remove(removed);
|
||||
}
|
||||
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.fromEntityType(entityType), EdqsEventType.DELETED));
|
||||
UUID customerId = removed.getCustomerId();
|
||||
if (customerId != null) {
|
||||
|
||||
@ -15,12 +15,15 @@
|
||||
*/
|
||||
package org.thingsboard.server.edqs.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.AttributeScope;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.ObjectType;
|
||||
@ -217,16 +220,24 @@ public class EdqsConverter {
|
||||
@RequiredArgsConstructor
|
||||
private static class JsonConverter<T> implements Converter<T> {
|
||||
|
||||
private static final ObjectMapper mapper = JsonMapper.builder()
|
||||
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
|
||||
.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
|
||||
.visibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE)
|
||||
.build();
|
||||
|
||||
private final Class<T> type;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public byte[] serialize(ObjectType objectType, T value) {
|
||||
return JacksonUtil.writeValueAsBytes(value);
|
||||
return mapper.writeValueAsBytes(value);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public T deserialize(ObjectType objectType, byte[] bytes) {
|
||||
return JacksonUtil.fromBytes(bytes, this.type);
|
||||
return mapper.readValue(bytes, this.type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ public interface ApiUsageStateRepository extends JpaRepository<ApiUsageStateEnti
|
||||
|
||||
@Query("SELECT new org.thingsboard.server.common.data.edqs.fields.ApiUsageStateFields(a.id, a.createdTime, a.tenantId," +
|
||||
"a.entityId, a.entityType, a.transportState, a.dbStorageState, a.reExecState, a.jsExecState, a.tbelExecState, " +
|
||||
"a.emailExecState, a.smsExecState, a.alarmExecState) FROM ApiUsageStateEntity a WHERE a.id > :id ORDER BY a.id")
|
||||
"a.emailExecState, a.smsExecState, a.alarmExecState, a.version) FROM ApiUsageStateEntity a WHERE a.id > :id ORDER BY a.id")
|
||||
List<ApiUsageStateFields> findNextBatch(@Param("id") UUID id, Limit limit);
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user