close to run
This commit is contained in:
@@ -123,8 +123,8 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
|
||||
// XXX
|
||||
if (id > 80000 || id < 72048)
|
||||
continue;
|
||||
// if (id > 80000 || id < 72009) //72048
|
||||
// continue;
|
||||
|
||||
|
||||
|
||||
@@ -163,6 +163,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
void postToAdam(Entry entry) throws Exception {
|
||||
UploadRecord record = new UploadRecord();
|
||||
String entryJson = jsonMapper.writeValueAsString(entry);
|
||||
Set<String> keywords = new HashSet<String>();
|
||||
|
||||
// globally applicable classifications
|
||||
record.addClassification("MediaAssistant-Migration");
|
||||
@@ -174,7 +175,8 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
record.addClassification(Definitions.mediaTypes.get(entry.mediaType.id));
|
||||
|
||||
// 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);
|
||||
@@ -209,7 +211,8 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
if (p.startsWith("Status.")) {
|
||||
if (!p.equals("Status.Released"))
|
||||
record.removeClassification("Status.Released");
|
||||
else if (record.hasClassificationStartingWith("Status.")){
|
||||
else if (record.hasClassificationStartingWith("Status.Draft")
|
||||
|| record.hasClassificationStartingWith("Status.Archived")) {
|
||||
log.warn("Classification Status.Released not added, different status already set");
|
||||
continue;
|
||||
}
|
||||
@@ -222,7 +225,6 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
}
|
||||
|
||||
if (p.startsWith("Brand.")) {
|
||||
// always use the most specific brand
|
||||
if (p.equals("Brand.General") && record.hasClassificationStartingWith("Brand.")) {
|
||||
log.warn("Classification Brand.General not added, different brand already set");
|
||||
continue;
|
||||
@@ -285,7 +287,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
String campaignGuid = null;
|
||||
for (Campaign c : campaigns) {
|
||||
if (c.name.equals(campaignName)) {
|
||||
log.debug("Found already existing campaign '" + campaignName + "' with guid " + campaignGuid);
|
||||
log.debug("Add existing campaign " + campaignName);
|
||||
campaignGuid = c.guid;
|
||||
record.addClassification(new WriteClassification(campaignGuid, 1));
|
||||
}
|
||||
@@ -329,9 +331,23 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
record.addField("byr_Title", "No title");
|
||||
}
|
||||
|
||||
// TODO
|
||||
record.addField("byr_ah_projectLead", Collections.singletonList(Definitions.defaultProjectLead));
|
||||
record.addField("byr_ah_brandCommunicationRepresentative", Collections.singletonList(Definitions.defaultProjectLead));
|
||||
// Project lead
|
||||
if (entry.user != null && entry.user.get("id") != null) {
|
||||
if (Definitions.users.get(entry.user.get("id")) != null) {
|
||||
record.addField("byr_ah_projectLead", Collections.singletonList(Definitions.users.get(entry.user.get("id"))));
|
||||
record.addField("byr_ah_brandCommunicationRepresentative", Collections.singletonList(Definitions.users.get(entry.user.get("id"))));
|
||||
}
|
||||
else {
|
||||
log.warn("Entry " + entry.id + ": MAM user " + entry.user.get("id") + " not available, assigning default user");
|
||||
record.addField("byr_ah_projectLead", Collections.singletonList(Definitions.defaultProjectLead));
|
||||
record.addField("byr_ah_brandCommunicationRepresentative", Collections.singletonList(Definitions.defaultProjectLead));
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.warn("Entry " + entry.id + ": No user, assigning default user");
|
||||
record.addField("byr_ah_projectLead", Collections.singletonList(Definitions.defaultProjectLead));
|
||||
record.addField("byr_ah_brandCommunicationRepresentative", Collections.singletonList(Definitions.defaultProjectLead));
|
||||
}
|
||||
|
||||
// Description / Additional Information
|
||||
String description = entry.description.get("en");
|
||||
@@ -381,21 +397,20 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
if (entry.gpc != null)
|
||||
record.addField("byr_ah_approvalNumber",entry.gpc.gpcNumber);
|
||||
|
||||
// XXX
|
||||
// Create record
|
||||
// HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
|
||||
// try {
|
||||
// URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, UploadRecord.class);
|
||||
// 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("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);
|
||||
// }
|
||||
HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
|
||||
try {
|
||||
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, UploadRecord.class);
|
||||
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("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 {
|
||||
|
||||
Reference in New Issue
Block a user