Search in sources :

Example 21 with Attribute

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

the class BasicFindPluginNGTest method getAttributes.

/**
 * Used to convert the string variant of attributes to the Attribute object
 *
 * @return the list of Attribute objects
 */
private ArrayList<Attribute> getAttributes() {
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    ArrayList<Attribute> attributes = new ArrayList<>();
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        GraphElementType type = GraphElementType.VERTEX;
        List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
        ReadableGraph rg = graph.getReadableGraph();
        for (int i = 0; i < result.size(); i++) {
            int attributeInt = rg.getAttribute(type, result.get(i));
            GraphAttribute ga = new GraphAttribute(rg, attributeInt);
            if (ga.getAttributeType().equals("string")) {
                attributes.add(new GraphAttribute(rg, attributeInt));
                System.out.println(attributes.get(i).getName() + " = attribute name");
            }
        }
        rg.close();
    }
    return attributes;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) FindViewTopComponent(au.gov.asd.tac.constellation.views.find2.FindViewTopComponent) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController)

Example 22 with Attribute

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

the class ReplacePluginNGTest method getAttributes.

/**
 * Used to convert the string variant of attributes to the Attribute object
 *
 * @return the list of Attribute objects
 */
private ArrayList<Attribute> getAttributes() {
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    ArrayList<Attribute> attributes = new ArrayList<>();
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        GraphElementType type = GraphElementType.VERTEX;
        List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
        ReadableGraph rg = graph.getReadableGraph();
        for (int i = 0; i < result.size(); i++) {
            int attributeInt = rg.getAttribute(type, result.get(i));
            GraphAttribute ga = new GraphAttribute(rg, attributeInt);
            if (ga.getAttributeType().equals("string")) {
                attributes.add(new GraphAttribute(rg, attributeInt));
            }
        }
        rg.close();
    }
    return attributes;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) FindViewTopComponent(au.gov.asd.tac.constellation.views.find2.FindViewTopComponent) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController)

Example 23 with Attribute

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

the class ResetStatePluginNGTest method setupGraph.

private void setupGraph() {
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    try {
        WritableGraph wg = graph.getWritableGraph("", true);
        final int stateId = FindViewConcept.MetaAttribute.FINDVIEW_STATE.ensure(wg);
        ArrayList<Attribute> attributeList = new ArrayList<>();
        BasicFindReplaceParameters parameters = new BasicFindReplaceParameters("label name", "", GraphElementType.GRAPH.VERTEX, attributeList, true, false, false, false, false, false, false, false, false);
        FindResultsList foundResult = new FindResultsList(2, parameters, graph.getId());
        wg.setObjectValue(stateId, 0, foundResult);
        wg.commit();
    } catch (final InterruptedException ex) {
        Exceptions.printStackTrace(ex);
        Thread.currentThread().interrupt();
    }
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArrayList(java.util.ArrayList) BasicFindReplaceParameters(au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters) FindResultsList(au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 24 with Attribute

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

the class FindViewControllerNGTest method testUpdateBasicReplaceParameters.

/**
 * Test of updateBasicReplaceParameters method, of class FindViewController.
 */
@Test
public void testUpdateBasicReplaceParameters() {
    System.out.println("updateBasicReplaceParameters");
    FindViewController instance = FindViewController.getDefault();
    List<Attribute> attributeList = new ArrayList<>();
    instance.updateBasicReplaceParameters(parameters);
    BasicFindReplaceParameters result = instance.getCurrentBasicReplaceParameters();
    // The object is copied in the updateBasicFindParameters function
    // This will cause a direct comparison of the object to be false
    assertEquals(result, parameters);
    assertNotEquals(result, parameters2);
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArrayList(java.util.ArrayList) BasicFindReplaceParameters(au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters) Test(org.testng.annotations.Test)

Example 25 with Attribute

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

the class GraphJsonWriter method writeElements.

/**
 * Write elements of a Graph to JSON.
 *
 * @param jg The JsonGenerator to use for writing.
 * @param graph The graph.
 * @param elementType The GraphElementType being written.
 * @param writeData If false, write out the attributes but not the data for
 * the given element type.
 *
 * @throws IOException
 */
private void writeElements(final JsonGenerator jg, final GraphReadMethods graph, final GraphElementType elementType, final boolean verbose, final boolean writeData) throws Exception {
    final String elementTypeLabel = IoUtilities.getGraphElementTypeString(elementType);
    if (progress != null) {
        progress.progress("Writing " + elementTypeLabel + " elements...");
    }
    final AbstractGraphIOProvider[] ioProviders = new AbstractGraphIOProvider[graph.getAttributeCapacity()];
    final ArrayList<Attribute> attrs = new ArrayList<>();
    for (int position = 0; position < graph.getAttributeCount(elementType); position++) {
        final int attrId = graph.getAttribute(elementType, position);
        final Attribute attr = new GraphAttribute(graph, attrId);
        ioProviders[attrId] = graphIoProviders.get(attr.getAttributeType());
        // Don't write non-META object types; we don't know what they are.
        if (!"object".equals(attr.getAttributeType()) || elementType == GraphElementType.META) {
            attrs.add(attr);
        }
    }
    // Here we go.
    jg.writeStartObject();
    jg.writeArrayFieldStart(elementTypeLabel);
    jg.writeStartObject();
    jg.writeArrayFieldStart("attrs");
    // Write the attributes.
    for (final Attribute attr : attrs) {
        jg.writeStartObject();
        jg.writeStringField("label", attr.getName());
        jg.writeStringField("type", attr.getAttributeType());
        if (attr.getDescription() != null) {
            jg.writeStringField("descr", attr.getDescription());
        }
        // actual attribute values inside the attribute descriptions.
        if (attr.getDefaultValue() != null && isNumeric(attr)) {
            jg.writeNumberField(DEFAULT_FIELD, ((Number) attr.getDefaultValue()).doubleValue());
        } else if (attr.getDefaultValue() != null && "boolean".equals(attr.getAttributeType())) {
            jg.writeBooleanField(DEFAULT_FIELD, (Boolean) attr.getDefaultValue());
        } else if (attr.getDefaultValue() != null) {
            jg.writeStringField(DEFAULT_FIELD, attr.getDefaultValue().toString());
        } else {
        // Do nothing
        }
        if (attr.getAttributeMerger() != null) {
            jg.writeStringField("merger", attr.getAttributeMerger().getId());
        }
        jg.writeNumberField("mod_count", graph.getValueModificationCounter(attr.getId()));
        jg.writeEndObject();
    }
    jg.writeEndArray();
    // Check for optional key.
    if (elementType == GraphElementType.VERTEX || elementType == GraphElementType.TRANSACTION) {
        final int[] key = graph.getPrimaryKey(elementType);
        if (key.length > 0) {
            // Write the labels of the key attributes.
            jg.writeArrayFieldStart("key");
            for (int i = 0; i < key.length; i++) {
                final Attribute attr = new GraphAttribute(graph, key[i]);
                jg.writeString(attr.getName());
            }
            jg.writeEndArray();
        }
    }
    jg.writeEndObject();
    // Write the main graph data (graph, vertex, transaction).
    jg.writeStartObject();
    jg.writeArrayFieldStart("data");
    if (!writeData) {
    // Do nothing
    } else if (elementType == GraphElementType.GRAPH || elementType == GraphElementType.META) {
        jg.writeStartObject();
        for (final Attribute attr : attrs) {
            final AbstractGraphIOProvider ioProvider = ioProviders[attr.getId()];
            if (ioProvider != null) {
                // Get the provider to write its data into an ObjectNode.
                // If they didn't write anything, don't write the data to the JSON.
                ioProvider.writeObject(attr, 0, jg, graph, byteWriter, verbose);
            } else {
                final Object value = graph.getObjectValue(attr.getId(), 0);
                final String className = value != null ? value.getClass().getName() : "<null>";
                final String msg = String.format("No I/O provider found for object type %s, attribute %s", className, attr);
                throw new Exception(msg);
            }
        }
        jg.writeEndObject();
    } else if (elementType == GraphElementType.VERTEX) {
        for (int position = 0; position < graph.getVertexCount(); position++) {
            final int vxId = graph.getVertex(position);
            jg.writeStartObject();
            jg.writeNumberField(GraphFileConstants.VX_ID, vxId);
            for (final Attribute attr : attrs) {
                final AbstractGraphIOProvider ioProvider = ioProviders[attr.getId()];
                if (ioProvider != null) {
                    // Get the provider to write its data into an ObjectNode.
                    // If they didn't write anything, don't write the data to the JSON.
                    ioProvider.writeObject(attr, vxId, jg, graph, byteWriter, verbose);
                } else {
                    throw new Exception("No IO provider found for attribute type: " + attr.getAttributeType());
                }
            }
            jg.writeEndObject();
            counter++;
            if (counter % REPORT_INTERVAL == 0 && isCancelled) {
                return;
            } else if (counter % REPORT_INTERVAL == 0 && progress != null) {
                progress.progress(counter);
            } else {
            // Do nothing
            }
        }
    } else if (elementType == GraphElementType.TRANSACTION) {
        for (int position = 0; position < graph.getTransactionCount(); position++) {
            final int txId = graph.getTransaction(position);
            jg.writeStartObject();
            jg.writeNumberField(GraphFileConstants.TX_ID, txId);
            jg.writeNumberField(GraphFileConstants.SRC, graph.getTransactionSourceVertex(txId));
            jg.writeNumberField(GraphFileConstants.DST, graph.getTransactionDestinationVertex(txId));
            jg.writeBooleanField(GraphFileConstants.DIR, graph.getTransactionDirection(txId) != Graph.UNDIRECTED);
            for (final Attribute attr : attrs) {
                final AbstractGraphIOProvider ioProvider = ioProviders[attr.getId()];
                if (ioProvider != null) {
                    // Get the provider to write its data into an ObjectNode.
                    // If they didn't write anything, don't write the data to the JSON.
                    ioProvider.writeObject(attr, txId, jg, graph, byteWriter, verbose);
                } else {
                    throw new Exception("No IO provider found for attribute type: " + attr.getAttributeType());
                }
            }
            jg.writeEndObject();
            counter++;
            if (counter % REPORT_INTERVAL == 0 && isCancelled) {
                return;
            } else if (counter % REPORT_INTERVAL == 0 && progress != null) {
                progress.progress(counter);
            }
        }
    } else {
    // Do nothing
    }
    jg.writeEndArray();
    jg.writeEndObject();
    jg.writeEndArray();
    jg.writeEndObject();
}
Also used : AbstractGraphIOProvider(au.gov.asd.tac.constellation.graph.attribute.io.AbstractGraphIOProvider) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

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