@Test void testValidateOwnLookupAttributesInvisible() { when(entityType.getOwnLookupAttributes()) .thenReturn(ImmutableList.of(lookupAttr1, lookupAttr2)); String lookupAttr1Id = "abcde"; String lookupAttr2Id = "defgh"; when(lookupAttr1.getIdentifier()).thenReturn(lookupAttr1Id); when(lookupAttr2.getIdentifier()).thenReturn(lookupAttr2Id); when(lookupAttr1.isVisible()).thenReturn(true); when(lookupAttr2.isVisible()).thenReturn(false); when(entityType.getId()).thenReturn("entity"); when(lookupAttr2.getName()).thenReturn("lookup2"); Exception exception = assertThrows( MolgenisValidationException.class, () -> EntityTypeValidator.validateOwnLookupAttributes( entityType, ImmutableMap.of(lookupAttr1Id, lookupAttr1, lookupAttr2Id, lookupAttr2))); assertThat(exception.getMessage()) .containsPattern( "Lookup attribute \\[lookup2\\] of entity type \\[entity\\] must be visible"); }
static void validateOwnLookupAttributes( EntityType entityType, Map<String, Attribute> ownAllAttrMap) { entityType .getOwnLookupAttributes() .forEach( ownLookupAttr -> { Attribute ownAttr = ownAllAttrMap.get(ownLookupAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] is not one of the attributes of entity [%s]", ownLookupAttr.getName(), entityType.getId()))); } if (!ownLookupAttr.isVisible()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] of entity type [%s] must be visible", ownLookupAttr.getName(), entityType.getId()))); } }); }
EntityTypeValidator { static void validateOwnLookupAttributes( EntityType entityType, Map<String, Attribute> ownAllAttrMap) { entityType .getOwnLookupAttributes() .forEach( ownLookupAttr -> { Attribute ownAttr = ownAllAttrMap.get(ownLookupAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] is not one of the attributes of entity [%s]", ownLookupAttr.getName(), entityType.getId()))); } if (!ownLookupAttr.isVisible()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] of entity type [%s] must be visible", ownLookupAttr.getName(), entityType.getId()))); } }); } }
EntityTypeValidator { static void validateOwnLookupAttributes( EntityType entityType, Map<String, Attribute> ownAllAttrMap) { entityType .getOwnLookupAttributes() .forEach( ownLookupAttr -> { Attribute ownAttr = ownAllAttrMap.get(ownLookupAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] is not one of the attributes of entity [%s]", ownLookupAttr.getName(), entityType.getId()))); } if (!ownLookupAttr.isVisible()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] of entity type [%s] must be visible", ownLookupAttr.getName(), entityType.getId()))); } }); } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); }
EntityTypeValidator { static void validateOwnLookupAttributes( EntityType entityType, Map<String, Attribute> ownAllAttrMap) { entityType .getOwnLookupAttributes() .forEach( ownLookupAttr -> { Attribute ownAttr = ownAllAttrMap.get(ownLookupAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] is not one of the attributes of entity [%s]", ownLookupAttr.getName(), entityType.getId()))); } if (!ownLookupAttr.isVisible()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] of entity type [%s] must be visible", ownLookupAttr.getName(), entityType.getId()))); } }); } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); void validate(EntityType entityType); }
EntityTypeValidator { static void validateOwnLookupAttributes( EntityType entityType, Map<String, Attribute> ownAllAttrMap) { entityType .getOwnLookupAttributes() .forEach( ownLookupAttr -> { Attribute ownAttr = ownAllAttrMap.get(ownLookupAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] is not one of the attributes of entity [%s]", ownLookupAttr.getName(), entityType.getId()))); } if (!ownLookupAttr.isVisible()) { throw new MolgenisValidationException( new ConstraintViolation( format( "Lookup attribute [%s] of entity type [%s] must be visible", ownLookupAttr.getName(), entityType.getId()))); } }); } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); void validate(EntityType entityType);  }