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) {
 | 
			
		||||
        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) {
 | 
			
		||||
            oldAsset = assetValidator.validate(asset, Asset::getTenantId);
 | 
			
		||||
        } else if (asset.getId() != null) {
 | 
			
		||||
            oldAsset = findAssetById(asset.getTenantId(), asset.getId());
 | 
			
		||||
            assetValidator.validate(asset, Asset::getTenantId);
 | 
			
		||||
        }
 | 
			
		||||
        AssetCacheEvictEvent evictEvent = new AssetCacheEvictEvent(asset.getTenantId(), asset.getName(), oldAsset != null ? oldAsset.getName() : null);
 | 
			
		||||
        Asset savedAsset;
 | 
			
		||||
@ -187,9 +188,6 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            asset.setType(assetProfile.getName());
 | 
			
		||||
            if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY) {
 | 
			
		||||
                uniquifyEntityName(asset, oldAsset, asset::setName, EntityType.ASSET, nameConflictStrategy);
 | 
			
		||||
            }
 | 
			
		||||
            savedAsset = assetDao.saveAndFlush(asset.getTenantId(), asset);
 | 
			
		||||
            publishEvictEvent(evictEvent);
 | 
			
		||||
            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) {
 | 
			
		||||
        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) {
 | 
			
		||||
            oldCustomer = customerValidator.validate(customer, Customer::getTenantId);
 | 
			
		||||
            customerValidator.validate(customer, Customer::getTenantId);
 | 
			
		||||
        }
 | 
			
		||||
        var evictEvent = new CustomerCacheEvictEvent(customer.getTenantId(), customer.getTitle(), oldCustomer != null ? oldCustomer.getTitle() : null);
 | 
			
		||||
        try {
 | 
			
		||||
            if (nameConflictStrategy.policy() == NameConflictPolicy.UNIQUIFY) {
 | 
			
		||||
                uniquifyEntityName(customer, oldCustomer, customer::setTitle, EntityType.CUSTOMER, nameConflictStrategy);
 | 
			
		||||
            }
 | 
			
		||||
            Customer savedCustomer = customerDao.saveAndFlush(customer.getTenantId(), customer);
 | 
			
		||||
            if (!savedCustomer.isPublic()) {
 | 
			
		||||
                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) {
 | 
			
		||||
        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) {
 | 
			
		||||
            oldDevice = deviceValidator.validate(device, Device::getTenantId);
 | 
			
		||||
        } else if (device.getId() != null) {
 | 
			
		||||
            oldDevice = findDeviceById(device.getTenantId(), device.getId());
 | 
			
		||||
            deviceValidator.validate(device, Device::getTenantId);
 | 
			
		||||
        }
 | 
			
		||||
        DeviceCacheEvictEvent deviceCacheEvictEvent = new DeviceCacheEvictEvent(device.getTenantId(), device.getId(), device.getName(), oldDevice != null ? oldDevice.getName() : null);
 | 
			
		||||
        try {
 | 
			
		||||
@ -256,9 +257,6 @@ public class DeviceServiceImpl extends CachedVersionedEntityService<DeviceCacheK
 | 
			
		||||
            }
 | 
			
		||||
            device.setType(deviceProfile.getName());
 | 
			
		||||
            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);
 | 
			
		||||
            deviceCacheEvictEvent.setSavedDevice(savedDevice);
 | 
			
		||||
            publishEvictEvent(deviceCacheEvictEvent);
 | 
			
		||||
 | 
			
		||||
@ -125,7 +125,7 @@ public class EntityViewServiceImpl extends CachedVersionedEntityService<EntityVi
 | 
			
		||||
    private EntityView saveEntityView(EntityView entityView, boolean doValidate, NameConflictStrategy nameConflictStrategy) {
 | 
			
		||||
        log.trace("Executing save entity view [{}]", entityView);
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
        if (doValidate) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user