CropReleaseCopyTool
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package com.bayer.edam.excelimport;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
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 org.apache.log4j.RollingFileAppender;
|
||||
|
||||
import com.univocity.parsers.csv.CsvParser;
|
||||
import com.univocity.parsers.csv.CsvParserSettings;
|
||||
|
||||
/**
|
||||
* Reads the file names of the release files from an Toolbox SQL export and copies the actual files another directory. This is used to sort
|
||||
* out which release files are actually in use and need to be uploaded to eDAM.
|
||||
*
|
||||
* @author gexce
|
||||
*
|
||||
*/
|
||||
public class CropReleaseCopyTool {
|
||||
|
||||
private static Logger log = Logger.getLogger(CropReleaseCopyTool.class);
|
||||
private static String logfilePath = "C:\\Temp\\Migration CS - SQL Server\\export_2017-08-23_incl_Releases.releasecopytool.log";
|
||||
|
||||
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export_2017-08-23_incl_Releases.csv";
|
||||
|
||||
private CsvParserSettings parserSettings = new CsvParserSettings();
|
||||
private List<String[]> inputRows;
|
||||
|
||||
HashSet<Integer> copiedReleases = new HashSet<Integer>();
|
||||
|
||||
|
||||
|
||||
public CropReleaseCopyTool() {
|
||||
readToolboxExport();
|
||||
|
||||
int lineNo = 0;
|
||||
|
||||
for (String[] line : inputRows) {
|
||||
lineNo++;
|
||||
if (!line[28].equals("NULL")) {
|
||||
int releaseId = Integer.parseInt(line[28]);
|
||||
|
||||
if (!copiedReleases.contains(releaseId)) {
|
||||
copiedReleases.add(releaseId);
|
||||
log.info(line[0] + " '" + line[1] + "' --> " + line[28] + " '" + line[29] + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info("noReleases: " + copiedReleases.size());
|
||||
}
|
||||
|
||||
private void readToolboxExport() {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
BasicConfigurator.configure(new RollingFileAppender(layout, logfilePath, false));
|
||||
log.setLevel(Level.INFO);
|
||||
|
||||
new CropReleaseCopyTool();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user