Search in sources :

Example 6 with Attribute

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

the class DataAccessStateIoProviderNGTest method writeObject.

@Test
public void writeObject() throws IOException {
    final DataAccessState state = new DataAccessState();
    state.newTab();
    state.add("key1", "value1");
    state.add("key2", "value2");
    state.newTab();
    state.add("key3", "value3");
    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(state);
    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();
    dataAccessStateIoProvider.writeObject(attribute, ELEMENT_ID, jsonGenerator, graph, null, false);
    jsonGenerator.writeEndObject();
    jsonGenerator.flush();
    final ObjectMapper objectMapper = new ObjectMapper();
    final JsonNode expected = objectMapper.readTree(new FileInputStream(getClass().getResource("resources/dataAccessStateWrite.json").getPath()));
    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) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Attribute(au.gov.asd.tac.constellation.graph.Attribute) 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) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 7 with Attribute

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

the class DataAccessStateIoProviderNGTest 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();
    dataAccessStateIoProvider.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) 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 8 with Attribute

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

the class FindViewController method populateAllAttributes.

/**
 * Returns a list of all available attributes on all open graphs. Used for
 * the attributes in the advanced find tab.
 *
 * @param type
 * @param attributeModificationCounter
 * @return
 */
public List<Attribute> populateAllAttributes(final GraphElementType type, final long attributeModificationCounter) {
    final List<Attribute> allAttributes = new ArrayList<>();
    for (final Graph graph : GraphManager.getDefault().getAllGraphs().values()) {
        // Call the plugin that retrieves all current attributes on the graph
        final GraphAttributePlugin attrPlugin = new GraphAttributePlugin(type, allAttributes, attributeModificationCounter);
        final Future<?> future = PluginExecution.withPlugin(attrPlugin).interactively(true).executeLater(graph);
        // Wait for the search to find its results:
        try {
            future.get();
        } catch (final InterruptedException ex) {
            LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
            Thread.currentThread().interrupt();
        } catch (final ExecutionException ex) {
            LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        }
        // get all the current attributes based on the currently selcted type
        allAttributes.addAll(attrPlugin.getAttributes());
    }
    final Set<Attribute> attributeSet = new LinkedHashSet<>();
    attributeSet.addAll(allAttributes);
    allAttributes.clear();
    allAttributes.addAll(attributeSet);
    allAttributes.sort(Comparator.comparing(Attribute::getName));
    return allAttributes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttributePlugin(au.gov.asd.tac.constellation.views.find2.plugins.GraphAttributePlugin) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with Attribute

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

the class BasicFindTab method saveSelected.

/**
 * Retrieves the selected list of the matching type, clears it, then re adds
 * all selected elements to that list
 *
 * @param type
 */
public void saveSelected(final GraphElementType type) {
    final List<Attribute> selectedAttributes = getMatchingAttributeList(type);
    selectedAttributes.clear();
    // if the attributes list is not empty
    if (!attributes.isEmpty()) {
        // loop through all attributes
        for (final Attribute a : attributes) {
            // if that attribute is selected
            if (!inAttributesMenu.getCheckModel().isEmpty() && inAttributesMenu.getCheckModel().isChecked(a.getName())) {
                // add it to the selected attributes list
                selectedAttributes.add(a);
            }
        }
    }
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute)

Example 10 with Attribute

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

the class FindTopComponent method performBasicSearch.

// public because BasicFindPanel calls this on enter as well.
public void performBasicSearch() {
    final ArrayList<Attribute> selectedAttributes = basicFindPanel.getSelectedAttributes();
    final String findString = basicFindPanel.getFindString();
    final boolean regex = basicFindPanel.hasRegex();
    final boolean ignoreCase = basicFindPanel.isIgnorecase();
    final boolean matchWholeWord = basicFindPanel.isExactMatch();
    final BasicFindPlugin basicfindPlugin = new BasicFindPlugin(type, selectedAttributes, findString, regex, ignoreCase, matchWholeWord, chkAddToSelection.isSelected());
    PluginExecution.withPlugin(basicfindPlugin).executeLater(graphNode.getGraph());
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) BasicFindPlugin(au.gov.asd.tac.constellation.views.find.BasicFindPlugin)

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