add checkEntityType for init node
This commit is contained in:
parent
f49b349396
commit
1564ba76f1
@ -127,6 +127,7 @@ public class TbChangeOriginatorNode extends TbAbstractTransformNode {
|
|||||||
log.error("EntityNamePattern not specified for type [{}]", conf.getEntityType());
|
log.error("EntityNamePattern not specified for type [{}]", conf.getEntityType());
|
||||||
throw new IllegalArgumentException("Wrong config for [{}] in TbChangeOriginatorNode!" + ENTITY_SOURCE);
|
throw new IllegalArgumentException("Wrong config for [{}] in TbChangeOriginatorNode!" + ENTITY_SOURCE);
|
||||||
}
|
}
|
||||||
|
EntitiesByNameAndTypeLoader.checkEntityType(EntityType.valueOf(conf.getEntityType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,8 +20,17 @@ import org.thingsboard.server.common.data.EntityType;
|
|||||||
import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo;
|
import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class EntitiesByNameAndTypeLoader {
|
public class EntitiesByNameAndTypeLoader {
|
||||||
|
|
||||||
|
private static final List<EntityType> AVAILABLE_ENTITY_TYPES = List.of(
|
||||||
|
EntityType.DEVICE,
|
||||||
|
EntityType.ASSET,
|
||||||
|
EntityType.ENTITY_VIEW,
|
||||||
|
EntityType.EDGE,
|
||||||
|
EntityType.USER);
|
||||||
|
|
||||||
public static EntityId findEntityId(TbContext ctx, EntityType entityType, String entityName) {
|
public static EntityId findEntityId(TbContext ctx, EntityType entityType, String entityName) {
|
||||||
SearchTextBasedWithAdditionalInfo<? extends EntityId> targetEntity;
|
SearchTextBasedWithAdditionalInfo<? extends EntityId> targetEntity;
|
||||||
switch (entityType) {
|
switch (entityType) {
|
||||||
@ -49,4 +58,10 @@ public class EntitiesByNameAndTypeLoader {
|
|||||||
return targetEntity.getId();
|
return targetEntity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkEntityType(EntityType entityType) {
|
||||||
|
if (!AVAILABLE_ENTITY_TYPES.contains(entityType)) {
|
||||||
|
throw new IllegalStateException("Unexpected entity type " + entityType.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user