Adminrechte
This commit is contained in:
+7
-3
@@ -1,6 +1,6 @@
|
||||
package com.bayer.edam;
|
||||
|
||||
public class Asset {
|
||||
public class CropScienceAsset {
|
||||
|
||||
Integer toolboxAssetId;
|
||||
|
||||
@@ -9,15 +9,19 @@ public class Asset {
|
||||
String appendClassification;
|
||||
|
||||
String byr_Title;
|
||||
String byr_MarketingId;
|
||||
String byr_cs_assetApproval;
|
||||
String byr_cs_brand;
|
||||
String byr_cs_releaseDate;
|
||||
String byr_cs_retireDate;
|
||||
String byr_cs_businessUnit;
|
||||
String byr_cs_license_classification;
|
||||
String byr_cs_description;
|
||||
String byr_cs_keywords_tl;
|
||||
|
||||
String byr_MarketingId;
|
||||
Long fileSize;
|
||||
|
||||
public Asset(Integer toolboxAssetId) {
|
||||
public CropScienceAsset(Integer toolboxAssetId) {
|
||||
this.toolboxAssetId = toolboxAssetId;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bayer.edam;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -14,6 +15,8 @@ import org.apache.log4j.PatternLayout;
|
||||
|
||||
import com.univocity.parsers.csv.CsvParser;
|
||||
import com.univocity.parsers.csv.CsvParserSettings;
|
||||
import com.univocity.parsers.csv.CsvWriter;
|
||||
import com.univocity.parsers.csv.CsvWriterSettings;
|
||||
|
||||
/**
|
||||
* Generates an import file from a toolbox CSV export.
|
||||
@@ -26,18 +29,23 @@ import com.univocity.parsers.csv.CsvParserSettings;
|
||||
* ,ai.AssetItemName
|
||||
* ,f.FocusItemID
|
||||
* ,fi.FocusItemName
|
||||
* ,img.OriginalSize
|
||||
*
|
||||
* FROM Assets a
|
||||
* LEFT JOIN AssetCategories c ON a.AssetCategoryID = c.AssetCategoryID
|
||||
* LEFT JOIN AssetItems ai ON a.AssetItemID = ai.AssetItemID
|
||||
* LEFT JOIN AssetFocusItemMap f ON a.AssetId = f.AssetID
|
||||
* LEFT JOIN FocusItems fi ON f.FocusItemID = fi.FocusItemID
|
||||
* LEFT JOIN AssetImages img ON a.AssetID = img.AssetID
|
||||
*
|
||||
* WHERE
|
||||
* a.AssetStatusID != 101
|
||||
* 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,
|
||||
* --19557,19048,18447,18446,18445,18444,16853,16171,15882,15313,14918,14400,
|
||||
* --13660,13641,13348,13323,13142,13135,12844,12814,12007)
|
||||
* </pre>
|
||||
*
|
||||
* @author GEXCE
|
||||
@@ -45,7 +53,8 @@ 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-07.csv";
|
||||
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 final Map<String, String> brandMap;
|
||||
private static final Map<String, String> unitMap;
|
||||
@@ -323,11 +332,11 @@ public class ToolboxImportFileGenerator {
|
||||
brandMap.put("ICP-Programs", "Bayer/General");
|
||||
brandMap.put("ICP - Veg/Potato", "Bayer/General");
|
||||
brandMap.put("Poncho/VOTiVO 2", "TEMPORARY"); // set both 'Poncho' and 'Votivo' via special rule
|
||||
brandMap.put("Poncho 1250/VOTiVO 2", "TEMPORARY"); // set both 'Poncho 250/1250' and 'Votivo' via special rule (there is no Votivo 2)
|
||||
brandMap.put("Poncho 1250/VOTiVO 2", "TEMPORARY"); // set both 'Poncho 250/1250' and 'Votivo' via special rule (there is no Votivo
|
||||
// 2)
|
||||
brandMap.put("Velum", "Velum One");
|
||||
brandMap.put("Velum Prime 3", "Velum Prime");
|
||||
|
||||
|
||||
unitMap = new HashMap<String, String>();
|
||||
unitMap.put("Bayer/General", "Crop Protection");
|
||||
unitMap.put("National Tradeshow", "Crop Protection");
|
||||
@@ -595,13 +604,14 @@ public class ToolboxImportFileGenerator {
|
||||
unitMap.put("Finish Pro", "Crop Protection");
|
||||
}
|
||||
|
||||
|
||||
private List<String[]> rows;
|
||||
private HashMap<Integer, Asset> assets = new HashMap<Integer, Asset>();
|
||||
private List<String[]> inputRows;
|
||||
private HashMap<Integer, CropScienceAsset> assets = new HashMap<Integer, CropScienceAsset>();
|
||||
private CsvParserSettings parserSettings = new CsvParserSettings();
|
||||
|
||||
public ToolboxImportFileGenerator() {
|
||||
readToolboxExport();
|
||||
generateAssetDecriptions();
|
||||
writeImportFile();
|
||||
}
|
||||
|
||||
private void generateAssetDecriptions() {
|
||||
@@ -611,7 +621,7 @@ public class ToolboxImportFileGenerator {
|
||||
long noTargetBrand = 0;
|
||||
long noTargetBusinessUnit = 0;
|
||||
|
||||
for (String[] line : rows) {
|
||||
for (String[] line : inputRows) {
|
||||
Integer assetId = Integer.parseInt(line[0]);
|
||||
|
||||
log.debug("Processing AssetID " + assetId);
|
||||
@@ -636,27 +646,29 @@ public class ToolboxImportFileGenerator {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Asset asset = assets.get(assetId);
|
||||
CropScienceAsset asset = assets.get(assetId);
|
||||
|
||||
if (asset == null) {
|
||||
asset = new Asset(assetId);
|
||||
asset = new CropScienceAsset(assetId);
|
||||
|
||||
asset.assetPath = "/Resources/Upload/Toolbox";
|
||||
asset.filename = line[1];
|
||||
//appendClassification
|
||||
|
||||
asset.byr_Title = line[2];
|
||||
asset.byr_cs_assetApproval = "No Approval"; // TODO check value
|
||||
//asset.byr_cs_license_classification = ???
|
||||
asset.byr_cs_assetApproval = "No Approval";
|
||||
// asset.byr_cs_releaseDate = ???
|
||||
// asset.fields|byr_cs_retireDate = ??? // TODO empty or 18 months?
|
||||
|
||||
asset.byr_cs_license_classification = "N/A";
|
||||
asset.byr_cs_description = line[4] + "\n[Asset imported from Toolbox, ID " + asset.toolboxAssetId + "]";
|
||||
asset.byr_cs_keywords_tl = "toolbox import";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
asset.byr_MarketingId = line[3];
|
||||
|
||||
asset.appendClassification = "/Definitions/Common/Status/Released";
|
||||
|
||||
asset.fileSize = Long.parseLong(line[16]);
|
||||
|
||||
assets.put(assetId, asset);
|
||||
}
|
||||
|
||||
@@ -664,12 +676,10 @@ public class ToolboxImportFileGenerator {
|
||||
asset.byr_cs_brand = brandMap.get(line[15]);
|
||||
asset.byr_cs_businessUnit = unitMap.get(asset.byr_cs_brand);
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
asset.byr_cs_brand = asset.byr_cs_brand + "\n" + line[15];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
log.info("Processed lines: " + processedLines);
|
||||
@@ -679,24 +689,41 @@ public class ToolboxImportFileGenerator {
|
||||
}
|
||||
|
||||
private void readToolboxExport() {
|
||||
CsvParserSettings settings = new CsvParserSettings();
|
||||
settings.getFormat().setLineSeparator("\r\n");
|
||||
settings.getFormat().setDelimiter(';');
|
||||
settings.getFormat().setCharToEscapeQuoteEscaping('"');
|
||||
settings.setHeaderExtractionEnabled(false);
|
||||
parserSettings.getFormat().setLineSeparator("\r\n");
|
||||
parserSettings.getFormat().setDelimiter(';');
|
||||
parserSettings.getFormat().setCharToEscapeQuoteEscaping('"');
|
||||
parserSettings.setHeaderExtractionEnabled(false);
|
||||
|
||||
CsvParser parser = new CsvParser(settings);
|
||||
CsvParser parser = new CsvParser(parserSettings);
|
||||
|
||||
rows = parser.parseAll(new File(toolboxExportFilePath));
|
||||
inputRows = parser.parseAll(new File(toolboxExportFilePath));
|
||||
}
|
||||
|
||||
private void writeImportFile() {
|
||||
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_cs_releaseDate, asset.byr_cs_retireDate, asset.byr_cs_description, asset.byr_cs_keywords_tl };
|
||||
csvOutputList.add(csvLine);
|
||||
}
|
||||
|
||||
CsvWriterSettings writerSettings = new CsvWriterSettings();
|
||||
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.writeRowsAndClose(csvOutputList);
|
||||
}
|
||||
|
||||
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.INFO);
|
||||
// BasicConfigurator.configure(new RollingFileAppender(layout, "ToolboxImportFileGenerator.log", true));
|
||||
log.setLevel(Level.DEBUG);
|
||||
|
||||
new ToolboxImportFileGenerator();
|
||||
|
||||
@@ -705,5 +732,4 @@ public class ToolboxImportFileGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user