Search in sources :

Example 1 with SchemaVertexType

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

the class VertexTypeIOProviderNGTest method testWriteTypeObject.

@Test
public void testWriteTypeObject() throws Exception {
    final SchemaVertexType type = new SchemaVertexType.Builder("type").setDescription("description").setColor(ConstellationColor.GREEN).setForegroundIcon(CharacterIconProvider.CHAR_0020).setBackgroundIcon(DefaultIconProvider.FLAT_CIRCLE).setDetectionRegex(Pattern.compile("\\+?([0-9]{8,13})", Pattern.CASE_INSENSITIVE)).setValidationRegex(Pattern.compile("\\+?([0-9]{8,15})", Pattern.CASE_INSENSITIVE)).setProperty("my key", "my value").setIncomplete(true).build();
    final ByteArrayOutputStream actual = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = new JsonFactory().createGenerator(actual, JsonEncoding.UTF8);
    jsonGenerator.writeStartObject();
    VertexTypeIOProvider.writeTypeObject(type, jsonGenerator);
    jsonGenerator.writeEndObject();
    jsonGenerator.close();
    final ByteArrayOutputStream expected = new ByteArrayOutputStream();
    jsonGenerator = new JsonFactory().createGenerator(expected, JsonEncoding.UTF8);
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("Name", "type");
    jsonGenerator.writeStringField("Description", "description");
    jsonGenerator.writeObjectFieldStart("Color");
    jsonGenerator.writeStringField("name", "Green");
    jsonGenerator.writeEndObject();
    jsonGenerator.writeStringField("Foreground Icon", "Character.Space");
    jsonGenerator.writeStringField("Background Icon", "Background.Flat Circle");
    jsonGenerator.writeStringField("Detection Regex", "\\+?([0-9]{8,13})");
    jsonGenerator.writeStringField("Validation Regex", "\\+?([0-9]{8,15})");
    jsonGenerator.writeObjectFieldStart("Properties");
    jsonGenerator.writeStringField("my key", "my value");
    jsonGenerator.writeEndObject();
    jsonGenerator.writeBooleanField("Incomplete", true);
    jsonGenerator.writeEndObject();
    jsonGenerator.close();
    Assert.assertEquals(actual.toString(), expected.toString());
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 2 with SchemaVertexType

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

the class VertexTypeIOProviderNGTest method testWriteTypeObjectWithParent.

@Test
public void testWriteTypeObjectWithParent() throws Exception {
    final SchemaVertexType parent = new SchemaVertexType.Builder("parent").setDescription("parent description").setColor(ConstellationColor.GREEN).setForegroundIcon(CharacterIconProvider.CHAR_0020).setBackgroundIcon(DefaultIconProvider.FLAT_CIRCLE).setDetectionRegex(Pattern.compile("\\+?([0-9]{8,13})", Pattern.CASE_INSENSITIVE)).setValidationRegex(Pattern.compile("\\+?([0-9]{8,15})", Pattern.CASE_INSENSITIVE)).setProperty("my key", "my value").setIncomplete(true).build();
    final SchemaVertexType child = new SchemaVertexType.Builder("child").setDescription("child description").setColor(ConstellationColor.GREEN).setForegroundIcon(CharacterIconProvider.CHAR_0020).setBackgroundIcon(DefaultIconProvider.FLAT_CIRCLE).setDetectionRegex(Pattern.compile("\\+?([0-9]{8,13})", Pattern.CASE_INSENSITIVE)).setValidationRegex(Pattern.compile("\\+?([0-9]{8,15})", Pattern.CASE_INSENSITIVE)).setSuperType(parent).setProperty("my key", "my value").setIncomplete(true).build();
    final ByteArrayOutputStream actual = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = new JsonFactory().createGenerator(actual, JsonEncoding.UTF8);
    // jsonGenerator.useDefaultPrettyPrinter();
    jsonGenerator.writeStartObject();
    VertexTypeIOProvider.writeTypeObject(child, jsonGenerator);
    jsonGenerator.writeEndObject();
    jsonGenerator.close();
    final ByteArrayOutputStream expected = new ByteArrayOutputStream();
    jsonGenerator = new JsonFactory().createGenerator(expected, JsonEncoding.UTF8);
    // jsonGenerator.useDefaultPrettyPrinter();
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("Name", "child");
    jsonGenerator.writeStringField("Description", "child description");
    jsonGenerator.writeObjectFieldStart("Color");
    jsonGenerator.writeStringField("name", "Green");
    jsonGenerator.writeEndObject();
    jsonGenerator.writeStringField("Foreground Icon", "Character.Space");
    jsonGenerator.writeStringField("Background Icon", "Background.Flat Circle");
    jsonGenerator.writeStringField("Detection Regex", "\\+?([0-9]{8,13})");
    jsonGenerator.writeStringField("Validation Regex", "\\+?([0-9]{8,15})");
    // supertype start
    jsonGenerator.writeObjectFieldStart("Super Type");
    jsonGenerator.writeStringField("Name", "parent");
    jsonGenerator.writeStringField("Description", "parent description");
    jsonGenerator.writeObjectFieldStart("Color");
    jsonGenerator.writeStringField("name", "Green");
    jsonGenerator.writeEndObject();
    jsonGenerator.writeStringField("Foreground Icon", "Character.Space");
    jsonGenerator.writeStringField("Background Icon", "Background.Flat Circle");
    jsonGenerator.writeStringField("Detection Regex", "\\+?([0-9]{8,13})");
    jsonGenerator.writeStringField("Validation Regex", "\\+?([0-9]{8,15})");
    jsonGenerator.writeObjectFieldStart("Properties");
    jsonGenerator.writeStringField("my key", "my value");
    jsonGenerator.writeEndObject();
    jsonGenerator.writeBooleanField("Incomplete", true);
    jsonGenerator.writeEndObject();
    // supertype end
    jsonGenerator.writeObjectFieldStart("Properties");
    jsonGenerator.writeStringField("my key", "my value");
    jsonGenerator.writeEndObject();
    jsonGenerator.writeBooleanField("Incomplete", true);
    jsonGenerator.writeEndObject();
    jsonGenerator.close();
    Assert.assertEquals(actual.toString(), expected.toString());
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 3 with SchemaVertexType

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

the class VertexTypeIOProvider method writeObject.

@Override
public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
    if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) {
        final SchemaVertexType attributeValue = graph.getObjectValue(attribute.getId(), elementId);
        if (attributeValue == null) {
            jsonGenerator.writeNullField(attribute.getName());
        } else {
            jsonGenerator.writeObjectFieldStart(attribute.getName());
            writeTypeObject(attributeValue, jsonGenerator);
            jsonGenerator.writeEndObject();
        }
    }
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)

Example 4 with SchemaVertexType

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

the class AnalyticSchemaV4UpdateProvider method schemaUpdate.

@Override
protected void schemaUpdate(final StoreGraph graph) {
    final int typeAttribute = AnalyticConcept.VertexAttribute.TYPE.get(graph);
    final Map<String, SchemaVertexType> typesToUpgrade = new HashMap<>();
    typesToUpgrade.put(AnalyticConcept.VertexType.MD5.getName(), AnalyticConcept.VertexType.MD5);
    typesToUpgrade.put(AnalyticConcept.VertexType.SHA1.getName(), AnalyticConcept.VertexType.SHA1);
    typesToUpgrade.put(AnalyticConcept.VertexType.SHA256.getName(), AnalyticConcept.VertexType.SHA256);
    typesToUpgrade.put(AnalyticConcept.VertexType.COUNTRY.getName(), AnalyticConcept.VertexType.COUNTRY);
    typesToUpgrade.put(AnalyticConcept.VertexType.GEOHASH.getName(), AnalyticConcept.VertexType.GEOHASH);
    typesToUpgrade.put(AnalyticConcept.VertexType.MGRS.getName(), AnalyticConcept.VertexType.MGRS);
    typesToUpgrade.put(AnalyticConcept.VertexType.IPV4.getName(), AnalyticConcept.VertexType.IPV4);
    typesToUpgrade.put(AnalyticConcept.VertexType.IPV6.getName(), AnalyticConcept.VertexType.IPV6);
    typesToUpgrade.put(AnalyticConcept.VertexType.EMAIL_ADDRESS.getName(), AnalyticConcept.VertexType.EMAIL_ADDRESS);
    typesToUpgrade.put(AnalyticConcept.VertexType.HOST_NAME.getName(), AnalyticConcept.VertexType.HOST_NAME);
    typesToUpgrade.put(AnalyticConcept.VertexType.URL.getName(), AnalyticConcept.VertexType.URL);
    typesToUpgrade.put(AnalyticConcept.VertexType.TELEPHONE_IDENTIFIER.getName(), AnalyticConcept.VertexType.TELEPHONE_IDENTIFIER);
    for (int vertex = 0; vertex < graph.getVertexCount(); vertex++) {
        final int vertexId = graph.getVertex(vertex);
        final SchemaVertexType oldType = graph.getObjectValue(typeAttribute, vertexId);
        if (oldType != null && typesToUpgrade.containsKey(oldType.getName())) {
            graph.setObjectValue(typeAttribute, vertexId, typesToUpgrade.get(oldType.getName()));
        }
    }
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap)

Example 5 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType 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)

Aggregations

SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)30 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)8 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)6 Map (java.util.Map)6 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)5 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)4 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)4 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)3 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3