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);
}
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);
}
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;
}
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);
}
}
}
}
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());
}
Aggregations