@Test void testValidateOwnAttributesAttributesWithSameName() { when(entityType.getId()).thenReturn("entity"); when(entityType.getAllAttributes()).thenReturn(newArrayList(idAttr, labelAttr)); when(idAttr.getName()).thenReturn("id"); when(labelAttr.getName()).thenReturn("id"); Exception exception = assertThrows( MolgenisValidationException.class, () -> EntityTypeValidator.validateOwnAttributes(entityType)); assertThat(exception.getMessage()) .containsPattern("EntityType \\[entity\\] contains multiple attributes with name \\[id\\]"); }
static void validateOwnAttributes(EntityType entityType) { if (stream(entityType.getAllAttributes()).collect(toList()).isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] does not contain any attributes. Did you use the correct package+entity name combination in both the entities as well as the attributes sheet?", entityType.getId()))); } Multimap<String, Attribute> attrMultiMap = stream(entityType.getAllAttributes()) .collect( MultimapCollectors.toArrayListMultimap(Attribute::getName, Function.identity())); attrMultiMap .keySet() .forEach( attrName -> { if (attrMultiMap.get(attrName).size() > 1) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] contains multiple attributes with name [%s]", entityType.getId(), attrName))); } }); Set<String> attributeIds = stream(entityType.getAllAttributes()).map(Attribute::getIdentifier).collect(toSet()); stream(entityType.getAllAttributes()) .filter(attr -> attr.getParent() != null) .forEach( attr -> { if (!attributeIds.contains(attr.getParent().getIdentifier())) { throw new MolgenisValidationException( new ConstraintViolation( format( "Attribute [%s] of EntityType [%s] has a non-existing parent attribute [%s]", attr.getName(), entityType.getId(), attr.getParent().getName()))); } }); }
EntityTypeValidator { static void validateOwnAttributes(EntityType entityType) { if (stream(entityType.getAllAttributes()).collect(toList()).isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] does not contain any attributes. Did you use the correct package+entity name combination in both the entities as well as the attributes sheet?", entityType.getId()))); } Multimap<String, Attribute> attrMultiMap = stream(entityType.getAllAttributes()) .collect( MultimapCollectors.toArrayListMultimap(Attribute::getName, Function.identity())); attrMultiMap .keySet() .forEach( attrName -> { if (attrMultiMap.get(attrName).size() > 1) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] contains multiple attributes with name [%s]", entityType.getId(), attrName))); } }); Set<String> attributeIds = stream(entityType.getAllAttributes()).map(Attribute::getIdentifier).collect(toSet()); stream(entityType.getAllAttributes()) .filter(attr -> attr.getParent() != null) .forEach( attr -> { if (!attributeIds.contains(attr.getParent().getIdentifier())) { throw new MolgenisValidationException( new ConstraintViolation( format( "Attribute [%s] of EntityType [%s] has a non-existing parent attribute [%s]", attr.getName(), entityType.getId(), attr.getParent().getName()))); } }); } }
EntityTypeValidator { static void validateOwnAttributes(EntityType entityType) { if (stream(entityType.getAllAttributes()).collect(toList()).isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] does not contain any attributes. Did you use the correct package+entity name combination in both the entities as well as the attributes sheet?", entityType.getId()))); } Multimap<String, Attribute> attrMultiMap = stream(entityType.getAllAttributes()) .collect( MultimapCollectors.toArrayListMultimap(Attribute::getName, Function.identity())); attrMultiMap .keySet() .forEach( attrName -> { if (attrMultiMap.get(attrName).size() > 1) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] contains multiple attributes with name [%s]", entityType.getId(), attrName))); } }); Set<String> attributeIds = stream(entityType.getAllAttributes()).map(Attribute::getIdentifier).collect(toSet()); stream(entityType.getAllAttributes()) .filter(attr -> attr.getParent() != null) .forEach( attr -> { if (!attributeIds.contains(attr.getParent().getIdentifier())) { throw new MolgenisValidationException( new ConstraintViolation( format( "Attribute [%s] of EntityType [%s] has a non-existing parent attribute [%s]", attr.getName(), entityType.getId(), attr.getParent().getName()))); } }); } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); }
EntityTypeValidator { static void validateOwnAttributes(EntityType entityType) { if (stream(entityType.getAllAttributes()).collect(toList()).isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] does not contain any attributes. Did you use the correct package+entity name combination in both the entities as well as the attributes sheet?", entityType.getId()))); } Multimap<String, Attribute> attrMultiMap = stream(entityType.getAllAttributes()) .collect( MultimapCollectors.toArrayListMultimap(Attribute::getName, Function.identity())); attrMultiMap .keySet() .forEach( attrName -> { if (attrMultiMap.get(attrName).size() > 1) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] contains multiple attributes with name [%s]", entityType.getId(), attrName))); } }); Set<String> attributeIds = stream(entityType.getAllAttributes()).map(Attribute::getIdentifier).collect(toSet()); stream(entityType.getAllAttributes()) .filter(attr -> attr.getParent() != null) .forEach( attr -> { if (!attributeIds.contains(attr.getParent().getIdentifier())) { throw new MolgenisValidationException( new ConstraintViolation( format( "Attribute [%s] of EntityType [%s] has a non-existing parent attribute [%s]", attr.getName(), entityType.getId(), attr.getParent().getName()))); } }); } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); void validate(EntityType entityType); }
EntityTypeValidator { static void validateOwnAttributes(EntityType entityType) { if (stream(entityType.getAllAttributes()).collect(toList()).isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] does not contain any attributes. Did you use the correct package+entity name combination in both the entities as well as the attributes sheet?", entityType.getId()))); } Multimap<String, Attribute> attrMultiMap = stream(entityType.getAllAttributes()) .collect( MultimapCollectors.toArrayListMultimap(Attribute::getName, Function.identity())); attrMultiMap .keySet() .forEach( attrName -> { if (attrMultiMap.get(attrName).size() > 1) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] contains multiple attributes with name [%s]", entityType.getId(), attrName))); } }); Set<String> attributeIds = stream(entityType.getAllAttributes()).map(Attribute::getIdentifier).collect(toSet()); stream(entityType.getAllAttributes()) .filter(attr -> attr.getParent() != null) .forEach( attr -> { if (!attributeIds.contains(attr.getParent().getIdentifier())) { throw new MolgenisValidationException( new ConstraintViolation( format( "Attribute [%s] of EntityType [%s] has a non-existing parent attribute [%s]", attr.getName(), entityType.getId(), attr.getParent().getName()))); } }); } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); void validate(EntityType entityType);  }