@Test void testValidateOwnIdAttributeNotUnique() { when(entityType.getId()).thenReturn("entity"); when(entityType.getOwnIdAttribute()).thenReturn(idAttr); String idAttributeIdentifier = "abcde"; when(idAttr.getIdentifier()).thenReturn(idAttributeIdentifier); when(idAttr.getName()).thenReturn("id"); when(idAttr.getDataType()).thenReturn(STRING); when(idAttr.isUnique()).thenReturn(false); Exception exception = assertThrows( MolgenisValidationException.class, () -> EntityTypeValidator.validateOwnIdAttribute( entityType, ImmutableMap.of(idAttributeIdentifier, idAttr))); assertThat(exception.getMessage()) .containsPattern("EntityType \\[entity\\] ID attribute \\[id\\] is not a unique attribute"); }
static void validateOwnIdAttribute(EntityType entityType, Map<String, Attribute> ownAllAttrMap) { Attribute ownIdAttr = entityType.getOwnIdAttribute(); if (ownIdAttr != null) { Attribute ownAttr = ownAllAttrMap.get(ownIdAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not part of the entity attributes", entityType.getId(), ownIdAttr.getName()))); } if (!AttributeUtils.isIdAttributeTypeAllowed(ownIdAttr)) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] type [%s] is not allowed", entityType.getId(), ownIdAttr.getName(), ownIdAttr.getDataType().toString()))); } if (!ownIdAttr.isUnique()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not a unique attribute", entityType.getId(), ownIdAttr.getName()))); } if (ownIdAttr.isNillable()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] cannot be nillable", entityType.getId(), ownIdAttr.getName()))); } } else { if (!entityType.isAbstract() && entityType.getIdAttribute() == null) { throw new MolgenisValidationException( new ConstraintViolation( format("EntityType [%s] is missing required ID attribute", entityType.getId()))); } } }
EntityTypeValidator { static void validateOwnIdAttribute(EntityType entityType, Map<String, Attribute> ownAllAttrMap) { Attribute ownIdAttr = entityType.getOwnIdAttribute(); if (ownIdAttr != null) { Attribute ownAttr = ownAllAttrMap.get(ownIdAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not part of the entity attributes", entityType.getId(), ownIdAttr.getName()))); } if (!AttributeUtils.isIdAttributeTypeAllowed(ownIdAttr)) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] type [%s] is not allowed", entityType.getId(), ownIdAttr.getName(), ownIdAttr.getDataType().toString()))); } if (!ownIdAttr.isUnique()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not a unique attribute", entityType.getId(), ownIdAttr.getName()))); } if (ownIdAttr.isNillable()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] cannot be nillable", entityType.getId(), ownIdAttr.getName()))); } } else { if (!entityType.isAbstract() && entityType.getIdAttribute() == null) { throw new MolgenisValidationException( new ConstraintViolation( format("EntityType [%s] is missing required ID attribute", entityType.getId()))); } } } }
EntityTypeValidator { static void validateOwnIdAttribute(EntityType entityType, Map<String, Attribute> ownAllAttrMap) { Attribute ownIdAttr = entityType.getOwnIdAttribute(); if (ownIdAttr != null) { Attribute ownAttr = ownAllAttrMap.get(ownIdAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not part of the entity attributes", entityType.getId(), ownIdAttr.getName()))); } if (!AttributeUtils.isIdAttributeTypeAllowed(ownIdAttr)) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] type [%s] is not allowed", entityType.getId(), ownIdAttr.getName(), ownIdAttr.getDataType().toString()))); } if (!ownIdAttr.isUnique()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not a unique attribute", entityType.getId(), ownIdAttr.getName()))); } if (ownIdAttr.isNillable()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] cannot be nillable", entityType.getId(), ownIdAttr.getName()))); } } else { if (!entityType.isAbstract() && entityType.getIdAttribute() == null) { throw new MolgenisValidationException( new ConstraintViolation( format("EntityType [%s] is missing required ID attribute", entityType.getId()))); } } } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); }
EntityTypeValidator { static void validateOwnIdAttribute(EntityType entityType, Map<String, Attribute> ownAllAttrMap) { Attribute ownIdAttr = entityType.getOwnIdAttribute(); if (ownIdAttr != null) { Attribute ownAttr = ownAllAttrMap.get(ownIdAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not part of the entity attributes", entityType.getId(), ownIdAttr.getName()))); } if (!AttributeUtils.isIdAttributeTypeAllowed(ownIdAttr)) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] type [%s] is not allowed", entityType.getId(), ownIdAttr.getName(), ownIdAttr.getDataType().toString()))); } if (!ownIdAttr.isUnique()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not a unique attribute", entityType.getId(), ownIdAttr.getName()))); } if (ownIdAttr.isNillable()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] cannot be nillable", entityType.getId(), ownIdAttr.getName()))); } } else { if (!entityType.isAbstract() && entityType.getIdAttribute() == null) { throw new MolgenisValidationException( new ConstraintViolation( format("EntityType [%s] is missing required ID attribute", entityType.getId()))); } } } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); void validate(EntityType entityType); }
EntityTypeValidator { static void validateOwnIdAttribute(EntityType entityType, Map<String, Attribute> ownAllAttrMap) { Attribute ownIdAttr = entityType.getOwnIdAttribute(); if (ownIdAttr != null) { Attribute ownAttr = ownAllAttrMap.get(ownIdAttr.getIdentifier()); if (ownAttr == null) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not part of the entity attributes", entityType.getId(), ownIdAttr.getName()))); } if (!AttributeUtils.isIdAttributeTypeAllowed(ownIdAttr)) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] type [%s] is not allowed", entityType.getId(), ownIdAttr.getName(), ownIdAttr.getDataType().toString()))); } if (!ownIdAttr.isUnique()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] is not a unique attribute", entityType.getId(), ownIdAttr.getName()))); } if (ownIdAttr.isNillable()) { throw new MolgenisValidationException( new ConstraintViolation( format( "EntityType [%s] ID attribute [%s] cannot be nillable", entityType.getId(), ownIdAttr.getName()))); } } else { if (!entityType.isAbstract() && entityType.getIdAttribute() == null) { throw new MolgenisValidationException( new ConstraintViolation( format("EntityType [%s] is missing required ID attribute", entityType.getId()))); } } } EntityTypeValidator(DataService dataService, SystemEntityTypeRegistry systemEntityTypeRegistry); void validate(EntityType entityType);  }