|
|
|
@ -27,6 +27,7 @@ import org.springframework.cache.Cache; |
|
|
|
import org.springframework.cache.CacheManager; |
|
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
@ -57,6 +58,7 @@ import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
|
import org.thingsboard.server.common.data.relation.EntitySearchDirection; |
|
|
|
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|
|
|
import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
|
|
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|
|
|
import org.thingsboard.server.dao.customer.CustomerDao; |
|
|
|
import org.thingsboard.server.dao.device.provision.ProvisionFailedException; |
|
|
|
import org.thingsboard.server.dao.device.provision.ProvisionRequest; |
|
|
|
@ -67,6 +69,7 @@ import org.thingsboard.server.dao.event.EventService; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
|
import org.thingsboard.server.dao.service.PaginatedRemover; |
|
|
|
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
|
|
|
import org.thingsboard.server.dao.tenant.TenantDao; |
|
|
|
import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|
|
|
|
|
|
|
@ -120,6 +123,10 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
|
|
|
@Autowired |
|
|
|
private EventService eventService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Lazy |
|
|
|
private TbTenantProfileCache tenantProfileCache; |
|
|
|
|
|
|
|
@Override |
|
|
|
public DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId) { |
|
|
|
log.trace("Executing findDeviceInfoById [{}]", deviceId); |
|
|
|
@ -520,6 +527,15 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void validateCreate(TenantId tenantId, Device device) { |
|
|
|
DefaultTenantProfileConfiguration profileConfiguration = |
|
|
|
(DefaultTenantProfileConfiguration)tenantProfileCache.get(tenantId).getProfileData().getConfiguration(); |
|
|
|
long maxDevices = profileConfiguration.getMaxDevices(); |
|
|
|
if (maxDevices > 0) { |
|
|
|
long currentDevicesCount = deviceDao.countDevicesByTenantId(tenantId); |
|
|
|
if (maxDevices >= currentDevicesCount) { |
|
|
|
throw new DataValidationException("Can't create devices more then " + maxDevices); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|