dev
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.bayer.edam;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -30,6 +32,8 @@ import com.univocity.parsers.csv.CsvWriterSettings;
|
||||
* ,f.FocusItemID
|
||||
* ,fi.FocusItemName
|
||||
* ,img.OriginalSize
|
||||
* ,a.publishDate
|
||||
* ,a.archiveDate
|
||||
*
|
||||
* FROM Assets a
|
||||
* LEFT JOIN AssetCategories c ON a.AssetCategoryID = c.AssetCategoryID
|
||||
@@ -43,7 +47,7 @@ import com.univocity.parsers.csv.CsvWriterSettings;
|
||||
* AND a.CreatedOn > Convert(datetime, '2012-07-01')
|
||||
* AND a.isDeleted = 0
|
||||
* AND (a.FocusID IS NULL OR a.FocusID != 3 OR (a.FocusID = 3 AND a.CreatedOn > Convert(datetime, '2016-01-01')))
|
||||
* --AND a.AssetID IN (24535,24534,23467,23392,22868,22488,22481,22440,22082,22021,21147,20731,
|
||||
* --AND a.AssetID IN (23467,23392,22868,22488,22481,22440,22082,22021,21147,20731,
|
||||
* --19557,19048,18447,18446,18445,18444,16853,16171,15882,15313,14918,14400,
|
||||
* --13660,13641,13348,13323,13142,13135,12844,12814,12007)
|
||||
* </pre>
|
||||
@@ -53,8 +57,8 @@ import com.univocity.parsers.csv.CsvWriterSettings;
|
||||
public class ToolboxImportFileGenerator {
|
||||
private static Logger log = Logger.getLogger(ToolboxImportFileGenerator.class);
|
||||
|
||||
private static String toolboxExportFilePath = "C:\\Users\\gexce\\Desktop\\Migration CS - SQL Server\\auszug.csv";
|
||||
private static String importFilePath = "C:\\\\Users\\\\gexce\\\\Desktop\\\\Migration CS - SQL Server\\importFile.csv";
|
||||
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\auszug.csv";
|
||||
private static String importFilePath = "C:\\Temp\\Migration CS - SQL Server\\importFile.csv";
|
||||
|
||||
private static final Map<String, String> brandMap;
|
||||
private static final Map<String, String> unitMap;
|
||||
@@ -607,16 +611,20 @@ public class ToolboxImportFileGenerator {
|
||||
private List<String[]> inputRows;
|
||||
private HashMap<Integer, CropScienceAsset> assets = new HashMap<Integer, CropScienceAsset>();
|
||||
private CsvParserSettings parserSettings = new CsvParserSettings();
|
||||
|
||||
private SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
private SimpleDateFormat outputDateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
||||
|
||||
public ToolboxImportFileGenerator() {
|
||||
public ToolboxImportFileGenerator() throws Exception {
|
||||
readToolboxExport();
|
||||
generateAssetDecriptions();
|
||||
writeImportFile();
|
||||
}
|
||||
|
||||
private void generateAssetDecriptions() {
|
||||
private void generateAssetDecriptions() throws Exception {
|
||||
|
||||
long processedLines = 0;
|
||||
long assetsIncluded = 0;
|
||||
long originalFilenameNull = 0;
|
||||
long noTargetBrand = 0;
|
||||
long noTargetBusinessUnit = 0;
|
||||
@@ -648,19 +656,29 @@ public class ToolboxImportFileGenerator {
|
||||
|
||||
CropScienceAsset asset = assets.get(assetId);
|
||||
|
||||
if (asset == null) {
|
||||
if (asset == null) { // Fields|byr_cs_country
|
||||
assetsIncluded++;
|
||||
asset = new CropScienceAsset(assetId);
|
||||
|
||||
asset.assetPath = "/Resources/Upload/Toolbox";
|
||||
asset.filename = line[1];
|
||||
|
||||
asset.byr_Title = line[2];
|
||||
asset.byr_cs_assetApproval = "No Approval";
|
||||
// asset.byr_cs_releaseDate = ???
|
||||
// asset.fields|byr_cs_retireDate = ??? // TODO empty or 18 months?
|
||||
asset.byr_cs_assetApproval = "No Approval"; // XXX "No Approval Required"?
|
||||
|
||||
if (!line[17].equals("NULL"))
|
||||
asset.byr_cs_releaseDate = outputDateFormat.format(inputDateFormat.parse(line[17]));
|
||||
if (!line[18].equals("NULL"))
|
||||
asset.byr_cs_retireDate = outputDateFormat.format(inputDateFormat.parse(line[18]));
|
||||
|
||||
asset.byr_cs_license_classification = "N/A";
|
||||
asset.byr_cs_description = line[4] + "\n[Asset imported from Toolbox, ID " + asset.toolboxAssetId + "]";
|
||||
|
||||
if (line[4] != null)
|
||||
asset.byr_cs_description = line[4] + "\n\n[Asset imported from Toolbox, ID " + asset.toolboxAssetId + "]";
|
||||
else
|
||||
asset.byr_cs_description = "[Asset imported from Toolbox, ID " + asset.toolboxAssetId + "]";
|
||||
|
||||
|
||||
asset.byr_cs_keywords_tl = "toolbox import";
|
||||
|
||||
asset.byr_MarketingId = line[3];
|
||||
@@ -683,6 +701,7 @@ public class ToolboxImportFileGenerator {
|
||||
}
|
||||
|
||||
log.info("Processed lines: " + processedLines);
|
||||
log.info("Assets included: " + assetsIncluded);
|
||||
log.info("Original filname NULL: " + originalFilenameNull);
|
||||
log.info("No target brand: " + noTargetBrand);
|
||||
log.info("No target business unit: " + noTargetBusinessUnit);
|
||||
@@ -703,7 +722,7 @@ public class ToolboxImportFileGenerator {
|
||||
List<Object[]> csvOutputList = new ArrayList<Object[]>();
|
||||
for (CropScienceAsset asset : assets.values()) {
|
||||
String[] csvLine = new String[] { asset.assetPath, asset.filename, asset.appendClassification, asset.byr_Title,
|
||||
asset.byr_MarketingId, asset.byr_cs_assetApproval, asset.byr_cs_brand, asset.byr_cs_businessUnit,
|
||||
asset.byr_MarketingId, asset.byr_cs_assetApproval, asset.byr_cs_license_classification, asset.byr_cs_brand, asset.byr_cs_businessUnit,
|
||||
asset.byr_cs_releaseDate, asset.byr_cs_retireDate, asset.byr_cs_description, asset.byr_cs_keywords_tl };
|
||||
csvOutputList.add(csvLine);
|
||||
}
|
||||
@@ -712,9 +731,9 @@ public class ToolboxImportFileGenerator {
|
||||
writerSettings.setFormat(parserSettings.getFormat());
|
||||
|
||||
CsvWriter writer = new CsvWriter(new File(importFilePath), writerSettings);
|
||||
writer.writeHeaders("assetpath", "filename", "append classification", "fields|byr_title", "fields|byr_marketingId",
|
||||
"fields|byr_cs_assetApproval", "fields|byr_cs_brand", "fields|byr_cs_businessUnit", "fields|byr_cs_releaseDate",
|
||||
"fields|byr_cs_retireDate", "fields|byr_cs_description", "fields|byr_cs_keywords_tl");
|
||||
writer.writeHeaders("assetpath", "filename", "append classification", "fields|byr_title", "fields|byr_MarketingId",
|
||||
"fields|byr_cs_assetApproval", "fields|byr_cs_license_classification", "fields|byr_cs_brand", "fields|byr_cs_businessUnit",
|
||||
"fields|byr_cs_releaseDate", "fields|byr_cs_retireDate", "fields|byr_cs_Description", "fields|byr_cs_keywords_tl");
|
||||
writer.writeRowsAndClose(csvOutputList);
|
||||
}
|
||||
|
||||
@@ -723,7 +742,7 @@ public class ToolboxImportFileGenerator {
|
||||
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);
|
||||
log.setLevel(Level.INFO);
|
||||
|
||||
new ToolboxImportFileGenerator();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user