Search in sources :

Example 16 with Graph

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

the class FindViewController method populateAllAttributes.

/**
 * Returns a list of all available attributes on all open graphs. Used for
 * the attributes in the advanced find tab.
 *
 * @param type
 * @param attributeModificationCounter
 * @return
 */
public List<Attribute> populateAllAttributes(final GraphElementType type, final long attributeModificationCounter) {
    final List<Attribute> allAttributes = new ArrayList<>();
    for (final Graph graph : GraphManager.getDefault().getAllGraphs().values()) {
        // Call the plugin that retrieves all current attributes on the graph
        final GraphAttributePlugin attrPlugin = new GraphAttributePlugin(type, allAttributes, attributeModificationCounter);
        final Future<?> future = PluginExecution.withPlugin(attrPlugin).interactively(true).executeLater(graph);
        // Wait for the search to find its results:
        try {
            future.get();
        } catch (final InterruptedException ex) {
            LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
            Thread.currentThread().interrupt();
        } catch (final ExecutionException ex) {
            LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        }
        // get all the current attributes based on the currently selcted type
        allAttributes.addAll(attrPlugin.getAttributes());
    }
    final Set<Attribute> attributeSet = new LinkedHashSet<>();
    attributeSet.addAll(allAttributes);
    allAttributes.clear();
    allAttributes.addAll(attributeSet);
    allAttributes.sort(Comparator.comparing(Attribute::getName));
    return allAttributes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttributePlugin(au.gov.asd.tac.constellation.views.find2.plugins.GraphAttributePlugin) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with Graph

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

the class FindTopComponent method setDefaultFindCriteriaPanels.

/**
 * add set of find criteria panel based on primary keys, otherwise just add
 * one with the first column in it
 */
private void setDefaultFindCriteriaPanels() {
    final Graph graph = graphNode.getGraph();
    ReadableGraph rg = graph.getReadableGraph();
    try {
        int[] keys = rg.getPrimaryKey(type);
        if (keys.length == 0) {
            addFindCriteriaPanel();
        } else {
            for (int i = 0; i < keys.length; i++) {
                Attribute attr = new GraphAttribute(rg, keys[i]);
                FindRule rule = new FindRule();
                rule.setAttribute(attr);
                if ("boolean".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addBooleanBasedRule(true);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("color".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addColorBasedRule(Color.BLACK);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("date".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addDateBasedRule(new Date(), new Date());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if (attr.getAttributeType().equalsIgnoreCase(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
                    rule.addDateTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if ("time".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if ("float".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addFloatBasedRule(0.0F, 0.0F);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("integer".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addIntegerBasedRule(0, 0);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("icon".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addIconBasedRule("");
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else {
                    // string
                    rule.addStringBasedRule("", false, false);
                    rule.setOperator(FindTypeOperators.Operator.CONTAINS);
                }
                addFindCriteriaPanel(rule);
            }
        }
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) FindRule(au.gov.asd.tac.constellation.views.find.advanced.FindRule) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 18 with Graph

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

the class FindTopComponent method saveStateToGraph.

/**
 * Causes the state to be gathered by collecting each 'rule' from all of the
 * <code>FindCriteriaPanel</code>s hosted.
 * <p>
 * Upon all rules being wrapped in an overall <code>FindState</code>,
 * invokes the write to graph plugin and passes it the state to write in the
 * background.
 *
 * @return The state saved to the graph.
 *
 * @see FindCriteriaPanel
 * @see FindState
 */
@SuppressWarnings("unchecked")
public FindState saveStateToGraph() {
    final Graph graph = graphNode.getGraph();
    // Collect the state of all of the FCPs (ie the current rules):
    final FindState newState = new FindState();
    for (Component c : panelFind.getComponents()) {
        if (c instanceof FindCriteriaPanel && !attributes.isEmpty()) {
            final FindCriteriaPanel fcp = (FindCriteriaPanel) c;
            newState.addRule(fcp.getState());
        }
    }
    // Save the GraphElementType:
    if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_VERTEX())) {
        newState.setGraphElementType(GraphElementType.VERTEX);
    } else if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_TRANSACTION())) {
        newState.setGraphElementType(GraphElementType.TRANSACTION);
    } else if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_EDGE())) {
        newState.setGraphElementType(GraphElementType.EDGE);
    } else {
        newState.setGraphElementType(GraphElementType.LINK);
    }
    // Save the AND/OR mode ('any'/'all'):
    newState.setAny(this.cmbMatch.getSelectedItem().equals(Bundle.Find_ANY()));
    // Save the hold selection mode:
    newState.setHeld(chkAddToSelection.isSelected());
    // Write what we have to the graph:
    final FindStatePlugin findStatePlugin = new FindStatePlugin(newState);
    PluginExecution.withPlugin(findStatePlugin).executeLater(graph);
    return newState;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) FindState(au.gov.asd.tac.constellation.views.find.advanced.FindState) FindStatePlugin(au.gov.asd.tac.constellation.views.find.advanced.FindStatePlugin) TopComponent(org.openide.windows.TopComponent) Component(java.awt.Component)

Example 19 with Graph

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

the class FindTopComponent method performSearch.

/**
 * Gathers the state from the graph, and executes the
 * <code>AdvancedQueryPlugin</code>, passing it the rules from the state.
 * <p>
 * (Where each <code>FindCriteriaPanel</code> represents an individual
 * rule.)
 */
@SuppressWarnings("unchecked")
private void performSearch() {
    final Graph graph = graphNode.getGraph();
    final FindState state = saveStateToGraph();
    final AdvancedFindPlugin queryPlugin = new AdvancedFindPlugin(type, state.getRules(), !state.isAny());
    final Future<?> future = PluginExecution.withPlugin(queryPlugin).interactively(true).executeLater(graph);
    // Wait for the search to find its results:
    try {
        future.get();
    } catch (final InterruptedException ex) {
        LOGGER.log(Level.SEVERE, "Thread was interrupted", ex);
        Thread.currentThread().interrupt();
    } catch (final ExecutionException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    final List<FindResult> results = queryPlugin.getResults();
    final SelectFindResultsPlugin selectPlugin = new SelectFindResultsPlugin(results, state.isHeld());
    PluginExecution.withPlugin(selectPlugin).interactively(true).executeLater(graph);
}
Also used : AdvancedFindPlugin(au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) FindState(au.gov.asd.tac.constellation.views.find.advanced.FindState) SelectFindResultsPlugin(au.gov.asd.tac.constellation.views.find.advanced.SelectFindResultsPlugin) ExecutionException(java.util.concurrent.ExecutionException) FindResult(au.gov.asd.tac.constellation.views.find.advanced.FindResult)

Example 20 with Graph

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

the class DataAccessUtilitiesNGTest method loadDataAccessState.

@Test
public void loadDataAccessState() {
    // Create current data access view state and set some parameters
    // The code currenly only looks at the first tab so parameter2
    // value will be ignored
    final DataAccessState currentState = new DataAccessState();
    currentState.newTab();
    currentState.add("parameter1", "parameter1_new_value");
    currentState.newTab();
    currentState.add("parameter2", "parameter2_new_value");
    // 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(currentState);
    // mock tab pane
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final TabPane tabPane = mock(TabPane.class);
    final Tab currentTab = mock(Tab.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
    when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
    when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(currentTab, mock(Tab.class)));
    try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
        daTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(currentTab)).thenReturn(queryPhasePane);
        final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
        final PluginParameters globalPluginParameters = mock(PluginParameters.class);
        final PluginParameter pluginParameter1 = mock(PluginParameter.class);
        final PluginParameter pluginParameter2 = mock(PluginParameter.class);
        when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
        when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
        when(globalPluginParameters.getParameters()).thenReturn(Map.of("parameter1", pluginParameter1, "parameter2", pluginParameter2));
        DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
        verify(pluginParameter1).setStringValue("parameter1_new_value");
        verify(pluginParameter2, never()).setStringValue(anyString());
        verify(rGraph).release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) TabPane(javafx.scene.control.TabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) 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) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) 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