|
|
@ -37,8 +37,10 @@ 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.service.DataValidator; |
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
import org.thingsboard.server.dao.service.PaginatedRemover; |
|
|
import org.thingsboard.server.dao.service.PaginatedRemover; |
|
|
import org.thingsboard.server.dao.service.Validator; |
|
|
import org.thingsboard.server.dao.service.Validator; |
|
|
@ -71,6 +73,9 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device |
|
|
@Autowired |
|
|
@Autowired |
|
|
private DataValidator<DeviceProfile> deviceProfileValidator; |
|
|
private DataValidator<DeviceProfile> deviceProfileValidator; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private QueueService queueService; |
|
|
|
|
|
|
|
|
private final Lock findOrCreateLock = new ReentrantLock(); |
|
|
private final Lock findOrCreateLock = new ReentrantLock(); |
|
|
|
|
|
|
|
|
@TransactionalEventListener(classes = DeviceProfileEvictEvent.class) |
|
|
@TransactionalEventListener(classes = DeviceProfileEvictEvent.class) |
|
|
@ -119,6 +124,12 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device |
|
|
DeviceProfile oldDeviceProfile = deviceProfileValidator.validate(deviceProfile, DeviceProfile::getTenantId); |
|
|
DeviceProfile oldDeviceProfile = deviceProfileValidator.validate(deviceProfile, DeviceProfile::getTenantId); |
|
|
DeviceProfile savedDeviceProfile; |
|
|
DeviceProfile savedDeviceProfile; |
|
|
try { |
|
|
try { |
|
|
|
|
|
if (deviceProfile.getDefaultQueueId() == null && StringUtils.isNotEmpty(deviceProfile.getDefaultQueueName())) { |
|
|
|
|
|
Queue existing = queueService.findQueueByTenantIdAndName(deviceProfile.getTenantId(), deviceProfile.getDefaultQueueName()); |
|
|
|
|
|
if (existing != null) { |
|
|
|
|
|
deviceProfile.setDefaultQueueId(existing.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
savedDeviceProfile = deviceProfileDao.saveAndFlush(deviceProfile.getTenantId(), deviceProfile); |
|
|
savedDeviceProfile = deviceProfileDao.saveAndFlush(deviceProfile.getTenantId(), deviceProfile); |
|
|
publishEvictEvent(new DeviceProfileEvictEvent(savedDeviceProfile.getTenantId(), savedDeviceProfile.getName(), |
|
|
publishEvictEvent(new DeviceProfileEvictEvent(savedDeviceProfile.getTenantId(), savedDeviceProfile.getName(), |
|
|
oldDeviceProfile != null ? oldDeviceProfile.getName() : null, savedDeviceProfile.getId(), savedDeviceProfile.isDefault())); |
|
|
oldDeviceProfile != null ? oldDeviceProfile.getName() : null, savedDeviceProfile.getId(), savedDeviceProfile.isDefault())); |
|
|
|