@Override public void validateEntityNotReferencedById(Object entityId, EntityType entityType) { validateEntityNotReferenced(entityId, entityType, getDefaultValueMap(entityType)); }
private void validateEntityNotReferenced( Object entityId, EntityType entityType, Multimap<String, Attribute> defaultValueMultiMap) { if (defaultValueMultiMap.containsKey(toAttributeDefaultValue(entityId))) { Collection<Attribute> attributes = defaultValueMultiMap.get(toAttributeDefaultValue(entityId)); throw new MolgenisValidationException( new ConstraintViolation( String.format( "'%s' with id '%s' is referenced as default value by attribute(s): '%s'", entityType.getLabel(), entityId.toString(), attributes.stream().map(Attribute::getName).collect(Collectors.joining(", "))))); } }
@Override public void validateEntityNotReferenced(Entity entity) { validateEntityNotReferencedById(entity.getIdValue(), entity.getEntityType()); }
@Override public void validateEntityTypeNotReferenced(EntityType entityType) { if (!getDefaultValueMap(entityType).isEmpty()) { throw new MolgenisValidationException( new ConstraintViolation( String.format( "'%s' entities are referenced as default value by attributes", entityType.getLabel()))); } }
@Override public Stream<Object> validateEntitiesNotReferencedById( Stream<Object> entityIdStream, EntityType entityType) { Multimap<String, Attribute> defaultValueMap = getDefaultValueMap(entityType); return entityIdStream.filter( entityId -> { validateEntityNotReferenced(entityId, entityType, defaultValueMap); return true; }); }
@Override public Stream<Entity> validateEntitiesNotReferenced( Stream<Entity> entityStream, EntityType entityType) { Multimap<String, Attribute> defaultValueMap = getDefaultValueMap(entityType); return entityStream.filter( entity -> { validateEntityNotReferenced(entity.getIdValue(), entityType, defaultValueMap); return true; }); }