moved name update before validation
This commit is contained in:
parent
e8d888e22b
commit
03077c2bc0
@ -160,11 +160,12 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
|||||||
|
|
||||||
private Asset saveAsset(Asset asset, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
private Asset saveAsset(Asset asset, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
||||||
log.trace("Executing saveAsset [{}]", asset);
|
log.trace("Executing saveAsset [{}]", asset);
|
||||||
Asset oldAsset = null;
|
Asset oldAsset = (asset.getId() != null) ? findAssetById(asset.getTenantId(), asset.getId()) : null;
|
||||||
|
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY && (oldAsset == null || !oldAsset.getName().equals(asset.getName()))) {
|
||||||
|
uniquifyEntityName(asset, oldAsset, asset::setName, EntityType.ASSET, nameConflictStrategy);
|
||||||
|
}
|
||||||
if (doValidate) {
|
if (doValidate) {
|
||||||
oldAsset = assetValidator.validate(asset, Asset::getTenantId);
|
assetValidator.validate(asset, Asset::getTenantId);
|
||||||
} else if (asset.getId() != null) {
|
|
||||||
oldAsset = findAssetById(asset.getTenantId(), asset.getId());
|
|
||||||
}
|
}
|
||||||
AssetCacheEvictEvent evictEvent = new AssetCacheEvictEvent(asset.getTenantId(), asset.getName(), oldAsset != null ? oldAsset.getName() : null);
|
AssetCacheEvictEvent evictEvent = new AssetCacheEvictEvent(asset.getTenantId(), asset.getName(), oldAsset != null ? oldAsset.getName() : null);
|
||||||
Asset savedAsset;
|
Asset savedAsset;
|
||||||
@ -187,9 +188,6 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
asset.setType(assetProfile.getName());
|
asset.setType(assetProfile.getName());
|
||||||
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY) {
|
|
||||||
uniquifyEntityName(asset, oldAsset, asset::setName, EntityType.ASSET, nameConflictStrategy);
|
|
||||||
}
|
|
||||||
savedAsset = assetDao.saveAndFlush(asset.getTenantId(), asset);
|
savedAsset = assetDao.saveAndFlush(asset.getTenantId(), asset);
|
||||||
publishEvictEvent(evictEvent);
|
publishEvictEvent(evictEvent);
|
||||||
eventPublisher.publishEvent(SaveEntityEvent.builder().tenantId(savedAsset.getTenantId()).entityId(savedAsset.getId())
|
eventPublisher.publishEvent(SaveEntityEvent.builder().tenantId(savedAsset.getTenantId()).entityId(savedAsset.getId())
|
||||||
|
|||||||
@ -156,15 +156,15 @@ public class CustomerServiceImpl extends AbstractCachedEntityService<CustomerCac
|
|||||||
|
|
||||||
private Customer saveCustomer(Customer customer, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
private Customer saveCustomer(Customer customer, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
||||||
log.trace("Executing saveCustomer [{}]", customer);
|
log.trace("Executing saveCustomer [{}]", customer);
|
||||||
Customer oldCustomer = null;
|
Customer oldCustomer = (customer.getId() != null) ? findCustomerById(customer.getTenantId(), customer.getId()) : null;
|
||||||
|
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY && (oldCustomer == null || !oldCustomer.getTitle().equals(customer.getTitle()))) {
|
||||||
|
uniquifyEntityName(customer, oldCustomer, customer::setTitle, EntityType.CUSTOMER, nameConflictStrategy);
|
||||||
|
}
|
||||||
if (doValidate) {
|
if (doValidate) {
|
||||||
oldCustomer = customerValidator.validate(customer, Customer::getTenantId);
|
customerValidator.validate(customer, Customer::getTenantId);
|
||||||
}
|
}
|
||||||
var evictEvent = new CustomerCacheEvictEvent(customer.getTenantId(), customer.getTitle(), oldCustomer != null ? oldCustomer.getTitle() : null);
|
var evictEvent = new CustomerCacheEvictEvent(customer.getTenantId(), customer.getTitle(), oldCustomer != null ? oldCustomer.getTitle() : null);
|
||||||
try {
|
try {
|
||||||
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY) {
|
|
||||||
uniquifyEntityName(customer, oldCustomer, customer::setTitle, EntityType.CUSTOMER, nameConflictStrategy);
|
|
||||||
}
|
|
||||||
Customer savedCustomer = customerDao.saveAndFlush(customer.getTenantId(), customer);
|
Customer savedCustomer = customerDao.saveAndFlush(customer.getTenantId(), customer);
|
||||||
if (!savedCustomer.isPublic()) {
|
if (!savedCustomer.isPublic()) {
|
||||||
dashboardService.updateCustomerDashboards(savedCustomer.getTenantId(), savedCustomer.getId());
|
dashboardService.updateCustomerDashboards(savedCustomer.getTenantId(), savedCustomer.getId());
|
||||||
|
|||||||
@ -229,11 +229,12 @@ public class DeviceServiceImpl extends CachedVersionedEntityService<DeviceCacheK
|
|||||||
|
|
||||||
private Device saveDeviceWithoutCredentials(Device device, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
private Device saveDeviceWithoutCredentials(Device device, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
||||||
log.trace("Executing saveDevice [{}]", device);
|
log.trace("Executing saveDevice [{}]", device);
|
||||||
Device oldDevice = null;
|
Device oldDevice = (device.getId() != null) ? findDeviceById(device.getTenantId(), device.getId()) : null;
|
||||||
|
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY && (oldDevice == null || !oldDevice.getName().equals(device.getName()))) {
|
||||||
|
uniquifyEntityName(device, oldDevice, device::setName, EntityType.DEVICE, nameConflictStrategy);
|
||||||
|
}
|
||||||
if (doValidate) {
|
if (doValidate) {
|
||||||
oldDevice = deviceValidator.validate(device, Device::getTenantId);
|
deviceValidator.validate(device, Device::getTenantId);
|
||||||
} else if (device.getId() != null) {
|
|
||||||
oldDevice = findDeviceById(device.getTenantId(), device.getId());
|
|
||||||
}
|
}
|
||||||
DeviceCacheEvictEvent deviceCacheEvictEvent = new DeviceCacheEvictEvent(device.getTenantId(), device.getId(), device.getName(), oldDevice != null ? oldDevice.getName() : null);
|
DeviceCacheEvictEvent deviceCacheEvictEvent = new DeviceCacheEvictEvent(device.getTenantId(), device.getId(), device.getName(), oldDevice != null ? oldDevice.getName() : null);
|
||||||
try {
|
try {
|
||||||
@ -256,9 +257,6 @@ public class DeviceServiceImpl extends CachedVersionedEntityService<DeviceCacheK
|
|||||||
}
|
}
|
||||||
device.setType(deviceProfile.getName());
|
device.setType(deviceProfile.getName());
|
||||||
device.setDeviceData(syncDeviceData(deviceProfile, device.getDeviceData()));
|
device.setDeviceData(syncDeviceData(deviceProfile, device.getDeviceData()));
|
||||||
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY) {
|
|
||||||
uniquifyEntityName(device, oldDevice, device::setName, EntityType.DEVICE, nameConflictStrategy);
|
|
||||||
}
|
|
||||||
Device savedDevice = deviceDao.saveAndFlush(device.getTenantId(), device);
|
Device savedDevice = deviceDao.saveAndFlush(device.getTenantId(), device);
|
||||||
deviceCacheEvictEvent.setSavedDevice(savedDevice);
|
deviceCacheEvictEvent.setSavedDevice(savedDevice);
|
||||||
publishEvictEvent(deviceCacheEvictEvent);
|
publishEvictEvent(deviceCacheEvictEvent);
|
||||||
|
|||||||
@ -125,7 +125,7 @@ public class EntityViewServiceImpl extends CachedVersionedEntityService<EntityVi
|
|||||||
private EntityView saveEntityView(EntityView entityView, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
private EntityView saveEntityView(EntityView entityView, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
|
||||||
log.trace("Executing save entity view [{}]", entityView);
|
log.trace("Executing save entity view [{}]", entityView);
|
||||||
EntityView old = (entityView.getId() != null) ? findEntityViewById(entityView.getTenantId(), entityView.getId(), false) : null;
|
EntityView old = (entityView.getId() != null) ? findEntityViewById(entityView.getTenantId(), entityView.getId(), false) : null;
|
||||||
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY) {
|
if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY && (old == null || !entityView.getName().equals(old.getName()))) {
|
||||||
uniquifyEntityName(entityView, old, entityView::setName, EntityType.ENTITY_VIEW, nameConflictStrategy);
|
uniquifyEntityName(entityView, old, entityView::setName, EntityType.ENTITY_VIEW, nameConflictStrategy);
|
||||||
}
|
}
|
||||||
if (doValidate) {
|
if (doValidate) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user