setting business unit, brands and keywords
This commit is contained in:
@@ -39,6 +39,35 @@ public class Definitions {
|
||||
classifications.put("Status.Released", new Classification("279fce5751584837bd3aa68a00d4f204", 1));
|
||||
classifications.put("Status.Archived", new Classification("4306204af75442fda297a7b4006b4a87", 1));
|
||||
|
||||
// /Bayer/Animal Health/Brands
|
||||
classifications.put("Brand.Advantage", new Classification("b3f04996de1644df9d08a6dd00cff70e", 1));
|
||||
classifications.put("Brand.Advantix", new Classification("dc758de7d91e44d6a768a6dd00cff7ad", 1));
|
||||
classifications.put("Brand.Advocate", new Classification("c7979fc30bb843e486bba6dd00cff835", 1));
|
||||
classifications.put("Brand.Baytril", new Classification("9c8a43adf3324ca6adb0a7d000f427f5", 1));
|
||||
classifications.put("Brand.Bolfo/Bay-o-Pet", new Classification("922a46fc3f6a44bfb025a7d000f428ac", 1));
|
||||
classifications.put("Brand.CVBD", new Classification("fc84b38665a44291a24ba70f00f7aa1f", 1));
|
||||
classifications.put("Brand.Drontal", new Classification("ca18ffb9735e4f1691cfa6dd00cffb07", 1));
|
||||
classifications.put("Brand.Procox", new Classification("a64abb14f3fc461ab973a6dd00cffb8f", 1));
|
||||
classifications.put("Brand.Profender", new Classification("6be697c82ec34354b0c3a6dd00cffc04", 1));
|
||||
classifications.put("Brand.Seresto", new Classification("2aea5f8d28294cde8346a6dd00cffc75", 1));
|
||||
classifications.put("Brand.Veraflox", new Classification("c2bd6003fa6b4093a50fa6dd00cffd3e", 1));
|
||||
|
||||
classifications.put("Brand.miscellaneous", new Classification("bc9d93616c0548f99f7fa6dd00cff69d", 1));
|
||||
classifications.put("Brand.Miscellaneous", new Classification("bc9d93616c0548f99f7fa6dd00cff69d", 1));
|
||||
|
||||
classifications.put("Brand.Baycox", new Classification("ef3028f6ba8744508035a6dd00cffe45", 1));
|
||||
classifications.put("Brand.Bayticol", new Classification("bd1819c976e643bf916ba6dd00cffec4", 1));
|
||||
classifications.put("Brand.Baytril", new Classification("1053978a142742ad8033a6dd00cfff42", 1));
|
||||
classifications.put("Brand.Bayvarol", new Classification("4f4816c552e04630b575a6dd00cfffcf", 1));
|
||||
classifications.put("Brand.Biosecurity", new Classification("ea123567d7174daf8a7ca6dd00d0008a", 1));
|
||||
classifications.put("Brand.Catosal", new Classification("55fba5b1c9084c74905ba6dd00d0011c", 1));
|
||||
classifications.put("Brand.Ceffect", new Classification("ac7c47b7959b46948697a6dd00d001bb", 1));
|
||||
classifications.put("Brand.Dairy Products", new Classification("a54fcbb0dd4741059f95a6dd00d00289", 1));
|
||||
classifications.put("Brand.Honey bee care", new Classification("996f2d1656f44368a87ba6dd00d00353", 1));
|
||||
classifications.put("Brand.Victrio", new Classification("9d260d0e9e864ab3b3a4a6dd00d005f1", 1));
|
||||
classifications.put("Brand.Zelnate", new Classification("b3887552c9554d6991e4a6dd00d006ee", 1));
|
||||
classifications.put("Brand.Droncit", new Classification("86251780660d4faf95cda7cb010c40fe", 1));
|
||||
|
||||
classifications.put("MediaType.Other", new Classification("7c13e620-7eb0-4c12-9dfb-a7b4008f19b1", 1));
|
||||
classifications.put("MediaType.Banner", new Classification("eb786339a5de44679ff6a7b4008f1ee0", 1));
|
||||
classifications.put("MediaType.Book", new Classification("25a59832a6f84cb0a477a73100a2a091", 1));
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -31,7 +32,10 @@ import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.adam.Token;
|
||||
import com.bayer.edam.migration.adam.WriteRecord;
|
||||
import com.bayer.edam.migration.adam.WriteRecord.Classification;
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
import com.bayer.edam.migration.mam.categories.CategoryTree;
|
||||
import com.bayer.edam.migration.mam.categories.CategoryTree.Node;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@SpringBootApplication
|
||||
@@ -65,13 +69,17 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
private ObjectMapper jsonMapper = new ObjectMapper();
|
||||
|
||||
private List<String> locations = new ArrayList<String>();
|
||||
private CategoryTree mamCategoryTree;
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
|
||||
|
||||
log.info("Write log headers");
|
||||
FileUtils.writeStringToFile(entryLog, "Location" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
FileUtils.writeStringToFile(problemLog, "entryId" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
|
||||
log.info("Read categories");
|
||||
mamCategoryTree = new CategoryTree("C:\\Temp\\Migration AH\\2017-10-19_categories.json", "C:\\Temp\\Migration AH\\Media_Assistant_Categories_131017_EDITED.csv");
|
||||
|
||||
restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
|
||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
|
||||
@@ -127,29 +135,49 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
// media type
|
||||
record.addClassification(Definitions.mediaTypes.get(entry.mediaType.id));
|
||||
|
||||
|
||||
|
||||
// TODO HIER GEHT'S WEITER
|
||||
// process table
|
||||
// process categories
|
||||
Set<String> keywords = new HashSet<String>();
|
||||
String status = "Status.Released";
|
||||
String businessUnit = "BusinessUnit.General";
|
||||
|
||||
for (int category : entry.categories) {
|
||||
if (entry.categories.size() > 1)
|
||||
log.warn("Entry " + entry.id + " has " + entry.categories.size() + " categories assigned");
|
||||
|
||||
for (int categoryId : entry.categories) {
|
||||
log.debug("Category: " + categoryId);
|
||||
|
||||
// TODO
|
||||
Node node = mamCategoryTree.getNode(categoryId);
|
||||
List<Node> path = new LinkedList<Node>();
|
||||
|
||||
Node tmpNode = node;
|
||||
while (tmpNode.id != CategoryTree.ROOT_NODE_ID) {
|
||||
path.add(0, tmpNode);
|
||||
tmpNode = tmpNode.parent;
|
||||
}
|
||||
|
||||
for (Node n : path) {
|
||||
if (n.action.equals("not migrated")) {
|
||||
log.warn("Skipping entry " + entry.id + " because of tag on (parent) category " + n.name + " (" + n.id + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
if (n.action.equals("classify")) {
|
||||
record.addClassification(n.parameter);
|
||||
}
|
||||
else if (n.action.equals("brand")) {
|
||||
String brandClassificationId = "Brand." + n.name.trim();
|
||||
record.addClassification(brandClassificationId);
|
||||
}
|
||||
else if (n.action.equals("campaign")) {
|
||||
|
||||
}
|
||||
else if (n.action.equals("keyword")) {
|
||||
log.debug("Adding keyword " + n.name.trim());
|
||||
keywords.add(n.name.trim());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
record.addClassification(status);
|
||||
record.addClassification(businessUnit);
|
||||
|
||||
|
||||
|
||||
|
||||
// Fields
|
||||
record.addField("byr_Title", entry.name.get("en"));
|
||||
|
||||
@@ -200,23 +228,22 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
// record.addField("byr_ah_approvalNumber",entry.gpc.gpcNumber);
|
||||
|
||||
|
||||
|
||||
// Create record
|
||||
HttpEntity<WriteRecord> httpEntity = new HttpEntity<WriteRecord>(record, adamHeaders);
|
||||
try {
|
||||
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, WriteRecord.class);
|
||||
log.info("Created " + location);
|
||||
|
||||
FileUtils.writeStringToFile(entryLog, location.toString() + fieldSeparator + entryJson + lineSeparator,
|
||||
Charset.forName("utf-8"), true);
|
||||
|
||||
locations.add(location.toString());
|
||||
|
||||
} catch (HttpStatusCodeException hsce) {
|
||||
log.error("Skipping entry " + entry.id + ": Error while creating record " + hsce.getStatusCode().toString());
|
||||
log.error(hsce.getResponseBodyAsString());
|
||||
FileUtils.writeStringToFile(problemLog, entry.id + fieldSeparator + entryJson + lineSeparator, Charset.forName("utf-8"), true);
|
||||
}
|
||||
// HttpEntity<WriteRecord> httpEntity = new HttpEntity<WriteRecord>(record, adamHeaders);
|
||||
// try {
|
||||
// URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, WriteRecord.class);
|
||||
// log.info("Created " + location);
|
||||
//
|
||||
// FileUtils.writeStringToFile(entryLog, location.toString() + fieldSeparator + entryJson + lineSeparator,
|
||||
// Charset.forName("utf-8"), true);
|
||||
//
|
||||
// locations.add(location.toString());
|
||||
//
|
||||
// } catch (HttpStatusCodeException hsce) {
|
||||
// log.error("Skipping entry " + entry.id + ": Error while creating record " + hsce.getStatusCode().toString());
|
||||
// log.error(hsce.getResponseBodyAsString());
|
||||
// FileUtils.writeStringToFile(problemLog, entry.id + fieldSeparator + entryJson + lineSeparator, Charset.forName("utf-8"), true);
|
||||
// }
|
||||
}
|
||||
|
||||
private HttpHeaders createMamHeaders() {
|
||||
|
||||
@@ -3,10 +3,15 @@ package com.bayer.edam.migration.adam;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bayer.edam.migration.Definitions;
|
||||
|
||||
public class WriteRecord {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WriteRecord.class);
|
||||
|
||||
public static class Classification {
|
||||
public String id;
|
||||
public Integer sortIndex;
|
||||
@@ -64,7 +69,15 @@ public class WriteRecord {
|
||||
}
|
||||
|
||||
public void addClassification(String name) {
|
||||
add(Definitions.classifications.get(name));
|
||||
Classification classification = Definitions.classifications.get(name);
|
||||
|
||||
if (classification == null) {
|
||||
log.error("Could not find classification for '" + name + "'");
|
||||
}
|
||||
else {
|
||||
log.debug("Adding classification " + name);
|
||||
add(classification);
|
||||
}
|
||||
}
|
||||
|
||||
public void addField(String name, String value) {
|
||||
|
||||
@@ -24,20 +24,21 @@ public class CategoryTree {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CategoryTree.class);
|
||||
|
||||
static class Node implements Comparable<Node> {
|
||||
int id;
|
||||
String name;
|
||||
Node parent;
|
||||
int parentId;
|
||||
List<Node> children = new ArrayList<Node>();
|
||||
public static class Node implements Comparable<Node> {
|
||||
public int id;
|
||||
public String name;
|
||||
public Node parent;
|
||||
public int parentId;
|
||||
public List<Node> children = new ArrayList<Node>();
|
||||
|
||||
String action;
|
||||
String parameter;
|
||||
public String action;
|
||||
public String parameter;
|
||||
|
||||
@Override
|
||||
public int compareTo(Node o) {
|
||||
return this.name.compareTo(o.name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class JsonCategory {
|
||||
@@ -60,10 +61,17 @@ public class CategoryTree {
|
||||
public static int ROOT_NODE_ID = 1; // ID of logical root "Intern"
|
||||
|
||||
public CategoryTree(String jsonFile, String mappingsFile) throws IOException {
|
||||
log.info("Reading categories from file " + jsonFile);
|
||||
readTree(jsonFile);
|
||||
|
||||
log.info("Reading category mappings from file " + mappingsFile);
|
||||
readMappings(mappingsFile);
|
||||
|
||||
printTree();
|
||||
// printTree();
|
||||
}
|
||||
|
||||
public Node getNode(int id) {
|
||||
return nodeMap.get(id);
|
||||
}
|
||||
|
||||
private void readMappings(String mappingsFile) {
|
||||
@@ -77,7 +85,7 @@ public class CategoryTree {
|
||||
|
||||
List<String[]> inputRows = parser.parseAll(new File(mappingsFile));
|
||||
int rowNum = 0;
|
||||
String[] currentPath = new String[6];
|
||||
String[] currentPath = new String[7];
|
||||
for (String[] row : inputRows) {
|
||||
rowNum++;
|
||||
|
||||
@@ -206,7 +214,7 @@ public class CategoryTree {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new CategoryTree("C:\\Temp\\Migration AH\\2017-10-17_categories.json", "C:\\Temp\\Migration AH\\Media_Assistant_Categories_131017_EDITED.csv");
|
||||
new CategoryTree("C:\\Temp\\Migration AH\\2017-10-19_categories.json", "C:\\Temp\\Migration AH\\Media_Assistant_Categories_131017_EDITED.csv");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user