use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class PlaceholderUtilities method collapsePlaceholders.
public static void collapsePlaceholders(final GraphWriteMethods graph, final Comparator<SchemaVertexType> dominanceComparator, final boolean debug) throws PluginException, InterruptedException {
final List<Integer> placeholderIds = new ArrayList<>();
final Map<Integer, List<Integer>> placeholderCorrelations = new HashMap<>();
final Map<Integer, List<Integer>> placeholderActivity = new HashMap<>();
final Map<Integer, Integer> placeholderNeighbours = new HashMap<>();
final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.get(graph);
final int transactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.get(graph);
// collect placeholders, their transactions and their neighbours
final int vertexCount = graph.getVertexCount();
for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
final int vertexId = graph.getVertex(vertexPosition);
final SchemaVertexType vertexType = graph.getObjectValue(vertexTypeAttributeId, vertexId);
if (vertexType.isSubTypeOf(AnalyticConcept.VertexType.PLACEHOLDER)) {
placeholderIds.add(vertexId);
final List<Integer> placeholderCorrelationList = new ArrayList<>();
final List<Integer> placeholderActivityList = new ArrayList<>();
final int transactionCount = graph.getVertexTransactionCount(vertexId);
for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
final int transactionId = graph.getVertexTransaction(vertexId, transactionPosition);
final SchemaTransactionType transactionType = graph.getObjectValue(transactionTypeAttributeId, transactionId);
if (transactionType.isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)) {
placeholderCorrelationList.add(transactionId);
} else {
placeholderActivityList.add(transactionId);
}
final int neighbourId = graph.getTransactionSourceVertex(transactionId) == vertexId ? graph.getTransactionDestinationVertex(transactionId) : graph.getTransactionSourceVertex(transactionId);
placeholderNeighbours.put(transactionId, neighbourId);
}
placeholderCorrelations.put(vertexId, placeholderCorrelationList);
placeholderActivity.put(vertexId, placeholderActivityList);
}
}
if (debug) {
GraphOpener.getDefault().openGraph(new DualGraph((StoreGraph) graph.copy(), true), GraphNode.getGraphNode(graph.getId()).getName() + "-debug-stage1");
}
// choose lead vertices to replace placeholders
placeholderIds.forEach(placeholderId -> {
final int leadVertex;
final List<Integer> placeholderCorrelationList = placeholderCorrelations.get(placeholderId);
if (!placeholderCorrelationList.isEmpty()) {
// calculate lead vertex
final SchemaVertexType leadVertexType = placeholderCorrelationList.stream().map(placeholderNeighbours::get).map(neighbourId -> (SchemaVertexType) graph.getObjectValue(vertexTypeAttributeId, neighbourId)).sorted(dominanceComparator).findFirst().get();
leadVertex = placeholderCorrelationList.stream().map(placeholderNeighbours::get).filter(neighbourId -> graph.getObjectValue(vertexTypeAttributeId, neighbourId).equals(leadVertexType)).findFirst().get();
// move correlations from the placeholder to the lead vertex of the entity
placeholderCorrelationList.forEach(correlationId -> {
if (graph.getTransactionSourceVertex(correlationId) == placeholderId && graph.getTransactionDestinationVertex(correlationId) != leadVertex) {
graph.setTransactionSourceVertex(correlationId, leadVertex);
} else if (graph.getTransactionDestinationVertex(correlationId) == placeholderId && graph.getTransactionSourceVertex(correlationId) != leadVertex) {
graph.setTransactionDestinationVertex(correlationId, leadVertex);
} else {
// Do nothing
}
});
// move activity from the placeholder to the lead vertex of the entity
final List<Integer> placeholderActivityList = placeholderActivity.get(placeholderId);
placeholderActivityList.forEach(activityId -> {
if (graph.getTransactionSourceVertex(activityId) == placeholderId) {
graph.setTransactionSourceVertex(activityId, leadVertex);
} else {
graph.setTransactionDestinationVertex(activityId, leadVertex);
}
});
}
});
if (debug) {
GraphOpener.getDefault().openGraph(new DualGraph((StoreGraph) graph.copy(), true), GraphNode.getGraphNode(graph.getId()).getName() + "-debug-stage2");
}
// remove all placeholders
placeholderIds.forEach(graph::removeVertex);
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class AttributeUtilitiesNGTest method testGetDateTimeAttributes.
@Test
public void testGetDateTimeAttributes() {
final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema());
final Set<String> typesUsedByGraph = AttributeUtilities.getDateTimeAttributes(new DualGraph(graph, false), GraphElementType.TRANSACTION);
assertEquals(typesUsedByGraph.size(), 5);
assertTrue(typesUsedByGraph.contains(TemporalConcept.TransactionAttribute.FIRST_SEEN.getName()));
assertTrue(typesUsedByGraph.contains(TemporalConcept.TransactionAttribute.LAST_SEEN.getName()));
assertTrue(typesUsedByGraph.contains(TemporalConcept.TransactionAttribute.DATETIME.getName()));
assertTrue(typesUsedByGraph.contains(TemporalConcept.TransactionAttribute.CREATED.getName()));
assertTrue(typesUsedByGraph.contains(TemporalConcept.TransactionAttribute.MODIFIED.getName()));
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class AttributeUtilitiesNGTest method testGetTypesUsedByGraph.
@Test
public void testGetTypesUsedByGraph() {
final int vx0, vx1, vx2, vx3;
final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema());
final int typeId = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
vx0 = graph.addVertex();
graph.setObjectValue(typeId, vx0, AnalyticConcept.VertexType.ORGANISATION);
vx1 = graph.addVertex();
graph.setObjectValue(typeId, vx1, AnalyticConcept.VertexType.ORGANISATION);
vx2 = graph.addVertex();
graph.setObjectValue(typeId, vx2, AnalyticConcept.VertexType.DOCUMENT);
vx3 = graph.addVertex();
graph.setStringValue(typeId, vx3, "Foo");
final Set<String> typesUsedByGraph = AttributeUtilities.getTypesUsedByGraph(new DualGraph(graph, false));
assertEquals(typesUsedByGraph.size(), 3);
assertTrue(typesUsedByGraph.contains(AnalyticConcept.VertexType.ORGANISATION.toString()));
assertTrue(typesUsedByGraph.contains(AnalyticConcept.VertexType.DOCUMENT.toString()));
assertTrue(typesUsedByGraph.contains("Foo"));
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class SchemaDestination method getGraph.
@Override
public Graph getGraph() {
final SchemaFactory schemaFactory = getDestination();
final Graph graph = new DualGraph(schemaFactory.createSchema());
final WritableGraph wg = graph.getWritableGraphNow("New Graph", true);
try {
graph.getSchema().newGraph(wg);
} finally {
wg.commit();
}
return graph;
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph 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();
}
}
Aggregations