Fix incorrect cache clearing on device delete
This commit is contained in:
parent
1c909d570e
commit
3bc5aa88a3
@ -28,6 +28,5 @@ public class DeviceProfileEvictEvent {
|
|||||||
private final DeviceProfileId deviceProfileId;
|
private final DeviceProfileId deviceProfileId;
|
||||||
private final boolean defaultProfile;
|
private final boolean defaultProfile;
|
||||||
private final String newProvisionDeviceKey;
|
private final String newProvisionDeviceKey;
|
||||||
private final String oldProvisionDeviceKey;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,8 +103,8 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
|||||||
if (StringUtils.isNotEmpty(event.getOldName()) && !event.getOldName().equals(event.getNewName())) {
|
if (StringUtils.isNotEmpty(event.getOldName()) && !event.getOldName().equals(event.getNewName())) {
|
||||||
keys.add(DeviceProfileCacheKey.fromName(event.getTenantId(), event.getOldName()));
|
keys.add(DeviceProfileCacheKey.fromName(event.getTenantId(), event.getOldName()));
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(event.getOldProvisionDeviceKey())) {
|
if (StringUtils.isNotEmpty(event.getNewProvisionDeviceKey())) {
|
||||||
keys.add(DeviceProfileCacheKey.fromProvisionDeviceKey(event.getOldProvisionDeviceKey()));
|
keys.add(DeviceProfileCacheKey.fromProvisionDeviceKey(event.getNewProvisionDeviceKey()));
|
||||||
}
|
}
|
||||||
cache.evict(keys);
|
cache.evict(keys);
|
||||||
}
|
}
|
||||||
@ -155,11 +155,11 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
|||||||
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(),
|
||||||
savedDeviceProfile.getProvisionDeviceKey(), oldDeviceProfile != null ? oldDeviceProfile.getProvisionDeviceKey() : null));
|
savedDeviceProfile.getProvisionDeviceKey()));
|
||||||
} catch (Exception t) {
|
} catch (Exception t) {
|
||||||
handleEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(),
|
handleEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(),
|
||||||
oldDeviceProfile != null ? oldDeviceProfile.getName() : null, null, deviceProfile.isDefault(),
|
oldDeviceProfile != null ? oldDeviceProfile.getName() : null, null, deviceProfile.isDefault(),
|
||||||
deviceProfile.getProvisionDeviceKey(), oldDeviceProfile != null ? oldDeviceProfile.getProvisionDeviceKey() : null));
|
deviceProfile.getProvisionDeviceKey()));
|
||||||
checkConstraintViolation(t,
|
checkConstraintViolation(t,
|
||||||
Map.of("device_profile_name_unq_key", DEVICE_PROFILE_WITH_SUCH_NAME_ALREADY_EXISTS,
|
Map.of("device_profile_name_unq_key", DEVICE_PROFILE_WITH_SUCH_NAME_ALREADY_EXISTS,
|
||||||
"device_provision_key_unq_key", "Device profile with such provision device key already exists!",
|
"device_provision_key_unq_key", "Device profile with such provision device key already exists!",
|
||||||
@ -200,7 +200,7 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
|||||||
deviceProfileDao.removeById(tenantId, deviceProfileId.getId());
|
deviceProfileDao.removeById(tenantId, deviceProfileId.getId());
|
||||||
publishEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(),
|
publishEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(),
|
||||||
null, deviceProfile.getId(), deviceProfile.isDefault(),
|
null, deviceProfile.getId(), deviceProfile.isDefault(),
|
||||||
deviceProfile.getProvisionDeviceKey(), null));
|
deviceProfile.getProvisionDeviceKey()));
|
||||||
} catch (Exception t) {
|
} catch (Exception t) {
|
||||||
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
|
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
|
||||||
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_device_profile")) {
|
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("fk_device_profile")) {
|
||||||
@ -298,14 +298,14 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
|
|||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
if (previousDefaultDeviceProfile == null) {
|
if (previousDefaultDeviceProfile == null) {
|
||||||
deviceProfileDao.save(tenantId, deviceProfile);
|
deviceProfileDao.save(tenantId, deviceProfile);
|
||||||
publishEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(), null, deviceProfile.getId(), true, deviceProfile.getProvisionDeviceKey(), null));
|
publishEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(), null, deviceProfile.getId(), true, deviceProfile.getProvisionDeviceKey()));
|
||||||
changed = true;
|
changed = true;
|
||||||
} else if (!previousDefaultDeviceProfile.getId().equals(deviceProfile.getId())) {
|
} else if (!previousDefaultDeviceProfile.getId().equals(deviceProfile.getId())) {
|
||||||
previousDefaultDeviceProfile.setDefault(false);
|
previousDefaultDeviceProfile.setDefault(false);
|
||||||
deviceProfileDao.save(tenantId, previousDefaultDeviceProfile);
|
deviceProfileDao.save(tenantId, previousDefaultDeviceProfile);
|
||||||
deviceProfileDao.save(tenantId, deviceProfile);
|
deviceProfileDao.save(tenantId, deviceProfile);
|
||||||
publishEvictEvent(new DeviceProfileEvictEvent(previousDefaultDeviceProfile.getTenantId(), previousDefaultDeviceProfile.getName(), null, previousDefaultDeviceProfile.getId(), false, deviceProfile.getProvisionDeviceKey(), null));
|
publishEvictEvent(new DeviceProfileEvictEvent(previousDefaultDeviceProfile.getTenantId(), previousDefaultDeviceProfile.getName(), null, previousDefaultDeviceProfile.getId(), false, deviceProfile.getProvisionDeviceKey()));
|
||||||
publishEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(), null, deviceProfile.getId(), true, deviceProfile.getProvisionDeviceKey(), null));
|
publishEvictEvent(new DeviceProfileEvictEvent(deviceProfile.getTenantId(), deviceProfile.getName(), null, deviceProfile.getId(), true, deviceProfile.getProvisionDeviceKey()));
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user