refactoring: InterfaceSimple add TenantId and CustomerId
This commit is contained in:
parent
aecaca734f
commit
0c1edc8685
@ -143,9 +143,10 @@ public class CustomerController extends BaseController {
|
|||||||
@RequestMapping(value = "/customer", method = RequestMethod.POST)
|
@RequestMapping(value = "/customer", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Customer saveCustomer(@ApiParam(value = "A JSON value representing the customer.") @RequestBody Customer customer) throws ThingsboardException {
|
public Customer saveCustomer(@ApiParam(value = "A JSON value representing the customer.") @RequestBody Customer customer) throws ThingsboardException {
|
||||||
customer.setTenantId(getCurrentUser().getTenantId());
|
customer.setTenantId(getTenantId());
|
||||||
checkEntity(customer.getId(), customer, Resource.CUSTOMER);
|
CustomerId customerId = customer.getId();
|
||||||
return tbCustomerService.save(customer, getCurrentUser());
|
checkEntity(customerId, customer, Resource.CUSTOMER);
|
||||||
|
return tbCustomerService.save(getTenantId(), customerId, customer, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Delete Customer (deleteCustomer)",
|
@ApiOperation(value = "Delete Customer (deleteCustomer)",
|
||||||
@ -161,7 +162,7 @@ public class CustomerController extends BaseController {
|
|||||||
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
||||||
Customer customer = checkCustomerId(customerId, Operation.DELETE);
|
Customer customer = checkCustomerId(customerId, Operation.DELETE);
|
||||||
try {
|
try {
|
||||||
tbCustomerService.delete(customer, getCurrentUser());
|
tbCustomerService.delete(getTenantId(), customerId, customer, getCurrentUser());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,6 @@ import org.thingsboard.common.util.JacksonUtil;
|
|||||||
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;
|
||||||
import org.thingsboard.server.common.data.HasName;
|
|
||||||
import org.thingsboard.server.common.data.HomeDashboard;
|
import org.thingsboard.server.common.data.HomeDashboard;
|
||||||
import org.thingsboard.server.common.data.HomeDashboardInfo;
|
import org.thingsboard.server.common.data.HomeDashboardInfo;
|
||||||
import org.thingsboard.server.common.data.Tenant;
|
import org.thingsboard.server.common.data.Tenant;
|
||||||
@ -182,9 +181,9 @@ public class DashboardController extends BaseController {
|
|||||||
public Dashboard saveDashboard(
|
public Dashboard saveDashboard(
|
||||||
@ApiParam(value = "A JSON value representing the dashboard.")
|
@ApiParam(value = "A JSON value representing the dashboard.")
|
||||||
@RequestBody Dashboard dashboard) throws ThingsboardException {
|
@RequestBody Dashboard dashboard) throws ThingsboardException {
|
||||||
dashboard.setTenantId(getCurrentUser().getTenantId());
|
dashboard.setTenantId(getTenantId());
|
||||||
checkEntity(dashboard.getId(), dashboard, Resource.DASHBOARD);
|
checkEntity(dashboard.getId(), dashboard, Resource.DASHBOARD);
|
||||||
return tbDashboardService.save(dashboard, getCurrentUser());
|
return tbDashboardService.save(getTenantId(), null, dashboard, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Delete the Dashboard (deleteDashboard)",
|
@ApiOperation(value = "Delete the Dashboard (deleteDashboard)",
|
||||||
@ -198,7 +197,7 @@ public class DashboardController extends BaseController {
|
|||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.DELETE);
|
Dashboard dashboard = checkDashboardId(dashboardId, Operation.DELETE);
|
||||||
tbDashboardService.delete(dashboard, getCurrentUser());
|
tbDashboardService.delete(getTenantId(), null, dashboard, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Assign the Dashboard (assignDashboardToCustomer)",
|
@ApiOperation(value = "Assign the Dashboard (assignDashboardToCustomer)",
|
||||||
|
|||||||
@ -204,7 +204,7 @@ public class DeviceProfileController extends BaseController {
|
|||||||
|
|
||||||
checkEntity(deviceProfile.getId(), deviceProfile, Resource.DEVICE_PROFILE);
|
checkEntity(deviceProfile.getId(), deviceProfile, Resource.DEVICE_PROFILE);
|
||||||
|
|
||||||
return tbDeviceProfileService.save(deviceProfile, getCurrentUser());
|
return tbDeviceProfileService.save(getTenantId(), getCurrentUser().getCustomerId(), deviceProfile, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Delete device profile (deleteDeviceProfile)",
|
@ApiOperation(value = "Delete device profile (deleteDeviceProfile)",
|
||||||
@ -220,7 +220,7 @@ public class DeviceProfileController extends BaseController {
|
|||||||
checkParameter(DEVICE_PROFILE_ID, strDeviceProfileId);
|
checkParameter(DEVICE_PROFILE_ID, strDeviceProfileId);
|
||||||
DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(strDeviceProfileId));
|
DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(strDeviceProfileId));
|
||||||
DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE);
|
DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE);
|
||||||
tbDeviceProfileService.delete(deviceProfile, getCurrentUser());
|
tbDeviceProfileService.delete(getTenantId(), getCurrentUser().getCustomerId(), deviceProfile, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Make Device Profile Default (setDefaultDeviceProfile)",
|
@ApiOperation(value = "Make Device Profile Default (setDefaultDeviceProfile)",
|
||||||
@ -236,7 +236,7 @@ public class DeviceProfileController extends BaseController {
|
|||||||
DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(strDeviceProfileId));
|
DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(strDeviceProfileId));
|
||||||
DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.WRITE);
|
DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.WRITE);
|
||||||
DeviceProfile previousDefaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(getTenantId());
|
DeviceProfile previousDefaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(getTenantId());
|
||||||
return tbDeviceProfileService.setDefaultDeviceProfile(deviceProfile, previousDefaultDeviceProfile, getCurrentUser());
|
return tbDeviceProfileService.setDefaultDeviceProfile(null, deviceProfile, previousDefaultDeviceProfile, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Get Device Profiles (getDeviceProfiles)",
|
@ApiOperation(value = "Get Device Profiles (getDeviceProfiles)",
|
||||||
|
|||||||
@ -16,12 +16,14 @@
|
|||||||
package org.thingsboard.server.service.entitiy;
|
package org.thingsboard.server.service.entitiy;
|
||||||
|
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
|
|
||||||
public interface SimpleTbEntityService<T> {
|
public interface SimpleTbEntityService<T> {
|
||||||
|
|
||||||
T save(T entity, SecurityUser user) throws ThingsboardException;
|
T save(TenantId tenantId, CustomerId customerId, T entity, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
void delete (T entity, SecurityUser user) throws ThingsboardException;
|
void delete (TenantId tenantId, CustomerId customerId, T entity, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,12 +40,11 @@ public class DefaultTbCustomerService extends AbstractTbEntityService implements
|
|||||||
private final TbClusterService tbClusterService;
|
private final TbClusterService tbClusterService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Customer save(Customer customer, SecurityUser user) throws ThingsboardException {
|
public Customer save(TenantId tenantId, CustomerId customerId, Customer customer, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
|
ActionType actionType = customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
|
||||||
TenantId tenantId = customer.getTenantId();
|
|
||||||
try {
|
try {
|
||||||
Customer savedCustomer = checkNotNull(customerService.saveCustomer(customer));
|
Customer savedCustomer = checkNotNull(customerService.saveCustomer(customer));
|
||||||
notificationEntityService.notifyCreateOrUpdateEntity(tenantId, savedCustomer.getId(), savedCustomer, savedCustomer.getId(), actionType, user);
|
notificationEntityService.notifyCreateOrUpdateEntity(tenantId, savedCustomer.getId(), savedCustomer, customerId, actionType, user);
|
||||||
return savedCustomer;
|
return savedCustomer;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.CUSTOMER), customer, null, actionType, user, e);
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.CUSTOMER), customer, null, actionType, user, e);
|
||||||
@ -55,18 +54,16 @@ public class DefaultTbCustomerService extends AbstractTbEntityService implements
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Customer customer, SecurityUser user) throws ThingsboardException {
|
public void delete(TenantId tenantId, CustomerId customerId, Customer customer, SecurityUser user) throws ThingsboardException {
|
||||||
TenantId tenantId = customer.getTenantId();
|
|
||||||
CustomerId customerId = customer.getId();
|
|
||||||
try {
|
try {
|
||||||
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, customerId);
|
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, customer.getId());
|
||||||
customerService.deleteCustomer(tenantId, customerId);
|
customerService.deleteCustomer(tenantId, customerId);
|
||||||
notificationEntityService.notifyDeleteEntity(tenantId, customerId, customer, customerId,
|
notificationEntityService.notifyDeleteEntity(tenantId, customer.getId(), customer, customerId,
|
||||||
ActionType.DELETED, relatedEdgeIds, user, customerId.toString());
|
ActionType.DELETED, relatedEdgeIds, user, customerId.toString());
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(tenantId, customerId, ComponentLifecycleEvent.DELETED);
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, customer.getId(), ComponentLifecycleEvent.DELETED);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.CUSTOMER), null, null,
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.CUSTOMER), null, null,
|
||||||
ActionType.DELETED, user, e, customerId.toString());
|
ActionType.DELETED, user, e, customer.getId().toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,31 +43,29 @@ import java.util.Set;
|
|||||||
public class DefaultTbDashboardService extends AbstractTbEntityService implements TbDashboardService {
|
public class DefaultTbDashboardService extends AbstractTbEntityService implements TbDashboardService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dashboard save(Dashboard dashboard, SecurityUser user) throws ThingsboardException {
|
public Dashboard save(TenantId tenantId, CustomerId customerId, Dashboard dashboard, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
|
ActionType actionType = dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
|
||||||
TenantId tenantId = dashboard.getTenantId();
|
|
||||||
try {
|
try {
|
||||||
Dashboard savedDashboard = checkNotNull(dashboardService.saveDashboard(dashboard));
|
Dashboard savedDashboard = checkNotNull(dashboardService.saveDashboard(dashboard));
|
||||||
notificationEntityService.notifyCreateOrUpdateEntity(tenantId, savedDashboard.getId(), savedDashboard,
|
notificationEntityService.notifyCreateOrUpdateEntity(tenantId, savedDashboard.getId(), savedDashboard,
|
||||||
null, actionType, user);
|
customerId, actionType, user);
|
||||||
return savedDashboard;
|
return savedDashboard;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), dashboard, null, actionType, user, e);
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), dashboard, customerId, actionType, user, e);
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Dashboard dashboard, SecurityUser user) throws ThingsboardException {
|
public void delete(TenantId tenantId, CustomerId customerId, Dashboard dashboard, SecurityUser user) throws ThingsboardException {
|
||||||
TenantId tenantId = dashboard.getTenantId();
|
|
||||||
DashboardId dashboardId = dashboard.getId();
|
DashboardId dashboardId = dashboard.getId();
|
||||||
try {
|
try {
|
||||||
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, dashboardId);
|
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, dashboardId);
|
||||||
dashboardService.deleteDashboard(tenantId, dashboardId);
|
dashboardService.deleteDashboard(tenantId, dashboardId);
|
||||||
notificationEntityService.notifyDeleteEntity(tenantId, dashboardId, dashboard, user.getCustomerId(),
|
notificationEntityService.notifyDeleteEntity(tenantId, dashboardId, dashboard, customerId,
|
||||||
ActionType.DELETED, relatedEdgeIds, user, dashboardId.toString());
|
ActionType.DELETED, relatedEdgeIds, user, dashboardId.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, customerId,
|
||||||
ActionType.DELETED, user, e, dashboardId.toString());
|
ActionType.DELETED, user, e, dashboardId.toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,8 @@ import org.thingsboard.server.common.data.DeviceProfile;
|
|||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.audit.ActionType;
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
|
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.plugin.ComponentLifecycleEvent;
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
@ -36,9 +38,8 @@ import java.util.Objects;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class DefaultTbDeviceProfileService extends AbstractTbEntityService implements TbDeviceProfileService {
|
public class DefaultTbDeviceProfileService extends AbstractTbEntityService implements TbDeviceProfileService {
|
||||||
@Override
|
@Override
|
||||||
public DeviceProfile save(DeviceProfile deviceProfile, SecurityUser user) throws ThingsboardException {
|
public DeviceProfile save(TenantId tenantId, CustomerId customerId, DeviceProfile deviceProfile, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = deviceProfile.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
|
ActionType actionType = deviceProfile.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
|
||||||
TenantId tenantId = user.getTenantId();
|
|
||||||
try {
|
try {
|
||||||
boolean isFirmwareChanged = false;
|
boolean isFirmwareChanged = false;
|
||||||
boolean isSoftwareChanged = false;
|
boolean isSoftwareChanged = false;
|
||||||
@ -55,12 +56,12 @@ public class DefaultTbDeviceProfileService extends AbstractTbEntityService imple
|
|||||||
DeviceProfile savedDeviceProfile = checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile));
|
DeviceProfile savedDeviceProfile = checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile));
|
||||||
|
|
||||||
tbClusterService.onDeviceProfileChange(savedDeviceProfile, null);
|
tbClusterService.onDeviceProfileChange(savedDeviceProfile, null);
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(deviceProfile.getTenantId(), savedDeviceProfile.getId(),
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, savedDeviceProfile.getId(),
|
||||||
actionType.equals(ActionType.ADDED) ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
actionType.equals(ActionType.ADDED) ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||||
|
|
||||||
otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged);
|
otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged);
|
||||||
|
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(user.getTenantId(), user.getCustomerId(), savedDeviceProfile.getId(), savedDeviceProfile, user, actionType, null);
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, customerId, savedDeviceProfile.getId(), savedDeviceProfile, user, actionType, null);
|
||||||
return savedDeviceProfile;
|
return savedDeviceProfile;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DEVICE_PROFILE), deviceProfile, null,
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DEVICE_PROFILE), deviceProfile, null,
|
||||||
@ -70,39 +71,39 @@ public class DefaultTbDeviceProfileService extends AbstractTbEntityService imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(DeviceProfile deviceProfile, SecurityUser user) throws ThingsboardException {
|
public void delete(TenantId tenantId, CustomerId customerId, DeviceProfile deviceProfile, SecurityUser user) throws ThingsboardException {
|
||||||
TenantId tenantId = user.getTenantId();
|
DeviceProfileId deviceProfileId = deviceProfile.getId();
|
||||||
try {
|
try {
|
||||||
deviceProfileService.deleteDeviceProfile(tenantId, deviceProfile.getId());
|
deviceProfileService.deleteDeviceProfile(tenantId, deviceProfileId);
|
||||||
|
|
||||||
tbClusterService.onDeviceProfileDelete(deviceProfile, null);
|
tbClusterService.onDeviceProfileDelete(deviceProfile, null);
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED);
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, deviceProfileId, ComponentLifecycleEvent.DELETED);
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(user.getTenantId(), user.getCustomerId(), deviceProfile.getId(), deviceProfile, user, ActionType.DELETED, null, deviceProfile.getId().toString());
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, customerId, deviceProfileId, deviceProfile, user, ActionType.DELETED, null, deviceProfileId.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(user.getTenantId(), user.getCustomerId(), emptyId(EntityType.DEVICE_PROFILE), null, user, ActionType.DELETED, e, deviceProfile.getId().toString());
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, customerId, emptyId(EntityType.DEVICE_PROFILE), null, user, ActionType.DELETED, e, deviceProfileId.toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeviceProfile setDefaultDeviceProfile(DeviceProfile deviceProfile, DeviceProfile previousDefaultDeviceProfile, SecurityUser user) throws ThingsboardException {
|
public DeviceProfile setDefaultDeviceProfile(CustomerId customerId, DeviceProfile deviceProfile, DeviceProfile previousDefaultDeviceProfile, SecurityUser user) throws ThingsboardException {
|
||||||
TenantId tenantId = user.getTenantId();
|
TenantId tenantId = deviceProfile.getTenantId();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (deviceProfileService.setDefaultDeviceProfile(user.getTenantId(), deviceProfile.getId())) {
|
if (deviceProfileService.setDefaultDeviceProfile(tenantId, deviceProfile.getId())) {
|
||||||
if (previousDefaultDeviceProfile != null) {
|
if (previousDefaultDeviceProfile != null) {
|
||||||
previousDefaultDeviceProfile = deviceProfileService.findDeviceProfileById(user.getTenantId(), previousDefaultDeviceProfile.getId());
|
previousDefaultDeviceProfile = deviceProfileService.findDeviceProfileById(tenantId, previousDefaultDeviceProfile.getId());
|
||||||
notificationEntityService.notifyEntity(tenantId, previousDefaultDeviceProfile.getId(), previousDefaultDeviceProfile, null,
|
notificationEntityService.notifyEntity(tenantId, previousDefaultDeviceProfile.getId(), previousDefaultDeviceProfile, customerId,
|
||||||
ActionType.UPDATED, user, null);
|
ActionType.UPDATED, user, null);
|
||||||
}
|
}
|
||||||
deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, deviceProfile.getId());
|
deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, deviceProfile.getId());
|
||||||
|
|
||||||
notificationEntityService.notifyEntity(tenantId, deviceProfile.getId(), deviceProfile, null,
|
notificationEntityService.notifyEntity(tenantId, deviceProfile.getId(), deviceProfile, customerId,
|
||||||
ActionType.UPDATED, user, null);
|
ActionType.UPDATED, user, null);
|
||||||
}
|
}
|
||||||
return deviceProfile;
|
return deviceProfile;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DEVICE_PROFILE), null, null,
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DEVICE_PROFILE), null, customerId,
|
||||||
ActionType.UPDATED, user, e, deviceProfile.getId().toString());
|
ActionType.UPDATED, user, e, deviceProfile.getId().toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,10 +17,11 @@ package org.thingsboard.server.service.entitiy.deviceProfile;
|
|||||||
|
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
|
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
|
|
||||||
public interface TbDeviceProfileService extends SimpleTbEntityService<DeviceProfile> {
|
public interface TbDeviceProfileService extends SimpleTbEntityService<DeviceProfile> {
|
||||||
|
|
||||||
DeviceProfile setDefaultDeviceProfile(DeviceProfile deviceProfile, DeviceProfile previousDefaultDeviceProfile, SecurityUser user) throws ThingsboardException;
|
DeviceProfile setDefaultDeviceProfile(CustomerId customerId, DeviceProfile deviceProfile, DeviceProfile previousDefaultDeviceProfile, SecurityUser user) throws ThingsboardException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,11 +35,12 @@ import org.thingsboard.server.service.security.model.SecurityUser;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class DefaultTbEntityRelationService extends AbstractTbEntityService implements TbEntityRelationService {
|
public class DefaultTbEntityRelationService extends AbstractTbEntityService implements TbEntityRelationService {
|
||||||
@Override
|
@Override
|
||||||
public void save(TenantId tenantId, CustomerId customerId, EntityRelation relation, SecurityUser user) throws ThingsboardException {
|
public EntityRelation save(TenantId tenantId, CustomerId customerId, EntityRelation relation, SecurityUser user) throws ThingsboardException {
|
||||||
try {
|
try {
|
||||||
relationService.saveRelation(tenantId, relation);
|
relationService.saveRelation(tenantId, relation);
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDeleteRelation (tenantId, customerId,
|
notificationEntityService.notifyCreateOrUpdateOrDeleteRelation (tenantId, customerId,
|
||||||
relation, user, ActionType.RELATION_ADD_OR_UPDATE, null, relation);
|
relation, user, ActionType.RELATION_ADD_OR_UPDATE, null, relation);
|
||||||
|
return relation;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDeleteRelation (tenantId, customerId,
|
notificationEntityService.notifyCreateOrUpdateOrDeleteRelation (tenantId, customerId,
|
||||||
relation, user, ActionType.RELATION_ADD_OR_UPDATE, e, relation);
|
relation, user, ActionType.RELATION_ADD_OR_UPDATE, e, relation);
|
||||||
|
|||||||
@ -20,13 +20,10 @@ import org.thingsboard.server.common.data.id.CustomerId;
|
|||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||||
|
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
|
|
||||||
public interface TbEntityRelationService {
|
public interface TbEntityRelationService extends SimpleTbEntityService<EntityRelation> {
|
||||||
|
|
||||||
void save(TenantId tenantId, CustomerId customerId, EntityRelation entity, SecurityUser user) throws ThingsboardException;
|
|
||||||
|
|
||||||
void delete(TenantId tenantId, CustomerId customerId, EntityRelation entity, SecurityUser user) throws ThingsboardException;
|
|
||||||
|
|
||||||
void deleteRelations (TenantId tenantId, CustomerId customerId, EntityId entityId, SecurityUser user, Exception e) throws ThingsboardException;
|
void deleteRelations (TenantId tenantId, CustomerId customerId, EntityId entityId, SecurityUser user, Exception e) throws ThingsboardException;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user