@Test void resolveDependenciesEntityCircularExtends() { when(entityType0.getExtends()).thenReturn(entityType3); when(entityType1.getExtends()).thenReturn(entityType0); when(entityType2.getExtends()).thenReturn(entityType1); when(entityType3.getExtends()).thenReturn(entityType2); Exception exception = assertThrows( MolgenisDataException.class, () -> entityTypeDependencyResolver.resolve(newArrayList(entityType0, entityType1))); assertThat(exception.getMessage()) .containsPattern( "Could not resolve dependencies of items \\[entity1, entity2, entity0, entity3\\]. Are there circular dependencies\\?"); }
public List<EntityType> resolve(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return emptyList(); } if (entityTypes.size() == 1) { return singletonList(entityTypes.iterator().next()); } Set<EntityTypeNode> entityTypeNodes = entityTypes.stream() .map(EntityTypeNode::new) .flatMap( node -> Stream.concat(Stream.of(node), expandEntityTypeDependencies(node).stream())) .collect(toCollection(HashSet::new)); List<EntityTypeNode> resolvedEntityMetaNodes = genericDependencyResolver.resolve(entityTypeNodes, getDependencies()); List<EntityType> resolvedEntityMetas = resolvedEntityMetaNodes.stream().map(EntityTypeNode::getEntityType).collect(toList()); if (resolvedEntityMetas.size() == entityTypes.size()) { return resolvedEntityMetas; } else { Map<String, EntityType> entityTypeMap = entityTypes.stream().collect(toMap(EntityType::getId, Function.identity())); return resolvedEntityMetas.stream() .filter(resolvedEntityMeta -> entityTypeMap.containsKey(resolvedEntityMeta.getId())) .collect(toList()); } }
EntityTypeDependencyResolver { public List<EntityType> resolve(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return emptyList(); } if (entityTypes.size() == 1) { return singletonList(entityTypes.iterator().next()); } Set<EntityTypeNode> entityTypeNodes = entityTypes.stream() .map(EntityTypeNode::new) .flatMap( node -> Stream.concat(Stream.of(node), expandEntityTypeDependencies(node).stream())) .collect(toCollection(HashSet::new)); List<EntityTypeNode> resolvedEntityMetaNodes = genericDependencyResolver.resolve(entityTypeNodes, getDependencies()); List<EntityType> resolvedEntityMetas = resolvedEntityMetaNodes.stream().map(EntityTypeNode::getEntityType).collect(toList()); if (resolvedEntityMetas.size() == entityTypes.size()) { return resolvedEntityMetas; } else { Map<String, EntityType> entityTypeMap = entityTypes.stream().collect(toMap(EntityType::getId, Function.identity())); return resolvedEntityMetas.stream() .filter(resolvedEntityMeta -> entityTypeMap.containsKey(resolvedEntityMeta.getId())) .collect(toList()); } } }
EntityTypeDependencyResolver { public List<EntityType> resolve(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return emptyList(); } if (entityTypes.size() == 1) { return singletonList(entityTypes.iterator().next()); } Set<EntityTypeNode> entityTypeNodes = entityTypes.stream() .map(EntityTypeNode::new) .flatMap( node -> Stream.concat(Stream.of(node), expandEntityTypeDependencies(node).stream())) .collect(toCollection(HashSet::new)); List<EntityTypeNode> resolvedEntityMetaNodes = genericDependencyResolver.resolve(entityTypeNodes, getDependencies()); List<EntityType> resolvedEntityMetas = resolvedEntityMetaNodes.stream().map(EntityTypeNode::getEntityType).collect(toList()); if (resolvedEntityMetas.size() == entityTypes.size()) { return resolvedEntityMetas; } else { Map<String, EntityType> entityTypeMap = entityTypes.stream().collect(toMap(EntityType::getId, Function.identity())); return resolvedEntityMetas.stream() .filter(resolvedEntityMeta -> entityTypeMap.containsKey(resolvedEntityMeta.getId())) .collect(toList()); } } EntityTypeDependencyResolver(GenericDependencyResolver genericDependencyResolver); }
EntityTypeDependencyResolver { public List<EntityType> resolve(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return emptyList(); } if (entityTypes.size() == 1) { return singletonList(entityTypes.iterator().next()); } Set<EntityTypeNode> entityTypeNodes = entityTypes.stream() .map(EntityTypeNode::new) .flatMap( node -> Stream.concat(Stream.of(node), expandEntityTypeDependencies(node).stream())) .collect(toCollection(HashSet::new)); List<EntityTypeNode> resolvedEntityMetaNodes = genericDependencyResolver.resolve(entityTypeNodes, getDependencies()); List<EntityType> resolvedEntityMetas = resolvedEntityMetaNodes.stream().map(EntityTypeNode::getEntityType).collect(toList()); if (resolvedEntityMetas.size() == entityTypes.size()) { return resolvedEntityMetas; } else { Map<String, EntityType> entityTypeMap = entityTypes.stream().collect(toMap(EntityType::getId, Function.identity())); return resolvedEntityMetas.stream() .filter(resolvedEntityMeta -> entityTypeMap.containsKey(resolvedEntityMeta.getId())) .collect(toList()); } } EntityTypeDependencyResolver(GenericDependencyResolver genericDependencyResolver); List<EntityType> resolve(Collection<EntityType> entityTypes); }
EntityTypeDependencyResolver { public List<EntityType> resolve(Collection<EntityType> entityTypes) { if (entityTypes.isEmpty()) { return emptyList(); } if (entityTypes.size() == 1) { return singletonList(entityTypes.iterator().next()); } Set<EntityTypeNode> entityTypeNodes = entityTypes.stream() .map(EntityTypeNode::new) .flatMap( node -> Stream.concat(Stream.of(node), expandEntityTypeDependencies(node).stream())) .collect(toCollection(HashSet::new)); List<EntityTypeNode> resolvedEntityMetaNodes = genericDependencyResolver.resolve(entityTypeNodes, getDependencies()); List<EntityType> resolvedEntityMetas = resolvedEntityMetaNodes.stream().map(EntityTypeNode::getEntityType).collect(toList()); if (resolvedEntityMetas.size() == entityTypes.size()) { return resolvedEntityMetas; } else { Map<String, EntityType> entityTypeMap = entityTypes.stream().collect(toMap(EntityType::getId, Function.identity())); return resolvedEntityMetas.stream() .filter(resolvedEntityMeta -> entityTypeMap.containsKey(resolvedEntityMeta.getId())) .collect(toList()); } } EntityTypeDependencyResolver(GenericDependencyResolver genericDependencyResolver); List<EntityType> resolve(Collection<EntityType> entityTypes);  }