added getEntityType method in EntityDaoService
This commit is contained in:
parent
3d27340cb5
commit
652a8c9e89
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao.entity;
|
||||
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -25,4 +26,6 @@ public interface EntityDaoService {
|
||||
|
||||
Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId);
|
||||
|
||||
EntityType getEntityType();
|
||||
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
import java.util.List;
|
||||
|
||||
public interface ResourceService extends EntityDaoService {
|
||||
|
||||
TbResource saveResource(TbResource resource);
|
||||
|
||||
TbResource getResource(TenantId tenantId, ResourceType resourceType, String resourceId);
|
||||
|
||||
@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.rpc.RpcStatus;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
public interface RpcService extends EntityDaoService {
|
||||
|
||||
Rpc save(Rpc rpc);
|
||||
|
||||
void deleteRpc(TenantId tenantId, RpcId id);
|
||||
|
||||
@ -108,10 +108,6 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
|
||||
@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.thingsboard.common.util.ThingsBoardThreadFactory;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmInfo;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmQuery;
|
||||
@ -409,4 +410,9 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
||||
return Optional.ofNullable(findAlarmById(tenantId, new AlarmId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ALARM;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.asset.AssetProfile;
|
||||
@ -272,6 +273,11 @@ public class AssetProfileServiceImpl extends AbstractCachedEntityService<AssetPr
|
||||
return Optional.ofNullable(findAssetProfileById(tenantId, new AssetProfileId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ASSET_PROFILE;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, AssetProfile> tenantAssetProfilesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
|
||||
|
||||
@ -437,4 +437,9 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
||||
return Optional.ofNullable(findAssetById(tenantId, new AssetId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ASSET;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
@ -186,4 +187,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
|
||||
return Optional.ofNullable(findCustomerById(tenantId, new CustomerId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.CUSTOMER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.DashboardInfo;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
@ -315,6 +316,11 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
return Optional.ofNullable(findDashboardById(tenantId, new DashboardId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DASHBOARD;
|
||||
}
|
||||
|
||||
private class CustomerDashboardsUnassigner extends PaginatedRemover<Customer, DashboardInfo> {
|
||||
|
||||
private Customer customer;
|
||||
|
||||
@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration;
|
||||
@ -294,6 +295,11 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
||||
return Optional.ofNullable(findDeviceProfileById(tenantId, new DeviceProfileId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE_PROFILE;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, DeviceProfile> tenantDeviceProfilesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
|
||||
|
||||
@ -713,4 +713,9 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
||||
return Optional.ofNullable(findDeviceById(tenantId, new DeviceId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -526,4 +526,9 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E
|
||||
return Optional.ofNullable(findEdgeById(tenantId, new EdgeId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.EDGE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,48 +15,39 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao.entity;
|
||||
|
||||
import org.apache.commons.text.CaseUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DefaultEntityServiceRegistry implements EntityServiceRegistry {
|
||||
|
||||
private static final String SERVICE_SUFFIX = "DaoService";
|
||||
|
||||
private Map<String, EntityDaoService> entityDaoServicesMap;
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
private final Map<EntityType, EntityDaoService> entityDaoServicesMap;
|
||||
|
||||
public DefaultEntityServiceRegistry(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityDaoServicesMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
entityDaoServicesMap = applicationContext.getBeansOfType(EntityDaoService.class);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
if (entityDaoServicesMap != null) {
|
||||
entityDaoServicesMap.clear();
|
||||
applicationContext.getBeansOfType(EntityDaoService.class).values().forEach(entityDaoService -> {
|
||||
EntityType entityType = entityDaoService.getEntityType();
|
||||
entityDaoServicesMap.put(entityType, entityDaoService);
|
||||
if (EntityType.RULE_CHAIN.equals(entityType)) {
|
||||
entityDaoServicesMap.put(EntityType.RULE_NODE, entityDaoService);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityDaoService getServiceByEntityType(EntityType entityType) {
|
||||
String beanName = EntityType.RULE_NODE.equals(entityType) ? getBeanName(EntityType.RULE_CHAIN) : getBeanName(entityType);
|
||||
return entityDaoServicesMap.get(beanName);
|
||||
}
|
||||
|
||||
private String getBeanName(EntityType entityType) {
|
||||
return CaseUtils.toCamelCase(entityType.name(), true, '_') + SERVICE_SUFFIX;
|
||||
return entityDaoServicesMap.get(entityType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -416,4 +416,9 @@ public class EntityViewServiceImpl extends AbstractCachedEntityService<EntityVie
|
||||
return Optional.ofNullable(findEntityViewById(tenantId, new EntityViewId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ENTITY_VIEW;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import org.thingsboard.server.cache.ota.OtaPackageDataCache;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.OtaPackage;
|
||||
import org.thingsboard.server.common.data.OtaPackageInfo;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
@ -241,4 +242,9 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
|
||||
return Optional.ofNullable(findOtaPackageInfoById(tenantId, new OtaPackageId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.OTA_PACKAGE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.TenantProfile;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
@ -127,6 +128,11 @@ public class BaseQueueService extends AbstractEntityService implements QueueServ
|
||||
return Optional.ofNullable(findQueueById(tenantId, new QueueId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.QUEUE;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, Queue> tenantQueuesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.ResourceType;
|
||||
import org.thingsboard.server.common.data.TbResource;
|
||||
import org.thingsboard.server.common.data.TbResourceInfo;
|
||||
@ -141,6 +142,11 @@ public class BaseResourceService implements ResourceService {
|
||||
return Optional.ofNullable(findResourceInfoById(tenantId, new TbResourceId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.TB_RESOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sumDataSizeByTenantId(TenantId tenantId) {
|
||||
return resourceDao.sumDataSizeByTenantId(tenantId);
|
||||
|
||||
@ -19,6 +19,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
@ -102,6 +103,11 @@ public class BaseRpcService implements RpcService {
|
||||
return Optional.ofNullable(findById(tenantId, new RpcId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.RPC;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, Rpc> tenantRpcRemover =
|
||||
new PaginatedRemover<>() {
|
||||
@Override
|
||||
|
||||
@ -768,6 +768,11 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
||||
return Optional.ofNullable(hasId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.RULE_CHAIN;
|
||||
}
|
||||
|
||||
private List<EntityRelation> getRuleChainToNodeRelations(TenantId tenantId, RuleChainId ruleChainId) {
|
||||
return relationService.findByFrom(tenantId, ruleChainId, RelationTypeGroup.RULE_CHAIN);
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import org.thingsboard.server.common.data.EntityInfo;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.TenantProfile;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
@ -212,6 +213,11 @@ public class TenantProfileServiceImpl extends AbstractCachedEntityService<Tenant
|
||||
return Optional.ofNullable(findTenantProfileById(tenantId, new TenantProfileId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.TENANT_PROFILE;
|
||||
}
|
||||
|
||||
private final PaginatedRemover<String, TenantProfile> tenantProfilesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import org.thingsboard.server.cache.TbTransactionalCache;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.TenantInfo;
|
||||
import org.thingsboard.server.common.data.TenantProfile;
|
||||
@ -264,4 +265,10 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findTenantById(new TenantId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.TENANT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -167,4 +167,10 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findApiUsageStateById(tenantId, new ApiUsageStateId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.API_USAGE_STATE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
@ -405,4 +406,9 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
|
||||
return Optional.ofNullable(findUserById(tenantId, new UserId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.USER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ package org.thingsboard.server.dao.widget;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -120,4 +121,9 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
|
||||
return Optional.ofNullable(findWidgetTypeById(tenantId, new WidgetTypeId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.WIDGET_TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ package org.thingsboard.server.dao.widget;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -159,6 +160,11 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
|
||||
return Optional.ofNullable(findWidgetsBundleById(tenantId, new WidgetsBundleId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.WIDGETS_BUNDLE;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, WidgetsBundle> tenantWidgetsBundleRemover =
|
||||
new PaginatedRemover<TenantId, WidgetsBundle>() {
|
||||
|
||||
|
||||
6
pom.xml
6
pom.xml
@ -61,7 +61,6 @@
|
||||
<commons-io.version>2.11.0</commons-io.version>
|
||||
<commons-logging.version>1.2</commons-logging.version>
|
||||
<commons-csv.version>1.4</commons-csv.version>
|
||||
<commons-text.version>1.9</commons-text.version>
|
||||
<apache-httpclient.version>4.5.13</apache-httpclient.version>
|
||||
<apache-httpcore.version>4.4.14</apache-httpcore.version>
|
||||
<joda-time.version>2.8.1</joda-time.version>
|
||||
@ -1364,11 +1363,6 @@
|
||||
<artifactId>commons-csv</artifactId>
|
||||
<version>${commons-csv.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>${commons-text.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user