Improvements for deletion by tenantId
This commit is contained in:
parent
6ed6cc298c
commit
1b8e4800d0
@ -36,4 +36,6 @@ public interface DeviceCredentialsService {
|
|||||||
|
|
||||||
void deleteDeviceCredentials(TenantId tenantId, DeviceCredentials deviceCredentials);
|
void deleteDeviceCredentials(TenantId tenantId, DeviceCredentials deviceCredentials);
|
||||||
|
|
||||||
|
void deleteDeviceCredentialsByDeviceId(TenantId tenantId, DeviceId deviceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -204,7 +204,6 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteAsset(TenantId tenantId, AssetId assetId) {
|
public void deleteAsset(TenantId tenantId, AssetId assetId) {
|
||||||
log.trace("Executing deleteAsset [{}]", assetId);
|
|
||||||
validateId(assetId, INCORRECT_ASSET_ID + assetId);
|
validateId(assetId, INCORRECT_ASSET_ID + assetId);
|
||||||
if (entityViewService.existsByTenantIdAndEntityId(tenantId, assetId)) {
|
if (entityViewService.existsByTenantIdAndEntityId(tenantId, assetId)) {
|
||||||
throw new DataValidationException("Can't delete asset that has entity views!");
|
throw new DataValidationException("Can't delete asset that has entity views!");
|
||||||
@ -216,6 +215,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void deleteAsset(TenantId tenantId, Asset asset) {
|
private void deleteAsset(TenantId tenantId, Asset asset) {
|
||||||
|
log.trace("Executing deleteAsset [{}]", asset.getId());
|
||||||
relationService.deleteEntityRelations(tenantId, asset.getAssetProfileId());
|
relationService.deleteEntityRelations(tenantId, asset.getAssetProfileId());
|
||||||
|
|
||||||
assetDao.removeById(tenantId, asset.getUuidId());
|
assetDao.removeById(tenantId, asset.getUuidId());
|
||||||
@ -276,7 +276,6 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
|||||||
return assetDao.findAssetsByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(assetIds));
|
return assetDao.findAssetsByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(assetIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAssetsByTenantId(TenantId tenantId) {
|
public void deleteAssetsByTenantId(TenantId tenantId) {
|
||||||
log.trace("Executing deleteAssetsByTenantId, tenantId [{}]", tenantId);
|
log.trace("Executing deleteAssetsByTenantId, tenantId [{}]", tenantId);
|
||||||
@ -453,7 +452,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
|||||||
protected void removeEntity(TenantId tenantId, Asset asset) {
|
protected void removeEntity(TenantId tenantId, Asset asset) {
|
||||||
deleteAsset(tenantId, asset);
|
deleteAsset(tenantId, asset);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final PaginatedRemover<CustomerId, Asset> customerAssetsUnasigner = new PaginatedRemover<CustomerId, Asset>() {
|
private final PaginatedRemover<CustomerId, Asset> customerAssetsUnasigner = new PaginatedRemover<CustomerId, Asset>() {
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao.device;
|
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.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||||
import org.thingsboard.server.dao.Dao;
|
import org.thingsboard.server.dao.Dao;
|
||||||
@ -53,4 +54,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentials> {
|
|||||||
*/
|
*/
|
||||||
DeviceCredentials findByCredentialsId(TenantId tenantId, String credentialsId);
|
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));
|
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,7 +316,6 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void deleteDevice(final TenantId tenantId, final DeviceId deviceId) {
|
public void deleteDevice(final TenantId tenantId, final DeviceId deviceId) {
|
||||||
log.trace("Executing deleteDevice [{}]", deviceId);
|
|
||||||
validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
|
validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
|
||||||
if (entityViewService.existsByTenantIdAndEntityId(tenantId, deviceId)) {
|
if (entityViewService.existsByTenantIdAndEntityId(tenantId, deviceId)) {
|
||||||
throw new DataValidationException("Can't delete device that has entity views!");
|
throw new DataValidationException("Can't delete device that has entity views!");
|
||||||
@ -328,10 +327,8 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDevice(TenantId tenantId, Device device) {
|
private void deleteDevice(TenantId tenantId, Device device) {
|
||||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId());
|
log.trace("Executing deleteDevice [{}]", device.getId());
|
||||||
if (deviceCredentials != null) {
|
deviceCredentialsService.deleteDeviceCredentialsByDeviceId(tenantId, device.getId());
|
||||||
deviceCredentialsService.deleteDeviceCredentials(tenantId, deviceCredentials);
|
|
||||||
}
|
|
||||||
relationService.deleteEntityRelations(tenantId, device.getId());
|
relationService.deleteEntityRelations(tenantId, device.getId());
|
||||||
|
|
||||||
deviceDao.removeById(tenantId, device.getUuidId());
|
deviceDao.removeById(tenantId, device.getUuidId());
|
||||||
@ -422,7 +419,6 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
|||||||
return deviceDao.findDevicesByIdsAsync(toUUIDs(deviceIds));
|
return deviceDao.findDevicesByIdsAsync(toUUIDs(deviceIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDevicesByTenantId(TenantId tenantId) {
|
public void deleteDevicesByTenantId(TenantId tenantId) {
|
||||||
log.trace("Executing deleteDevicesByTenantId, tenantId [{}]", tenantId);
|
log.trace("Executing deleteDevicesByTenantId, tenantId [{}]", tenantId);
|
||||||
|
|||||||
@ -16,6 +16,9 @@
|
|||||||
package org.thingsboard.server.dao.sql.device;
|
package org.thingsboard.server.dao.sql.device;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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 org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -29,4 +32,8 @@ public interface DeviceCredentialsRepository extends JpaRepository<DeviceCredent
|
|||||||
|
|
||||||
DeviceCredentialsEntity findByCredentialsId(String credentialsId);
|
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.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
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.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||||
import org.thingsboard.server.dao.DaoUtil;
|
import org.thingsboard.server.dao.DaoUtil;
|
||||||
@ -67,4 +68,9 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt
|
|||||||
return DaoUtil.getData(deviceCredentialsRepository.findByCredentialsId(credentialsId));
|
return DaoUtil.getData(deviceCredentialsRepository.findByCredentialsId(credentialsId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceCredentials removeByDeviceId(TenantId tenantId, DeviceId deviceId) {
|
||||||
|
return DaoUtil.getData(deviceCredentialsRepository.deleteByDeviceId(deviceId.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user