|
|
|
@ -314,14 +314,20 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
|
|
|
public Device assignDeviceToCustomer(TenantId tenantId, DeviceId deviceId, CustomerId customerId) { |
|
|
|
Device device = findDeviceById(tenantId, deviceId); |
|
|
|
device.setCustomerId(customerId); |
|
|
|
return saveDevice(device); |
|
|
|
Device savedDevice = saveDevice(device); |
|
|
|
removeDeviceFromCacheByName(tenantId, device.getName()); |
|
|
|
removeDeviceFromCacheById(tenantId, device.getId()); |
|
|
|
return savedDevice; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Device unassignDeviceFromCustomer(TenantId tenantId, DeviceId deviceId) { |
|
|
|
Device device = findDeviceById(tenantId, deviceId); |
|
|
|
device.setCustomerId(null); |
|
|
|
return saveDevice(device); |
|
|
|
Device savedDevice = saveDevice(device); |
|
|
|
removeDeviceFromCacheByName(tenantId, device.getName()); |
|
|
|
removeDeviceFromCacheById(tenantId, device.getId()); |
|
|
|
return savedDevice; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -550,10 +556,6 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Caching(evict= { |
|
|
|
@CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}"), |
|
|
|
@CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.id}") |
|
|
|
}) |
|
|
|
@Override |
|
|
|
public Device assignDeviceToTenant(TenantId tenantId, Device device) { |
|
|
|
log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device); |
|
|
|
@ -572,9 +574,18 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
|
|
|
|
|
|
|
relationService.removeRelations(device.getTenantId(), device.getId()); |
|
|
|
|
|
|
|
TenantId oldTenantId = device.getTenantId(); |
|
|
|
|
|
|
|
device.setTenantId(tenantId); |
|
|
|
device.setCustomerId(null); |
|
|
|
return doSaveDevice(device, null, true); |
|
|
|
Device savedDevice = doSaveDevice(device, null, true); |
|
|
|
|
|
|
|
// explicitly remove device with previous tenant id from cache
|
|
|
|
// result device object will have different tenant id and will not remove entity from cache
|
|
|
|
removeDeviceFromCacheByName(oldTenantId, device.getName()); |
|
|
|
removeDeviceFromCacheById(oldTenantId, device.getId()); |
|
|
|
|
|
|
|
return savedDevice; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|