Merge pull request #7804 from ShvaykaD/feature/base-entity-service-improvement
[3.5] improvements for base entity service v2
This commit is contained in:
commit
19513ec027
@ -561,7 +561,7 @@ public class DefaultDataUpdateService implements DataUpdateService {
|
||||
while (hasNext) {
|
||||
for (Alarm alarm : alarms.getData()) {
|
||||
if (alarm.getCustomerId() == null && alarm.getOriginator() != null) {
|
||||
alarm.setCustomerId(entityService.fetchEntityCustomerId(tenantId, alarm.getOriginator()));
|
||||
alarm.setCustomerId(entityService.fetchEntityCustomerId(tenantId, alarm.getOriginator()).get());
|
||||
alarmDao.save(tenantId, alarm);
|
||||
}
|
||||
if (processed.incrementAndGet() % 1000 == 0) {
|
||||
|
||||
@ -115,10 +115,6 @@
|
||||
<artifactId>awaitility</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -30,14 +30,14 @@ import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.query.AlarmData;
|
||||
import org.thingsboard.server.common.data.query.AlarmDataQuery;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 11.05.17.
|
||||
*/
|
||||
public interface AlarmService extends TbEntityService {
|
||||
public interface AlarmService extends EntityDaoService {
|
||||
|
||||
AlarmOperationResult createOrUpdateAlarm(Alarm alarm);
|
||||
|
||||
|
||||
@ -21,9 +21,9 @@ import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
public interface AssetProfileService extends TbEntityService {
|
||||
public interface AssetProfileService extends EntityDaoService {
|
||||
|
||||
AssetProfile findAssetProfileById(TenantId tenantId, AssetProfileId assetProfileId);
|
||||
|
||||
|
||||
@ -27,11 +27,11 @@ import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AssetService extends TbEntityService {
|
||||
public interface AssetService extends EntityDaoService {
|
||||
|
||||
AssetInfo findAssetInfoById(TenantId tenantId, AssetId assetId);
|
||||
|
||||
|
||||
@ -25,11 +25,10 @@ import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.TimePageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AuditLogService extends TbEntityService {
|
||||
public interface AuditLogService {
|
||||
|
||||
PageData<AuditLog> findAuditLogsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, List<ActionType> actionTypes, TimePageLink pageLink);
|
||||
|
||||
|
||||
@ -21,11 +21,11 @@ import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CustomerService extends TbEntityService {
|
||||
public interface CustomerService extends EntityDaoService {
|
||||
|
||||
Customer findCustomerById(TenantId tenantId, CustomerId customerId);
|
||||
|
||||
|
||||
@ -24,11 +24,11 @@ import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DashboardService extends TbEntityService {
|
||||
public interface DashboardService extends EntityDaoService {
|
||||
|
||||
Dashboard findDashboardById(TenantId tenantId, DashboardId dashboardId);
|
||||
|
||||
|
||||
@ -21,9 +21,9 @@ import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
public interface DeviceProfileService extends TbEntityService {
|
||||
public interface DeviceProfileService extends EntityDaoService {
|
||||
|
||||
DeviceProfile findDeviceProfileById(TenantId tenantId, DeviceProfileId deviceProfileId);
|
||||
|
||||
|
||||
@ -33,12 +33,12 @@ import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||
import org.thingsboard.server.dao.device.provision.ProvisionRequest;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface DeviceService extends TbEntityService {
|
||||
public interface DeviceService extends EntityDaoService {
|
||||
|
||||
DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId);
|
||||
|
||||
|
||||
@ -26,12 +26,12 @@ import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface EdgeService extends TbEntityService {
|
||||
public interface EdgeService extends EntityDaoService {
|
||||
|
||||
Edge findEdgeById(TenantId tenantId, EdgeId edgeId);
|
||||
|
||||
|
||||
@ -15,14 +15,17 @@
|
||||
*/
|
||||
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;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface TbEntityService {
|
||||
public interface EntityDaoService {
|
||||
|
||||
Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId);
|
||||
Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId);
|
||||
|
||||
EntityType getEntityType();
|
||||
|
||||
}
|
||||
@ -29,7 +29,7 @@ public interface EntityService {
|
||||
|
||||
Optional<String> fetchEntityName(TenantId tenantId, EntityId entityId);
|
||||
|
||||
CustomerId fetchEntityCustomerId(TenantId tenantId, EntityId entityId);
|
||||
Optional<CustomerId> fetchEntityCustomerId(TenantId tenantId, EntityId entityId);
|
||||
|
||||
long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query);
|
||||
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 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.dao.entity;
|
||||
|
||||
import org.apache.commons.text.CaseUtils;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
|
||||
@Service
|
||||
public class EntityServiceBeanFactory {
|
||||
|
||||
private static final String SERVICE_SUFFIX = "DaoService";
|
||||
|
||||
private final BeanFactory beanFactory;
|
||||
|
||||
public EntityServiceBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
public TbEntityService getServiceByEntityType(EntityType entityType) {
|
||||
String beanName = EntityType.RULE_NODE.equals(entityType) ? getBeanName(EntityType.RULE_CHAIN) : getBeanName(entityType);
|
||||
return beanFactory.getBean(beanName, TbEntityService.class);
|
||||
}
|
||||
|
||||
private String getBeanName(EntityType entityType) {
|
||||
return CaseUtils.toCamelCase(entityType.name(), true, '_') + SERVICE_SUFFIX;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 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.dao.entity;
|
||||
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
|
||||
public interface EntityServiceRegistry {
|
||||
|
||||
EntityDaoService getServiceByEntityType(EntityType entityType);
|
||||
|
||||
}
|
||||
@ -27,14 +27,14 @@ import org.thingsboard.server.common.data.id.EntityViewId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Victor Basanets on 8/27/2017.
|
||||
*/
|
||||
public interface EntityViewService extends TbEntityService {
|
||||
public interface EntityViewService extends EntityDaoService {
|
||||
|
||||
EntityView saveEntityView(EntityView entityView);
|
||||
|
||||
|
||||
@ -24,11 +24,10 @@ import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.TimePageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EventService extends TbEntityService {
|
||||
public interface EventService {
|
||||
|
||||
ListenableFuture<Void> saveAsync(Event event);
|
||||
|
||||
|
||||
@ -25,11 +25,11 @@ import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
|
||||
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public interface OtaPackageService extends TbEntityService {
|
||||
public interface OtaPackageService extends EntityDaoService {
|
||||
|
||||
OtaPackageInfo saveOtaPackageInfo(OtaPackageInfo otaPackageInfo, boolean isUrl);
|
||||
|
||||
|
||||
@ -20,11 +20,11 @@ import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.queue.Queue;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface QueueService extends TbEntityService {
|
||||
public interface QueueService extends EntityDaoService {
|
||||
|
||||
Queue saveQueue(Queue queue);
|
||||
|
||||
|
||||
@ -23,11 +23,12 @@ import org.thingsboard.server.common.data.id.TbResourceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ResourceService extends TbEntityService {
|
||||
public interface ResourceService extends EntityDaoService {
|
||||
|
||||
TbResource saveResource(TbResource resource);
|
||||
|
||||
TbResource getResource(TenantId tenantId, ResourceType resourceType, String resourceId);
|
||||
|
||||
@ -23,9 +23,10 @@ import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.rpc.Rpc;
|
||||
import org.thingsboard.server.common.data.rpc.RpcStatus;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
public interface RpcService extends EntityDaoService {
|
||||
|
||||
public interface RpcService extends TbEntityService {
|
||||
Rpc save(Rpc rpc);
|
||||
|
||||
void deleteRpc(TenantId tenantId, RpcId id);
|
||||
|
||||
@ -31,7 +31,7 @@ import org.thingsboard.server.common.data.rule.RuleChainMetaData;
|
||||
import org.thingsboard.server.common.data.rule.RuleChainType;
|
||||
import org.thingsboard.server.common.data.rule.RuleChainUpdateResult;
|
||||
import org.thingsboard.server.common.data.rule.RuleNode;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -39,7 +39,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by igor on 3/12/18.
|
||||
*/
|
||||
public interface RuleChainService extends TbEntityService {
|
||||
public interface RuleChainService extends EntityDaoService {
|
||||
|
||||
RuleChain saveRuleChain(RuleChain ruleChain);
|
||||
|
||||
|
||||
@ -21,9 +21,9 @@ import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.TenantProfileId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
public interface TenantProfileService extends TbEntityService {
|
||||
public interface TenantProfileService extends EntityDaoService {
|
||||
|
||||
TenantProfile findTenantProfileById(TenantId tenantId, TenantProfileId tenantProfileId);
|
||||
|
||||
|
||||
@ -22,11 +22,11 @@ import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.TenantProfileId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TenantService extends TbEntityService {
|
||||
public interface TenantService extends EntityDaoService {
|
||||
|
||||
Tenant findTenantById(TenantId tenantId);
|
||||
|
||||
|
||||
@ -19,9 +19,9 @@ import org.thingsboard.server.common.data.ApiUsageState;
|
||||
import org.thingsboard.server.common.data.id.ApiUsageStateId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
public interface ApiUsageStateService extends TbEntityService {
|
||||
public interface ApiUsageStateService extends EntityDaoService {
|
||||
|
||||
ApiUsageState createDefaultApiUsageState(TenantId id, EntityId entityId);
|
||||
|
||||
|
||||
@ -24,9 +24,9 @@ import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.security.UserCredentials;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
public interface UserService extends TbEntityService {
|
||||
public interface UserService extends EntityDaoService {
|
||||
|
||||
User findUserById(TenantId tenantId, UserId userId);
|
||||
|
||||
|
||||
@ -20,11 +20,11 @@ import org.thingsboard.server.common.data.id.WidgetTypeId;
|
||||
import org.thingsboard.server.common.data.widget.WidgetType;
|
||||
import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
|
||||
import org.thingsboard.server.common.data.widget.WidgetTypeInfo;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface WidgetTypeService extends TbEntityService {
|
||||
public interface WidgetTypeService extends EntityDaoService {
|
||||
|
||||
WidgetType findWidgetTypeById(TenantId tenantId, WidgetTypeId widgetTypeId);
|
||||
|
||||
|
||||
@ -20,11 +20,11 @@ import org.thingsboard.server.common.data.id.WidgetsBundleId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
||||
import org.thingsboard.server.dao.entity.TbEntityService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface WidgetsBundleService extends TbEntityService {
|
||||
public interface WidgetsBundleService extends EntityDaoService {
|
||||
|
||||
WidgetsBundle findWidgetsBundleById(TenantId tenantId, WidgetsBundleId widgetsBundleId);
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -115,7 +116,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
||||
if (alarm.getEndTs() == 0L) {
|
||||
alarm.setEndTs(alarm.getStartTs());
|
||||
}
|
||||
alarm.setCustomerId(entityService.fetchEntityCustomerId(alarm.getTenantId(), alarm.getOriginator()));
|
||||
alarm.setCustomerId(entityService.fetchEntityCustomerId(alarm.getTenantId(), alarm.getOriginator()).get());
|
||||
if (alarm.getId() == null) {
|
||||
Alarm existing = alarmDao.findLatestByOriginatorAndType(alarm.getTenantId(), alarm.getOriginator(), alarm.getType());
|
||||
if (existing == null || existing.getStatus().isCleared()) {
|
||||
@ -286,8 +287,8 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
||||
return Futures.transform(alarmDao.findAlarmByIdAsync(tenantId, alarmId.getId()),
|
||||
a -> {
|
||||
AlarmInfo alarmInfo = new AlarmInfo(a);
|
||||
Optional<String> originatorNameOpt = entityService.fetchEntityName(tenantId, alarmInfo.getOriginator());
|
||||
alarmInfo.setOriginatorName(originatorNameOpt.isEmpty() ? "N/A" : originatorNameOpt.get());
|
||||
alarmInfo.setOriginatorName(
|
||||
entityService.fetchEntityName(tenantId, alarmInfo.getOriginator()).orElse("N/A"));
|
||||
return alarmInfo;
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
@ -313,8 +314,8 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
||||
private ListenableFuture<PageData<AlarmInfo>> fetchAlarmsOriginators(TenantId tenantId, PageData<AlarmInfo> alarms) {
|
||||
List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(alarms.getData().size());
|
||||
for (AlarmInfo alarmInfo : alarms.getData()) {
|
||||
Optional<String> originatorNameOpt = entityService.fetchEntityName(tenantId, alarmInfo.getOriginator());
|
||||
alarmInfo.setOriginatorName(originatorNameOpt.isEmpty() ? "Deleted" : originatorNameOpt.get());
|
||||
alarmInfo.setOriginatorName(
|
||||
entityService.fetchEntityName(tenantId, alarmInfo.getOriginator()).orElse("Deleted"));
|
||||
alarmFutures.add(Futures.immediateFuture(alarmInfo));
|
||||
}
|
||||
return Futures.transform(Futures.successfulAsList(alarmFutures),
|
||||
@ -407,8 +408,13 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -268,10 +269,15 @@ public class AssetProfileServiceImpl extends AbstractCachedEntityService<AssetPr
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findAssetProfileById(tenantId, new AssetProfileId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ASSET_PROFILE;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, AssetProfile> tenantAssetProfilesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
|
||||
|
||||
@ -433,8 +433,13 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findAssetById(tenantId, new AssetId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ASSET;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,7 +36,6 @@ import org.thingsboard.server.common.data.audit.AuditLog;
|
||||
import org.thingsboard.server.common.data.id.AuditLogId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
@ -54,7 +53,6 @@ import org.thingsboard.server.dao.service.DataValidator;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -62,7 +60,7 @@ import static org.thingsboard.server.dao.service.Validator.validateEntityId;
|
||||
import static org.thingsboard.server.dao.service.Validator.validateId;
|
||||
|
||||
@Slf4j
|
||||
@Service("AuditLogDaoService")
|
||||
@Service
|
||||
@ConditionalOnProperty(prefix = "audit-log", value = "enabled", havingValue = "true")
|
||||
public class AuditLogServiceImpl implements AuditLogService {
|
||||
|
||||
@ -128,8 +126,7 @@ public class AuditLogServiceImpl implements AuditLogService {
|
||||
entityName = entity.getName();
|
||||
} else {
|
||||
try {
|
||||
Optional<String> entityNameOpt = entityService.fetchEntityName(tenantId, entityId);
|
||||
entityName = entityNameOpt.orElse(entityName);
|
||||
entityName = entityService.fetchEntityName(tenantId, entityId).orElse(entityName);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
@ -406,9 +403,4 @@ public class AuditLogServiceImpl implements AuditLogService {
|
||||
return Futures.allAsList(futures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,16 +23,14 @@ import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.audit.AuditLog;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.TimePageLink;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service("AuditLogDaoService")
|
||||
@Service
|
||||
@ConditionalOnProperty(prefix = "audit-log", value = "enabled", havingValue = "false")
|
||||
public class DummyAuditLogServiceImpl implements AuditLogService {
|
||||
|
||||
@ -61,9 +59,4 @@ public class DummyAuditLogServiceImpl implements AuditLogService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -182,8 +183,13 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -311,10 +312,15 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -290,10 +291,15 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findDeviceProfileById(tenantId, new DeviceProfileId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE_PROFILE;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, DeviceProfile> tenantDeviceProfilesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
|
||||
|
||||
@ -709,8 +709,13 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findDeviceById(tenantId, new DeviceId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DEVICE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -522,8 +522,13 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findEdgeById(tenantId, new EdgeId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.EDGE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
|
||||
private EntityQueryDao entityQueryDao;
|
||||
|
||||
@Autowired
|
||||
EntityServiceBeanFactory entityServiceBeanFactory;
|
||||
EntityServiceRegistry entityServiceRegistry;
|
||||
|
||||
@Override
|
||||
public long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query) {
|
||||
@ -77,8 +77,8 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
|
||||
@Override
|
||||
public Optional<String> fetchEntityName(TenantId tenantId, EntityId entityId) {
|
||||
log.trace("Executing fetchEntityName [{}]", entityId);
|
||||
TbEntityService tbEntityService = entityServiceBeanFactory.getServiceByEntityType(entityId.getEntityType());
|
||||
Optional<HasId<?>> hasIdOpt = tbEntityService.fetchEntity(tenantId, entityId);
|
||||
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityId.getEntityType());
|
||||
Optional<HasId<?>> hasIdOpt = entityDaoService.findEntity(tenantId, entityId);
|
||||
if (hasIdOpt.isPresent()) {
|
||||
HasId<?> hasId = hasIdOpt.get();
|
||||
if (hasId instanceof HasName) {
|
||||
@ -90,18 +90,22 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomerId fetchEntityCustomerId(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<CustomerId> fetchEntityCustomerId(TenantId tenantId, EntityId entityId) {
|
||||
log.trace("Executing fetchEntityCustomerId [{}]", entityId);
|
||||
TbEntityService tbEntityService = entityServiceBeanFactory.getServiceByEntityType(entityId.getEntityType());
|
||||
Optional<HasId<?>> hasIdOpt = tbEntityService.fetchEntity(tenantId, entityId);
|
||||
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityId.getEntityType());
|
||||
Optional<HasId<?>> hasIdOpt = entityDaoService.findEntity(tenantId, entityId);
|
||||
if (hasIdOpt.isPresent()) {
|
||||
HasId<?> hasId = hasIdOpt.get();
|
||||
if (hasId instanceof HasCustomerId) {
|
||||
HasCustomerId hasCustomerId = (HasCustomerId) hasId;
|
||||
return hasCustomerId.getCustomerId();
|
||||
CustomerId customerId = hasCustomerId.getCustomerId();
|
||||
if (customerId == null) {
|
||||
customerId = NULL_CUSTOMER_ID;
|
||||
}
|
||||
return Optional.of(customerId);
|
||||
}
|
||||
}
|
||||
return NULL_CUSTOMER_ID;
|
||||
return Optional.of(NULL_CUSTOMER_ID);
|
||||
}
|
||||
|
||||
private static void validateEntityCountQuery(EntityCountQuery query) {
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 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.dao.entity;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DefaultEntityServiceRegistry implements EntityServiceRegistry {
|
||||
|
||||
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() {
|
||||
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) {
|
||||
return entityDaoServicesMap.get(entityType);
|
||||
}
|
||||
|
||||
}
|
||||
@ -412,8 +412,13 @@ public class EntityViewServiceImpl extends AbstractCachedEntityService<EntityVie
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findEntityViewById(tenantId, new EntityViewId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.ENTITY_VIEW;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -31,19 +31,17 @@ import org.thingsboard.server.common.data.event.LifecycleEvent;
|
||||
import org.thingsboard.server.common.data.event.RuleChainDebugEvent;
|
||||
import org.thingsboard.server.common.data.event.RuleNodeDebugEvent;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.TimePageLink;
|
||||
import org.thingsboard.server.dao.service.DataValidator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service("EventDaoService")
|
||||
@Service
|
||||
@Slf4j
|
||||
public class BaseEventService implements EventService {
|
||||
|
||||
@ -151,9 +149,4 @@ public class BaseEventService implements EventService {
|
||||
return list == null ? null : list.stream().map(e -> e.toInfo(entityType)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -237,8 +238,13 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -123,10 +124,15 @@ public class BaseQueueService extends AbstractEntityService implements QueueServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findQueueById(tenantId, new QueueId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.QUEUE;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, Queue> tenantQueuesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
|
||||
|
||||
@ -375,9 +375,9 @@ public class BaseRelationService implements RelationService {
|
||||
private ListenableFuture<EntityRelationInfo> fetchRelationInfoAsync(TenantId tenantId, EntityRelation relation,
|
||||
Function<EntityRelation, EntityId> entityIdGetter,
|
||||
BiConsumer<EntityRelationInfo, String> entityNameSetter) {
|
||||
Optional<String> entityNameOpt = entityService.fetchEntityName(tenantId, entityIdGetter.apply(relation));
|
||||
EntityRelationInfo relationInfo = new EntityRelationInfo(relation);
|
||||
entityNameSetter.accept(relationInfo, entityNameOpt.orElse("N/A"));
|
||||
entityNameSetter.accept(relationInfo,
|
||||
entityService.fetchEntityName(tenantId, entityIdGetter.apply(relation)).orElse("N/A"));
|
||||
return Futures.immediateFuture(relationInfo);
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -137,10 +138,15 @@ public class BaseResourceService implements ResourceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -98,10 +99,15 @@ public class BaseRpcService implements RpcService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findById(tenantId, new RpcId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.RPC;
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, Rpc> tenantRpcRemover =
|
||||
new PaginatedRemover<>() {
|
||||
@Override
|
||||
|
||||
@ -761,13 +761,18 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
HasId<?> hasId = EntityType.RULE_NODE.equals(entityId.getEntityType()) ?
|
||||
findRuleNodeById(tenantId, new RuleNodeId(entityId.getId())) :
|
||||
findRuleChainById(tenantId, new RuleChainId(entityId.getId()));
|
||||
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;
|
||||
@ -208,10 +209,15 @@ public class TenantProfileServiceImpl extends AbstractCachedEntityService<Tenant
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -261,7 +262,13 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findTenantById(new TenantId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.TENANT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -164,7 +164,13 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -401,8 +402,13 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
return Optional.ofNullable(findUserById(tenantId, new UserId(entityId.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.USER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -327,12 +327,12 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend
|
||||
counter.clear();
|
||||
if (printTenantNames) {
|
||||
String name = tenantNamesCache.computeIfAbsent(tenantId, tId -> {
|
||||
String defaultName = "N/A";
|
||||
try {
|
||||
Optional<String> entityNameOpt = entityService.fetchEntityName(TenantId.SYS_TENANT_ID, tenantId);
|
||||
return entityNameOpt.orElse("N/A");
|
||||
return entityService.fetchEntityName(TenantId.SYS_TENANT_ID, tenantId).orElse(defaultName);
|
||||
} catch (Exception e) {
|
||||
log.error("[{}] Failed to get tenant name", tenantId, e);
|
||||
return "N/A";
|
||||
return defaultName;
|
||||
}
|
||||
});
|
||||
log.info("[{}][{}] Rate limited requests: {}", tenantId, name, rateLimitedRequests);
|
||||
|
||||
@ -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;
|
||||
@ -116,8 +117,13 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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;
|
||||
@ -155,10 +156,15 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> fetchEntity(TenantId tenantId, EntityId entityId) {
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
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>() {
|
||||
|
||||
|
||||
@ -16,31 +16,31 @@
|
||||
package org.thingsboard.server.dao.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.dao.entity.EntityServiceBeanFactory;
|
||||
import org.thingsboard.server.dao.rule.BaseRuleChainService;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
import org.thingsboard.server.dao.entity.EntityServiceRegistry;
|
||||
import org.thingsboard.server.dao.rule.RuleChainService;
|
||||
|
||||
@Slf4j
|
||||
public abstract class BaseEntityServiceBeanFactoryTest extends AbstractServiceTest {
|
||||
public abstract class BaseEntityServiceRegistryTest extends AbstractServiceTest {
|
||||
|
||||
@Autowired
|
||||
private EntityServiceBeanFactory entityServiceBeanFactory;
|
||||
private EntityServiceRegistry entityServiceRegistry;
|
||||
|
||||
@Test
|
||||
public void givenAllEntityTypes_whenGetServiceByEntityTypeCalled_thenNoExceptionsThrows() {
|
||||
public void givenAllEntityTypes_whenGetServiceByEntityTypeCalled_thenAllBeansExists() {
|
||||
for (EntityType entityType : EntityType.values()) {
|
||||
Assertions.assertThatCode(() -> entityServiceBeanFactory.getServiceByEntityType(entityType))
|
||||
.doesNotThrowAnyException();
|
||||
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityType);
|
||||
Assert.assertNotNull("entityDaoService bean is missed for type: " + entityType.name(), entityDaoService);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRuleNodeEntityType_whenGetServiceByEntityTypeCalled_thenReturnedRuleChainDaoService() {
|
||||
Assert.assertTrue(entityServiceBeanFactory.getServiceByEntityType(EntityType.RULE_NODE) instanceof BaseRuleChainService);
|
||||
public void givenRuleNodeEntityType_whenGetServiceByEntityTypeCalled_thenReturnedRuleChainService() {
|
||||
Assert.assertTrue(entityServiceRegistry.getServiceByEntityType(EntityType.RULE_NODE) instanceof RuleChainService);
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao.service.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.BaseEntityServiceBeanFactoryTest;
|
||||
import org.thingsboard.server.dao.service.BaseEntityServiceRegistryTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class EntityServiceBeanFactorySqlTest extends BaseEntityServiceBeanFactoryTest {
|
||||
public class EntityServiceRegistrySqlTest extends BaseEntityServiceRegistryTest {
|
||||
|
||||
}
|
||||
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>
|
||||
@ -1365,11 +1364,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