Search in sources :

Example 26 with Schema

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

the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenario.

@Test
public void testReadWithDuplicateGraphScenario() throws InterruptedException {
    int vx0, vx1, vx2, tx0, tx1;
    int identifierAttribute, typeAttribute, uniqueIdAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
    // typeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(identifierAttribute, vx0, "vx0");
    originalGraph.setStringValue(identifierAttribute, vx1, "vx1");
    originalGraph.setStringValue(identifierAttribute, vx2, "vx2");
    Graph compareGraph;
    GraphRecordStore compareAll;
    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((GraphReadMethods) originalGraph);
        compareGraph = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
    } catch (PluginException ex) {
        compareGraph = null;
        Assert.fail(ex.getLocalizedMessage());
    }
    final WritableGraph wg = compareGraph.getWritableGraph("remove a node", true);
    try {
        Assert.assertEquals(wg.getVertexCount(), 3);
        Assert.assertEquals(wg.getTransactionCount(), 2);
        wg.removeVertex(vx1);
        Assert.assertEquals(wg.getVertexCount(), 2);
        Assert.assertEquals(wg.getTransactionCount(), 0);
    } finally {
        wg.commit();
    }
    ReadableGraph rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
    final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    Graph finalGraph = null;
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        assertEquals(changes.size(), 5);
        finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
    } catch (InterruptedException | PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    changes.reset();
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    rg = finalGraph.getReadableGraph();
    try {
        int vxCount = rg.getVertexCount();
        int txCount = rg.getTransactionCount();
        assertEquals(vxCount, 3);
        assertEquals(txCount, 2);
    } finally {
        rg.release();
    }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
        SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "finalGraph", true);
    } catch (IOException | InterruptedException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) 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) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 27 with Schema

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

the class AttributeUtilities method getRegisteredAttributeIdsFromGraph.

/**
 * Return the attribute id's for a {@link GraphElementType} used by a graph
 *
 * @param graph The graph
 * @param graphElementType The element type
 * @return Set of attribute id's being used on a given graph
 */
public static Map<String, Integer> getRegisteredAttributeIdsFromGraph(final GraphReadMethods graph, final GraphElementType graphElementType) {
    final Map<String, Integer> attributeIds = new TreeMap<>();
    final Schema schema = graph.getSchema();
    if (schema != null) {
        final SchemaFactory factory = schema.getFactory();
        final Map<String, SchemaAttribute> attrsMap = factory.getRegisteredAttributes(graphElementType);
        attrsMap.values().stream().forEach(schemaAttribute -> {
            final int attributeId = graph.getAttribute(graphElementType, schemaAttribute.getName());
            if (attributeId != Graph.NOT_FOUND) {
                attributeIds.put(schemaAttribute.getName(), attributeId);
            }
        });
    }
    return attributeIds;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) TreeMap(java.util.TreeMap) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 28 with Schema

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

the class VisualGraphTopComponent method init.

/**
 * Initialise the TopComponent state.
 */
private void init() {
    displayPanel.add(visualManager.getVisualComponent(), BorderLayout.CENTER);
    DropTargetAdapter dta = new DropTargetAdapter() {

        @Override
        public void dragEnter(DropTargetDragEvent dtde) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY);
        }

        @Override
        public void drop(DropTargetDropEvent dtde) {
            final Transferable transferable = dtde.getTransferable();
            if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                try {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY);
                    // files will be list of file which extends from object type
                    @SuppressWarnings("unchecked") final List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
                    for (final File file : files) {
                        try (final InputStream in = StringUtils.endsWithIgnoreCase(file.getName(), FileExtensionConstants.GZIP) ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file)) {
                            final RecordStore recordStore = RecordStoreUtilities.fromTsv(in);
                            PluginExecution.withPlugin(new ImportRecordFile(recordStore)).executeLater(graph);
                        }
                    }
                } catch (final UnsupportedFlavorException | IOException ex) {
                    LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
                    dtde.rejectDrop();
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };
    displayPanel.setDropTarget(new DropTarget(displayPanel, DnDConstants.ACTION_COPY, dta, true));
    content.add(getActionMap());
    savable = new MySavable();
    saveAs = new MySaveAs();
    content.add(saveAs);
    content.add(graphNode.getDataObject());
    content.add(graph);
    content.add(graphNode);
    associateLookup(new AbstractLookup(content));
    setActivatedNodes(new Node[] { graphNode });
    getActionMap().put("cut-to-clipboard", new CutToClipboardAction(graphNode));
    getActionMap().put("copy-to-clipboard", new CopyToClipboardAction(graphNode));
    getActionMap().put("paste-from-clipboard", new PasteFromClipboardAction(graphNode));
    // The actions below are per-graph.
    // NetBeans creates a single instance of an action and uses it globally, which doesn't do us any good,
    // because we want to have different toggle states on different graphs, for instance.
    // Therefore, we'll ignore NetBeans and create our own per-graph action instances.
    expandCompositesAction = new ExpandAllCompositesAction(graphNode);
    contractCompositesAction = new ContractAllCompositesAction(graphNode);
    drawNodesAction = new DrawNodesAction(graphNode);
    drawConnectionsAction = new DrawConnectionsAction(graphNode);
    drawNodeLabelsAction = new DrawNodeLabelsAction(graphNode);
    drawConnectionLabelsAction = new DrawConnectionLabelsAction(graphNode);
    drawBlazesAction = new DrawBlazesAction(graphNode);
    final ButtonGroup drawButtonGroup = new ButtonGroup();
    drawLinksAction = new DrawLinksAction(graphNode, drawButtonGroup);
    drawEdgesAction = new DrawEdgesAction(graphNode, drawButtonGroup);
    drawTransactionsAction = new DrawTransactionsAction(graphNode, drawButtonGroup);
    final ButtonGroup displayModeButtonGroup = new ButtonGroup();
    display3dAction = new Toggle3DAction(graphNode, displayModeButtonGroup);
    final ButtonGroup addModeButtonGroup = new ButtonGroup();
    toggleSelectModeAction = new ToggleSelectionModeAction(graphNode, addModeButtonGroup);
    final ButtonGroup directedModeButtonGroup = new ButtonGroup();
    toggleDrawDirectedAction = new ToggleDrawDirectedAction(graphNode, directedModeButtonGroup);
    toggleGraphVisibilityAction = new ToggleGraphVisibilityAction(graphNode);
    final JToolBar sidebar = new JToolBar(SwingConstants.VERTICAL);
    sidebar.setFloatable(false);
    sidebar.setRollover(true);
    sidebar.add(display3dAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(drawLinksAction.getToolbarPresenter());
    sidebar.add(drawEdgesAction.getToolbarPresenter());
    sidebar.add(drawTransactionsAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(drawNodesAction.getToolbarPresenter());
    sidebar.add(drawConnectionsAction.getToolbarPresenter());
    sidebar.add(drawNodeLabelsAction.getToolbarPresenter());
    sidebar.add(drawConnectionLabelsAction.getToolbarPresenter());
    sidebar.add(drawBlazesAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(toggleGraphVisibilityAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(expandCompositesAction.getToolbarPresenter());
    sidebar.add(contractCompositesAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(toggleSelectModeAction.getToolbarPresenter());
    sidebar.add(toggleDrawDirectedAction.getToolbarPresenter());
    // Add this so the side bar isn't too long.
    // Without this, the side bar has a height that extends past the icons and stops other TopComponents
    // from growing past it.
    sidebar.setMinimumSize(new Dimension(0, 0));
    // Set the modification counters to whatever they are now.
    // This causes any setup changes to be ignored.
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        graphModificationCountBase = rg.getGlobalModificationCounter();
        graphModificationCount = graphModificationCountBase;
    } finally {
        rg.release();
    }
    // Initial update so that the sidebar actions are updated to match the graph.
    visualUpdate();
    this.add(sidebar, BorderLayout.WEST);
    // Listen to graph changes so we can update our modified flag. This will determine
    // whether or not we need to enable saving of the graph.
    graph.addGraphChangeListener(this);
    final InputMap keys = getInputMap(VisualGraphTopComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    final KeyStroke key = KeyStroke.getKeyStroke("Control W");
    final CloseAction ca = new CloseAction(graphNode);
    keys.put(key, ca);
    // Set the icon.
    final Schema schema = graph.getSchema();
    final Image image = getBufferedImageForSchema(schema, false);
    VisualGraphTopComponent.this.setIcon(getNebulaIcon(image));
    final UpdateComponent<GraphReadMethods> visualUpdateComponent = new UpdateComponent<GraphReadMethods>() {

        @Override
        protected boolean update(GraphReadMethods updateState) {
            visualUpdate();
            return true;
        }
    };
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAW_FLAGS));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.VISIBLE_ABOVE_THRESHOLD));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DISPLAY_MODE_3D));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAWING_MODE));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAW_DIRECTED_TRANSACTIONS));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.CONNECTION_MODE));
    graphUpdateManager.setManaged(true);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) DrawConnectionsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionsAction) PasteFromClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.PasteFromClipboardAction) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) DrawTransactionsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawTransactionsAction) CutToClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CutToClipboardAction) ArrayList(java.util.ArrayList) List(java.util.List) DrawLinksAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawLinksAction) ExpandAllCompositesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ExpandAllCompositesAction) DrawNodesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodesAction) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) AbstractLookup(org.openide.util.lookup.AbstractLookup) FileInputStream(java.io.FileInputStream) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) File(java.io.File) ContractAllCompositesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ContractAllCompositesAction) CloseAction(au.gov.asd.tac.constellation.graph.interaction.plugins.io.CloseAction) DrawNodeLabelsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodeLabelsAction) GZIPInputStream(java.util.zip.GZIPInputStream) DrawEdgesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawEdgesAction) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) ToggleDrawDirectedAction(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleDrawDirectedAction) DrawConnectionLabelsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionLabelsAction) Toggle3DAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.Toggle3DAction) ToggleGraphVisibilityAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.ToggleGraphVisibilityAction) ToggleSelectionModeAction(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleSelectionModeAction) CopyToClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToClipboardAction) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Transferable(java.awt.datatransfer.Transferable) UpdateComponent(au.gov.asd.tac.constellation.plugins.update.UpdateComponent) IOException(java.io.IOException) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ButtonGroup(javax.swing.ButtonGroup) DrawBlazesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawBlazesAction)

Example 29 with Schema

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

the class CutCopyPasteNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    final Schema ss = SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema();
    graph = new DualGraph(ss);
    WritableGraph wg = graph.getWritableGraph("add", 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 : Schema(au.gov.asd.tac.constellation.graph.schema.Schema) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 30 with Schema

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

the class AutosaveGraphPluginNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    graph = new DualGraph(schema);
    WritableGraph wg = graph.getWritableGraph("Autosave", true);
    try {
        attrX = VisualConcept.VertexAttribute.X.ensure(wg);
        attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
        attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
        vAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        tAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        vxId1 = wg.addVertex();
        wg.setFloatValue(attrX, vxId1, 1.0f);
        wg.setFloatValue(attrY, vxId1, 1.0f);
        wg.setBooleanValue(vAttrId, vxId1, false);
        vxId2 = wg.addVertex();
        wg.setFloatValue(attrX, vxId2, 5.0f);
        wg.setFloatValue(attrY, vxId2, 1.0f);
        wg.setBooleanValue(vAttrId, vxId2, true);
        vxId3 = wg.addVertex();
        wg.setFloatValue(attrX, vxId3, 1.0f);
        wg.setFloatValue(attrY, vxId3, 5.0f);
        wg.setBooleanValue(vAttrId, vxId3, false);
        vxId4 = wg.addVertex();
        wg.setFloatValue(attrX, vxId4, 5.0f);
        wg.setFloatValue(attrY, vxId4, 5.0f);
        wg.setBooleanValue(vAttrId, vxId4, false);
        vxId5 = wg.addVertex();
        wg.setFloatValue(attrX, vxId5, 10.0f);
        wg.setFloatValue(attrY, vxId5, 10.0f);
        wg.setBooleanValue(vAttrId, vxId5, true);
        vxId6 = wg.addVertex();
        wg.setFloatValue(attrX, vxId6, 15.0f);
        wg.setFloatValue(attrY, vxId6, 15.0f);
        vxId7 = wg.addVertex();
        wg.setFloatValue(attrX, vxId7, 100.0f);
        wg.setFloatValue(attrY, vxId7, 100.0f);
        txId1 = wg.addTransaction(vxId1, vxId2, false);
        txId2 = wg.addTransaction(vxId1, vxId3, false);
        txId3 = wg.addTransaction(vxId2, vxId4, true);
        txId4 = wg.addTransaction(vxId4, vxId2, true);
        txId5 = wg.addTransaction(vxId5, vxId6, false);
    } finally {
        wg.commit();
    }
}
Also used : Schema(au.gov.asd.tac.constellation.graph.schema.Schema) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Schema (au.gov.asd.tac.constellation.graph.schema.Schema)74 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)63 BeforeMethod (org.testng.annotations.BeforeMethod)50 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)17 Graph (au.gov.asd.tac.constellation.graph.Graph)15 Test (org.testng.annotations.Test)13 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)10 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)8 ArrayList (java.util.ArrayList)8 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)7 IOException (java.io.IOException)6 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)5 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)3 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)3 CopyToNewGraphPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin)2 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)2