use of org.graylog2.contentpacks.exceptions.UnexpectedEntitiesException in project graylog2-server by Graylog2.
the class ContentPackService method buildEntityGraph.
private ImmutableGraph<Entity> buildEntityGraph(Entity rootEntity, Set<Entity> entities, Map<String, ValueReference> parameters) {
final Map<EntityDescriptor, Entity> entityDescriptorMap = entities.stream().collect(Collectors.toMap(Entity::toEntityDescriptor, Function.identity()));
final MutableGraph<Entity> dependencyGraph = GraphBuilder.directed().allowsSelfLoops(false).expectedNodeCount(entities.size()).build();
for (Map.Entry<EntityDescriptor, Entity> entry : entityDescriptorMap.entrySet()) {
final EntityDescriptor entityDescriptor = entry.getKey();
final Entity entity = entry.getValue();
final EntityWithExcerptFacade<?, ?> facade = entityFacades.getOrDefault(entity.type(), UnsupportedEntityFacade.INSTANCE);
final Graph<Entity> entityGraph = facade.resolveForInstallation(entity, parameters, entityDescriptorMap);
LOG.trace("Dependencies of entity {}: {}", entityDescriptor, entityGraph);
dependencyGraph.putEdge(rootEntity, entity);
Graphs.merge(dependencyGraph, entityGraph);
LOG.trace("New dependency graph: {}", dependencyGraph);
}
final Set<Entity> unexpectedEntities = dependencyGraph.nodes().stream().filter(entity -> !rootEntity.equals(entity)).filter(entity -> !entities.contains(entity)).collect(Collectors.toSet());
if (!unexpectedEntities.isEmpty()) {
throw new UnexpectedEntitiesException(unexpectedEntities);
}
return ImmutableGraph.copyOf(dependencyGraph);
}
Aggregations