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