use of com.mercedesbenz.sechub.developertools.admin.importer.CSVRow in project sechub by mercedes-benz.
the class ExportJSONToCSVAdapterDialogAction method execute.
@Override
protected void execute(ActionEvent e) throws Exception {
/* convert to rows */
String json = getMappingUI().getJSON();
List<CSVRow> rows = csvSupport.toCSVRows(MappingData.fromString(json));
/* select */
String defaultPath = ConfigurationSetup.SECHUB_MASS_OPERATION_PARENTDIRECTORY.getStringValue(System.getProperty("user.home"));
File defaultFile = new File(defaultPath, getMappingUI().getMappingId() + ".csv");
File file = getDialogUI().getContext().getDialogUI().selectFile(defaultFile.getAbsolutePath());
if (file == null) {
return;
}
/* export */
SimpleCSVExporter exporter = new SimpleCSVExporter();
exporter.exportCSVFile(file, rows, 3);
/* inform */
getDialogUI().getContext().getOutputUI().output("Exported to CSV file:" + file.getAbsolutePath());
}
use of com.mercedesbenz.sechub.developertools.admin.importer.CSVRow 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