fix_bug: Entity delete with delete relations
This commit is contained in:
parent
dea933d906
commit
34814e8d8a
@ -24,6 +24,7 @@ import com.google.common.util.concurrent.MoreExecutors;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.thingsboard.common.util.ThingsBoardThreadFactory;
|
import org.thingsboard.common.util.ThingsBoardThreadFactory;
|
||||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||||
@ -142,6 +143,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public AlarmOperationResult deleteAlarm(TenantId tenantId, AlarmId alarmId) {
|
public AlarmOperationResult deleteAlarm(TenantId tenantId, AlarmId alarmId) {
|
||||||
try {
|
try {
|
||||||
log.debug("Deleting Alarm Id: {}", alarmId);
|
log.debug("Deleting Alarm Id: {}", alarmId);
|
||||||
|
|||||||
@ -20,10 +20,9 @@ import com.google.common.util.concurrent.Futures;
|
|||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.util.Pair;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
import org.thingsboard.server.common.data.EntitySubtype;
|
import org.thingsboard.server.common.data.EntitySubtype;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
@ -150,6 +149,7 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteAsset(TenantId tenantId, AssetId assetId) {
|
public void deleteAsset(TenantId tenantId, AssetId assetId) {
|
||||||
log.trace("Executing deleteAsset [{}]", assetId);
|
log.trace("Executing deleteAsset [{}]", assetId);
|
||||||
validateId(assetId, INCORRECT_ASSET_ID + assetId);
|
validateId(assetId, INCORRECT_ASSET_ID + assetId);
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.thingsboard.server.common.data.Customer;
|
import org.thingsboard.server.common.data.Customer;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
@ -110,6 +111,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteCustomer(TenantId tenantId, CustomerId customerId) {
|
public void deleteCustomer(TenantId tenantId, CustomerId customerId) {
|
||||||
log.trace("Executing deleteCustomer [{}]", customerId);
|
log.trace("Executing deleteCustomer [{}]", customerId);
|
||||||
Validator.validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
|
Validator.validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.thingsboard.server.common.data.Customer;
|
import org.thingsboard.server.common.data.Customer;
|
||||||
import org.thingsboard.server.common.data.Dashboard;
|
import org.thingsboard.server.common.data.Dashboard;
|
||||||
import org.thingsboard.server.common.data.DashboardInfo;
|
import org.thingsboard.server.common.data.DashboardInfo;
|
||||||
@ -158,6 +159,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteDashboard(TenantId tenantId, DashboardId dashboardId) {
|
public void deleteDashboard(TenantId tenantId, DashboardId dashboardId) {
|
||||||
log.trace("Executing deleteDashboard [{}]", dashboardId);
|
log.trace("Executing deleteDashboard [{}]", dashboardId);
|
||||||
Validator.validateId(dashboardId, INCORRECT_DASHBOARD_ID + dashboardId);
|
Validator.validateId(dashboardId, INCORRECT_DASHBOARD_ID + dashboardId);
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import org.hibernate.exception.ConstraintViolationException;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
import org.thingsboard.server.common.data.Device;
|
import org.thingsboard.server.common.data.Device;
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
@ -36,7 +37,6 @@ import org.thingsboard.server.common.data.id.DeviceProfileId;
|
|||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
import org.thingsboard.server.common.data.page.PageLink;
|
||||||
import org.thingsboard.server.common.data.queue.Queue;
|
|
||||||
import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
|
import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
|
||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
import org.thingsboard.server.dao.queue.QueueService;
|
import org.thingsboard.server.dao.queue.QueueService;
|
||||||
@ -159,7 +159,8 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
|||||||
this.removeDeviceProfile(tenantId, deviceProfile);
|
this.removeDeviceProfile(tenantId, deviceProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeDeviceProfile(TenantId tenantId, DeviceProfile deviceProfile) {
|
@Transactional
|
||||||
|
void removeDeviceProfile(TenantId tenantId, DeviceProfile deviceProfile) {
|
||||||
DeviceProfileId deviceProfileId = deviceProfile.getId();
|
DeviceProfileId deviceProfileId = deviceProfile.getId();
|
||||||
try {
|
try {
|
||||||
deviceProfileDao.removeById(tenantId, deviceProfileId.getId());
|
deviceProfileDao.removeById(tenantId, deviceProfileId.getId());
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
import org.thingsboard.common.util.JacksonUtil;
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
import org.thingsboard.server.common.data.EntitySubtype;
|
import org.thingsboard.server.common.data.EntitySubtype;
|
||||||
@ -182,6 +183,7 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteEdge(TenantId tenantId, EdgeId edgeId) {
|
public void deleteEdge(TenantId tenantId, EdgeId edgeId) {
|
||||||
log.trace("Executing deleteEdge [{}]", edgeId);
|
log.trace("Executing deleteEdge [{}]", edgeId);
|
||||||
validateId(edgeId, INCORRECT_EDGE_ID + edgeId);
|
validateId(edgeId, INCORRECT_EDGE_ID + edgeId);
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import com.google.common.util.concurrent.MoreExecutors;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
import org.thingsboard.server.common.data.EntitySubtype;
|
import org.thingsboard.server.common.data.EntitySubtype;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
@ -294,6 +295,7 @@ public class EntityViewServiceImpl extends AbstractCachedEntityService<EntityVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteEntityView(TenantId tenantId, EntityViewId entityViewId) {
|
public void deleteEntityView(TenantId tenantId, EntityViewId entityViewId) {
|
||||||
log.trace("Executing deleteEntityView [{}]", entityViewId);
|
log.trace("Executing deleteEntityView [{}]", entityViewId);
|
||||||
validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId);
|
validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId);
|
||||||
|
|||||||
@ -748,6 +748,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteRuleNodes(TenantId tenantId, RuleChainId ruleChainId) {
|
public void deleteRuleNodes(TenantId tenantId, RuleChainId ruleChainId) {
|
||||||
List<EntityRelation> nodeRelations = getRuleChainToNodeRelations(tenantId, ruleChainId);
|
List<EntityRelation> nodeRelations = getRuleChainToNodeRelations(tenantId, ruleChainId);
|
||||||
for (EntityRelation relation : nodeRelations) {
|
for (EntityRelation relation : nodeRelations) {
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
import org.thingsboard.server.common.data.EntityInfo;
|
import org.thingsboard.server.common.data.EntityInfo;
|
||||||
@ -112,7 +111,8 @@ public class TenantProfileServiceImpl extends AbstractCachedEntityService<Tenant
|
|||||||
this.removeTenantProfile(tenantId, tenantProfileId, false);
|
this.removeTenantProfile(tenantId, tenantProfileId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeTenantProfile(TenantId tenantId, TenantProfileId tenantProfileId, boolean isDefault) {
|
@Transactional
|
||||||
|
void removeTenantProfile(TenantId tenantId, TenantProfileId tenantProfileId, boolean isDefault) {
|
||||||
try {
|
try {
|
||||||
tenantProfileDao.removeById(tenantId, tenantProfileId.getId());
|
tenantProfileDao.removeById(tenantId, tenantProfileId.getId());
|
||||||
} catch (Exception t) {
|
} catch (Exception t) {
|
||||||
|
|||||||
@ -171,6 +171,7 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteTenant(TenantId tenantId) {
|
public void deleteTenant(TenantId tenantId) {
|
||||||
log.trace("Executing deleteTenant [{}]", tenantId);
|
log.trace("Executing deleteTenant [{}]", tenantId);
|
||||||
Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.springframework.context.ApplicationEventPublisher;
|
|||||||
import org.springframework.security.authentication.DisabledException;
|
import org.springframework.security.authentication.DisabledException;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.thingsboard.common.util.JacksonUtil;
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
import org.thingsboard.server.common.data.User;
|
import org.thingsboard.server.common.data.User;
|
||||||
@ -201,6 +202,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteUser(TenantId tenantId, UserId userId) {
|
public void deleteUser(TenantId tenantId, UserId userId) {
|
||||||
log.trace("Executing deleteUser [{}]", userId);
|
log.trace("Executing deleteUser [{}]", userId);
|
||||||
validateId(userId, INCORRECT_USER_ID + userId);
|
validateId(userId, INCORRECT_USER_ID + userId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user