Search in sources :

Example 21 with Graph

use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.

the class DataAccessUtilitiesNGTest method loadDataAccessState_empty_state.

@Test
public void loadDataAccessState_empty_state() {
    // mock graph
    final Graph graph = mock(Graph.class);
    final ReadableGraph rGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(rGraph);
    // mock data access state attribute in graph
    when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
    when(rGraph.getObjectValue(2, 0)).thenReturn(new DataAccessState());
    // mock tab pane
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final Tab currentTab = mock(Tab.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
    try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
        daTabPaneMockedStatic.verifyNoInteractions();
        verify(rGraph).release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Tab(javafx.scene.control.Tab) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) Test(org.testng.annotations.Test)

Example 22 with Graph

use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.

the class TransactionQuickSearchProvider method evaluate.

/**
 * Determines whether any content from the current Graph matches the search
 * term.
 *
 * @param request The content being entered into the QuickSearch box.
 * @param response The content to be returned to the QuickSearch box.
 */
@Override
@SuppressWarnings("unchecked")
public void evaluate(final SearchRequest request, final SearchResponse response) {
    final Graph graph = graphRetriever.getGraph();
    if (graph != null) {
        final QuickFindPlugin plugin = new QuickFindPlugin(GraphElementType.TRANSACTION, request.getText());
        final Future<?> future = PluginExecution.withPlugin(plugin).interactively(true).executeLater(graph);
        // Wait for results:
        try {
            future.get();
        } catch (final InterruptedException ex) {
            LOGGER.log(Level.SEVERE, "Quick Find was interrupted", ex);
            Thread.currentThread().interrupt();
        } catch (final ExecutionException ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
        final List<FindResult> results = plugin.getResults();
        for (FindResult item : results) {
            if (item != null) {
                // We have a valid result, so report:
                response.addResult(new SelectContent(graph, item), item.toString());
            }
        }
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) ExecutionException(java.util.concurrent.ExecutionException) QuickFindPlugin(au.gov.asd.tac.constellation.views.find.advanced.QuickFindPlugin) FindResult(au.gov.asd.tac.constellation.views.find.advanced.FindResult)

Example 23 with Graph

use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.

the class FindViewControllerNGTest method testReplaceMatchingElements.

// // Populate the attribute list with the attributes of the given type
// for (Graph graph : gm.getAllGraphs().values()) {
// try {
// System.out.println("in for graph try");
// 
// WritableGraph wg = graph.getWritableGraph("", true);
// for (int i = 0; i < stringAttributeList.size(); i++) {
// int attributeInt = wg.getAttribute(type, stringAttributeList.get(i));
// attributes.add(new GraphAttribute(wg, attributeInt));
// System.out.println(attributes.get(i).getName() + " = attribute name");
// 
// }
// 
// instance.updateBasicFindParameters(parameters);
// 
// System.out.println("before method call");
// 
// instance.retriveMatchingElements(true, false);
// 
// System.out.println("before assert");
// System.out.println(wg.getStringValue(labelV, vxId1));
// 
// System.out.println(wg.getBooleanValue(selectedV, vxId1));
// assertEquals(wg.getBooleanValue(selectedV, vxId1), true);
// System.out.println("after equals");
// 
// wg.commit();
// 
// } catch (final InterruptedException ex) {
// Exceptions.printStackTrace(ex);
// Thread.currentThread().interrupt();
// }
// 
// }
// 
// }
/**
 * Test of replaceMatchingElements method, of class FindViewController.
 */
@Test
public void testReplaceMatchingElements() {
    System.out.println("replaceMatchingElements");
    /**
     * Set up the graph with 4 vertexs, 4 transactions, 3 vertex attributes
     * (2 of type string), 3 transaction attributes (2 of type string)
     */
    setupGraph();
    /**
     * Create a mock of the top component, get an instance of the
     * controller, create a mock of the graph manager, when getAllGraphs is
     * called return the graphMap created in this class
     */
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    when(gm.getActiveGraph()).thenReturn(graph);
    System.out.println("before try");
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        System.out.println("in try");
        try (MockedStatic<PluginExecution> mockedStaticPlugin = Mockito.mockStatic(PluginExecution.class)) {
            PluginExecution pluginExecution = mock(PluginExecution.class);
            /**
             * The first test should execute the plugin once on graph as the
             * parameters are not set to look at all graphs
             */
            when(pluginExecution.executeLater(Mockito.eq(graph))).thenReturn(null);
            mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
            instance.replaceMatchingElements(true, false);
            verify(pluginExecution).executeLater(Mockito.eq(graph));
            /**
             * Set the parameters to find in all graphs and repeat the same
             * process. The plugin should be executed on graph a second
             * time, and should be executed on graph2 for the first time.
             */
            instance.updateBasicReplaceParameters(parametersAllGraphs);
            when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
            mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
            instance.replaceMatchingElements(true, false);
            verify(pluginExecution, times(2)).executeLater(Mockito.eq(graph));
            verify(pluginExecution).executeLater(Mockito.eq(graph2));
        }
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 24 with Graph

use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.

the class CompareGraphPlugin method read.

@Override
protected void read(final GraphReadMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final String originalGraphName = parameters.getParameters().get(ORIGINAL_GRAPH_PARAMETER_ID).getStringValue();
    final String compareGraphName = parameters.getParameters().get(COMPARE_GRAPH_PARAMETER_ID).getStringValue();
    if (originalGraphName == null || compareGraphName == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "You must choose two graphs to compare");
    }
    final List<String> ignoreVertexAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_VERTEX_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
    final List<String> ignoreTransactionAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
    final ConstellationColor addedColour = parameters.getParameters().get(ADDED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor removedColour = parameters.getParameters().get(REMOVED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor changedColour = parameters.getParameters().get(CHANGED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor unchangedColour = parameters.getParameters().get(UNCHANGED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor addedColourValue = ConstellationColor.getColorValue(addedColour.getRed(), addedColour.getGreen(), addedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor removedColourValue = ConstellationColor.getColorValue(removedColour.getRed(), removedColour.getGreen(), removedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor changedColourValue = ConstellationColor.getColorValue(changedColour.getRed(), changedColour.getGreen(), changedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor unchangedColourValue = ConstellationColor.getColorValue(unchangedColour.getRed(), unchangedColour.getGreen(), unchangedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final Graph originalGraph = getGraphFromName(originalGraphName);
    final Graph compareGraph = getGraphFromName(compareGraphName);
    if (originalGraph == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, originalGraphName));
    }
    if (compareGraph == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, compareGraphName));
    }
    final GraphRecordStore originalAll;
    final GraphRecordStore compareAll;
    final Set<String> vertexPrimaryKeys;
    final Set<String> transactionPrimaryKeys;
    // get a copy of the graph's record store and statistical info
    ReadableGraph rg = originalGraph.getReadableGraph();
    try {
        originalAll = GraphRecordStoreUtilities.getAll(rg, false, true);
        vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.VERTEX);
        transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.TRANSACTION);
    } finally {
        rg.release();
    }
    rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    // ignore the id attributes to avoid reporting on them
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // graph changes
    final String title = String.format("Compare: %s <> %s", originalGraphName, compareGraphName);
    final GraphRecordStore changes = compareGraphs(title, originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, addedColourValue, removedColourValue, changedColourValue, unchangedColourValue);
    // create new graph
    createComparisonGraph(originalGraph, changes);
    interaction.setProgress(1, 0, changes + " changes were found.", true);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)

Example 25 with Graph

use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.

the class CompareGraphPlugin method createComparisonGraph.

/**
 * Create the comparison graph using the original graph as the starting
 * point and add the result record store
 *
 * @param originalGraph
 * @param changes
 * @param initializeWithSchema
 * @param completeWithSchema
 * @return
 * @throws InterruptedException
 */
protected Graph createComparisonGraph(final Graph originalGraph, final GraphRecordStore changes) throws InterruptedException {
    Graph copy;
    final ReadableGraph rg = originalGraph.getReadableGraph();
    try {
        try {
            final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
            final PluginParameters copyParams = copyGraphPlugin.createParameters();
            copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
            PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow(rg);
            copy = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
        } catch (final PluginException ex) {
            copy = null;
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
        if (copy == null) {
            // The copy failed, drop out now.
            return null;
        }
    } finally {
        rg.release();
    }
    final List<String> vertexIdAttributes = new ArrayList<>();
    vertexIdAttributes.add(VisualConcept.VertexAttribute.LABEL.getName() + "<string>");
    final WritableGraph wgcopy = copy.getWritableGraph("Add changes", true);
    try {
        changes.reset();
        GraphRecordStoreUtilities.addRecordStoreToGraph(wgcopy, changes, false, false, null);
        final int vertexColorReferenceAttribute = VisualConcept.GraphAttribute.NODE_COLOR_REFERENCE.ensure(wgcopy);
        final int transactionColorReferenceAttribute = VisualConcept.GraphAttribute.TRANSACTION_COLOR_REFERENCE.ensure(wgcopy);
        wgcopy.setObjectValue(vertexColorReferenceAttribute, 0, VisualConcept.VertexAttribute.OVERLAY_COLOR.getName());
        wgcopy.setObjectValue(transactionColorReferenceAttribute, 0, VisualConcept.TransactionAttribute.OVERLAY_COLOR.getName());
    } finally {
        wgcopy.commit();
    }
    // only returning this so that this method can be tested
    return copy;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) SimpleReadPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleReadPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Aggregations

Graph (au.gov.asd.tac.constellation.graph.Graph)211 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)86 Test (org.testng.annotations.Test)65 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)40 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)36 ArrayList (java.util.ArrayList)32 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)31 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)30 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)26 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)26 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)21 List (java.util.List)21 ExecutionException (java.util.concurrent.ExecutionException)21 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)20 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)20 IOException (java.io.IOException)20 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)17 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)17 File (java.io.File)17 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)16