Asset Type fix
This commit is contained in:
@@ -0,0 +1,88 @@
|
|||||||
|
package com.bayer.edam.excelimport;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
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;
|
||||||
|
import com.univocity.parsers.csv.CsvWriter;
|
||||||
|
import com.univocity.parsers.csv.CsvWriterSettings;
|
||||||
|
|
||||||
|
public class FilenameComparator {
|
||||||
|
private static Logger log = Logger.getLogger(FilenameComparator.class);
|
||||||
|
private static String logfilePath = "C:\\Temp\\Migration CS - PhotoGallery\\FilenameComparator.log";
|
||||||
|
|
||||||
|
private static String migrationFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\Frederic - Toolbox Migration 2 DB export.csv";
|
||||||
|
private static String importFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\all imported IDs - toolbox export.csv";
|
||||||
|
private static String outputFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\all imported IDs - toolbox export - without Migration 2.csv";
|
||||||
|
|
||||||
|
private CsvParserSettings parserSettings = new CsvParserSettings();
|
||||||
|
private List<String[]> migrationRows;
|
||||||
|
private HashSet<String> migration2filenames = new HashSet<String>();
|
||||||
|
private List<String[]> importRows;
|
||||||
|
private List<Object[]> csvOutputList = new ArrayList<Object[]>();
|
||||||
|
|
||||||
|
public FilenameComparator() throws IOException {
|
||||||
|
parserSettings.getFormat().setLineSeparator("\r\n");
|
||||||
|
parserSettings.getFormat().setDelimiter(';');
|
||||||
|
parserSettings.getFormat().setCharToEscapeQuoteEscaping('"');
|
||||||
|
parserSettings.setHeaderExtractionEnabled(false);
|
||||||
|
CsvParser parser = new CsvParser(parserSettings);
|
||||||
|
migrationRows = parser.parseAll(new File(migrationFilePath));
|
||||||
|
|
||||||
|
for (String[] line : migrationRows) {
|
||||||
|
migration2filenames.add(line[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
importRows = parser.parseAll(new File(importFilePath));
|
||||||
|
|
||||||
|
int lineNo = 0;
|
||||||
|
for (String[] importLine : importRows) {
|
||||||
|
lineNo++;
|
||||||
|
|
||||||
|
if (migration2filenames.contains(importLine[1])) {
|
||||||
|
log.info("Line " + lineNo + " - Removing file " + importLine[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] csvLine = new String[importLine.length];
|
||||||
|
for (int i = 0; i < importLine.length; i++)
|
||||||
|
csvLine[i] = importLine[i];
|
||||||
|
|
||||||
|
csvOutputList.add(csvLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
CsvWriterSettings writerSettings = new CsvWriterSettings();
|
||||||
|
writerSettings.setFormat(parserSettings.getFormat());
|
||||||
|
|
||||||
|
CsvWriter writer = new CsvWriter(new File(outputFilePath), writerSettings);
|
||||||
|
writer.writeRowsAndClose(csvOutputList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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 FilenameComparator();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -29,13 +29,13 @@ 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:\\Temp\\Migration CS - PhotoGallery\\all imported IDs - toolbox export.csv";
|
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\export - 2017-08-28 - logos and tags not included in first migration-update.csv";
|
||||||
private static String logfilePath = "C:\\Temp\\Migration CS - PhotoGallery\\all imported IDs - toolbox export.log";
|
private static String logfilePath = "C:\\Temp\\Migration CS - PhotoGallery\\export - 2017-08-28 - logos and tags not included in first migration-update.log";
|
||||||
private static String licenseGuidsFilePath = "C:\\Temp\\Migration CS - SQL Server\\Release_GUIDs.csv";
|
private static String licenseGuidsFilePath = "C:\\Temp\\Migration CS - SQL Server\\Release_GUIDs.csv";
|
||||||
|
|
||||||
// XXX Spreadsheet needs be be named "Records" in Excel for the importer
|
// XXX Spreadsheet needs be be named "Records" in Excel for the importer
|
||||||
private static String importFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\all imported IDs - toolbox export-IMPORT.csv";
|
private static String importFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\export - 2017-08-28 - logos and tags not included in first migration-update-IMPORT.csv";
|
||||||
private static String uploadPath = "/Resources/Upload/ToolboxMigration";
|
private static String uploadPath = "/Resources/Upload/ToolboxLogosAndTags";
|
||||||
|
|
||||||
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;
|
||||||
@@ -214,8 +214,8 @@ public class ToolboxImportFileGenerator {
|
|||||||
brandMap.put("Prosper FX", "Prosper");
|
brandMap.put("Prosper FX", "Prosper");
|
||||||
brandMap.put("Protech Plus", "TEMPORARY");
|
brandMap.put("Protech Plus", "TEMPORARY");
|
||||||
brandMap.put("ProTechPlus", "TEMPORARY");
|
brandMap.put("ProTechPlus", "TEMPORARY");
|
||||||
brandMap.put("Prot�g�", "TEMPORARY"); // XXX
|
brandMap.put("Protégé", "TEMPORARY"); // XXX
|
||||||
brandMap.put("Prot�g� FL", "TEMPORARY"); // XXX
|
brandMap.put("Protégé FL", "TEMPORARY"); // XXX
|
||||||
brandMap.put("Provado", "TEMPORARY");
|
brandMap.put("Provado", "TEMPORARY");
|
||||||
brandMap.put("Provost", "Provost");
|
brandMap.put("Provost", "Provost");
|
||||||
brandMap.put("Provost Opti", "Provost Opti");
|
brandMap.put("Provost Opti", "Provost Opti");
|
||||||
@@ -1072,7 +1072,7 @@ public class ToolboxImportFileGenerator {
|
|||||||
|
|
||||||
asset.byr_MarketingId = line[3];
|
asset.byr_MarketingId = line[3];
|
||||||
|
|
||||||
asset.fileSize = Long.parseLong(line[15]);
|
// asset.fileSize = Long.parseLong(line[15]);
|
||||||
|
|
||||||
if (!line[16].equals("NULL"))
|
if (!line[16].equals("NULL"))
|
||||||
asset.byr_cs_releaseDate = outputDateFormat.format(inputDateFormat.parse(line[16]));
|
asset.byr_cs_releaseDate = outputDateFormat.format(inputDateFormat.parse(line[16]));
|
||||||
@@ -1123,9 +1123,12 @@ public class ToolboxImportFileGenerator {
|
|||||||
String assetCategory = line[11] + " : " + line[12];
|
String assetCategory = line[11] + " : " + line[12];
|
||||||
String targetType = categoryMap.get(assetCategory);
|
String targetType = categoryMap.get(assetCategory);
|
||||||
if (targetType != null) {
|
if (targetType != null) {
|
||||||
|
String categoryClassification = targetType.substring(0, targetType.indexOf(" : "));
|
||||||
|
String subCategoryClassification = targetType.substring(targetType.indexOf(" : ") + 3);
|
||||||
|
|
||||||
asset.appendClassification = asset.appendClassification
|
asset.appendClassification = asset.appendClassification
|
||||||
+ "\n/Bayer/Crop Science/CategoryItem/" + targetType.substring(0, targetType.indexOf(" : "))
|
+ "\n/Bayer/Crop Science/CategoryItem/" + categoryClassification
|
||||||
+ "\n/Bayer/Crop Science/CategoryItem/" + targetType.substring(targetType.indexOf(" : ") + 3);
|
+ "\n/Bayer/Crop Science/CategoryItem/" + categoryClassification + "/" + subCategoryClassification;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
noAssetType++;
|
noAssetType++;
|
||||||
@@ -1228,6 +1231,13 @@ 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()) {
|
||||||
|
|
||||||
|
// XXX export only assets with license data
|
||||||
|
// if (asset.licenseRecords.size() == 0)
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
// if (!asset.filename.equals("BCS_SED_I4_6666_140x180_Concept_R2[1].jpg"))
|
||||||
|
// continue;
|
||||||
|
|
||||||
// XXX This filename is broken (because of the question mark)
|
// XXX This filename is broken (because of the question mark)
|
||||||
if (asset.filename.equals("Texas Cotton Growers Achieve Excellence with FiberMax?.mp4"))
|
if (asset.filename.equals("Texas Cotton Growers Achieve Excellence with FiberMax?.mp4"))
|
||||||
asset.filename = "CR0715FIBMAXA232V00R0.MP4";
|
asset.filename = "CR0715FIBMAXA232V00R0.MP4";
|
||||||
@@ -1255,13 +1265,15 @@ public class ToolboxImportFileGenerator {
|
|||||||
licenseTypes += "\n";
|
licenseTypes += "\n";
|
||||||
licenseTypes += licenseType;
|
licenseTypes += licenseType;
|
||||||
}
|
}
|
||||||
|
if (licenseTypes.length() == 0)
|
||||||
|
licenseTypes = "No License required";
|
||||||
|
|
||||||
|
|
||||||
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_businessUnit,
|
asset.byr_MarketingId, asset.byr_cs_assetApproval, asset.byr_cs_businessUnit,
|
||||||
brands, asset.byr_cs_releaseDate, asset.byr_cs_retireDate, asset.byr_cs_description, asset.byr_cs_keywords_tl,
|
brands, asset.byr_cs_releaseDate, asset.byr_cs_retireDate, asset.byr_cs_description, asset.byr_cs_keywords_tl,
|
||||||
asset.byr_campaignYearLabel, asset.byr_campaignTitle, asset.byr_cs_IsShouldBePublished, asset.byr_cs_warehouseAvailable,
|
asset.byr_campaignYearLabel, asset.byr_campaignTitle, asset.byr_cs_IsShouldBePublished, asset.byr_cs_warehouseAvailable,
|
||||||
asset.byr_cs_country,*/ licenseRecords, licenseTypes, asset.byr_licenseScope, asset.byr_licenseOwner,
|
asset.byr_cs_country, licenseRecords, licenseTypes, asset.byr_licenseScope, asset.byr_licenseOwner,
|
||||||
asset.byr_licenseInformation };
|
asset.byr_licenseInformation };
|
||||||
|
|
||||||
csvOutputList.add(csvLine);
|
csvOutputList.add(csvLine);
|
||||||
@@ -1271,11 +1283,11 @@ 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_businessUnit", "fields|byr_cs_brand",
|
"fields|byr_cs_assetApproval", "fields|byr_cs_businessUnit", "fields|byr_cs_brand",
|
||||||
"fields|byr_cs_releaseDate", "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",
|
||||||
"fields|byr_campaignYearLabel", "fields|byr_campaignTitleLabel", "fields|byr_cs_IsShouldBePublished",
|
"fields|byr_campaignYearLabel", "fields|byr_campaignTitleLabel", "fields|byr_cs_IsShouldBePublished",
|
||||||
"fields|byr_cs_warehouseAvailable", "fields|byr_cs_country",*/ "fields|byr_cs_licenseRecord", "fields|byr_cs_licenseType",
|
"fields|byr_cs_warehouseAvailable", "fields|byr_cs_country", "fields|byr_cs_licenseRecord", "fields|byr_cs_licenseType",
|
||||||
"fields|byr_licenseScope", "fields|byr_licenseOwner", "fields|byr_licenseInformation");
|
"fields|byr_licenseScope", "fields|byr_licenseOwner", "fields|byr_licenseInformation");
|
||||||
writer.writeRowsAndClose(csvOutputList);
|
writer.writeRowsAndClose(csvOutputList);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user