Remove SearchText from Device
This commit is contained in:
parent
fa41086e6d
commit
f05f2e2053
@ -0,0 +1,108 @@
|
||||
/**
|
||||
* 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 com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.server.common.data.id.UUIDBased;
|
||||
import org.thingsboard.server.common.data.validation.NoXss;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 19.02.18.
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class BaseDataWithAdditionalInfo<I extends UUIDBased> extends BaseData<I> implements HasAdditionalInfo {
|
||||
|
||||
public static final ObjectMapper mapper = new ObjectMapper();
|
||||
@NoXss
|
||||
private transient JsonNode additionalInfo;
|
||||
@JsonIgnore
|
||||
private byte[] additionalInfoBytes;
|
||||
|
||||
public BaseDataWithAdditionalInfo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BaseDataWithAdditionalInfo(I id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public BaseDataWithAdditionalInfo(BaseDataWithAdditionalInfo<I> baseData) {
|
||||
super(baseData);
|
||||
setAdditionalInfo(baseData.getAdditionalInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getAdditionalInfo() {
|
||||
return getJson(() -> additionalInfo, () -> additionalInfoBytes);
|
||||
}
|
||||
|
||||
public void setAdditionalInfo(JsonNode addInfo) {
|
||||
setJson(addInfo, json -> this.additionalInfo = json, bytes -> this.additionalInfoBytes = bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
BaseDataWithAdditionalInfo<?> that = (BaseDataWithAdditionalInfo<?>) o;
|
||||
return Arrays.equals(additionalInfoBytes, that.additionalInfoBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), additionalInfoBytes);
|
||||
}
|
||||
|
||||
public static JsonNode getJson(Supplier<JsonNode> jsonData, Supplier<byte[]> binaryData) {
|
||||
JsonNode json = jsonData.get();
|
||||
if (json != null) {
|
||||
return json;
|
||||
} else {
|
||||
byte[] data = binaryData.get();
|
||||
if (data != null) {
|
||||
try {
|
||||
return mapper.readTree(new ByteArrayInputStream(data));
|
||||
} catch (IOException e) {
|
||||
log.warn("Can't deserialize json data: ", e);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setJson(JsonNode json, Consumer<JsonNode> jsonConsumer, Consumer<byte[]> bytesConsumer) {
|
||||
jsonConsumer.accept(json);
|
||||
try {
|
||||
bytesConsumer.accept(mapper.writeValueAsBytes(json));
|
||||
} catch (JsonProcessingException e) {
|
||||
log.warn("Can't serialize json data: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ import java.util.Optional;
|
||||
@ApiModel
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Slf4j
|
||||
public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasLabel, HasTenantId, HasCustomerId, HasOtaPackage, ExportableEntity<DeviceId> {
|
||||
public class Device extends BaseDataWithAdditionalInfo<DeviceId> implements HasLabel, HasTenantId, HasCustomerId, HasOtaPackage, ExportableEntity<DeviceId> {
|
||||
|
||||
private static final long serialVersionUID = 2807343040519543363L;
|
||||
|
||||
@ -201,11 +201,6 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSearchText() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@ApiModelProperty(position = 10, value = "JSON object with Ota Package Id.")
|
||||
public OtaPackageId getFirmwareId() {
|
||||
return firmwareId;
|
||||
|
||||
@ -261,6 +261,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository {
|
||||
entityNameColumns.put(EntityType.ENTITY_VIEW, "name");
|
||||
entityNameColumns.put(EntityType.TB_RESOURCE, "search_text");
|
||||
entityNameColumns.put(EntityType.EDGE, "name");
|
||||
entityNameColumns.put(EntityType.QUEUE, "name");
|
||||
}
|
||||
|
||||
public static EntityType[] RELATION_QUERY_ENTITY_TYPES = new EntityType[]{
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.rule.engine.util;
|
||||
|
||||
import org.thingsboard.rule.engine.api.TbContext;
|
||||
import org.thingsboard.server.common.data.BaseData;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -32,7 +33,7 @@ public class EntitiesByNameAndTypeLoader {
|
||||
EntityType.USER);
|
||||
|
||||
public static EntityId findEntityId(TbContext ctx, EntityType entityType, String entityName) {
|
||||
SearchTextBasedWithAdditionalInfo<? extends EntityId> targetEntity;
|
||||
BaseData<? extends EntityId> targetEntity;
|
||||
switch (entityType) {
|
||||
case DEVICE:
|
||||
targetEntity = ctx.getDeviceService().findDeviceByTenantIdAndName(ctx.getTenantId(), entityName);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user