98 lines
2.6 KiB
Java
98 lines
2.6 KiB
Java
package com.bayer.edam;
|
|
|
|
import java.io.File;
|
|
import java.util.HashMap;
|
|
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 com.univocity.parsers.csv.CsvParser;
|
|
import com.univocity.parsers.csv.CsvParserSettings;
|
|
|
|
public class ToolboxImportFileGenerator {
|
|
private static Logger log = Logger.getLogger(ToolboxImportFileGenerator.class);
|
|
|
|
private static String toolboxExportFilePath = "C:\\Users\\gexce\\Desktop\\Migration CS - SQL Server\\export-2017-08-03.csv";
|
|
|
|
private List<String[]> rows;
|
|
private HashMap<Integer, Asset> assets = new HashMap<Integer, Asset>();
|
|
|
|
public ToolboxImportFileGenerator() {
|
|
readToolboxExport();
|
|
generateAssetDecriptions();
|
|
}
|
|
|
|
private void generateAssetDecriptions() {
|
|
for (String[] line : rows) {
|
|
Integer assetId = Integer.parseInt(line[0]);
|
|
|
|
// check exclusion criteria
|
|
if (line[1].equals("NULL")) {
|
|
log.warn("Skipping AssetID " + assetId + " - OriginalFilename is 'NULL'");
|
|
continue;
|
|
}
|
|
else {
|
|
log.debug("Processing AssetID " + assetId);
|
|
}
|
|
|
|
Asset asset = assets.get(assetId);
|
|
if (asset == null) {
|
|
asset = new Asset(assetId);
|
|
assets.put(assetId, asset);
|
|
}
|
|
|
|
asset.assetPath = "/Resources/Upload/Toolbox";
|
|
asset.filename = line[1];
|
|
asset.byr_Title = line[2];
|
|
asset.byr_cs_assetApproval = "No Approval";
|
|
asset.byr_cs_license_classification = "N/A";
|
|
asset.byr_cs_keywords_tl = "toolbox import";
|
|
|
|
asset.byr_MarketingId = line[3];
|
|
|
|
// asset.byr_cs_brand = ;
|
|
// asset.byr_cs_businessUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
private void readToolboxExport() {
|
|
CsvParserSettings settings = new CsvParserSettings();
|
|
settings.getFormat().setLineSeparator("\r\n");
|
|
settings.getFormat().setDelimiter(';');
|
|
settings.getFormat().setCharToEscapeQuoteEscaping('"');
|
|
settings.setHeaderExtractionEnabled(false);
|
|
|
|
CsvParser parser = new CsvParser(settings);
|
|
|
|
rows = parser.parseAll(new File(toolboxExportFilePath));
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
try {
|
|
Layout layout = new PatternLayout("%p %m%n"); // "%d{ISO8601} - %p %m%n"
|
|
BasicConfigurator.configure(new ConsoleAppender(layout));
|
|
//BasicConfigurator.configure(new RollingFileAppender(layout, "ToolboxImportFileGenerator.log", true));
|
|
log.setLevel(Level.DEBUG);
|
|
|
|
new ToolboxImportFileGenerator();
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
}
|