Started testing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -43,7 +44,7 @@ import com.bayer.edam.migration.mam.categories.CategoryTree;
|
||||
import com.bayer.edam.migration.mam.categories.CategoryTree.Node;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
//@SpringBootApplication
|
||||
@SpringBootApplication
|
||||
@PropertySource("file:secret.properties")
|
||||
public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
@@ -51,11 +52,11 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
static final String adamHost = "https://edam-q.bayer.com:2015";
|
||||
static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com";
|
||||
static final int[] selection = { 71948, /*71048, 70778, 70746, 70142,*/ 70361, /*63924, 71263, 63201, 56942, 57641, 70745, 70440, 70340,
|
||||
70288, 71725*/ };
|
||||
private List<Integer> entrySelection = new ArrayList<Integer>(Arrays.asList( 28861, 28860, 71948, /*71048, 70778, 70746, 70142,*/ 70361/*, 63924, 71263, 63201, 56942, 57641, 70745, 70440, 70340,
|
||||
70288, 71725*/));
|
||||
|
||||
static final String categoryJson = "C:\\Users\\gexce\\git\\mam-migration\\AH MAM Migration\\resources\\2017-10-19_categories.json";
|
||||
static final String categoryMapping = "C:\\Users\\gexce\\git\\mam-migration\\AH MAM Migration\\resources\\Media_Assistant_Categories_131017_EDITED.csv";
|
||||
static final String categoryJson = "resources/2017-10-19_categories.json";
|
||||
static final String categoryMapping = "resources/Media_Assistant_Categories_131017_EDITED_without_archive.csv";
|
||||
|
||||
static final File entryLog = new File("C:\\Temp\\Migration AH\\files\\entry.log");
|
||||
static final File problemLog = new File("C:\\Temp\\Migration AH\\files\\problem.log");
|
||||
@@ -84,6 +85,8 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
|
||||
// readEntryIDsFromFile();
|
||||
|
||||
log.info("Write log headers for " + entryLog.getAbsolutePath());
|
||||
FileUtils.writeStringToFile(entryLog, "Location" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
log.info("Write log headers for " + problemLog.getAbsolutePath());
|
||||
@@ -114,22 +117,24 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
}
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
|
||||
for (int id : selection) {
|
||||
for (int id : entrySelection) {
|
||||
log.info("GET entry " + id);
|
||||
|
||||
Entry entry = restTemplate.exchange(mamHost + "/rest/migration/entry/{id}", HttpMethod.GET, entity, Entry.class, id).getBody();
|
||||
|
||||
log.debug("Name: " + entry.name.get("en"));
|
||||
|
||||
// check exclusion criteria
|
||||
if (entry.stateId == 7) {
|
||||
log.info("Skipping entry " + entry.id + ": Status " + entry.stateId + "(LOCKED_BY_ADMIN)");
|
||||
log.info("RESULT Skipping entry " + entry.id + ": Status " + entry.stateId + "(LOCKED_BY_ADMIN)");
|
||||
continue;
|
||||
}
|
||||
else if (entry.stateId == 8) {
|
||||
log.info("Skipping entry " + entry.id + ": Status " + entry.stateId + "(ASSIGNED_TO_INDEXATION)");
|
||||
log.info("RESULT Skipping entry " + entry.id + ": Status " + entry.stateId + "(ASSIGNED_TO_INDEXATION)");
|
||||
continue;
|
||||
}
|
||||
else if (entry.stateId == 10) {
|
||||
log.info("Skipping entry " + entry.id + ": Status " + entry.stateId + "(ARCHIVED)");
|
||||
log.info("RESULT Skipping entry " + entry.id + ": Status " + entry.stateId + "(ARCHIVED)");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -155,24 +160,27 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
// process categories
|
||||
Set<String> keywords = new HashSet<String>();
|
||||
|
||||
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);
|
||||
|
||||
Node node = mamCategoryTree.getNode(categoryId);
|
||||
log.debug("Node: " + node);
|
||||
List<Node> path = new LinkedList<Node>();
|
||||
|
||||
Node tmpNode = node;
|
||||
while (tmpNode.id != CategoryTree.ROOT_NODE_ID) {
|
||||
if (tmpNode.id == 0) {
|
||||
log.info("RESULT Skipping entry " + entry.id + ": Node outside of category tree (" + node.toString() + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
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 + ")");
|
||||
log.info("RESULT Skipping entry " + entry.id + " because of tag on (parent) category " + n.name + " (" + n.id + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -206,7 +214,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
}
|
||||
|
||||
if (yearClassification == null) {
|
||||
log.info("Create campaign year " + campaignYear);
|
||||
log.debug("Create campaign year " + campaignYear);
|
||||
|
||||
UploadClassification newYear = new UploadClassification(campaignYear, campaignYear);
|
||||
|
||||
@@ -215,8 +223,6 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
EntityId classificationId = restTemplate.exchange(adamHost + "/classifications", HttpMethod.POST, httpEntity, EntityId.class).getBody();
|
||||
newYear.guid = classificationId.id;
|
||||
|
||||
log.info("Created campaign year: " + campaignYear);
|
||||
|
||||
// retrieve the newly created classification back
|
||||
yearClassification = restTemplate.exchange(adamHost + "/classification/" + newYear.guid, HttpMethod.GET, adamHeadersEntity, Classification.class).getBody();
|
||||
campaignYears.add(yearClassification);
|
||||
@@ -246,19 +252,16 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
try {
|
||||
EntityId campaignId = restTemplate.exchange(adamHost + "/classifications", HttpMethod.POST, httpEntity, EntityId.class).getBody();
|
||||
campaign.guid = campaignId.id;
|
||||
|
||||
log.info("Created campaign: " + campaignName + ";" + campaignLabel + ";" + campaign.guid);
|
||||
record.addClassification(new WriteClassification(campaign.guid, 1));
|
||||
|
||||
campaigns.add(campaign);
|
||||
|
||||
} catch (HttpStatusCodeException hsce) {
|
||||
}
|
||||
catch (HttpStatusCodeException hsce) {
|
||||
log.error("Could not create campaign '" + campaignName + "' for entry " + entry.id + ": " + hsce.getStatusCode().toString());
|
||||
log.error(hsce.getResponseBodyAsString());
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
log.warn("Could not parse year from string " + campaignYear);
|
||||
log.error("Could not parse year from string " + campaignYear);
|
||||
}
|
||||
}
|
||||
else if (n.action.equals("keyword")) {
|
||||
@@ -323,17 +326,30 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
|
||||
try {
|
||||
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, UploadRecord.class);
|
||||
log.info("Entry " + entry.id + " migrated to record " + location);
|
||||
log.info("RESULT Entry " + entry.id + " migrated to record " + location);
|
||||
|
||||
FileUtils.writeStringToFile(entryLog, location.toString() + fieldSeparator + entryJson + lineSeparator,
|
||||
Charset.forName("utf-8"), true);
|
||||
}
|
||||
catch (HttpStatusCodeException hsce) {
|
||||
log.error("Skipping entry " + entry.id + ": Error while creating record " + hsce.getStatusCode().toString());
|
||||
log.error("RESULT 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 void readEntryIDsFromFile() throws IOException {
|
||||
File idFile = new File("resources/entrylist_2017-10-25.txt");
|
||||
log.debug("Reading entry IDs from " + idFile.getAbsolutePath());
|
||||
List<String> entryIdList = FileUtils.readLines(idFile, Charset.forName("utf-8"));
|
||||
|
||||
entrySelection = new ArrayList<Integer>();
|
||||
|
||||
log.debug("Parsing " + entryIdList.size() + " IDs");
|
||||
for (String s : entryIdList) {
|
||||
entrySelection.add(Integer.parseInt(s));
|
||||
}
|
||||
}
|
||||
|
||||
private HttpHeaders createMamHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
Reference in New Issue
Block a user