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);
}
}
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);
}
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();
}
}
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 };
}
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;
}
Aggregations