deleted redundant constraint check, refactoring
This commit is contained in:
		
							parent
							
								
									374b6cf22f
								
							
						
					
					
						commit
						3fa9b877ab
					
				@ -178,18 +178,25 @@ public abstract class AbstractEntityService {
 | 
				
			|||||||
                .filter(e -> (oldEntity == null || !e.getId().equals(oldEntity.getId())))
 | 
					                .filter(e -> (oldEntity == null || !e.getId().equals(oldEntity.getId())))
 | 
				
			||||||
                .map(EntityInfo::getName)
 | 
					                .map(EntityInfo::getName)
 | 
				
			||||||
                .collect(Collectors.toSet());
 | 
					                .collect(Collectors.toSet());
 | 
				
			||||||
        if (!existingNames.isEmpty()) {
 | 
					
 | 
				
			||||||
            int idx = 1;
 | 
					        if (existingNames.contains(entity.getName())) {
 | 
				
			||||||
            String suffix = (strategy.uniquifyStrategy() == RANDOM) ? StringUtils.randomAlphanumeric(6) : String.valueOf(idx);
 | 
					            String uniqueName = generateUniqueName(entity.getName(), existingNames, strategy);
 | 
				
			||||||
            while (true) {
 | 
					            setName.accept(uniqueName);
 | 
				
			||||||
                String newName = entity.getName() + strategy.separator() + suffix;
 | 
					 | 
				
			||||||
                if (!existingNames.contains(newName)) {
 | 
					 | 
				
			||||||
                    setName.accept(newName);
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                suffix = (strategy.uniquifyStrategy() == RANDOM) ? StringUtils.randomAlphanumeric(6) : String.valueOf(idx++);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String generateUniqueName(String baseName, Set<String> existingNames, NameConflictStrategy strategy) {
 | 
				
			||||||
 | 
					        String newName;
 | 
				
			||||||
 | 
					        int index = 1;
 | 
				
			||||||
 | 
					        String separator = strategy.separator();
 | 
				
			||||||
 | 
					        boolean isRandom = strategy.uniquifyStrategy() == RANDOM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        do {
 | 
				
			||||||
 | 
					            String suffix = isRandom ? StringUtils.randomAlphanumeric(6) : String.valueOf(index++);
 | 
				
			||||||
 | 
					            newName = baseName + separator + suffix;
 | 
				
			||||||
 | 
					        } while (existingNames.contains(newName));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return newName;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -139,8 +139,7 @@ public class EntityViewServiceImpl extends CachedVersionedEntityService<EntityVi
 | 
				
			|||||||
            return saved;
 | 
					            return saved;
 | 
				
			||||||
        } catch (Exception t) {
 | 
					        } catch (Exception t) {
 | 
				
			||||||
            checkConstraintViolation(t,
 | 
					            checkConstraintViolation(t,
 | 
				
			||||||
                    "entity_view_external_id_unq_key", "Entity View with such external id already exists!",
 | 
					                    "entity_view_external_id_unq_key", "Entity View with such external id already exists!");
 | 
				
			||||||
                    "entity_view_name_unq_key", "Entity View with such name already exists!");
 | 
					 | 
				
			||||||
            throw t;
 | 
					            throw t;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user