commit
a1d73faa26
@ -129,6 +129,8 @@ public interface AlarmService extends EntityDaoService {
|
||||
|
||||
void deleteEntityAlarmRelations(TenantId tenantId, EntityId entityId);
|
||||
|
||||
void deleteEntityAlarmRecordsByTenantId(TenantId tenantId);
|
||||
|
||||
long countAlarmsByQuery(TenantId tenantId, CustomerId customerId, AlarmCountQuery query);
|
||||
|
||||
PageData<EntitySubtype> findAlarmTypesByTenantId(TenantId tenantId, PageLink pageLink);
|
||||
|
||||
@ -36,4 +36,6 @@ public interface DeviceCredentialsService {
|
||||
|
||||
void deleteDeviceCredentials(TenantId tenantId, DeviceCredentials deviceCredentials);
|
||||
|
||||
void deleteDeviceCredentialsByDeviceId(TenantId tenantId, DeviceId deviceId);
|
||||
|
||||
}
|
||||
|
||||
@ -76,6 +76,8 @@ public interface EntityViewService extends EntityDaoService {
|
||||
|
||||
List<EntityView> findEntityViewsByTenantIdAndEntityId(TenantId tenantId, EntityId entityId);
|
||||
|
||||
boolean existsByTenantIdAndEntityId(TenantId tenantId, EntityId entityId);
|
||||
|
||||
void deleteEntityView(TenantId tenantId, EntityViewId entityViewId);
|
||||
|
||||
void deleteEntityViewsByTenantId(TenantId tenantId);
|
||||
|
||||
@ -86,6 +86,8 @@ public interface AlarmDao extends Dao<Alarm> {
|
||||
|
||||
void deleteEntityAlarmRecords(TenantId tenantId, EntityId entityId);
|
||||
|
||||
void deleteEntityAlarmRecordsByTenantId(TenantId tenantId);
|
||||
|
||||
AlarmApiCallResult createOrUpdateActiveAlarm(AlarmCreateOrUpdateActiveRequest request, boolean alarmCreationEnabled);
|
||||
|
||||
AlarmApiCallResult updateAlarm(AlarmUpdateRequest request);
|
||||
|
||||
@ -440,9 +440,16 @@ public class BaseAlarmService extends AbstractCachedEntityService<TenantId, Page
|
||||
|
||||
@Override
|
||||
public void deleteEntityAlarmRelations(TenantId tenantId, EntityId entityId) {
|
||||
log.trace("Executing deleteEntityAlarms [{}]", entityId);
|
||||
alarmDao.deleteEntityAlarmRecords(tenantId, entityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEntityAlarmRecordsByTenantId(TenantId tenantId) {
|
||||
log.trace("Executing deleteEntityAlarmRecordsByTenantId [{}]", tenantId);
|
||||
alarmDao.deleteEntityAlarmRecordsByTenantId(tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countAlarmsByQuery(TenantId tenantId, CustomerId customerId, AlarmCountQuery query) {
|
||||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
||||
|
||||
@ -26,7 +26,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.EntityView;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.asset.AssetInfo;
|
||||
@ -205,21 +204,25 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteAsset(TenantId tenantId, AssetId assetId) {
|
||||
log.trace("Executing deleteAsset [{}]", assetId);
|
||||
validateId(assetId, INCORRECT_ASSET_ID + assetId);
|
||||
deleteEntityRelations(tenantId, assetId);
|
||||
|
||||
Asset asset = assetDao.findById(tenantId, assetId.getId());
|
||||
List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityId(asset.getTenantId(), assetId);
|
||||
if (entityViews != null && !entityViews.isEmpty()) {
|
||||
if (entityViewService.existsByTenantIdAndEntityId(tenantId, assetId)) {
|
||||
throw new DataValidationException("Can't delete asset that has entity views!");
|
||||
}
|
||||
|
||||
Asset asset = assetDao.findById(tenantId, assetId.getId());
|
||||
alarmService.deleteEntityAlarmRelations(tenantId, assetId);
|
||||
deleteAsset(tenantId, asset);
|
||||
}
|
||||
|
||||
private void deleteAsset(TenantId tenantId, Asset asset) {
|
||||
log.trace("Executing deleteAsset [{}]", asset.getId());
|
||||
relationService.deleteEntityRelations(tenantId, asset.getAssetProfileId());
|
||||
|
||||
assetDao.removeById(tenantId, asset.getUuidId());
|
||||
|
||||
publishEvictEvent(new AssetCacheEvictEvent(asset.getTenantId(), asset.getName(), null));
|
||||
countService.publishCountEntityEvictEvent(tenantId, EntityType.ASSET);
|
||||
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(assetId).build());
|
||||
|
||||
assetDao.removeById(tenantId, assetId.getId());
|
||||
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(asset.getId()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -438,21 +441,20 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
||||
return assetDao.findAssetsByTenantIdAndEdgeIdAndType(tenantId.getId(), edgeId.getId(), type, pageLink);
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, Asset> tenantAssetsRemover =
|
||||
new PaginatedRemover<TenantId, Asset>() {
|
||||
private final PaginatedRemover<TenantId, Asset> tenantAssetsRemover = new PaginatedRemover<>() {
|
||||
|
||||
@Override
|
||||
protected PageData<Asset> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) {
|
||||
return assetDao.findAssetsByTenantId(id.getId(), pageLink);
|
||||
}
|
||||
@Override
|
||||
protected PageData<Asset> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) {
|
||||
return assetDao.findAssetsByTenantId(id.getId(), pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, Asset entity) {
|
||||
deleteAsset(tenantId, new AssetId(entity.getId().getId()));
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, Asset asset) {
|
||||
deleteAsset(tenantId, asset);
|
||||
}
|
||||
};
|
||||
|
||||
private PaginatedRemover<CustomerId, Asset> customerAssetsUnasigner = new PaginatedRemover<CustomerId, Asset>() {
|
||||
private final PaginatedRemover<CustomerId, Asset> customerAssetsUnasigner = new PaginatedRemover<CustomerId, Asset>() {
|
||||
|
||||
@Override
|
||||
protected PageData<Asset> findEntities(TenantId tenantId, CustomerId id, PageLink pageLink) {
|
||||
|
||||
@ -18,6 +18,8 @@ package org.thingsboard.server.dao.dashboard;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
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.Dao;
|
||||
import org.thingsboard.server.dao.ExportableEntityDao;
|
||||
import org.thingsboard.server.dao.TenantEntityDao;
|
||||
@ -40,4 +42,6 @@ public interface DashboardDao extends Dao<Dashboard>, TenantEntityDao, Exportabl
|
||||
|
||||
List<Dashboard> findByTenantIdAndTitle(UUID tenantId, String title);
|
||||
|
||||
PageData<DashboardId> findIdsByTenantId(TenantId tenantId, PageLink pageLink);
|
||||
|
||||
}
|
||||
|
||||
@ -364,19 +364,18 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
return dashboardDao.findByTenantIdAndTitle(tenantId.getId(), title);
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, DashboardInfo> tenantDashboardsRemover =
|
||||
new PaginatedRemover<TenantId, DashboardInfo>() {
|
||||
private final PaginatedRemover<TenantId, DashboardId> tenantDashboardsRemover = new PaginatedRemover<>() {
|
||||
|
||||
@Override
|
||||
protected PageData<DashboardInfo> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) {
|
||||
return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink);
|
||||
}
|
||||
@Override
|
||||
protected PageData<DashboardId> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) {
|
||||
return dashboardDao.findIdsByTenantId(id, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
|
||||
deleteDashboard(tenantId, new DashboardId(entity.getUuidId()));
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, DashboardId dashboardId) {
|
||||
deleteDashboard(tenantId, dashboardId);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao.device;
|
||||
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||
import org.thingsboard.server.dao.Dao;
|
||||
@ -53,4 +54,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentials> {
|
||||
*/
|
||||
DeviceCredentials findByCredentialsId(TenantId tenantId, String credentialsId);
|
||||
|
||||
DeviceCredentials removeByDeviceId(TenantId tenantId, DeviceId deviceId);
|
||||
|
||||
}
|
||||
|
||||
@ -400,4 +400,13 @@ public class DeviceCredentialsServiceImpl extends AbstractCachedEntityService<St
|
||||
publishEvictEvent(new DeviceCredentialsEvictEvent(deviceCredentials.getCredentialsId(), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeviceCredentialsByDeviceId(TenantId tenantId, DeviceId deviceId) {
|
||||
log.trace("Executing deleteDeviceCredentialsByDeviceId [{}]", deviceId);
|
||||
DeviceCredentials credentials = deviceCredentialsDao.removeByDeviceId(tenantId, deviceId);
|
||||
if (credentials != null) {
|
||||
publishEvictEvent(new DeviceCredentialsEvictEvent(credentials.getCredentialsId(), null));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -316,26 +316,27 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteDevice(final TenantId tenantId, final DeviceId deviceId) {
|
||||
log.trace("Executing deleteDevice [{}]", deviceId);
|
||||
validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
|
||||
|
||||
Device device = deviceDao.findById(tenantId, deviceId.getId());
|
||||
DeviceCacheEvictEvent deviceCacheEvictEvent = new DeviceCacheEvictEvent(device.getTenantId(), device.getId(), device.getName(), null);
|
||||
List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityId(device.getTenantId(), deviceId);
|
||||
if (entityViews != null && !entityViews.isEmpty()) {
|
||||
if (entityViewService.existsByTenantIdAndEntityId(tenantId, deviceId)) {
|
||||
throw new DataValidationException("Can't delete device that has entity views!");
|
||||
}
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, deviceId);
|
||||
if (deviceCredentials != null) {
|
||||
deviceCredentialsService.deleteDeviceCredentials(tenantId, deviceCredentials);
|
||||
}
|
||||
deleteEntityRelations(tenantId, deviceId);
|
||||
|
||||
deviceDao.removeById(tenantId, deviceId.getId());
|
||||
Device device = deviceDao.findById(tenantId, deviceId.getId());
|
||||
alarmService.deleteEntityAlarmRelations(tenantId, deviceId);
|
||||
deleteDevice(tenantId, device);
|
||||
}
|
||||
|
||||
private void deleteDevice(TenantId tenantId, Device device) {
|
||||
log.trace("Executing deleteDevice [{}]", device.getId());
|
||||
deviceCredentialsService.deleteDeviceCredentialsByDeviceId(tenantId, device.getId());
|
||||
relationService.deleteEntityRelations(tenantId, device.getId());
|
||||
|
||||
deviceDao.removeById(tenantId, device.getUuidId());
|
||||
|
||||
DeviceCacheEvictEvent deviceCacheEvictEvent = new DeviceCacheEvictEvent(device.getTenantId(), device.getId(), device.getName(), null);
|
||||
publishEvictEvent(deviceCacheEvictEvent);
|
||||
countService.publishCountEntityEvictEvent(tenantId, EntityType.DEVICE);
|
||||
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(deviceId).build());
|
||||
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(device.getId()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -650,21 +651,20 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
||||
deleteDevice(tenantId, (DeviceId) id);
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, Device> tenantDevicesRemover =
|
||||
new PaginatedRemover<>() {
|
||||
private final PaginatedRemover<TenantId, Device> tenantDevicesRemover = new PaginatedRemover<>() {
|
||||
|
||||
@Override
|
||||
protected PageData<Device> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) {
|
||||
return deviceDao.findDevicesByTenantId(id.getId(), pageLink);
|
||||
}
|
||||
@Override
|
||||
protected PageData<Device> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) {
|
||||
return deviceDao.findDevicesByTenantId(id.getId(), pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, Device entity) {
|
||||
deleteDevice(tenantId, new DeviceId(entity.getUuidId()));
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, Device device) {
|
||||
deleteDevice(tenantId, device);
|
||||
}
|
||||
};
|
||||
|
||||
private PaginatedRemover<CustomerId, Device> customerDeviceUnasigner = new PaginatedRemover<CustomerId, Device>() {
|
||||
private final PaginatedRemover<CustomerId, Device> customerDeviceUnasigner = new PaginatedRemover<CustomerId, Device>() {
|
||||
|
||||
@Override
|
||||
protected PageData<Device> findEntities(TenantId tenantId, CustomerId id, PageLink pageLink) {
|
||||
|
||||
@ -74,9 +74,7 @@ public abstract class AbstractEntityService {
|
||||
}
|
||||
|
||||
protected void deleteEntityRelations(TenantId tenantId, EntityId entityId) {
|
||||
log.trace("Executing deleteEntityRelations [{}]", entityId);
|
||||
relationService.deleteEntityRelations(tenantId, entityId);
|
||||
log.trace("Executing deleteEntityAlarms [{}]", entityId);
|
||||
alarmService.deleteEntityAlarmRelations(tenantId, entityId);
|
||||
}
|
||||
|
||||
|
||||
@ -148,6 +148,8 @@ public interface EntityViewDao extends Dao<EntityView>, ExportableEntityDao<Enti
|
||||
|
||||
List<EntityView> findEntityViewsByTenantIdAndEntityId(UUID tenantId, UUID entityId);
|
||||
|
||||
boolean existsByTenantIdAndEntityId(UUID tenantId, UUID entityId);
|
||||
|
||||
/**
|
||||
* Find tenants entity view types.
|
||||
*
|
||||
|
||||
@ -316,6 +316,11 @@ public class EntityViewServiceImpl extends AbstractCachedEntityService<EntityVie
|
||||
EntityViewCacheValue::getEntityViews, v -> new EntityViewCacheValue(null, v), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByTenantIdAndEntityId(TenantId tenantId, EntityId entityId) {
|
||||
return entityViewDao.existsByTenantIdAndEntityId(tenantId.getId(), entityId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteEntityView(TenantId tenantId, EntityViewId entityViewId) {
|
||||
|
||||
@ -15,12 +15,11 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao.service;
|
||||
|
||||
import org.thingsboard.server.common.data.id.IdBased;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
|
||||
public abstract class PaginatedRemover<I, D extends IdBased<?>> {
|
||||
public abstract class PaginatedRemover<I, D> {
|
||||
|
||||
private static final int DEFAULT_LIMIT = 100;
|
||||
|
||||
|
||||
@ -34,4 +34,8 @@ public interface EntityAlarmRepository extends JpaRepository<EntityAlarmEntity,
|
||||
@Modifying
|
||||
@Query("DELETE FROM EntityAlarmEntity e where e.entityId = :entityId")
|
||||
void deleteByEntityId(@Param("entityId") UUID entityId);
|
||||
|
||||
@Transactional
|
||||
void deleteByTenantId(UUID tenantId);
|
||||
|
||||
}
|
||||
|
||||
@ -310,10 +310,14 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
|
||||
|
||||
@Override
|
||||
public void deleteEntityAlarmRecords(TenantId tenantId, EntityId entityId) {
|
||||
log.trace("[{}] Try to delete entity alarm records using [{}]", tenantId, entityId);
|
||||
entityAlarmRepository.deleteByEntityId(entityId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEntityAlarmRecordsByTenantId(TenantId tenantId) {
|
||||
entityAlarmRepository.deleteByTenantId(tenantId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlarmApiCallResult createOrUpdateActiveAlarm(AlarmCreateOrUpdateActiveRequest request, boolean alarmCreationEnabled) {
|
||||
AlarmPropagationInfo ap = getSafePropagationInfo(request.getPropagation());
|
||||
|
||||
@ -40,4 +40,7 @@ public interface DashboardRepository extends JpaRepository<DashboardEntity, UUID
|
||||
@Query("SELECT externalId FROM DashboardEntity WHERE id = :id")
|
||||
UUID getExternalIdById(@Param("id") UUID id);
|
||||
|
||||
@Query("SELECT d.id FROM DashboardEntity d WHERE d.tenantId = :tenantId")
|
||||
Page<UUID> findIdsByTenantId(@Param("tenantId") UUID tenantId, Pageable pageable);
|
||||
|
||||
}
|
||||
|
||||
@ -80,6 +80,11 @@ public class JpaDashboardDao extends JpaAbstractDao<DashboardEntity, Dashboard>
|
||||
return DaoUtil.convertDataList(dashboardRepository.findByTenantIdAndTitle(tenantId, title));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<DashboardId> findIdsByTenantId(TenantId tenantId, PageLink pageLink) {
|
||||
return DaoUtil.pageToPageData(dashboardRepository.findIdsByTenantId(tenantId.getId(), DaoUtil.toPageable(pageLink)).map(DashboardId::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return EntityType.DASHBOARD;
|
||||
|
||||
@ -16,6 +16,9 @@
|
||||
package org.thingsboard.server.dao.sql.device;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -28,4 +31,9 @@ public interface DeviceCredentialsRepository extends JpaRepository<DeviceCredent
|
||||
DeviceCredentialsEntity findByDeviceId(UUID deviceId);
|
||||
|
||||
DeviceCredentialsEntity findByCredentialsId(String credentialsId);
|
||||
|
||||
@Transactional
|
||||
@Query(value = "DELETE FROM device_credentials WHERE device_id = :deviceId RETURNING *", nativeQuery = true)
|
||||
DeviceCredentialsEntity deleteByDeviceId(@Param("deviceId") UUID deviceId);
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||
import org.thingsboard.server.dao.DaoUtil;
|
||||
@ -66,4 +67,10 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt
|
||||
public DeviceCredentials findByCredentialsId(TenantId tenantId, String credentialsId) {
|
||||
return DaoUtil.getData(deviceCredentialsRepository.findByCredentialsId(credentialsId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceCredentials removeByDeviceId(TenantId tenantId, DeviceId deviceId) {
|
||||
return DaoUtil.getData(deviceCredentialsRepository.deleteByDeviceId(deviceId.getId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -118,6 +118,8 @@ public interface EntityViewRepository extends JpaRepository<EntityViewEntity, UU
|
||||
|
||||
List<EntityViewEntity> findAllByTenantIdAndEntityId(UUID tenantId, UUID entityId);
|
||||
|
||||
boolean existsByTenantIdAndEntityId(UUID tenantId, UUID entityId);
|
||||
|
||||
@Query("SELECT DISTINCT ev.type FROM EntityViewEntity ev WHERE ev.tenantId = :tenantId")
|
||||
List<String> findTenantEntityViewTypes(@Param("tenantId") UUID tenantId);
|
||||
|
||||
|
||||
@ -165,6 +165,11 @@ public class JpaEntityViewDao extends JpaAbstractDao<EntityViewEntity, EntityVie
|
||||
entityViewRepository.findAllByTenantIdAndEntityId(tenantId, entityId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByTenantIdAndEntityId(UUID tenantId, UUID entityId) {
|
||||
return entityViewRepository.existsByTenantIdAndEntityId(tenantId, entityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<List<EntitySubtype>> findTenantEntityViewTypesAsync(UUID tenantId) {
|
||||
return service.submit(() -> convertTenantEntityTypesToDto(tenantId, EntityType.ENTITY_VIEW, entityViewRepository.findTenantEntityViewTypes(tenantId)));
|
||||
|
||||
@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.security.UserCredentials;
|
||||
import org.thingsboard.server.dao.DaoUtil;
|
||||
import org.thingsboard.server.dao.model.sql.UserCredentialsEntity;
|
||||
@ -62,4 +63,10 @@ public class JpaUserCredentialsDao extends JpaAbstractDao<UserCredentialsEntity,
|
||||
public UserCredentials findByResetToken(TenantId tenantId, String resetToken) {
|
||||
return DaoUtil.getData(userCredentialsRepository.findByResetToken(resetToken));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByUserId(TenantId tenantId, UserId userId) {
|
||||
userCredentialsRepository.removeByUserId(userId.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.server.dao.sql.user;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.thingsboard.server.dao.model.sql.UserCredentialsEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -30,4 +31,8 @@ public interface UserCredentialsRepository extends JpaRepository<UserCredentials
|
||||
UserCredentialsEntity findByActivateToken(String activateToken);
|
||||
|
||||
UserCredentialsEntity findByResetToken(String resetToken);
|
||||
|
||||
@Transactional
|
||||
void removeByUserId(UUID userId);
|
||||
|
||||
}
|
||||
|
||||
@ -245,7 +245,8 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
|
||||
tenantDao.removeById(tenantId, tenantId.getId());
|
||||
publishEvictEvent(new TenantEvictEvent(tenantId, true));
|
||||
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(TenantId.SYS_TENANT_ID).entityId(tenantId).build());
|
||||
deleteEntityRelations(tenantId, tenantId);
|
||||
relationService.deleteEntityRelations(tenantId, tenantId);
|
||||
alarmService.deleteEntityAlarmRecordsByTenantId(tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.server.dao.user;
|
||||
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.security.UserCredentials;
|
||||
import org.thingsboard.server.dao.Dao;
|
||||
|
||||
@ -58,4 +59,6 @@ public interface UserCredentialsDao extends Dao<UserCredentials> {
|
||||
*/
|
||||
UserCredentials findByResetToken(TenantId tenantId, String resetToken);
|
||||
|
||||
void removeByUserId(TenantId tenantId, UserId userId);
|
||||
|
||||
}
|
||||
|
||||
@ -252,10 +252,10 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
|
||||
UserId userId = user.getId();
|
||||
log.trace("[{}] Executing deleteUser [{}]", tenantId, userId);
|
||||
validateId(userId, INCORRECT_USER_ID + userId);
|
||||
UserCredentials userCredentials = userCredentialsDao.findByUserId(tenantId, userId.getId());
|
||||
userCredentialsDao.removeById(tenantId, userCredentials.getUuidId());
|
||||
userCredentialsDao.removeByUserId(tenantId, userId);
|
||||
userAuthSettingsDao.removeByUserId(userId);
|
||||
deleteEntityRelations(tenantId, userId);
|
||||
|
||||
userDao.removeById(tenantId, userId.getId());
|
||||
eventPublisher.publishEvent(new UserCredentialsInvalidationEvent(userId));
|
||||
countService.publishCountEntityEvictEvent(tenantId, EntityType.USER);
|
||||
@ -446,8 +446,8 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, User entity) {
|
||||
deleteUser(tenantId, entity);
|
||||
protected void removeEntity(TenantId tenantId, User user) {
|
||||
deleteUser(tenantId, user);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user