Search in sources :

Example 6 with SchemaAttribute

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

the class LayersViewStateIoProvider 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 {
    if (!jnode.isNull()) {
        final List<BitMaskQuery> vxlayerDescriptions = new ArrayList<>();
        final ArrayNode vertexLayersArray = (ArrayNode) jnode.withArray("vertexLayers");
        for (int i = 0; i < vertexLayersArray.size(); i++) {
            if (vertexLayersArray.get(i).isNull()) {
                vxlayerDescriptions.add(null);
            } else {
                final BitMaskQuery query = new BitMaskQuery(new Query(GraphElementType.VERTEX, StringUtils.equals("null", vertexLayersArray.get(i).get(2).asText()) ? "" : vertexLayersArray.get(i).get(2).asText()), vertexLayersArray.get(i).get(0).asInt(), vertexLayersArray.get(i).get(3).asText());
                query.setVisibility(vertexLayersArray.get(i).get(1).asBoolean());
                vxlayerDescriptions.add(query);
            }
        }
        final List<BitMaskQuery> txlayerDescriptions = new ArrayList<>();
        final ArrayNode transactionLayersArray = (ArrayNode) jnode.withArray("transactionLayers");
        for (int i = 0; i < transactionLayersArray.size(); i++) {
            if (transactionLayersArray.get(i).isNull()) {
                txlayerDescriptions.add(null);
            } else {
                final BitMaskQuery query = new BitMaskQuery(new Query(GraphElementType.TRANSACTION, StringUtils.equals("null", transactionLayersArray.get(i).get(2).asText()) ? "" : transactionLayersArray.get(i).get(2).asText()), transactionLayersArray.get(i).get(0).asInt(), transactionLayersArray.get(i).get(3).asText());
                query.setVisibility(transactionLayersArray.get(i).get(1).asBoolean());
                txlayerDescriptions.add(query);
            }
        }
        final List<SchemaAttribute> layerAttributes = new ArrayList<>();
        final ArrayNode layerAttributesArray = (ArrayNode) jnode.withArray("layerAttributes");
        for (int i = 0; i < layerAttributesArray.size(); i++) {
            if (layerAttributesArray.get(i).isNull()) {
                layerAttributes.add(null);
            } else {
                layerAttributes.add(SchemaAttributeUtilities.getAttribute(GraphElementType.getValue(layerAttributesArray.get(i).get(0).asText()), layerAttributesArray.get(i).get(1).asText()));
            }
        }
        BitMaskQueryCollection vxQueries = new BitMaskQueryCollection(GraphElementType.VERTEX);
        vxQueries.setQueries(vxlayerDescriptions.toArray(new BitMaskQuery[64]));
        BitMaskQueryCollection txQueries = new BitMaskQueryCollection(GraphElementType.TRANSACTION);
        txQueries.setQueries(txlayerDescriptions.toArray(new BitMaskQuery[64]));
        final LayersViewState state = new LayersViewState(layerAttributes, vxQueries, txQueries);
        graph.setObjectValue(attributeId, elementId, state);
    }
}
Also used : BitMaskQueryCollection(au.gov.asd.tac.constellation.views.layers.query.BitMaskQueryCollection) BitMaskQuery(au.gov.asd.tac.constellation.views.layers.query.BitMaskQuery) Query(au.gov.asd.tac.constellation.views.layers.query.Query) BitMaskQuery(au.gov.asd.tac.constellation.views.layers.query.BitMaskQuery) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 7 with SchemaAttribute

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

the class LayersViewStateIoProvider 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 LayersViewState originalState = graph.getObjectValue(attribute.getId(), elementId);
        if (originalState == null) {
            jsonGenerator.writeNullField(attribute.getName());
        } else {
            // make a copy in case the state on the graph is currently being modified.
            final LayersViewState state = new LayersViewState(originalState);
            jsonGenerator.writeObjectFieldStart(attribute.getName());
            jsonGenerator.writeArrayFieldStart("vertexLayers");
            for (final BitMaskQuery layer : state.getVxQueriesCollection().getQueries()) {
                if (layer == null) {
                    jsonGenerator.writeNull();
                } else {
                    jsonGenerator.writeStartArray("index", layer.getIndex());
                    jsonGenerator.writeNumber(layer.getIndex());
                    jsonGenerator.writeBoolean(layer.isVisible());
                    jsonGenerator.writeString(layer.getQueryString());
                    jsonGenerator.writeString(layer.getDescription());
                    jsonGenerator.writeEndArray();
                }
            }
            jsonGenerator.writeEndArray();
            jsonGenerator.writeArrayFieldStart("transactionLayers");
            for (final BitMaskQuery layer : state.getTxQueriesCollection().getQueries()) {
                if (layer == null) {
                    jsonGenerator.writeNull();
                } else {
                    jsonGenerator.writeStartArray("index", layer.getIndex());
                    jsonGenerator.writeNumber(layer.getIndex());
                    jsonGenerator.writeBoolean(layer.isVisible());
                    jsonGenerator.writeString(layer.getQueryString());
                    jsonGenerator.writeString(layer.getDescription());
                    jsonGenerator.writeEndArray();
                }
            }
            jsonGenerator.writeEndArray();
            jsonGenerator.writeArrayFieldStart("layerAttributes");
            int count = 0;
            for (final SchemaAttribute attr : state.getLayerAttributes()) {
                if (attr == null) {
                    jsonGenerator.writeNull();
                } else {
                    jsonGenerator.writeStartArray("index", count++);
                    jsonGenerator.writeString(attr.getElementType().toString());
                    jsonGenerator.writeString(attr.getName());
                    jsonGenerator.writeEndArray();
                }
            }
            jsonGenerator.writeEndArray();
            jsonGenerator.writeEndObject();
        }
    }
}
Also used : BitMaskQuery(au.gov.asd.tac.constellation.views.layers.query.BitMaskQuery) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 8 with SchemaAttribute

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

the class AttributeNodeProvider method getSchemaInfo.

private List<AttributeEntry> getSchemaInfo(final Graph graph) {
    final List<AttributeEntry> attrs = new ArrayList<>();
    final Schema schema = graph.getSchema();
    final SchemaFactory factory = schema.getFactory();
    // Get the keys for each element type.
    final Map<GraphElementType, List<String>> elementKeys = new HashMap<>();
    for (final GraphElementType et : new GraphElementType[] { GraphElementType.VERTEX, GraphElementType.TRANSACTION }) {
        final List<SchemaAttribute> keys = factory.getKeyAttributes(et);
        final List<String> keyLabels = keys.stream().map(key -> key.getName()).collect(Collectors.toList());
        elementKeys.put(et, keyLabels);
    }
    for (final GraphElementType et : GraphElementType.values()) {
        final Map<String, SchemaAttribute> attrsMap = factory.getRegisteredAttributes(et);
        attrsMap.values().stream().forEach(schemaAttribute -> {
            final int keyIx = elementKeys.containsKey(schemaAttribute.getElementType()) ? elementKeys.get(schemaAttribute.getElementType()).indexOf(schemaAttribute.getName()) : -1;
            final Collection<SchemaConcept> concepts = SchemaConceptUtilities.getAttributeConcepts(schemaAttribute);
            final StringBuilder categories = new StringBuilder();
            for (SchemaConcept concept : concepts) {
                categories.append(concept.getName()).append(",");
            }
            if (categories.length() > 0) {
                categories.deleteCharAt(categories.length() - 1);
            }
            attrs.add(new AttributeEntry(schemaAttribute, categories.toString(), keyIx));
        });
    }
    return attrs;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Pos(javafx.geometry.Pos) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) GraphManagerListener(au.gov.asd.tac.constellation.graph.manager.GraphManagerListener) VBox(javafx.scene.layout.VBox) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Graph(au.gov.asd.tac.constellation.graph.Graph) Insets(javafx.geometry.Insets) Map(java.util.Map) ServiceProvider(org.openide.util.lookup.ServiceProvider) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) TableView(javafx.scene.control.TableView) UserInterfaceIconProvider(au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaConceptUtilities(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConceptUtilities) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Collection(java.util.Collection) StaticResource(org.netbeans.api.annotations.common.StaticResource) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) ToggleGroup(javafx.scene.control.ToggleGroup) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) RadioButton(javafx.scene.control.RadioButton) ImageView(javafx.scene.image.ImageView) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) ObservableList(javafx.collections.ObservableList) Image(javafx.scene.image.Image) HashMap(java.util.HashMap) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) ArrayList(java.util.ArrayList) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 9 with SchemaAttribute

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

the class LevenshteinDistancePlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    final List<String> stringAttributes = new ArrayList<>();
    if (graph.getSchema() != null) {
        final Map<String, SchemaAttribute> attributes = graph.getSchema().getFactory().getRegisteredAttributes(GraphElementType.VERTEX);
        for (final String attr : attributes.keySet()) {
            final SchemaAttribute attribute = attributes.get(attr);
            final String attributeType = attribute.getAttributeType();
            if (attributeType.equals(StringAttributeDescription.ATTRIBUTE_NAME)) {
                stringAttributes.add(attr);
            }
        }
    }
    stringAttributes.sort(String::compareTo);
    if (parameters != null && parameters.getParameters() != null) {
        // ATTRIBUTE_PARAMETER_ID is created as a SingleChoiceParmeter in this class on line 71.
        @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> compareAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(ATTRIBUTE_PARAMETER_ID);
        SingleChoiceParameterType.setOptions(compareAttribute, stringAttributes);
        if (stringAttributes.contains(VisualConcept.VertexAttribute.IDENTIFIER.getName())) {
            SingleChoiceParameterType.setChoice(compareAttribute, VisualConcept.VertexAttribute.IDENTIFIER.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 10 with SchemaAttribute

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

Aggregations

SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)17 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)9 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)7 ArrayList (java.util.ArrayList)6 Graph (au.gov.asd.tac.constellation.graph.Graph)5 List (java.util.List)5 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)3 SchemaFactoryUtilities (au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 Attribute (au.gov.asd.tac.constellation.graph.Attribute)2 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)2 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)2 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)2 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)2 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)2 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)2 VisualSchemaFactory (au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaFactory)2 SchemaUpdateProvider (au.gov.asd.tac.constellation.graph.versioning.SchemaUpdateProvider)2