Search in sources :

Example 1 with CSVRow

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());
}
Also used : SimpleCSVExporter(com.mercedesbenz.sechub.developertools.admin.importer.SimpleCSVExporter) CSVRow(com.mercedesbenz.sechub.developertools.admin.importer.CSVRow) File(java.io.File)

Example 2 with CSVRow

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());
}
Also used : MappingData(com.mercedesbenz.sechub.sharedkernel.mapping.MappingData) CSVRow(com.mercedesbenz.sechub.developertools.admin.importer.CSVRow) SimpleCSVImporter(com.mercedesbenz.sechub.developertools.admin.importer.SimpleCSVImporter) File(java.io.File)

Aggregations

CSVRow (com.mercedesbenz.sechub.developertools.admin.importer.CSVRow)2 File (java.io.File)2 SimpleCSVExporter (com.mercedesbenz.sechub.developertools.admin.importer.SimpleCSVExporter)1 SimpleCSVImporter (com.mercedesbenz.sechub.developertools.admin.importer.SimpleCSVImporter)1 MappingData (com.mercedesbenz.sechub.sharedkernel.mapping.MappingData)1