Search in sources :

Example 1 with RawData

use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.

the class AnalyticSchemaV2UpdateProvider method schemaUpdate.

@Override
protected void schemaUpdate(final StoreGraph graph) {
    boolean updateVertexKeys = false;
    // update vertex raw attribute
    final int oldVertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.get(graph);
    final Attribute oldVertexRawAttribute = new GraphAttribute(graph, oldVertexRawAttributeId);
    if (!oldVertexRawAttribute.getAttributeType().equals(RawAttributeDescription.ATTRIBUTE_NAME)) {
        graph.setPrimaryKey(GraphElementType.VERTEX);
        final int newVertexRawAttribute = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
        final int vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
        for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
            final int vertexId = graph.getVertex(vertexPosition);
            final String rawValue = graph.getStringValue(oldVertexRawAttributeId, vertexId);
            graph.setObjectValue(newVertexRawAttribute, vertexId, new RawData(rawValue, null));
            if (graph.getStringValue(vertexIdentifierAttribute, vertexId) == null) {
                graph.setObjectValue(vertexIdentifierAttribute, vertexId, rawValue);
            }
        }
        graph.removeAttribute(oldVertexRawAttributeId);
        updateVertexKeys = true;
    }
    // update vertex type attribute
    if (AnalyticConcept.VertexAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
        updateVertexKeys = true;
    }
    final int oldVertexTypeAttributeId = graph.getAttribute(GraphElementType.VERTEX, "Type");
    final Attribute oldVertexTypeAttribute = new GraphAttribute(graph, oldVertexTypeAttributeId);
    if (!oldVertexTypeAttribute.getAttributeType().equals(VertexTypeAttributeDescription.ATTRIBUTE_NAME)) {
        graph.setPrimaryKey(GraphElementType.VERTEX);
        final int newVertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
        final int vertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
        for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
            final int vertexId = graph.getVertex(vertexPosition);
            final String typeValue = graph.getStringValue(oldVertexTypeAttributeId, vertexId);
            final SchemaVertexType type = SchemaVertexTypeUtilities.getType(typeValue);
            graph.setObjectValue(newVertexTypeAttributeId, graph.getVertex(vertexPosition), type);
            final RawData rawValue = graph.getObjectValue(vertexRawAttributeId, graph.getVertex(vertexPosition));
            graph.setObjectValue(vertexRawAttributeId, vertexId, rawValue != null ? new RawData(rawValue.getRawIdentifier(), typeValue) : new RawData(null, null));
        }
        graph.removeAttribute(oldVertexTypeAttributeId);
        updateVertexKeys = true;
    }
    // update vertex keys and complete vertices
    if (updateVertexKeys && graph.getSchema() != null) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.VERTEX);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.VERTEX, keyAttributeIds);
    }
    boolean updateTransactionKeys = false;
    // update transaction type attribute
    if (AnalyticConcept.TransactionAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
        updateTransactionKeys = true;
    }
    final int oldTransactionTypeAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, "Type");
    final Attribute oldTransactionTypeAttribute = new GraphAttribute(graph, oldTransactionTypeAttributeId);
    if (!oldTransactionTypeAttribute.getAttributeType().equals(TransactionTypeAttributeDescription.ATTRIBUTE_NAME)) {
        graph.setPrimaryKey(GraphElementType.TRANSACTION);
        final int newTransactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
        for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
            final int transactionId = graph.getTransaction(transactionPosition);
            final String typeValue = graph.getStringValue(oldTransactionTypeAttributeId, transactionId);
            final SchemaTransactionType type = SchemaTransactionTypeUtilities.getType(typeValue);
            graph.setObjectValue(newTransactionTypeAttributeId, transactionId, type);
        }
        graph.removeAttribute(oldTransactionTypeAttributeId);
        updateTransactionKeys = true;
    }
    // update transaction datetime attribute
    if (TemporalConcept.TransactionAttribute.DATETIME.get(graph) == Graph.NOT_FOUND) {
        updateTransactionKeys = true;
    }
    // update transaction keys and complete transactions
    if (updateTransactionKeys && graph.getSchema() != null) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.TRANSACTION);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.TRANSACTION, keyAttributeIds);
    }
}
Also used : RawData(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) AnalyticSchemaFactory(au.gov.asd.tac.constellation.graph.schema.analytic.AnalyticSchemaFactory) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) UpdateProvider(au.gov.asd.tac.constellation.graph.versioning.UpdateProvider) RawAttributeDescription(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.RawAttributeDescription) TransactionTypeAttributeDescription(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.TransactionTypeAttributeDescription) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) VertexTypeAttributeDescription(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.VertexTypeAttributeDescription) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) SchemaUpdateProvider(au.gov.asd.tac.constellation.graph.versioning.SchemaUpdateProvider) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) Graph(au.gov.asd.tac.constellation.graph.Graph) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) List(java.util.List) SchemaFactoryUtilities(au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) RawData(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData) TemporalConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.TemporalConcept) ServiceProvider(org.openide.util.lookup.ServiceProvider) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 2 with RawData

use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.

the class RawIOProvider method readObject.

@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException {
    final Object newValue;
    if (jnode.isNull()) {
        newValue = null;
    } else {
        final JsonNode identifier = jnode.get(RAW_IDENTIFIER_TAG);
        final JsonNode type = jnode.get(RAW_TYPE_TAG);
        final RawData attributeValue = new RawData(identifier.isNull() ? null : identifier.textValue(), type.isNull() ? null : jnode.get(RAW_TYPE_TAG).textValue());
        newValue = cache.deduplicate(attributeValue);
    }
    graph.setObjectValue(attributeId, elementId, newValue);
}
Also used : RawData(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with RawData

use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.

the class RawIOProvider method writeObject.

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

Example 4 with RawData

use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.

the class Scatter3dArranger method getFloatValueFromObject.

private float getFloatValueFromObject(final Object attributeValue, final boolean logarithmic) {
    if (attributeValue == null) {
        return 0.0F;
    }
    if (attributeValue instanceof Float) {
        return scaleValue((float) attributeValue, logarithmic);
    }
    if (attributeValue instanceof Double) {
        return scaleValue((float) attributeValue, logarithmic);
    }
    if (attributeValue instanceof String) {
        String val = (String) attributeValue;
        float finalVal = 0.0F;
        float multiplier = 1;
        for (int i = 0; i < val.length(); i++) {
            char ch = val.charAt(i);
            float chVal = (float) ch;
            finalVal += ((float) chVal) * multiplier;
            multiplier /= 26;
        }
        return scaleValue(finalVal, logarithmic);
    }
    if (attributeValue instanceof Integer) {
        float ret = (Integer) attributeValue;
        return scaleValue(ret, logarithmic);
    }
    if (attributeValue instanceof ConstellationColor) {
        ConstellationColor color = (ConstellationColor) attributeValue;
        float red = color.getRed() / 256;
        float green = color.getGreen() / 256;
        float blue = color.getBlue() / 256;
        return scaleValue((red + green + blue) * 100, logarithmic);
    }
    if (attributeValue instanceof ZonedDateTime) {
        ZonedDateTime c = (ZonedDateTime) attributeValue;
        float year = c.getYear();
        float month = c.getMonthValue();
        float monthDay = c.getDayOfMonth();
        float hour = c.getHour();
        float minute = c.getMinute();
        return scaleValue((year - 2010) + month / 12 + monthDay / (366) + hour / (366 * 24) + minute / (366 * 24 * 60), logarithmic);
    }
    if (attributeValue instanceof RawData) {
        String s = ((RawData) attributeValue).toString();
        return getFloatValueFromObject(s, logarithmic);
    }
    return 0.0F;
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) RawData(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData) ZonedDateTime(java.time.ZonedDateTime)

Aggregations

RawData (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData)4 Attribute (au.gov.asd.tac.constellation.graph.Attribute)1 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)1 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)1 SchemaFactoryUtilities (au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities)1 AnalyticSchemaFactory (au.gov.asd.tac.constellation.graph.schema.analytic.AnalyticSchemaFactory)1 RawAttributeDescription (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.RawAttributeDescription)1 TransactionTypeAttributeDescription (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.TransactionTypeAttributeDescription)1 VertexTypeAttributeDescription (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.VertexTypeAttributeDescription)1 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)1 TemporalConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.TemporalConcept)1 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)1 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)1 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)1 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)1 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)1 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)1