|
|
|
@ -20,8 +20,17 @@ import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
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) { |
|
|
|
SearchTextBasedWithAdditionalInfo<? extends EntityId> targetEntity; |
|
|
|
switch (entityType) { |
|
|
|
@ -49,4 +58,10 @@ public class EntitiesByNameAndTypeLoader { |
|
|
|
return targetEntity.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void checkEntityType(EntityType entityType) { |
|
|
|
if (!AVAILABLE_ENTITY_TYPES.contains(entityType)) { |
|
|
|
throw new IllegalStateException("Unexpected entity type " + entityType.name()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|