Search in sources :

Example 46 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.

the class TableViewStateIoProviderNGTest method writeObjectStateIsNull.

@Test
public void writeObjectStateIsNull() throws IOException {
    final Attribute attribute = mock(Attribute.class);
    when(attribute.getId()).thenReturn(ATTRIBUTE_ID);
    when(attribute.getName()).thenReturn("ATTR NAME");
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    when(graph.isDefaultValue(ATTRIBUTE_ID, ELEMENT_ID)).thenReturn(false);
    when(graph.getObjectValue(ATTRIBUTE_ID, ELEMENT_ID)).thenReturn(null);
    final JsonFactory factory = new JsonFactory();
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = factory.createGenerator(output);
    // The code is written with the assumption that it is called within a document
    // that has already started being written. Without starting the object in the test
    // the code would throw invalid json exceptions.
    jsonGenerator.writeStartObject();
    tableViewStateIoProvider.writeObject(attribute, ELEMENT_ID, jsonGenerator, graph, null, false);
    jsonGenerator.writeEndObject();
    jsonGenerator.flush();
    final ObjectMapper objectMapper = new ObjectMapper();
    final JsonNode expected = objectMapper.readTree("{\"ATTR NAME\": null}");
    final JsonNode actual = objectMapper.readTree(new String(output.toByteArray(), StandardCharsets.UTF_8));
    assertEquals(actual, expected);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 47 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.

the class TableViewStateIoProviderNGTest method readObject.

@Test
public void readObject() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    final JsonNode jsonNode = objectMapper.readTree(new FileInputStream(getClass().getResource("resources/tableViewStateRead.json").getPath()));
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    when(graph.getAttribute(GraphElementType.TRANSACTION, "My Transaction")).thenReturn(1);
    when(graph.getAttribute(GraphElementType.VERTEX, "My Vertex")).thenReturn(2);
    tableViewStateIoProvider.readObject(ATTRIBUTE_ID, ELEMENT_ID, jsonNode, graph, null, null, null, null);
    // Capture the call on the graph setter, pulling out the state
    final ArgumentCaptor<TableViewState> captor = ArgumentCaptor.forClass(TableViewState.class);
    verify(graph, times(1)).setObjectValue(eq(ATTRIBUTE_ID), eq(ELEMENT_ID), captor.capture());
    final TableViewState actual = captor.getValue();
    final TableViewState expected = new TableViewState();
    assertTrue(actual.isSelectedOnly());
    assertEquals(actual.getElementType(), GraphElementType.VERTEX);
    assertEquals(actual.getTransactionColumnAttributes().size(), 1);
    final Tuple<String, Attribute> transactionColumnAttr = actual.getTransactionColumnAttributes().get(0);
    assertEquals(transactionColumnAttr.getFirst(), "transactionPrefix");
    assertEquals(transactionColumnAttr.getSecond(), new GraphAttribute(graph, 1));
    assertEquals(actual.getVertexColumnAttributes().size(), 1);
    final Tuple<String, Attribute> vertexColumnAttr = actual.getVertexColumnAttributes().get(0);
    assertEquals(vertexColumnAttr.getFirst(), "vertexPrefix");
    assertEquals(vertexColumnAttr.getSecond(), new GraphAttribute(graph, 2));
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 48 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.

the class TimelineTopComponent method populateFromGraph.

private void populateFromGraph(final Graph graph, final boolean isFullRefresh) {
    final Thread t = new Thread() {

        @Override
        public void run() {
            if (graph == null) {
                // with no graph to populate from there's no point continuing
                return;
            }
            datetimeAttributes = new ArrayList<>();
            final ReadableGraph rg = graph.getReadableGraph();
            try {
                final int attributeCount = rg.getAttributeCount(GraphElementType.TRANSACTION);
                for (int i = 0; i < attributeCount; i++) {
                    final int attrID = rg.getAttribute(GraphElementType.TRANSACTION, i);
                    final Attribute attribute = new GraphAttribute(rg, attrID);
                    final String attributeType = attribute.getAttributeType();
                    if (SUPPORTED_DATETIME_ATTRIBUTE_TYPES.contains(attributeType)) {
                        datetimeAttributes.add(attribute.getName());
                    }
                }
                if (!datetimeAttributes.isEmpty()) {
                    if (state != null && datetimeAttributes.contains(state.getDateTimeAttr())) {
                        currentDatetimeAttribute = state.getDateTimeAttr();
                        GraphManager.getDefault().setDatetimeAttr(currentDatetimeAttribute);
                    } else {
                        // Set the current datetime to the first found datetime attribute from the graph:
                        currentDatetimeAttribute = datetimeAttributes.get(0);
                        GraphManager.getDefault().setDatetimeAttr(currentDatetimeAttribute);
                    }
                } else {
                    // There are no datetime attributes on the graph:
                    currentDatetimeAttribute = null;
                    GraphManager.getDefault().setDatetimeAttr(currentDatetimeAttribute);
                    hideTimeline(Bundle.NoTemporal());
                    return;
                }
                if (currentDatetimeAttribute != null) {
                    currentTemporalAttributeModificationCount = rg.getValueModificationCounter(rg.getAttribute(GraphElementType.TRANSACTION, currentDatetimeAttribute));
                    // We've calculated everything, so start populating the graph:
                    Platform.runLater(() -> {
                        final ReadableGraph rg1 = graph.getReadableGraph();
                        try {
                            // Now that the heights are known, set the position of the splitPane divider:
                            splitPane.setDividerPositions(splitPanePosition);
                            // Clear anything already on the charts:
                            timelinePanel.clearTimeline();
                            overviewPanel.clearHistogram(!isFullRefresh);
                            // Ensure that everything is visible:
                            timelinePanel.setDisable(false);
                            // if visibility is set to false at the constructor, the javafx thread gets stuck in an endless loop under
                            // certain conditions (with timeline open, create graph, close graph) so we set opacity to 0 in the constructor so that it is 'invisible'
                            splitPane.setVisible(true);
                            splitPane.setDisable(false);
                            // Add the datetime attributes:
                            timelinePanel.setDateTimeAttributes(datetimeAttributes, currentDatetimeAttribute);
                            timelinePanel.setTimeZone(state == null ? TimeZoneUtilities.UTC : state.getTimeZone());
                            // Add the label attributes:
                            timelinePanel.setNodeLabelAttributes(GraphManager.getDefault().getVertexAttributeNames());
                            final boolean selectedOnly = state != null && state.isShowingSelectedOnly();
                            timelinePanel.setIsShowingSelectedOnly(selectedOnly);
                            if (state != null && state.getNodeLabelsAttr() != null) {
                                timelinePanel.setNodeLabelAttribute(state.getNodeLabelsAttr());
                                timelinePanel.setIsShowingNodeLabelAttributes(state.isShowingNodeLabels());
                                timelinePanel.populateFromGraph(rg1, currentDatetimeAttribute, state.getNodeLabelsAttr(), selectedOnly, state.getTimeZone());
                            } else {
                                timelinePanel.populateFromGraph(rg1, currentDatetimeAttribute, null, selectedOnly, state == null ? TimeZoneUtilities.UTC : state.getTimeZone());
                            }
                            overviewPanel.populateHistogram(rg1, currentDatetimeAttribute, getTimelineLowerTimeExtent(), getTimelineUpperTimeExtent(), isFullRefresh, selectedOnly);
                        } finally {
                            rg1.release();
                        }
                        // Restore the dimming state if we have it:
                        if (state != null) {
                            if (state.getLowerTimeExtent() == 0) {
                                setExtents(getTimelineLowerTimeExtent(), getTimelineUpperTimeExtent());
                            }
                            timelinePanel.setExclusionState(state.exclusionState());
                        } else {
                            // There is no state, so lets create a new one:
                            state = new TimelineState(getTimelineLowerTimeExtent(), getTimelineUpperTimeExtent(), 0, false, currentDatetimeAttribute, false, null, TimeZoneUtilities.UTC);
                        }
                        setExtents(state.getLowerTimeExtent(), state.getUpperTimeExtent());
                    });
                }
            } finally {
                rg.release();
            }
        }
    };
    t.setName(UPDATE_TIMELINE_THREAD_NAME);
    t.start();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 49 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute 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 50 with Attribute

use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.

the class AttributeReader method updateElementAttributeNames.

private void updateElementAttributeNames(final ReadableGraph rg, final List<GraphElementType> elementTypes, final Set<String> hiddenAttrsSet, final Map<GraphElementType, Boolean> showAllPrefs) {
    elementAttributeData.clear();
    for (final GraphElementType elementType : elementTypes) {
        final int attributeCount = rg.getAttributeCount(elementType);
        final ArrayList<AttributeData> attributeNames = new ArrayList<>();
        final boolean showAll = showAllPrefs.get(elementType);
        for (int i = 0; i < attributeCount; i++) {
            final Attribute attr = new GraphAttribute(rg, rg.getAttribute(elementType, i));
            if (!showAll && hiddenAttrsSet.contains(attr.getElementType().toString() + attr.getName())) {
                continue;
            }
            final boolean isSchemaAttr = rg.getSchema() != null && rg.getSchema().getFactory().getRegisteredAttributes(attr.getElementType()).containsKey(attr.getName());
            final AttributeData attrData = new AttributeData(attr.getName(), attr.getDescription(), attr.getId(), rg.getValueModificationCounter(attr.getId()), elementType, attr.getAttributeType(), attr.getDefaultValue(), rg.isPrimaryKey(attr.getId()), isSchemaAttr);
            attributeNames.add(attrData);
        }
        Collections.sort(attributeNames, (o1, o2) -> o1.getAttributeName().compareTo(o2.getAttributeName()));
        elementAttributeCounts.put(elementType, attributeCount);
        elementAttributeData.put(elementType, attributeNames);
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Aggregations

Attribute (au.gov.asd.tac.constellation.graph.Attribute)94 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)55 ArrayList (java.util.ArrayList)30 Test (org.testng.annotations.Test)23 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)18 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)15 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)13 Graph (au.gov.asd.tac.constellation.graph.Graph)12 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObservableList (javafx.collections.ObservableList)8 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)7 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)7 TableColumn (javafx.scene.control.TableColumn)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)5 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)5