use of com.mercedesbenz.sechub.developertools.admin.importer.SimpleCSVImporter in project sechub by mercedes-benz.
the class ImportCSVToJSONAdapterDialogAction method execute.
@Override
protected void execute(ActionEvent e) throws Exception {
/* select */
String defaultPath = ConfigurationSetup.SECHUB_MASS_OPERATION_PARENTDIRECTORY.getStringValue(System.getProperty("user.home"));
String mappingId = getMappingUI().getMappingId();
File defaultFile = new File(defaultPath, mappingId + ".csv");
File file = getDialogUI().getContext().getDialogUI().selectFile(defaultFile.getAbsolutePath());
if (file == null) {
return;
}
if (!file.getName().equals(defaultFile.getName())) {
boolean confirmed = getDialogUI().getContext().getDialogUI().confirm("File name not as expected - is mappingId:" + mappingId + " really saved inside " + file.getName() + " ?");
if (!confirmed) {
getDialogUI().getContext().getOutputUI().output("Canceled by user");
return;
}
}
/* import */
SimpleCSVImporter importer = new SimpleCSVImporter();
List<CSVRow> rows = importer.importCSVFile(file, 3, 1);
/* convert */
MappingData data = csvSupport.fromCSVRows(rows, 0);
String json = data.toJSON();
/* output beautified */
getMappingUI().setJSON(JSONDeveloperHelper.INSTANCE.beatuifyJSON(json));
/* inform */
getDialogUI().getContext().getOutputUI().output("Imported from CSV file:" + file.getAbsolutePath());
}
Aggregations