Search in sources :

Example 16 with DualGraph

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

the class MiscNGTest method testCreateTransactionToNonexistentDestinationInPluginTest.

@Test
public void testCreateTransactionToNonexistentDestinationInPluginTest() {
    try {
        final DualGraph graph = new DualGraph(null);
        graph.setUndoManager(new UndoRedo.Manager());
        PluginExecution.withPlugin(new SimpleEditPlugin() {

            @Override
            public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                for (int i = 0; i < 10; i++) {
                    final String s = String.format("x%d", i);
                    wg.addAttribute(GraphElementType.VERTEX, ObjectAttributeDescription.ATTRIBUTE_NAME, s, s, 99, null);
                    wg.addAttribute(GraphElementType.TRANSACTION, FloatAttributeDescription.ATTRIBUTE_NAME, s, s, 99, null);
                }
                int vx = 0;
                for (int i = 0; i < 100; i++) {
                    vx = wg.addVertex();
                }
                final int tx = wg.addTransaction(vx, vx + 1, true);
                Assert.fail("Shouldn't get here, wg.addTransaction() should fail.");
                System.out.printf("New transaction: %d\n", tx);
            }

            @Override
            public String getName() {
                return "Build graph + tx failure test";
            }
        }).executeNow(graph);
    } catch (InterruptedException ex) {
        Assert.fail("Nothing was interrupted.");
    } catch (PluginException ex) {
        Assert.fail("There shouldn't be a plugin exception.");
    } catch (RuntimeException ex) {
        final boolean containsIllegalArgumentException = ex.getLocalizedMessage().contains("Attempt to create transaction to destination vertex that does not exist");
        Assert.assertTrue(containsIllegalArgumentException);
    }
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) UndoRedo(org.openide.awt.UndoRedo) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 17 with DualGraph

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

the class DefaultPluginInteractionNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    environment = new DefaultPluginEnvironment();
    plugin = new TestPlugin();
    graph = new DualGraph(null);
    synchroniser = new PluginSynchronizer(1);
    graphReport = new GraphReport(graph.getId());
    manager = new PluginManager(environment, plugin, graph, false, synchroniser);
    report = new PluginReport(graphReport, plugin);
}
Also used : PluginSynchronizer(au.gov.asd.tac.constellation.plugins.PluginSynchronizer) PluginReport(au.gov.asd.tac.constellation.plugins.reporting.PluginReport) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphReport(au.gov.asd.tac.constellation.plugins.reporting.GraphReport) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 18 with DualGraph

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

the class UndoRedoNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    graph = new DualGraph(null);
    undoMgr = new UndoManager();
    graph.setUndoManager(undoMgr);
    WritableGraph wg = graph.getWritableGraph("original load", true);
    try {
        attrX = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "x", "x", 0.0, null);
        if (attrX == Graph.NOT_FOUND) {
            fail();
        }
        attrY = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "y", "y", 0.0, null);
        if (attrY == Graph.NOT_FOUND) {
            fail();
        }
        attrZ = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "z", "z", 0.0, null);
        if (attrZ == Graph.NOT_FOUND) {
            fail();
        }
        vNameAttr = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
        if (vNameAttr == Graph.NOT_FOUND) {
            fail();
        }
        tNameAttr = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
        if (tNameAttr == Graph.NOT_FOUND) {
            fail();
        }
        vSelAttr = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
        if (vSelAttr == Graph.NOT_FOUND) {
            fail();
        }
        tSelAttr = wg.addAttribute(GraphElementType.TRANSACTION, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
        if (tSelAttr == Graph.NOT_FOUND) {
            fail();
        }
        vxId1 = wg.addVertex();
        wg.setFloatValue(attrX, vxId1, 1.0f);
        wg.setFloatValue(attrY, vxId1, 1.0f);
        wg.setBooleanValue(vSelAttr, vxId1, false);
        wg.setStringValue(vNameAttr, vxId1, "name1");
        vxId2 = wg.addVertex();
        wg.setFloatValue(attrX, vxId2, 5.0f);
        wg.setFloatValue(attrY, vxId2, 1.0f);
        wg.setBooleanValue(vSelAttr, vxId2, true);
        wg.setStringValue(vNameAttr, vxId2, "name2");
        vxId3 = wg.addVertex();
        wg.setFloatValue(attrX, vxId3, 1.0f);
        wg.setFloatValue(attrY, vxId3, 5.0f);
        wg.setBooleanValue(vSelAttr, vxId3, false);
        wg.setStringValue(vNameAttr, vxId3, "name3");
        vxId4 = wg.addVertex();
        wg.setFloatValue(attrX, vxId4, 5.0f);
        wg.setFloatValue(attrY, vxId4, 5.4f);
        wg.setBooleanValue(vSelAttr, vxId4, true);
        wg.setStringValue(vNameAttr, vxId4, "name4");
        vxId5 = wg.addVertex();
        wg.setFloatValue(attrX, vxId5, 15.0f);
        wg.setFloatValue(attrY, vxId5, 15.5f);
        wg.setBooleanValue(vSelAttr, vxId5, false);
        wg.setStringValue(vNameAttr, vxId5, "name5");
        vxId6 = wg.addVertex();
        wg.setFloatValue(attrX, vxId6, 26.0f);
        wg.setFloatValue(attrY, vxId6, 26.60f);
        wg.setBooleanValue(vSelAttr, vxId6, true);
        wg.setStringValue(vNameAttr, vxId6, "name6");
        vxId7 = wg.addVertex();
        wg.setFloatValue(attrX, vxId7, 37.0f);
        wg.setFloatValue(attrY, vxId7, 37.7f);
        wg.setBooleanValue(vSelAttr, vxId7, false);
        wg.setStringValue(vNameAttr, vxId7, "name7");
        txId1 = wg.addTransaction(vxId1, vxId2, true);
        wg.setBooleanValue(tSelAttr, txId1, false);
        wg.setStringValue(tNameAttr, txId1, "name101");
        txId2 = wg.addTransaction(vxId1, vxId3, true);
        wg.setBooleanValue(tSelAttr, txId2, true);
        wg.setStringValue(tNameAttr, txId2, "name102");
        txId3 = wg.addTransaction(vxId2, vxId4, true);
        wg.setBooleanValue(tSelAttr, txId3, false);
        wg.setStringValue(tNameAttr, txId3, "name103");
        txId4 = wg.addTransaction(vxId4, vxId2, true);
        wg.setBooleanValue(tSelAttr, txId4, true);
        wg.setStringValue(tNameAttr, txId4, "name104");
        txId5 = wg.addTransaction(vxId5, vxId6, true);
        wg.setBooleanValue(tSelAttr, txId5, false);
        wg.setStringValue(tNameAttr, txId5, "name105");
    } finally {
        wg.commit();
    }
}
Also used : UndoManager(javax.swing.undo.UndoManager) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 19 with DualGraph

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

the class NewSchemaGraphAction method getMenuPresenters.

@Override
public JComponent[] getMenuPresenters() {
    menu = new JMenu("New Graph");
    for (final SchemaFactory schemaFactory : SchemaFactoryUtilities.getSchemaFactories().values()) {
        if (isValid(schemaFactory)) {
            if (!ICON_CACHE.containsKey(schemaFactory.getName())) {
                ICON_CACHE.put(schemaFactory.getName(), schemaFactory.getIcon().buildIcon(16));
            }
            final JMenuItem item = new JMenuItem(schemaFactory.getLabel(), ICON_CACHE.get(schemaFactory.getName()));
            item.setToolTipText(schemaFactory.getDescription());
            item.setActionCommand(schemaFactory.getName());
            item.addActionListener((final ActionEvent e) -> new Thread() {

                @Override
                public void run() {
                    setName(GRAPH_ACTION_THREAD_NAME);
                    final Graph graph = new DualGraph(schemaFactory.createSchema());
                    final WritableGraph wg = graph.getWritableGraphNow("New " + schemaFactory.getName(), false);
                    try {
                        graph.getSchema().newGraph(wg);
                    } finally {
                        wg.commit();
                    }
                    final String graphName = schemaFactory.getLabel().trim().toLowerCase();
                    GraphOpener.getDefault().openGraph(graph, graphName);
                }
            }.start());
            menu.add(item);
        }
    }
    menu.addSeparator();
    recreateTemplateMenuItems();
    return new JComponent[] { menu };
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) 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) ActionEvent(java.awt.event.ActionEvent) JComponent(javax.swing.JComponent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 20 with DualGraph

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

the class PlaceholderUtilities method collapsePlaceholders.

public static StoreGraph collapsePlaceholders(final StoreGraphRecordStore graph, final Record record, final DatumProcessor<Record, ?> rowProcessor, final Comparator<GraphVertex> dominanceComparator, final boolean cleanupGraph, final boolean debug) throws PluginException, InterruptedException {
    graph.complete();
    graph.validateKeys();
    GraphWrapper g = new GraphWrapper(graph);
    // remove all transactions with type 'unknown' and all nodes with identifier 'unknown'
    if (cleanupGraph) {
        g.streamTransactions().filter(transaction -> transaction.getTypeValue().equals(SchemaTransactionTypeUtilities.getDefaultType())).forEach(GraphTransaction::deferRemove);
        g.streamVertices().filter(vertex -> "unknown".equals(vertex.getStringValue(VisualConcept.VertexAttribute.IDENTIFIER))).forEach(GraphVertex::deferRemove);
        g.completeDeferred();
    }
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage1");
    }
    // connect all nodes with type 'placeholder'
    g.streamVertices().filter(v -> v.getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER)).map(v -> v.walkNeighbours(s -> s.getTransaction().getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION) && s.getDestinationVertex().getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER), true).map(GraphStep::getDestinationVertex).collect(Collectors.toSet())).distinct().forEach(c -> {
        String newIdentifier = c.stream().map(v -> v.getStringValue(VisualConcept.VertexAttribute.IDENTIFIER)).collect(Collectors.joining(SeparatorConstants.HYPHEN));
        c.stream().forEach(v -> {
            v.setStringValue(VisualConcept.VertexAttribute.IDENTIFIER, newIdentifier);
            v.completeWithSchema();
        });
    });
    g.validateKeys();
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage2");
    }
    // replace nodes with type 'placeholder' with the dominant correlated node
    g.streamVertices().filter(v -> v.getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER)).forEach(v -> {
        Optional<GraphVertex> dominant = v.streamNeighbours().filter(n -> n.getDirection() != GraphDirection.LOOPBACK).filter(n -> n.getTransaction().getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)).map(n -> n.getDestinationVertex()).distinct().sorted(dominanceComparator).findFirst();
        // TODO: needed to create a special case for 'unknown' type vertices, but not sure why...
        if (dominant.isPresent() && !dominant.get().getTypeValue().equals(SchemaVertexTypeUtilities.getDefaultType())) {
            v.setStringValue(VisualConcept.VertexAttribute.IDENTIFIER, dominant.get().getStringValue(VisualConcept.VertexAttribute.IDENTIFIER));
            v.setTypeValue(dominant.get().getTypeValue());
            v.setRawValue(dominant.get().getRawValue());
            v.completeWithSchema();
        } else {
            v.deferRemove();
        }
    });
    g.completeDeferred();
    g.validateKeys();
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage3");
    }
    // remove transactions that correlate nodes with themselves
    g.streamTransactions().filter(t -> t.getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)).filter(t -> t.getSourceVertex().equals(t.getDestinationVertex())).forEach(GraphTransaction::deferRemove);
    g.completeDeferred();
    return graph;
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) DatumProcessor(au.gov.asd.tac.constellation.graph.processing.DatumProcessor) ProcessingException(au.gov.asd.tac.constellation.graph.processing.ProcessingException) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) GraphOpener(au.gov.asd.tac.constellation.graph.file.opener.GraphOpener) GraphVertex(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphVertex) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Map(java.util.Map) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphDirection(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphDirection) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) GraphWrapper(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphWrapper) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphTransaction(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) GraphStep(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) Record(au.gov.asd.tac.constellation.graph.processing.Record) Optional(java.util.Optional) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Comparator(java.util.Comparator) GraphVertex(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphVertex) GraphStep(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep) GraphWrapper(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphWrapper) GraphTransaction(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph)

Aggregations

DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)66 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)41 Test (org.testng.annotations.Test)30 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)21 Graph (au.gov.asd.tac.constellation.graph.Graph)19 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)18 ArrayList (java.util.ArrayList)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)10 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)10 BeforeMethod (org.testng.annotations.BeforeMethod)9 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)7 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)5 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)4 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)3 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)3 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)3