Search in sources :

Example 21 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 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);
}
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) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) ArrayList(java.util.ArrayList) List(java.util.List) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 22 with DualGraph

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()));
}
Also used : DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 23 with DualGraph

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"));
}
Also used : DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 24 with DualGraph

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;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 25 with DualGraph

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

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