Search in sources :

Example 1 with DirectedPseudograph

use of org.jgrapht.graph.DirectedPseudograph in project admin-console-beta by connexta.

the class CreateFeatureDependencyGraph method createFeatureDependenciesGraph.

private DirectedGraph<Field, DependencyEdge> createFeatureDependenciesGraph(List<FeatureField> features) {
    DirectedGraph<Field, DependencyEdge> graph = new DirectedPseudograph<>(DependencyEdge.class);
    FEATURE_BUNDLE_VERTEX_PROV.getAttributes().forEach(attri -> exporter.registerAttribute(attri.getAttriName(), attri.getCategory(), attri.getType()));
    features.forEach(graph::addVertex);
    Map<String, FeatureField> featuresById = features.stream().collect(Collectors.toMap(FeatureField::id, f -> f));
    for (FeatureField feature : features) {
        for (String featId : feature.featDeps()) {
            try {
                Feature feat = featureUtils.getFeature(featId);
                if (feat != null && featuresById.containsKey(feat.getId())) {
                    graph.addEdge(feature, featuresById.get(feat.getId()), DependencyEdge.create(null));
                } else {
                    LOGGER.error("Failed to find feature {} while creating feature dependency graph.", featId);
                }
            } catch (Exception e) {
                LOGGER.error("Failed to find feature {} while creating feature dependency graph.", featId, e);
            }
        }
        feature.bundleDeps().forEach(dep -> {
            graph.addVertex(dep);
            graph.addEdge(feature, dep, DependencyEdge.create(null));
        });
    }
    return graph;
}
Also used : DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) LoggerFactory(org.slf4j.LoggerFactory) DIRECTORY_DOES_NOT_EXIST(org.codice.ddf.admin.common.report.message.DefaultMessages.DIRECTORY_DOES_NOT_EXIST) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField) DefaultMessages.failedPersistError(org.codice.ddf.admin.common.report.message.DefaultMessages.failedPersistError) ImmutableList(com.google.common.collect.ImmutableList) FAILED_PERSIST(org.codice.ddf.admin.common.report.message.DefaultMessages.FAILED_PERSIST) Map(java.util.Map) BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) Field(org.codice.ddf.admin.api.Field) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) BaseFunctionField(org.codice.ddf.admin.common.fields.base.BaseFunctionField) Feature(org.apache.karaf.features.Feature) Set(java.util.Set) GraphMLExporter(org.jgrapht.ext.GraphMLExporter) Collectors(java.util.stream.Collectors) FeatureUtils(org.codice.ddf.admin.query.dev.system.dependency.FeatureUtils) List(java.util.List) Paths(java.nio.file.Paths) DependencyEdge(org.codice.ddf.admin.query.dev.system.graph.DependencyEdge) DirectedGraph(org.jgrapht.DirectedGraph) FeatureGraphProvider(org.codice.ddf.admin.query.dev.system.graph.FeatureGraphProvider) DirectoryField(org.codice.ddf.admin.common.fields.common.DirectoryField) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField) BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) Field(org.codice.ddf.admin.api.Field) BaseFunctionField(org.codice.ddf.admin.common.fields.base.BaseFunctionField) DirectoryField(org.codice.ddf.admin.common.fields.common.DirectoryField) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField) DependencyEdge(org.codice.ddf.admin.query.dev.system.graph.DependencyEdge) Feature(org.apache.karaf.features.Feature) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph)

Example 2 with DirectedPseudograph

use of org.jgrapht.graph.DirectedPseudograph in project Smack by igniterealtime.

the class ModularXmppClientToServerConnectionStateGraphTest method testStateGraphDotOutput.

@Test
public void testStateGraphDotOutput() throws IOException, ImportException {
    URL stateGraphDotFileUrl = Resources.getResource("state-graph.dot");
    String expectedStateGraphDot = Resources.toString(stateGraphDotFileUrl, StandardCharsets.UTF_8);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ModularXmppClientToServerConnectionTool.printStateGraph(pw, false);
    String currentStateGraphDot = sw.toString();
    @SuppressWarnings("serial") DOTImporter<String, DefaultEdge> dotImporter = new DOTImporter<>((id, attributes) -> id, (from, to, label, attributes) -> {
        return new DefaultEdge() {

            @Override
            public int hashCode() {
                return HashCode.builder().append(getSource()).append(getTarget()).build();
            }

            @Override
            public boolean equals(Object other) {
                return EqualsUtil.equals(this, other, (b, o) -> b.append(getSource(), o.getSource()).append(getTarget(), o.getTarget()));
            }
        };
    });
    DirectedPseudograph<String, DefaultEdge> currentStateGraph = new DirectedPseudograph<>(DefaultEdge.class);
    DirectedPseudograph<String, DefaultEdge> expectedStateGraph = new DirectedPseudograph<>(DefaultEdge.class);
    dotImporter.importGraph(expectedStateGraph, new StringReader(expectedStateGraphDot));
    dotImporter.importGraph(currentStateGraph, new StringReader(currentStateGraphDot));
    assertEquals(expectedStateGraph, currentStateGraph);
}
Also used : DOTImporter(org.jgrapht.io.DOTImporter) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) DefaultEdge(org.jgrapht.graph.DefaultEdge) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) URL(java.net.URL) PrintWriter(java.io.PrintWriter) Test(org.junit.jupiter.api.Test)

Example 3 with DirectedPseudograph

use of org.jgrapht.graph.DirectedPseudograph in project admin-console-beta by connexta.

the class CreateServiceDependencyGraph method createServiceDepsGraph.

private DirectedGraph<BundleField, DependencyEdge<ServiceReferenceField>> createServiceDepsGraph(List<BundleField> bundles) {
    DirectedGraph graph = new DirectedPseudograph<>(ServiceReferenceField.class);
    bundles.forEach(graph::addVertex);
    bundles.forEach(bundle -> populateGraphWithServices(bundle, graph, bundles));
    return graph;
}
Also used : DirectedGraph(org.jgrapht.DirectedGraph) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph)

Example 4 with DirectedPseudograph

use of org.jgrapht.graph.DirectedPseudograph in project admin-console-beta by connexta.

the class CreatePackageDependencyGraph method createPkgDependencyGraph.

private DirectedGraph<BundleField, DependencyEdge<PackageField>> createPkgDependencyGraph() {
    DirectedGraph graph = new DirectedPseudograph<>(ServiceReferenceField.class);
    List<BundleField> allBundles = bundleUtils.getAllBundleFields();
    allBundles.forEach(graph::addVertex);
    allBundles.forEach(bundle -> createEdgesFromPkgs(bundle, graph, allBundles));
    return graph;
}
Also used : BundleField(org.codice.ddf.admin.query.dev.system.fields.BundleField) DirectedGraph(org.jgrapht.DirectedGraph) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph)

Aggregations

DirectedPseudograph (org.jgrapht.graph.DirectedPseudograph)4 DirectedGraph (org.jgrapht.DirectedGraph)3 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Feature (org.apache.karaf.features.Feature)1 Field (org.codice.ddf.admin.api.Field)1 FunctionField (org.codice.ddf.admin.api.fields.FunctionField)1 BaseFunctionField (org.codice.ddf.admin.common.fields.base.BaseFunctionField)1 BooleanField (org.codice.ddf.admin.common.fields.base.scalar.BooleanField)1 DirectoryField (org.codice.ddf.admin.common.fields.common.DirectoryField)1 DIRECTORY_DOES_NOT_EXIST (org.codice.ddf.admin.common.report.message.DefaultMessages.DIRECTORY_DOES_NOT_EXIST)1