|
|
@ -36,6 +36,7 @@ import org.springframework.cache.CacheManager; |
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
import org.thingsboard.server.common.data.DashboardInfo; |
|
|
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; |
|
|
import org.thingsboard.server.common.data.DeviceProfileInfo; |
|
|
import org.thingsboard.server.common.data.DeviceProfileInfo; |
|
|
@ -61,9 +62,12 @@ 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.rule.RuleChain; |
|
|
|
|
|
import org.thingsboard.server.dao.dashboard.DashboardService; |
|
|
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|
|
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.firmware.FirmwareService; |
|
|
import org.thingsboard.server.dao.firmware.FirmwareService; |
|
|
|
|
|
import org.thingsboard.server.dao.rule.RuleChainService; |
|
|
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; |
|
|
@ -117,6 +121,12 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
|
|
@Autowired |
|
|
@Autowired |
|
|
private FirmwareService firmwareService; |
|
|
private FirmwareService firmwareService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private RuleChainService ruleChainService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DashboardService dashboardService; |
|
|
|
|
|
|
|
|
private final Lock findOrCreateLock = new ReentrantLock(); |
|
|
private final Lock findOrCreateLock = new ReentrantLock(); |
|
|
|
|
|
|
|
|
@Cacheable(cacheNames = DEVICE_PROFILE_CACHE, key = "{#deviceProfileId.id}") |
|
|
@Cacheable(cacheNames = DEVICE_PROFILE_CACHE, key = "{#deviceProfileId.id}") |
|
|
@ -336,7 +346,7 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private DataValidator<DeviceProfile> deviceProfileValidator = |
|
|
private DataValidator<DeviceProfile> deviceProfileValidator = |
|
|
new DataValidator<DeviceProfile>() { |
|
|
new DataValidator<>() { |
|
|
@Override |
|
|
@Override |
|
|
protected void validateDataImpl(TenantId tenantId, DeviceProfile deviceProfile) { |
|
|
protected void validateDataImpl(TenantId tenantId, DeviceProfile deviceProfile) { |
|
|
if (StringUtils.isEmpty(deviceProfile.getName())) { |
|
|
if (StringUtils.isEmpty(deviceProfile.getName())) { |
|
|
@ -402,6 +412,20 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (deviceProfile.getDefaultRuleChainId() != null) { |
|
|
|
|
|
RuleChain ruleChain = ruleChainService.findRuleChainById(tenantId, deviceProfile.getDefaultRuleChainId()); |
|
|
|
|
|
if (ruleChain == null) { |
|
|
|
|
|
throw new DataValidationException("Can't assign non-existent rule chain!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (deviceProfile.getDefaultDashboardId() != null) { |
|
|
|
|
|
DashboardInfo dashboard = dashboardService.findDashboardInfoById(tenantId, deviceProfile.getDefaultDashboardId()); |
|
|
|
|
|
if (dashboard == null) { |
|
|
|
|
|
throw new DataValidationException("Can't assign non-existent dashboard!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (deviceProfile.getFirmwareId() != null) { |
|
|
if (deviceProfile.getFirmwareId() != null) { |
|
|
Firmware firmware = firmwareService.findFirmwareById(tenantId, deviceProfile.getFirmwareId()); |
|
|
Firmware firmware = firmwareService.findFirmwareById(tenantId, deviceProfile.getFirmwareId()); |
|
|
if (firmware == null) { |
|
|
if (firmware == null) { |
|
|
|