Search in sources :

Example 6 with GraphAttribute

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

the class FindStateIOProvider method getRule.

/**
 * Helper method that deserialises an individual rule from a JSON node.
 *
 * @param graph The graph that is being loaded.
 * @param node The node that contains an individual FindRule.
 * @return A single FindRule.
 */
private static FindRule getRule(final GraphReadMethods graph, final JsonNode node) {
    final FindRule rule = new FindRule();
    final int attrID = graph.getAttribute(GraphElementType.getValue(node.get(ELMT).asText()), node.get(ATTR).asText());
    if (attrID != Graph.NOT_FOUND) {
        final Attribute attr = new GraphAttribute(graph, attrID);
        rule.setAttribute(attr);
        rule.setOperator(FindTypeOperators.Operator.getTypeEnum(node.get(OPER).textValue()));
        rule.setType(FindTypeOperators.Type.getTypeEnum(node.get(TYPE).textValue()));
        rule.setHeld(node.get(HOLD).asBoolean());
        rule.setArgs(getArguments(node.get(ARGS)));
        return rule;
    }
    return null;
}
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)

Example 7 with GraphAttribute

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

the class GraphAttributePlugin method retrieveAttributes.

/**
 * Helper method that performs the attribute query operation.
 * <p>
 * Sets any found attributes to an internal variable which can be later
 * returned through use of the <code>getAttributes()</code> method.
 *
 * @param graph The graph to retrieve attributes for.
 *
 * @see Graph
 */
private void retrieveAttributes(final GraphReadMethods graph) {
    final long amc = graph.getAttributeModificationCounter();
    attributes.clear();
    final int attrCount = graph.getAttributeCount(type);
    for (int position = 0; position < attrCount; position++) {
        final int attr = graph.getAttribute(type, position);
        final Attribute candidate = new GraphAttribute(graph, attr);
        attributes.add(candidate);
    }
    attributeModificationCounter = amc;
}
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)

Example 8 with GraphAttribute

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

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

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

the class ReplaceTabNGTest method setupGraph.

private void setupGraph() {
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    graph2 = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    graphMap.put(graph.getId(), graph);
    graphMap.put(graph2.getId(), graph2);
    try {
        WritableGraph wg = graph.getWritableGraph("", true);
        // Create Selected Attributes
        selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        labelV = VisualConcept.VertexAttribute.LABEL.ensure(wg);
        identifierV = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
        xV = VisualConcept.VertexAttribute.X.ensure(wg);
        selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        labelT = VisualConcept.TransactionAttribute.LABEL.ensure(wg);
        identiferT = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(wg);
        widthT = VisualConcept.TransactionAttribute.WIDTH.ensure(wg);
        vxId1 = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId1, false);
        wg.setStringValue(labelV, vxId1, "label name");
        wg.setStringValue(identifierV, vxId1, "identifer name");
        wg.setIntValue(xV, vxId1, 1);
        /**
         * Get the label and the identifier vertex attributes and add them
         * to the attributes list
         */
        GraphElementType elementType = GraphElementType.VERTEX;
        // The label attribute
        int attributeInt = wg.getAttribute(elementType, 1);
        labelAttributeV = new GraphAttribute(wg, attributeInt);
        replaceTab.attributes.add(labelAttributeV);
        // The identifier attribute
        attributeInt = wg.getAttribute(elementType, 2);
        identifierAttributeV = new GraphAttribute(wg, attributeInt);
        replaceTab.attributes.add(identifierAttributeV);
        elementType = GraphElementType.TRANSACTION;
        attributeInt = wg.getAttribute(elementType, 1);
        labelAttributeT = new GraphAttribute(wg, attributeInt);
        attributeInt = wg.getAttribute(elementType, 2);
        identifierAttributeT = new GraphAttribute(wg, attributeInt);
        wg.commit();
    } catch (final InterruptedException ex) {
        Exceptions.printStackTrace(ex);
        Thread.currentThread().interrupt();
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Aggregations

GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)65 Attribute (au.gov.asd.tac.constellation.graph.Attribute)45 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)25 ArrayList (java.util.ArrayList)25 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)19 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)15 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)10 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)9 Graph (au.gov.asd.tac.constellation.graph.Graph)8 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)8 FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)8 TopComponent (org.openide.windows.TopComponent)8 TableColumn (javafx.scene.control.TableColumn)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 List (java.util.List)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)4 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)3