use of au.gov.asd.tac.constellation.plugins.importexport.delimited.parser.InputSource in project constellation by constellation-app.
the class DelimitedSourcePane method addFile.
private void addFile(final DelimitedImportController importController) {
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(defaultDirectory);
final ImportFileParser parser = DelimitedSourcePane.this.importFileParserComboBox.getSelectionModel().getSelectedItem();
if (parser != null) {
final ExtensionFilter extensionFilter = parser.getExtensionFilter();
if (extensionFilter != null) {
fileChooser.getExtensionFilters().add(extensionFilter);
fileChooser.setSelectedExtensionFilter(extensionFilter);
}
}
final List<File> newFiles = fileChooser.showOpenMultipleDialog(DelimitedSourcePane.this.getScene().getWindow());
if (newFiles != null) {
if (!newFiles.isEmpty()) {
defaultDirectory = newFiles.get(0).getParentFile();
DelimitedSourcePane.this.importFileParserComboBox.setDisable(true);
}
final ObservableList<File> files = FXCollections.observableArrayList(fileListView.getItems());
final StringBuilder sb = new StringBuilder();
final String alertText = "The following files could not be parsed and have been excluded from the import set:\n";
sb.append(alertText);
for (final File file : newFiles) {
// prevent adding the same file again
if (fileAlreadyAdded(file)) {
continue;
}
// Attempt to parse/preview, if a failure is detected don't add the file to the set of files to import.
try {
if (parser != null) {
parser.preview(new InputSource(file), null, PREVIEW_LIMIT);
files.add(file);
}
} catch (final IOException ex) {
// Append the name of each file that could not be imported.
sb.append("\n");
sb.append(file.getName());
LOGGER.log(Level.INFO, "Unable to parse the file {0}, " + "excluding from import set.", new Object[] { file.toString() });
LOGGER.log(Level.WARNING, ex.toString());
}
}
// If file names have been appended to sb, then some files could not be imported, so notify user.
if (!sb.toString().equals(alertText)) {
NotifyDisplayer.displayAlert("Import from File", "Invalid file(s) found", sb.toString(), Alert.AlertType.WARNING);
}
fileListView.setItems(files);
if (!newFiles.isEmpty()) {
fileListView.getSelectionModel().select(newFiles.get(0));
fileListView.requestFocus();
}
final ObservableList<File> selectedFiles = fileListView.getSelectionModel().getSelectedItems();
importController.setFiles(files, selectedFiles.isEmpty() ? null : selectedFiles.get(0));
importController.validateFileStructure(newFiles);
}
}
use of au.gov.asd.tac.constellation.plugins.importexport.delimited.parser.InputSource in project constellation by constellation-app.
the class JSONImportFielParserNGTest method checkPreviewEmptyList2.
@Test
public void checkPreviewEmptyList2() throws InterruptedException {
// Confirm that attempts to preview JSON containing a list containing
// only empty lists return a clean IOException exception.
final JSONImportFileParser parser = new JSONImportFileParser();
try {
parser.preview(new InputSource(new File(this.getClass().getResource("./resources/JSON-emptyList2.json").getFile())), null, 100);
Assert.fail("Expected exception not received");
} catch (IOException ex) {
Assert.assertTrue(ex.getMessage().contains(private_noValidListMsg));
} catch (Exception ex) {
Assert.fail("Unexpected exception received: " + ex.getClass().getName());
}
}
use of au.gov.asd.tac.constellation.plugins.importexport.delimited.parser.InputSource in project constellation by constellation-app.
the class JSONImportFielParserNGTest method checkPreviewInvalidJSON.
@Test
public void checkPreviewInvalidJSON() throws InterruptedException {
// Confirm that attempts to preview invalid JSON return a clean
// IOException exception.
final JSONImportFileParser parser = new JSONImportFileParser();
try {
parser.preview(new InputSource(new File(this.getClass().getResource("./resources/JSON-invalidContent.json").getFile())), null, 100);
Assert.fail("Expected exception not received");
} catch (IOException ex) {
Assert.assertTrue(ex.getMessage().contains(private_invalidJSONMsg));
} catch (Exception ex) {
Assert.fail("Unexpected exception received: " + ex.getClass().getName());
}
}
use of au.gov.asd.tac.constellation.plugins.importexport.delimited.parser.InputSource in project constellation by constellation-app.
the class JSONImportFielParserNGTest method checkParseEmptyList3.
@Test
public void checkParseEmptyList3() throws InterruptedException {
final JSONImportFileParser parser = new JSONImportFileParser();
try {
parser.parse(new InputSource(new File(this.getClass().getResource("./resources/JSON-emptyList3.json").getFile())), null);
Assert.fail("Expected exception not received");
} catch (IOException ex) {
Assert.assertTrue(ex.getMessage().contains(private_noValidListMsg));
} catch (Exception ex) {
Assert.fail("Unexpected exception received: " + ex.getClass().getName());
}
}
use of au.gov.asd.tac.constellation.plugins.importexport.delimited.parser.InputSource in project constellation by constellation-app.
the class JSONImportFielParserNGTest method checkPreviewEmptyObject.
@Test
public void checkPreviewEmptyObject() throws InterruptedException {
// Confirm that attempts to preview JSON containing only an empty object
// return a clean IOException exception.
final JSONImportFileParser parser = new JSONImportFileParser();
try {
parser.preview(new InputSource(new File(this.getClass().getResource("./resources/JSON-emptyObject.json").getFile())), null, 100);
Assert.fail("Expected exception not received");
} catch (IOException ex) {
Assert.assertTrue(ex.getMessage().contains(private_noValidListMsg));
} catch (Exception ex) {
Assert.fail("Unexpected exception received: " + ex.getClass().getName());
}
}
Aggregations