Search in sources :

Example 6 with ReadableGraph

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

the class DataAccessUtilities method loadDataAccessState.

/**
 * Load the data access graph state and update the data access view.
 * <p/>
 * Currently only looking at string parameter types and only shows the first
 * step if it exists.
 *
 * @param dataAccessPane the data access pane
 * @param graph the active graph to load the state from
 */
public static void loadDataAccessState(final DataAccessPane dataAccessPane, final Graph graph) {
    if (graph != null && dataAccessPane.getDataAccessTabPane().getCurrentTab() != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int dataAccessStateAttribute = DataAccessConcept.MetaAttribute.DATAACCESS_STATE.get(readableGraph);
            if (dataAccessStateAttribute != Graph.NOT_FOUND) {
                final DataAccessState dataAccessState = readableGraph.getObjectValue(dataAccessStateAttribute, 0);
                if (dataAccessState != null && !dataAccessState.getState().isEmpty()) {
                    // TODO: support multiple tabs (not just first one in state) and not
                    // introduce memory leaks
                    final Map<String, String> tabState = dataAccessState.getState().get(0);
                    final Tab step = dataAccessPane.getDataAccessTabPane().getTabPane().getTabs().get(0);
                    DataAccessTabPane.getQueryPhasePane(step).getGlobalParametersPane().getParams().getParameters().entrySet().stream().forEach(param -> {
                        final PluginParameter<?> pp = param.getValue();
                        final String paramvalue = tabState.get(param.getKey());
                        if (paramvalue != null) {
                            pp.setStringValue(paramvalue);
                        }
                    });
                }
            }
        } finally {
            readableGraph.release();
        }
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Tab(javafx.scene.control.Tab)

Example 7 with ReadableGraph

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

the class SelectAllPluginNGTest method testEdit0.

/**
 * Test of edit method, of class SelectAllPlugin. select all edit with only
 * attributes on graph
 */
@Test
public void testEdit0() throws Exception {
    System.out.println("select all edit with nothing on graph but attributes");
    // Open a new graph
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    int vxCount = 0;
    int txCount = 0;
    final WritableGraph wg = graph.getWritableGraph("TEST", true);
    try {
        // Create Selected Attributes
        selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
    } finally {
        wg.commit();
    }
    // run select all plugin
    PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
    // Verify no extra elements are added
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        assertEquals(rg.getVertexCount(), vxCount);
        assertEquals(rg.getTransactionCount(), txCount);
    } finally {
        rg.close();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 8 with ReadableGraph

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

the class SelectAllPluginNGTest method testEdit2.

/**
 * Test of edit method, of class SelectAllPlugin. select all edit with both
 * vx and tx on graph
 */
@Test
public void testEdit2() throws Exception {
    System.out.println("select all edit with vx and tx on graph");
    // Open a new graph
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    int vxCount = 0;
    int txCount = 0;
    final WritableGraph wg = graph.getWritableGraph("TEST", true);
    try {
        // Create Selected Attributes
        selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        // Add vertices
        vxId1 = wg.addVertex();
        vxId2 = wg.addVertex();
        // Add transactions
        txId1 = wg.addTransaction(vxId1, vxId2, true);
        txId2 = wg.addTransaction(vxId2, vxId1, false);
        // check default value is unselected
        assertFalse(wg.getBooleanValue(selectedV, vxId1));
        assertFalse(wg.getBooleanValue(selectedV, vxId2));
        assertFalse(wg.getBooleanValue(selectedV, txId1));
        assertFalse(wg.getBooleanValue(selectedV, txId2));
        vxCount = wg.getVertexCount();
        txCount = wg.getTransactionCount();
    } finally {
        wg.commit();
    }
    // run select all plugin
    PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
    // Verify both selected and same amount of vx and tx are present
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        assertTrue(rg.getBooleanValue(selectedV, vxId1));
        assertTrue(rg.getBooleanValue(selectedV, vxId2));
        assertTrue(rg.getBooleanValue(selectedV, txId1));
        assertTrue(rg.getBooleanValue(selectedV, txId2));
        assertEquals(rg.getVertexCount(), vxCount);
        assertEquals(rg.getTransactionCount(), txCount);
    } finally {
        rg.close();
    }
    // rerun plugin to ensure values are not only toggled, but are set explicitly as selected
    // run select all plugin
    PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
    // Verify both selected and same amount of vx and tx are present
    final ReadableGraph rg2 = graph.getReadableGraph();
    try {
        assertTrue(rg2.getBooleanValue(selectedV, vxId1));
        assertTrue(rg2.getBooleanValue(selectedV, vxId2));
        assertTrue(rg.getBooleanValue(selectedV, txId1));
        assertTrue(rg.getBooleanValue(selectedV, txId2));
        assertEquals(rg2.getVertexCount(), vxCount);
        assertEquals(rg.getTransactionCount(), txCount);
    } finally {
        rg2.close();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 9 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph 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)

Example 10 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph 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)

Aggregations

ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)167 Test (org.testng.annotations.Test)62 Graph (au.gov.asd.tac.constellation.graph.Graph)57 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)43 ArrayList (java.util.ArrayList)40 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)26 HashMap (java.util.HashMap)16 Attribute (au.gov.asd.tac.constellation.graph.Attribute)14 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)12 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)12 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)12 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)12 HashSet (java.util.HashSet)12 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)11 List (java.util.List)10 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)9 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)9 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)9 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)9 File (java.io.File)9