private static boolean isNameUsedInHierarchy(String aName, FIBModelObject object) { if (object.getName() != null && object.getName().equals(aName)) { return true; } if (object.getEmbeddedObjects() != null) { for (FIBModelObject o : object.getEmbeddedObjects()) { if (isNameUsedInHierarchy(aName, o)) return true; } } return false; }
private static List<FIBModelObject> retrieveObjectsWithName( String aName, FIBModelObject object, List<FIBModelObject> list) { if (object.getName() != null && object.getName().equals(aName)) { list.add(object); } if (object.getEmbeddedObjects() != null) { for (FIBModelObject o : object.getEmbeddedObjects()) { retrieveObjectsWithName(aName, o, list); } } return list; }
@Override public ValidationIssue<FIBModelObjectShouldHaveAUniqueName, FIBModelObject> applyValidation( FIBModelObject object) { if (StringUtils.isNotEmpty(object.getName())) { List<FIBModelObject> allObjectsWithThatName = object.getObjectsWithName(object.getName()); if (allObjectsWithThatName.size() > 1) { allObjectsWithThatName.remove(object); GenerateUniqueName fixProposal = new GenerateUniqueName(); ProblemIssue<FIBModelObjectShouldHaveAUniqueName, FIBModelObject> returned; if (object instanceof FIBWidget && ((FIBWidget) object).getManageDynamicModel()) { returned = new ValidationError<FIBModelObjectShouldHaveAUniqueName, FIBModelObject>( this, object, "object_($object.toString)_has_duplicated_name", fixProposal); } else { returned = new ValidationWarning<FIBModelObjectShouldHaveAUniqueName, FIBModelObject>( this, object, "object_($object.toString)_has_duplicated_name", fixProposal); } returned.addToRelatedValidableObjects(allObjectsWithThatName); return returned; } } return null; }