use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class PluginFinderNGTest method find.
@Test
public void find() {
final String pluginName1 = "plugin 1";
final String pluginName2 = "plugin 2";
final DataSourceTitledPane tp1 = mock(DataSourceTitledPane.class);
final DataSourceTitledPane tp2 = mock(DataSourceTitledPane.class);
final Plugin plugin = mock(Plugin.class);
final Alert alert = mock(Alert.class);
final DialogPane dialogPane = mock(DialogPane.class);
when(alert.getDialogPane()).thenReturn(dialogPane);
doReturn(alert).when(pluginFinder).createAlertDialog();
when(queryPhasePane.getDataAccessPanes()).thenReturn(List.of(tp1, tp2));
when(tp1.getPlugin()).thenReturn(plugin);
when(tp2.getPlugin()).thenReturn(plugin);
when(plugin.getName()).thenReturn(pluginName1).thenReturn(pluginName2);
pluginFinder.find(queryPhasePane);
final ArgumentCaptor<VBox> captor = ArgumentCaptor.forClass(VBox.class);
verify(dialogPane).setContent(captor.capture());
assertEquals(((ListView) captor.getValue().getChildren().get(1)).getItems(), FXCollections.observableArrayList(pluginName1, pluginName2));
// TODO Figure out a way to simply trigger the event actions so that
// the global property "result" is set.
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class FindViewControllerNGTest method testRetriveMatchingElements.
/**
* Test of retriveMatchingElements method, of class FindViewController.
*/
@Test
public void testRetriveMatchingElements() {
System.out.println("retriveMatchingElements");
/**
* 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.retriveMatchingElements(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.updateBasicFindParameters(parametersAllGraphs);
when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
instance.retriveMatchingElements(true, false);
verify(pluginExecution, times(2)).executeLater(Mockito.eq(graph));
verify(pluginExecution).executeLater(Mockito.eq(graph2));
}
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class NewSchemaGraphAction method createTemplate.
static void createTemplate(final String templateName) {
final Plugin plugin = PluginRegistry.get(GraphNodePluginRegistry.LOAD_TEMPLATE);
PluginParameters params = plugin.createParameters();
params.setObjectValue(LoadTemplatePlugin.TEMPLATE_FILE_PARAMETER_ID, new File(templateDirectory, templates.get(templateName) + "/" + templateName));
params.setStringValue(LoadTemplatePlugin.TEMPLATE_NAME_PARAMETER_ID, templateName);
PluginExecution.withPlugin(plugin).withParameters(params).executeLater(null);
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class PluginsNodeProvider method setContent.
@Override
public void setContent(final Tab tab) {
final Map<String, String> pluginNames = new TreeMap<>();
final Map<String, ObservableList<PluginParameter<?>>> pluginParameters = new HashMap<>();
final Map<String, String> dataAccessTypes = new HashMap<>();
// Get plugins in order of description.
PluginRegistry.getPluginClassNames().stream().forEach(pluginClassName -> {
boolean isEnabled = true;
final Plugin plugin = PluginRegistry.get(pluginClassName);
final String pluginName = plugin.getName();
if (plugin instanceof DataAccessPlugin) {
final DataAccessPlugin dataAccessPlugin = (DataAccessPlugin) plugin;
final String dataAccessType = dataAccessPlugin.getType();
isEnabled = dataAccessPlugin.isEnabled();
if (isEnabled && !dataAccessType.equals(DataAccessPluginCoreType.EXPERIMENTAL) && !dataAccessType.equals(DataAccessPluginCoreType.DEVELOPER)) {
dataAccessTypes.put(pluginName != null ? pluginName : pluginClassName, dataAccessType);
}
}
if (isEnabled) {
if (pluginName == null) {
LOGGER.log(Level.WARNING, "null name for plugin %s{0}", pluginClassName);
} else if (pluginNames.containsKey(pluginName)) {
LOGGER.log(Level.WARNING, "duplicate name {0} for plugins {1}, {2}", new Object[] { pluginName, pluginClassName, pluginNames.get(pluginName) });
} else {
// Do nothing
}
pluginNames.put(pluginName != null ? pluginName : pluginClassName, pluginClassName);
try {
final PluginParameters parameters = plugin.createParameters();
if (parameters != null) {
final ObservableList<PluginParameter<?>> parameterList = FXCollections.observableArrayList();
parameters.getParameters().entrySet().stream().forEach(entry -> {
final PluginParameter<?> parameter = entry.getValue();
parameterList.add(parameter);
});
Collections.sort(parameterList, (a, b) -> a.getId().compareToIgnoreCase(b.getId()));
pluginParameters.put(pluginName != null ? pluginName : pluginClassName, parameterList);
}
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, "plugin " + pluginClassName + " created an exception", ex);
}
}
});
final Accordion pluginList = new Accordion();
pluginNames.entrySet().stream().forEach(entry -> {
final String pluginName = entry.getKey();
final String pluginClassName = entry.getValue();
final GridPane grid = new GridPane();
grid.setPadding(new Insets(0, 0, 0, 5));
grid.setHgap(5);
grid.setVgap(10);
grid.add(boldLabel("Name"), 0, 0);
grid.add(new Label(pluginClassName), 1, 0);
grid.add(boldLabel("Alias"), 0, 1);
grid.add(new Label(PluginRegistry.getAlias(pluginClassName)), 1, 1);
if (PluginRegistry.get(pluginClassName).getDescription() != null) {
grid.add(boldLabel("Description"), 0, 2);
final Label description = new Label(PluginRegistry.get(pluginClassName).getDescription());
description.setPrefHeight(Region.USE_PREF_SIZE);
description.setWrapText(true);
grid.add(description, 1, 2);
}
final VBox pluginContent = new VBox();
if (pluginParameters.containsKey(pluginName)) {
grid.add(boldLabel("Parameters"), 0, 3);
final TableColumn<PluginParameter<?>, String> colName = new TableColumn<>("Name");
colName.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getId()));
final TableColumn<PluginParameter<?>, String> colType = new TableColumn<>("Type");
colType.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getType().getId()));
final TableColumn<PluginParameter<?>, String> colLabel = new TableColumn<>("Label");
colLabel.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getName()));
final TableColumn<PluginParameter<?>, String> colDescr = new TableColumn<>("Description");
colDescr.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDescription()));
final TableColumn<PluginParameter<?>, String> colDefault = new TableColumn<>("Default Value");
colDefault.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getStringValue()));
final TableView<PluginParameter<?>> parameterTable = new TableView<>(pluginParameters.get(pluginName));
parameterTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
parameterTable.getColumns().addAll(colName, colType, colLabel, colDescr, colDefault);
parameterTable.setFixedCellSize(25);
parameterTable.prefHeightProperty().bind(parameterTable.fixedCellSizeProperty().multiply(Bindings.size(parameterTable.getItems()).add(1.01)));
parameterTable.minHeightProperty().bind(parameterTable.prefHeightProperty());
parameterTable.maxHeightProperty().bind(parameterTable.prefHeightProperty());
pluginContent.getChildren().add(grid);
pluginContent.getChildren().add(parameterTable);
} else {
pluginContent.getChildren().add(grid);
}
final TitledPane pluginPane = new TitledPane(pluginName, pluginContent);
if (dataAccessTypes.containsKey(pluginName)) {
final ImageView iv = new ImageView(UserInterfaceIconProvider.VISIBLE.buildImage(16, ConstellationColor.CLOUDS.getJavaColor()));
final Label l = new Label(String.format("(%s)", dataAccessTypes.get(pluginName)));
final HBox box = new HBox(iv, l);
pluginPane.setGraphic(box);
pluginPane.setGraphicTextGap(20);
pluginPane.setContentDisplay(ContentDisplay.RIGHT);
}
pluginList.getPanes().add(pluginPane);
});
final Button exportPluginsButton = new Button();
exportPluginsButton.setTooltip(new Tooltip("Export Plugin Details to CSV"));
exportPluginsButton.setGraphic(new ImageView(UserInterfaceIconProvider.DOWNLOAD.buildImage(16, ConstellationColor.CLOUDS.getJavaColor())));
exportPluginsButton.setOnAction(action -> exportPluginsToCsv(tab.getContent().getScene().getWindow()));
Platform.runLater(() -> {
pane.setAlignment(Pos.TOP_RIGHT);
final ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(pluginList);
scrollPane.setFitToWidth(true);
pane.getChildren().add(exportPluginsButton);
pane.getChildren().add(scrollPane);
tab.setContent(pane);
});
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class ScriptingViewPane method executeScript.
private void executeScript() {
if (topComponent.getCurrentGraph() != null) {
scriptParser.clearError();
scriptEditor.forceReparsing(scriptParser);
final Plugin plugin = PluginRegistry.get(ScriptingRegistry.SCRIPT_EXECUTOR_PLUGIN);
final PluginParameters parameters = DefaultPluginParameters.getDefaultParameters(plugin);
parameters.getParameters().get(ScriptingExecutePlugin.SCRIPT_PARAMETER_ID).setStringValue(scriptEditor.getText());
parameters.getParameters().get(ScriptingExecutePlugin.NEW_OUTPUT_PARAMETER_ID).setBooleanValue(newOutput);
parameters.getParameters().get(ScriptingExecutePlugin.GRAPH_NAME_PARAMETER_ID).setStringValue(GraphNode.getGraphNode(topComponent.getCurrentGraph()).getDisplayName());
final Future<?> f = PluginExecution.withPlugin(plugin).withParameters(parameters).executeLater(topComponent.getCurrentGraph());
new Thread(() -> {
try {
setName(SCRIPTING_VIEW_THREAD_NAME);
f.get();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, "Script Execution was interrupted", ex);
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
final Exception ex = (Exception) parameters.getParameters().get(ScriptingExecutePlugin.OUTPUT_EXCEPTION_PARAMETER_ID).getObjectValue();
if (ex != null) {
LOGGER.severe(ex.getLocalizedMessage());
int line = -1;
final String msg = ex.getMessage();
final Throwable cause = ex.getCause();
if (cause != null) {
LOGGER.log(Level.SEVERE, "Cause of error is {0}", cause.getClass());
// If this is Jython, we can walk the traceback to find the line where things went bad.
if (cause instanceof PyException) {
final PyException pyex = (PyException) cause;
PyTraceback tb = pyex.traceback;
while (tb != null) {
line = tb.tb_lineno - 1;
LOGGER.log(Level.SEVERE, "{0} traceback {1}", new Object[] { LANGUAGE, tb.tb_lineno });
tb = (PyTraceback) tb.tb_next;
}
}
}
if (line >= 0) {
scriptParser.setError(msg, line);
} else {
// Search the exception message to find the line (and possibly column) where the error occurred.
final Pattern linePattern = Pattern.compile(" at line number (\\d+)");
final Matcher lineMatcher = linePattern.matcher(msg);
if (lineMatcher.find()) {
final String ln = lineMatcher.group(1);
line = Integer.parseInt(ln) - 1;
final Pattern columnPattern = Pattern.compile(" at column number (\\d+)");
final Matcher columnMatcher = columnPattern.matcher(msg);
if (columnMatcher.find()) {
final String col = columnMatcher.group(1);
final int column = Integer.parseInt(col) - 1;
try {
final int lso = scriptEditor.getLineStartOffset(line);
final int leo = scriptEditor.getLineEndOffset(line);
final int length = (leo - lso) - column;
scriptParser.setError(msg, line, lso + column, length);
} catch (final BadLocationException ex1) {
scriptParser.setError(msg, line);
}
} else {
scriptParser.setError(msg, line);
}
}
}
scriptEditor.forceReparsing(scriptParser);
}
}).start();
} else {
final NotifyDescriptor notifyDescriptor = new NotifyDescriptor("Scripts require a graph.", "Scripting", NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[] { NotifyDescriptor.OK_OPTION }, NotifyDescriptor.OK_OPTION);
DialogDisplayer.getDefault().notify(notifyDescriptor);
}
}
Aggregations