Search in sources :

Example 11 with Graph

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

the class DataAccessUtilities method saveDataAccessState.

/**
 * Build a data access state from the passed tab pane and save it to the graph.
 * <p/>
 * Currently only global parameters are saved.
 *
 * @param tabs the tab pane to build the new data access state from
 * @param graph the active graph to save the state to
 */
public static void saveDataAccessState(final TabPane tabs, final Graph graph) {
    if (graph != null) {
        // Build a new data access state from the passed tabs
        final DataAccessState dataAccessState = new DataAccessState();
        tabs.getTabs().forEach(step -> {
            dataAccessState.newTab();
            DataAccessTabPane.getQueryPhasePane(step).getGlobalParametersPane().getParams().getParameters().entrySet().stream().filter(entry -> entry.getValue().getStringValue() != null).forEach(entry -> dataAccessState.add(entry.getKey(), entry.getValue().getStringValue()));
        });
        // Save the state onto the graph
        WritableGraph wg = null;
        try {
            wg = graph.getWritableGraph("Update Data Access State", true);
            final int dataAccessStateAttribute = DataAccessConcept.MetaAttribute.DATAACCESS_STATE.ensure(wg);
            wg.setObjectValue(dataAccessStateAttribute, 0, dataAccessState);
        } catch (final InterruptedException ex) {
            Exceptions.printStackTrace(ex);
            Thread.currentThread().interrupt();
        } finally {
            if (wg != null) {
                wg.commit();
            }
        }
    }
}
Also used : TopComponent(org.openide.windows.TopComponent) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) InvocationTargetException(java.lang.reflect.InvocationTargetException) Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) SwingUtilities(javax.swing.SwingUtilities) TabPane(javafx.scene.control.TabPane) Tab(javafx.scene.control.Tab) Exceptions(org.openide.util.Exceptions) WindowManager(org.openide.windows.WindowManager) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) DataAccessViewTopComponent(au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent) DataAccessConcept(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessConcept) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 12 with Graph

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

the class DataAccessPaneNGTest method update_pass_non_null_graph.

@Test
public void update_pass_non_null_graph() {
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final Tab currentTab = mock(Tab.class);
    final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
    final DataSourceTitledPane dataSourceTitledPane = mock(DataSourceTitledPane.class);
    final Plugin plugin = mock(Plugin.class);
    final PluginParameters pluginParameters = mock(PluginParameters.class);
    final Graph graph = mock(Graph.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
    when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
    when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane));
    when(dataSourceTitledPane.getPlugin()).thenReturn(plugin);
    when(dataSourceTitledPane.getParameters()).thenReturn(pluginParameters);
    when(graph.getId()).thenReturn("graphId");
    dataAccessPane.update(graph);
    verify(plugin).updateParameters(graph, pluginParameters);
    verify(dataAccessPane).update("graphId");
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Graph(au.gov.asd.tac.constellation.graph.Graph) Tab(javafx.scene.control.Tab) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 13 with Graph

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

the class QueryPhasePaneNGTest method testRunPlugins.

@Test
public void testRunPlugins() {
    // Initialize the current graph in the state.
    DataAccessPaneState.setCurrentGraphId("GraphId");
    final QueryPhasePane instance = spy(new QueryPhasePane(new HashMap<>(), null, null));
    // Setup the graph manager
    final GraphManager graphManager = mock(GraphManager.class);
    final Graph graph = mock(Graph.class);
    when(graphManager.getActiveGraph()).thenReturn(graph);
    // Setup the global parameters
    final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
    final PluginParameters globalPluginParameters = mock(PluginParameters.class);
    final PluginParameter globalPluginParameter1 = mock(PluginParameter.class);
    final PluginParameter globalPluginParameter2 = mock(PluginParameter.class);
    doReturn(globalParametersPane).when(instance).getGlobalParametersPane();
    when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
    when(globalPluginParameters.getParameters()).thenReturn(Map.of("abc.parameter1", globalPluginParameter1, "global.parameter1", globalPluginParameter2));
    when(globalPluginParameter1.getObjectValue()).thenReturn("GLOBAL PARAMETER 1");
    // Setup data access panes
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    doReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2)).when(instance).getDataAccessPanes();
    // Pane 1 is disabled so will not be run
    when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
    when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
    // Setup the plugin for pane 2
    final Plugin plugin = mock(Plugin.class);
    when(plugin.getName()).thenReturn("Plugin Name");
    when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin);
    // Pane 2 has two parameters. One of them matches in name to one of
    // the global parameters which means its value will be overriden with
    // the global value.
    final PluginParameters pluginParameters = mock(PluginParameters.class);
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    when(pluginParameters.getParameters()).thenReturn(Map.of("abc.parameter1", pluginParameter1, "abc.parameter2", pluginParameter2));
    when(pluginParameters.copy()).thenReturn(pluginParameters);
    when(dataSourceTitledPane2.getParameters()).thenReturn(pluginParameters);
    try (final MockedStatic<PluginRegistry> pluginRegistry = Mockito.mockStatic(PluginRegistry.class);
        final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class);
        final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class);
        final MockedConstruction<PluginSynchronizer> pluginSynchMocks = Mockito.mockConstruction(PluginSynchronizer.class, (pluginSyncMock, cnxt) -> {
            assertEquals(cnxt.arguments(), List.of(1));
        })) {
        // Not sure why this is being done but just retuning the same plugin
        // to save creating another mock.
        pluginRegistry.when(() -> PluginRegistry.get(plugin.getClass().getName())).thenReturn(plugin);
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        // This is the future that will be returned when the plugin begins execution
        final Future future = CompletableFuture.completedFuture("Plugin Complete!");
        // This is the future of a plugin that was run previously
        final Future existingFuture = CompletableFuture.completedFuture("Previous Plugin Complete!");
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(plugin)).thenReturn(pluginExecution);
        // We don't need to verify any of these again (with the exception of the plugin synchronizer)
        // because a null pointer will happen if any of the params don't match up.
        when(pluginExecution.withParameters(pluginParameters)).thenReturn(pluginExecution);
        when(pluginExecution.waitingFor(List.of(existingFuture))).thenReturn(pluginExecution);
        when(pluginExecution.synchronizingOn(any(PluginSynchronizer.class))).thenReturn(pluginExecution);
        when(pluginExecution.executeLater(graph)).thenReturn(future);
        // Verify that the return contains the plugin future as defined above
        assertEquals(instance.runPlugins(List.of(existingFuture)), List.of(future));
        // Verify the state's running plugin list has been updated
        assertEquals(DataAccessPaneState.getRunningPlugins(), Map.of(future, "Plugin Name"));
        // Verify the local plugin parameter was updated with the global parameter value
        verify(pluginParameter1).setObjectValue("GLOBAL PARAMETER 1");
        // Verify the created plugin synchronizer is passed to the plugin execution
        verify(pluginExecution).synchronizingOn(pluginSynchMocks.constructed().get(0));
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginSynchronizer(au.gov.asd.tac.constellation.plugins.PluginSynchronizer) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) HashMap(java.util.HashMap) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginRegistry(au.gov.asd.tac.constellation.plugins.PluginRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) Test(org.testng.annotations.Test)

Example 14 with Graph

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

the class ExtractWordsFromTextPluginNGTest method testUpdateParameters.

/**
 * Test updateParameters
 */
@Test
public void testUpdateParameters() {
    ExtractWordsFromTextPlugin instance = new ExtractWordsFromTextPlugin();
    PluginParameters parameters = new PluginParameters();
    final PluginParameter<SingleChoiceParameterValue> attributeType = SingleChoiceParameterType.build(ATTRIBUTE_PARAMETER_ID);
    parameters.addParameter(attributeType);
    final PluginParameter<StringParameterValue> textParameter = StringParameterType.build(WORDS_PARAMETER_ID);
    textParameter.setStringValue("text");
    parameters.addParameter(textParameter);
    final PluginParameter<BooleanParameterValue> useRegexParameter = BooleanParameterType.build(USE_REGEX_PARAMETER_ID);
    useRegexParameter.setBooleanValue(true);
    parameters.addParameter(useRegexParameter);
    Graph graph1 = new DualGraph(graph.getSchema(), graph);
    instance.updateParameters(graph1, parameters);
    assertEquals(parameters.getParameters().size(), 3);
    assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.ATTRIBUTE_PARAMETER_ID));
    assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.WORDS_PARAMETER_ID).getStringValue(), "text");
    assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.USE_REGEX_PARAMETER_ID).getBooleanValue(), true);
    assertFalse(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
    parameters = instance.createParameters();
    instance.updateParameters(graph1, parameters);
    assertEquals(parameters.getParameters().size(), 11);
    assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 15 with Graph

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

the class RecordStoreQueryPluginNGTest method testEdit.

/**
 * Test of edit method, of class RecordStoreQueryPlugin.
 */
@Test
public void testEdit() throws InterruptedException, PluginException {
    System.out.println("edit");
    final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    // only using a dual graph because of the need to pass a GraphWriteMethods graph to the edit() method.
    final Graph graph = new DualGraph(schema);
    final PluginInteraction interaction = null;
    final PluginParameters parameters = null;
    ReadableGraph rg = graph.getReadableGraph();
    try {
        instance.read(rg, interaction, parameters);
        instance.query(interaction, parameters);
    } finally {
        rg.release();
    }
    GraphRecordStore query;
    rg = graph.getReadableGraph();
    try {
        query = GraphRecordStoreUtilities.getAll(rg, false, false);
    } finally {
        rg.release();
    }
    final WritableGraph wg = graph.getWritableGraph("", true);
    try {
        VisualConcept.VertexAttribute.X.ensure(wg);
        VisualConcept.VertexAttribute.Y.ensure(wg);
        VisualConcept.VertexAttribute.Z.ensure(wg);
        VisualConcept.GraphAttribute.CAMERA.ensure(wg);
        instance.edit(wg, interaction, parameters);
    } finally {
        wg.commit();
    }
    rg = graph.getReadableGraph();
    try {
        query = GraphRecordStoreUtilities.getTransactions(rg, false, false);
    } finally {
        rg.release();
    }
    // verify nothing has moved
    query.reset();
    query.next();
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "20.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "20.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "20.0");
    query.next();
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "40.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "40.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "40.0");
}
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) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

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