setting business unit, brands and keywords

This commit is contained in:
gexce
2017-10-19 18:35:11 +02:00
parent f9cb742495
commit 885b38bb6c
4 changed files with 120 additions and 43 deletions
@@ -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() {