Search in sources :

Example 21 with Edge

use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.

the class DAGConverter method printDAG.

public static void printDAG(DAG dag) {
    if (dag.nodes != null && dag.edges != null) {
        Map<Integer, Node> nodeMap = ResultDAGConverter.createNodeMap(dag.nodes);
        DirectedAcyclicGraph<Node, Edge> graph = getNodeEdgeDirectedAcyclicGraph(dag, nodeMap);
        DepthFirstIterator<Node, Edge> depthFirstIterator = new DepthFirstIterator<>(graph);
        Node rootNode = null;
        while (depthFirstIterator.hasNext()) {
            depthFirstIterator.setCrossComponentTraversal(false);
            Node node = depthFirstIterator.next();
            if (rootNode == null) {
                rootNode = node;
            }
            DijkstraShortestPath<Node, Edge> path = new DijkstraShortestPath<>(graph, rootNode, node);
            printNode(node, (int) Math.round(path.getPathLength()));
        }
    }
}
Also used : DepthFirstIterator(org.jgrapht.traverse.DepthFirstIterator) Node(org.codice.alliance.nsili.common.UCO.Node) Edge(org.codice.alliance.nsili.common.UCO.Edge) DijkstraShortestPath(org.jgrapht.alg.DijkstraShortestPath)

Example 22 with Edge

use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.

the class DAGConverter method isNodeChildOfStart.

/**
 * Determines if the end node is a child of the start node.
 *
 * @param graph - The complete graph.
 * @param start - Starting node.
 * @param end - Child node to check
 * @return true if the end node is a child of the start node in the provided graph.
 */
private static boolean isNodeChildOfStart(DirectedAcyclicGraph<Node, Edge> graph, Node start, Node end) {
    boolean endNodeInTree = false;
    DepthFirstIterator<Node, Edge> depthFirstIterator = new DepthFirstIterator<>(graph, start);
    while (depthFirstIterator.hasNext()) {
        Node currNode = depthFirstIterator.next();
        if (currNode.id == end.id) {
            endNodeInTree = true;
        }
    }
    return endNodeInTree;
}
Also used : DepthFirstIterator(org.jgrapht.traverse.DepthFirstIterator) Node(org.codice.alliance.nsili.common.UCO.Node) Edge(org.codice.alliance.nsili.common.UCO.Edge)

Example 23 with Edge

use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.

the class DAGConverterTest method testMessageViewConversion.

/**
 * Test the Message View DAG to Metacard
 *
 * <p>NSIL_PRODUCT NSIL_APPROVAL NSIL_CARD NSIL_FILE NSIL_STREAM NSIL_METADATASECURITY
 * NSIL_RELATED_FILE NSIL_SECURITY NSIL_PART NSIL_SECURITY NSIL_COMMON NSIL_COVERAGE
 * NSIL_EXPLOITATION_INFO NSIL_MESSAGE NSIL_ASSOCIATION NSIL_RELATION NSIL_SOURCE NSIL_CARD
 * NSIL_DESTINATION NSIL_CARD
 */
@Test
public void testMessageViewConversion() {
    DAG dag = new DAG();
    DirectedAcyclicGraph<Node, Edge> graph = new DirectedAcyclicGraph<>(Edge.class);
    Node productNode = createRootNode();
    graph.addVertex(productNode);
    addCardNode(graph, productNode);
    addFileNode(graph, productNode);
    addStreamNode(graph, productNode);
    addMetadataSecurity(graph, productNode);
    addSecurityNode(graph, productNode);
    addMessagePart(graph, productNode);
    graph.addVertex(productNode);
    NsiliCommonUtils.setUCOEdgeIds(graph);
    NsiliCommonUtils.setUCOEdges(productNode, graph);
    dag.edges = NsiliCommonUtils.getEdgeArrayFromGraph(graph);
    dag.nodes = NsiliCommonUtils.getNodeArrayFromGraph(graph);
    MetacardImpl metacard = dagConverter.convertDAG(dag, false, SOURCE_ID);
    if (SHOULD_PRINT_CARD) {
        File file = new File("/tmp/output-message.txt");
        if (file.exists()) {
            file.delete();
        }
        try (PrintStream outStream = new PrintStream(file)) {
            printMetacard(metacard, outStream);
        } catch (IOException ioe) {
        // Ignore the error
        }
    }
    // Check top-level meta-card attributes
    assertThat(metacard.getId(), is(CARD_ID));
    assertThat(metacard.getCreatedDate(), notNullValue());
    assertThat(metacard.getEffectiveDate(), notNullValue());
    assertThat(metacard.getModifiedDate(), is(cal.getTime()));
    assertThat(metacard.getLocation(), is(WKT_LOCATION));
    assertThat(metacard.getAttribute(Core.RESOURCE_URI).getValue().toString(), is(FILE_PRODUCT_URL));
    checkCommonAttributes(metacard);
    checkExploitationInfoAttributes(metacard);
    checkSecurityAttributes(metacard);
    checkCoverageAttributes(metacard);
}
Also used : PrintStream(java.io.PrintStream) Node(org.codice.alliance.nsili.common.UCO.Node) DAG(org.codice.alliance.nsili.common.UCO.DAG) IOException(java.io.IOException) Edge(org.codice.alliance.nsili.common.UCO.Edge) File(java.io.File) DirectedAcyclicGraph(org.jgrapht.experimental.dag.DirectedAcyclicGraph) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 24 with Edge

use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.

the class DAGConverterTest method testCCIRMRFIViewConversion.

/**
 * Test the Message View DAG to Metacard
 *
 * <p>NSIL_PRODUCT NSIL_APPROVAL NSIL_CARD NSIL_STREAM NSIL_FILE NSIL_METADATASECURITY
 * NSIL_RELATED_FILE NSIL_SECURITY NSIL_PART NSIL_SECURITY NSIL_COMMON NSIL_COVERAGE
 * NSIL_EXPLOITATION_INFO NSIL_RFI NSIL_ASSOCIATION NSIL_RELATION NSIL_SOURCE NSIL_CARD
 * NSIL_DESTINATION NSIL_CARD
 */
@Test
public void testCCIRMRFIViewConversion() {
    DAG dag = new DAG();
    DirectedAcyclicGraph<Node, Edge> graph = new DirectedAcyclicGraph<>(Edge.class);
    Node productNode = createRootNode();
    graph.addVertex(productNode);
    addCardNode(graph, productNode);
    addFileNode(graph, productNode);
    addMetadataSecurity(graph, productNode);
    addSecurityNode(graph, productNode);
    addRFIPart(graph, productNode);
    graph.addVertex(productNode);
    NsiliCommonUtils.setUCOEdgeIds(graph);
    NsiliCommonUtils.setUCOEdges(productNode, graph);
    dag.edges = NsiliCommonUtils.getEdgeArrayFromGraph(graph);
    dag.nodes = NsiliCommonUtils.getNodeArrayFromGraph(graph);
    MetacardImpl metacard = dagConverter.convertDAG(dag, false, SOURCE_ID);
    if (SHOULD_PRINT_CARD) {
        File file = new File("/tmp/output-ccirm-rfi.txt");
        if (file.exists()) {
            file.delete();
        }
        try (PrintStream outStream = new PrintStream(file)) {
            printMetacard(metacard, outStream);
        } catch (IOException ioe) {
        // Ignore the error
        }
    }
    // Check top-level meta-card attributes
    assertThat(metacard.getTitle(), is(FILE_TITLE));
    assertThat(metacard.getId(), is(CARD_ID));
    assertThat(metacard.getCreatedDate(), notNullValue());
    assertThat(metacard.getEffectiveDate(), notNullValue());
    assertThat(metacard.getModifiedDate(), is(cal.getTime()));
    assertThat(metacard.getDescription(), is(COM_DESCRIPTION_ABSTRACT));
    assertThat(metacard.getLocation(), is(WKT_LOCATION));
    assertThat(metacard.getAttribute(Core.RESOURCE_URI).getValue().toString(), is(FILE_PRODUCT_URL));
    checkCommonAttributes(metacard);
    checkExploitationInfoAttributes(metacard);
    checkRFIAttributes(metacard);
    checkSecurityAttributes(metacard);
    checkCoverageAttributes(metacard);
}
Also used : PrintStream(java.io.PrintStream) Node(org.codice.alliance.nsili.common.UCO.Node) DAG(org.codice.alliance.nsili.common.UCO.DAG) IOException(java.io.IOException) Edge(org.codice.alliance.nsili.common.UCO.Edge) File(java.io.File) DirectedAcyclicGraph(org.jgrapht.experimental.dag.DirectedAcyclicGraph) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 25 with Edge

use of org.codice.alliance.nsili.common.UCO.Edge in project alliance by codice.

the class DAGConverterTest method testEndNodeOfEdgeNull.

@Test
public void testEndNodeOfEdgeNull() {
    DAG dag = new DAG();
    DirectedAcyclicGraph<Node, Edge> graph = new DirectedAcyclicGraph<>(Edge.class);
    // Create invalid root node
    Node rootNode = createRootNode();
    graph.addVertex(rootNode);
    Edge[] edges = new Edge[1];
    Edge edge = new Edge(1, 2, "");
    edges[0] = edge;
    dag.nodes = NsiliCommonUtils.getNodeArrayFromGraph(graph);
    dag.edges = edges;
    MetacardImpl metacard = dagConverter.convertDAG(dag, false, SOURCE_ID);
    assertThat(metacard.getTitle(), nullValue());
}
Also used : Node(org.codice.alliance.nsili.common.UCO.Node) DAG(org.codice.alliance.nsili.common.UCO.DAG) Edge(org.codice.alliance.nsili.common.UCO.Edge) DirectedAcyclicGraph(org.jgrapht.experimental.dag.DirectedAcyclicGraph) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

Edge (org.codice.alliance.nsili.common.UCO.Edge)31 Node (org.codice.alliance.nsili.common.UCO.Node)31 DirectedAcyclicGraph (org.jgrapht.experimental.dag.DirectedAcyclicGraph)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)21 DAG (org.codice.alliance.nsili.common.UCO.DAG)21 Test (org.junit.Test)19 File (java.io.File)11 IOException (java.io.IOException)11 PrintStream (java.io.PrintStream)11 DepthFirstIterator (org.jgrapht.traverse.DepthFirstIterator)6 ArrayList (java.util.ArrayList)4 Metacard (ddf.catalog.data.Metacard)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 Serializable (java.io.Serializable)1 ArrayDeque (java.util.ArrayDeque)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Product (org.codice.alliance.nsili.common.UID.Product)1 DijkstraShortestPath (org.jgrapht.alg.DijkstraShortestPath)1 ConnectedComponentTraversalEvent (org.jgrapht.event.ConnectedComponentTraversalEvent)1