ImportFileCleaner
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.bayer.edam.excelimport;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.ConsoleAppender;
|
||||
import org.apache.log4j.Layout;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
|
||||
import com.univocity.parsers.csv.CsvParser;
|
||||
import com.univocity.parsers.csv.CsvParserSettings;
|
||||
import com.univocity.parsers.csv.CsvWriter;
|
||||
import com.univocity.parsers.csv.CsvWriterSettings;
|
||||
|
||||
/**
|
||||
* Quick and dirty: Remove all files from the import Excel spreadsheet that are not shown in a directory listing.
|
||||
*
|
||||
* @author gezvf
|
||||
*
|
||||
*/
|
||||
public class ImportFileCleaner {
|
||||
|
||||
private static Logger log = Logger.getLogger(ImportFileCleaner.class);
|
||||
|
||||
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15-update.csv";
|
||||
private static String listingFilePath = "D:\\listing.txt";
|
||||
private static String outputFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15-update-smallSet.csv";
|
||||
|
||||
private CsvParserSettings parserSettings = new CsvParserSettings();
|
||||
private List<String[]> inputRows;
|
||||
private List<String> filenames;
|
||||
private List<String[]> linesToKeep = new ArrayList<String[]>();
|
||||
|
||||
public ImportFileCleaner() throws IOException {
|
||||
parserSettings.getFormat().setLineSeparator("\r\n");
|
||||
parserSettings.getFormat().setDelimiter(';');
|
||||
parserSettings.getFormat().setCharToEscapeQuoteEscaping('"');
|
||||
parserSettings.setHeaderExtractionEnabled(false);
|
||||
CsvParser parser = new CsvParser(parserSettings);
|
||||
inputRows = parser.parseAll(new File(toolboxExportFilePath));
|
||||
|
||||
filenames = FileUtils.readLines(new File(listingFilePath), "UTF-8");
|
||||
|
||||
for (String[] line : inputRows) {
|
||||
if (filenames.contains(line[1]))
|
||||
linesToKeep.add(line);
|
||||
}
|
||||
|
||||
List<Object[]> csvOutputList = new ArrayList<Object[]>();
|
||||
for (String[] line : linesToKeep) {
|
||||
csvOutputList.add(line);
|
||||
}
|
||||
|
||||
CsvWriterSettings writerSettings = new CsvWriterSettings();
|
||||
writerSettings.setFormat(parserSettings.getFormat());
|
||||
|
||||
CsvWriter writer = new CsvWriter(new File(outputFilePath), writerSettings);
|
||||
writer.writeRowsAndClose(csvOutputList);
|
||||
|
||||
log.info("No input lines: " + inputRows.size());
|
||||
log.info("No output lines: " + linesToKeep.size());
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Layout layout = new PatternLayout("%d{ISO8601} - %p %m%n"); // "%d{ISO8601} - %p %m%n"
|
||||
BasicConfigurator.configure(new ConsoleAppender(layout));
|
||||
log.setLevel(Level.INFO);
|
||||
|
||||
new ImportFileCleaner();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,8 +29,8 @@ import com.univocity.parsers.csv.CsvWriterSettings;
|
||||
public class ToolboxImportFileGenerator {
|
||||
private static Logger log = Logger.getLogger(ToolboxImportFileGenerator.class);
|
||||
|
||||
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15-update.csv";
|
||||
private static String importFilePath = "C:\\Temp\\Migration CS - SQL Server\\importFile.csv";
|
||||
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15-update-smallSet.csv";
|
||||
private static String importFilePath = "C:\\Temp\\Migration CS - SQL Server\\importFile-smallSet.csv";
|
||||
|
||||
private static final Map<String, String> brandMap;
|
||||
private static final Map<String, String> unitMap;
|
||||
@@ -617,6 +617,7 @@ public class ToolboxImportFileGenerator {
|
||||
categoryMap.put("LocalCampaignTools : Local Print Ad", "Advertising - Print : Print ad - local rep use");
|
||||
categoryMap.put("LocalTradeshowsEventTools : Agenda template", "Field Day \\/ Tradeshow \\/ Event Materials : Agenda");
|
||||
categoryMap.put("LocalTradeshowsEventTools : Banner - 3'X4'", "Field Day \\/ Tradeshow \\/ Event Materials : Banner");
|
||||
categoryMap.put("LocalTradeshowsEventTools : Banner - 3'X8' ", "Field Day \\/ Tradeshow \\/ Event Materials : Banner"); // XXX
|
||||
categoryMap.put("LocalTradeshowsEventTools : Banner - 3'X8'", "Field Day \\/ Tradeshow \\/ Event Materials : Banner");
|
||||
categoryMap.put("LocalTradeshowsEventTools : Bannerup", "Field Day \\/ Tradeshow \\/ Event Materials : Banner Up");
|
||||
categoryMap.put("LocalTradeshowsEventTools : BannerUp Base (for dual-sided graphics)", "Field Day \\/ Tradeshow \\/ Event Materials : Banner Up");
|
||||
|
||||
Reference in New Issue
Block a user