use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method loadDataAccessState_empty_state.
@Test
public void loadDataAccessState_empty_state() {
// mock graph
final Graph graph = mock(Graph.class);
final ReadableGraph rGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(rGraph);
// mock data access state attribute in graph
when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
when(rGraph.getObjectValue(2, 0)).thenReturn(new DataAccessState());
// mock tab pane
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final Tab currentTab = mock(Tab.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
daTabPaneMockedStatic.verifyNoInteractions();
verify(rGraph).release();
}
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class TransactionQuickSearchProvider method evaluate.
/**
* Determines whether any content from the current Graph matches the search
* term.
*
* @param request The content being entered into the QuickSearch box.
* @param response The content to be returned to the QuickSearch box.
*/
@Override
@SuppressWarnings("unchecked")
public void evaluate(final SearchRequest request, final SearchResponse response) {
final Graph graph = graphRetriever.getGraph();
if (graph != null) {
final QuickFindPlugin plugin = new QuickFindPlugin(GraphElementType.TRANSACTION, request.getText());
final Future<?> future = PluginExecution.withPlugin(plugin).interactively(true).executeLater(graph);
// Wait for results:
try {
future.get();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, "Quick Find was interrupted", ex);
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
final List<FindResult> results = plugin.getResults();
for (FindResult item : results) {
if (item != null) {
// We have a valid result, so report:
response.addResult(new SelectContent(graph, item), item.toString());
}
}
}
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class FindViewControllerNGTest method testReplaceMatchingElements.
// // Populate the attribute list with the attributes of the given type
// for (Graph graph : gm.getAllGraphs().values()) {
// try {
// System.out.println("in for graph try");
//
// WritableGraph wg = graph.getWritableGraph("", true);
// for (int i = 0; i < stringAttributeList.size(); i++) {
// int attributeInt = wg.getAttribute(type, stringAttributeList.get(i));
// attributes.add(new GraphAttribute(wg, attributeInt));
// System.out.println(attributes.get(i).getName() + " = attribute name");
//
// }
//
// instance.updateBasicFindParameters(parameters);
//
// System.out.println("before method call");
//
// instance.retriveMatchingElements(true, false);
//
// System.out.println("before assert");
// System.out.println(wg.getStringValue(labelV, vxId1));
//
// System.out.println(wg.getBooleanValue(selectedV, vxId1));
// assertEquals(wg.getBooleanValue(selectedV, vxId1), true);
// System.out.println("after equals");
//
// wg.commit();
//
// } catch (final InterruptedException ex) {
// Exceptions.printStackTrace(ex);
// Thread.currentThread().interrupt();
// }
//
// }
//
// }
/**
* Test of replaceMatchingElements method, of class FindViewController.
*/
@Test
public void testReplaceMatchingElements() {
System.out.println("replaceMatchingElements");
/**
* Set up the graph with 4 vertexs, 4 transactions, 3 vertex attributes
* (2 of type string), 3 transaction attributes (2 of type string)
*/
setupGraph();
/**
* Create a mock of the top component, get an instance of the
* controller, create a mock of the graph manager, when getAllGraphs is
* called return the graphMap created in this class
*/
final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
when(gm.getActiveGraph()).thenReturn(graph);
System.out.println("before try");
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
System.out.println("in try");
try (MockedStatic<PluginExecution> mockedStaticPlugin = Mockito.mockStatic(PluginExecution.class)) {
PluginExecution pluginExecution = mock(PluginExecution.class);
/**
* The first test should execute the plugin once on graph as the
* parameters are not set to look at all graphs
*/
when(pluginExecution.executeLater(Mockito.eq(graph))).thenReturn(null);
mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
instance.replaceMatchingElements(true, false);
verify(pluginExecution).executeLater(Mockito.eq(graph));
/**
* Set the parameters to find in all graphs and repeat the same
* process. The plugin should be executed on graph a second
* time, and should be executed on graph2 for the first time.
*/
instance.updateBasicReplaceParameters(parametersAllGraphs);
when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
instance.replaceMatchingElements(true, false);
verify(pluginExecution, times(2)).executeLater(Mockito.eq(graph));
verify(pluginExecution).executeLater(Mockito.eq(graph2));
}
}
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class CompareGraphPlugin method read.
@Override
protected void read(final GraphReadMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final String originalGraphName = parameters.getParameters().get(ORIGINAL_GRAPH_PARAMETER_ID).getStringValue();
final String compareGraphName = parameters.getParameters().get(COMPARE_GRAPH_PARAMETER_ID).getStringValue();
if (originalGraphName == null || compareGraphName == null) {
throw new PluginException(PluginNotificationLevel.ERROR, "You must choose two graphs to compare");
}
final List<String> ignoreVertexAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_VERTEX_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
final List<String> ignoreTransactionAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
final ConstellationColor addedColour = parameters.getParameters().get(ADDED_COLOUR_PARAMETER_ID).getColorValue();
final ConstellationColor removedColour = parameters.getParameters().get(REMOVED_COLOUR_PARAMETER_ID).getColorValue();
final ConstellationColor changedColour = parameters.getParameters().get(CHANGED_COLOUR_PARAMETER_ID).getColorValue();
final ConstellationColor unchangedColour = parameters.getParameters().get(UNCHANGED_COLOUR_PARAMETER_ID).getColorValue();
final ConstellationColor addedColourValue = ConstellationColor.getColorValue(addedColour.getRed(), addedColour.getGreen(), addedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
final ConstellationColor removedColourValue = ConstellationColor.getColorValue(removedColour.getRed(), removedColour.getGreen(), removedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
final ConstellationColor changedColourValue = ConstellationColor.getColorValue(changedColour.getRed(), changedColour.getGreen(), changedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
final ConstellationColor unchangedColourValue = ConstellationColor.getColorValue(unchangedColour.getRed(), unchangedColour.getGreen(), unchangedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
final Graph originalGraph = getGraphFromName(originalGraphName);
final Graph compareGraph = getGraphFromName(compareGraphName);
if (originalGraph == null) {
throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, originalGraphName));
}
if (compareGraph == null) {
throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, compareGraphName));
}
final GraphRecordStore originalAll;
final GraphRecordStore compareAll;
final Set<String> vertexPrimaryKeys;
final Set<String> transactionPrimaryKeys;
// get a copy of the graph's record store and statistical info
ReadableGraph rg = originalGraph.getReadableGraph();
try {
originalAll = GraphRecordStoreUtilities.getAll(rg, false, true);
vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.VERTEX);
transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.TRANSACTION);
} finally {
rg.release();
}
rg = compareGraph.getReadableGraph();
try {
compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
} finally {
rg.release();
}
// ignore the id attributes to avoid reporting on them
ignoreVertexAttributes.add("[id]");
ignoreTransactionAttributes.add("[id]");
// graph changes
final String title = String.format("Compare: %s <> %s", originalGraphName, compareGraphName);
final GraphRecordStore changes = compareGraphs(title, originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, addedColourValue, removedColourValue, changedColourValue, unchangedColourValue);
// create new graph
createComparisonGraph(originalGraph, changes);
interaction.setProgress(1, 0, changes + " changes were found.", true);
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class CompareGraphPlugin method createComparisonGraph.
/**
* Create the comparison graph using the original graph as the starting
* point and add the result record store
*
* @param originalGraph
* @param changes
* @param initializeWithSchema
* @param completeWithSchema
* @return
* @throws InterruptedException
*/
protected Graph createComparisonGraph(final Graph originalGraph, final GraphRecordStore changes) throws InterruptedException {
Graph copy;
final ReadableGraph rg = originalGraph.getReadableGraph();
try {
try {
final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
final PluginParameters copyParams = copyGraphPlugin.createParameters();
copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow(rg);
copy = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
} catch (final PluginException ex) {
copy = null;
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
if (copy == null) {
// The copy failed, drop out now.
return null;
}
} finally {
rg.release();
}
final List<String> vertexIdAttributes = new ArrayList<>();
vertexIdAttributes.add(VisualConcept.VertexAttribute.LABEL.getName() + "<string>");
final WritableGraph wgcopy = copy.getWritableGraph("Add changes", true);
try {
changes.reset();
GraphRecordStoreUtilities.addRecordStoreToGraph(wgcopy, changes, false, false, null);
final int vertexColorReferenceAttribute = VisualConcept.GraphAttribute.NODE_COLOR_REFERENCE.ensure(wgcopy);
final int transactionColorReferenceAttribute = VisualConcept.GraphAttribute.TRANSACTION_COLOR_REFERENCE.ensure(wgcopy);
wgcopy.setObjectValue(vertexColorReferenceAttribute, 0, VisualConcept.VertexAttribute.OVERLAY_COLOR.getName());
wgcopy.setObjectValue(transactionColorReferenceAttribute, 0, VisualConcept.TransactionAttribute.OVERLAY_COLOR.getName());
} finally {
wgcopy.commit();
}
// only returning this so that this method can be tested
return copy;
}
Aggregations