new structure for campaign labels
This commit is contained in:
@@ -2,4 +2,4 @@
|
|||||||
logging.level.com.bayer=DEBUG
|
logging.level.com.bayer=DEBUG
|
||||||
#logging.level.com.bayer.edam.migration.interceptors=INFO
|
#logging.level.com.bayer.edam.migration.interceptors=INFO
|
||||||
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level- %msg%n
|
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level- %msg%n
|
||||||
logging.file=application-THU.log
|
logging.file=entrylist_2017-11-09.log
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -19,7 +20,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -40,9 +40,9 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
/**
|
/**
|
||||||
* If true, files are downloaded. If false, only the IDs are written into the outputfile.
|
* If true, files are downloaded. If false, only the IDs are written into the outputfile.
|
||||||
*/
|
*/
|
||||||
private final boolean downloadFiles = true;
|
private final boolean downloadFiles = false;
|
||||||
|
|
||||||
File outputfile = new File("C:\\Temp\\Migration AH\\files\\entrylist_2017-11-07.txt");
|
File outputfile = new File("C:\\Temp\\Migration AH\\files\\entrylist_2017-11-09.txt");
|
||||||
|
|
||||||
|
|
||||||
@Value("${mam.auth}")
|
@Value("${mam.auth}")
|
||||||
@@ -99,8 +99,14 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
if (!downloadFiles) {
|
if (!downloadFiles) {
|
||||||
// only create a list with all IDs
|
// only create a list with all IDs
|
||||||
try {
|
try {
|
||||||
FileUtils.writeStringToFile(outputfile, entrylist.entries[i].mediaAssistantId + "\n", Charset.forName("utf-8"), true);
|
log.info("Get " + i + "/" + entrylist.entries.length);
|
||||||
} catch (IOException e) {
|
TimeUnit.SECONDS.sleep(1); // XXX
|
||||||
|
int id = Integer.parseInt(entrylist.entries[i].mediaAssistantId);
|
||||||
|
Entry entry = restTemplate.exchange(mamHost + "/rest/migration/entry/{id}", HttpMethod.GET, entity, Entry.class, id).getBody();
|
||||||
|
String entryJson = jsonMapper.writeValueAsString(entry);
|
||||||
|
FileUtils.writeStringToFile(outputfile, id + separator + entryJson + "\n", Charset.forName("utf-8"), true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Could not get entry " + entrylist.entries[i].mediaAssistantId);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
|
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
|
||||||
|
|
||||||
static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com";
|
static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com";
|
||||||
private List<Integer> entrySelection = new ArrayList<Integer>(Arrays.asList( 71725 /*, 71263, 71048, 70778, 70746, 70745, 70440, 70361, 70340, 70288, 70161, 70142, 63924, 63201, 57641, 56942 */));
|
private List<Integer> entrySelection = new ArrayList<Integer>(Arrays.asList( /*71725, 71263, 71048, 70778, 70746, 70745, 70440, 70361, 70340, 70288, 70161, 70142, 63924, */63201, 57641, 56942 ));
|
||||||
|
|
||||||
static final String fileCache = "E:\\";
|
static final String fileCache = "E:\\";
|
||||||
|
|
||||||
@@ -104,7 +104,6 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
log.info("Read categories");
|
log.info("Read categories");
|
||||||
mamCategoryTree = new CategoryTree(categoryJson, categoryMapping);
|
mamCategoryTree = new CategoryTree(categoryJson, categoryMapping);
|
||||||
|
|
||||||
// XXX
|
|
||||||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
||||||
requestFactory.setBufferRequestBody(false);
|
requestFactory.setBufferRequestBody(false);
|
||||||
fileTransferTemplate = new RestTemplate(requestFactory);
|
fileTransferTemplate = new RestTemplate(requestFactory);
|
||||||
@@ -126,7 +125,6 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
for (Classification yearClassification : campaignYears) {
|
for (Classification yearClassification : campaignYears) {
|
||||||
List<Classification> campaignClassifications = restTemplate.exchange(Definitions.adamHost + "/classification/" + yearClassification.id + "/children", HttpMethod.GET, adamHeadersEntity, ClassificationList.class).getBody().items;
|
List<Classification> campaignClassifications = restTemplate.exchange(Definitions.adamHost + "/classification/" + yearClassification.id + "/children", HttpMethod.GET, adamHeadersEntity, ClassificationList.class).getBody().items;
|
||||||
for (Classification campaignClassification : campaignClassifications) {
|
for (Classification campaignClassification : campaignClassifications) {
|
||||||
//log.debug(yearClassification.name + ": " + campaignClassification.name + ", " + campaignClassification.labels[0].value + ", " + campaignClassification.id);
|
|
||||||
Campaign campaign = new Campaign(campaignClassification.name, campaignClassification.labels[0].value, yearClassification.name);
|
Campaign campaign = new Campaign(campaignClassification.name, campaignClassification.labels[0].value, yearClassification.name);
|
||||||
campaign.guid = campaignClassification.id;
|
campaign.guid = campaignClassification.id;
|
||||||
campaigns.add(campaign);
|
campaigns.add(campaign);
|
||||||
@@ -142,6 +140,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
log.info("GET entry " + id);
|
log.info("GET entry " + id);
|
||||||
|
|
||||||
Entry entry = restTemplate.exchange(mamHost + "/rest/migration/entry/{id}", HttpMethod.GET, entity, Entry.class, id).getBody();
|
Entry entry = restTemplate.exchange(mamHost + "/rest/migration/entry/{id}", HttpMethod.GET, entity, Entry.class, id).getBody();
|
||||||
@@ -171,7 +170,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
|
|
||||||
while (openUploads.size() > 0) {
|
while (openUploads.size() > 0) {
|
||||||
log.debug("Sleeping...");
|
log.debug("Sleeping...");
|
||||||
TimeUnit.SECONDS.sleep(5); // XXX
|
TimeUnit.SECONDS.sleep(10); // XXX
|
||||||
|
|
||||||
log.debug("Checking back on open uploads");
|
log.debug("Checking back on open uploads");
|
||||||
attachOpenUploads();
|
attachOpenUploads();
|
||||||
@@ -215,6 +214,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
List<Node> path = new LinkedList<Node>();
|
List<Node> path = new LinkedList<Node>();
|
||||||
|
|
||||||
Node tmpNode = node;
|
Node tmpNode = node;
|
||||||
|
String currentBrand = null;
|
||||||
while (tmpNode.id != CategoryTree.ROOT_NODE_ID) {
|
while (tmpNode.id != CategoryTree.ROOT_NODE_ID) {
|
||||||
if (tmpNode.id == 0) {
|
if (tmpNode.id == 0) {
|
||||||
log.info("RESULT Skipping entry " + entry.id + ": Node outside of category tree (" + node.toString() + ")");
|
log.info("RESULT Skipping entry " + entry.id + ": Node outside of category tree (" + node.toString() + ")");
|
||||||
@@ -263,17 +263,16 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
if ((p.equals("Brand.General") || p.equals("Brand.CAP.Others") || p.equals("Brand.FAP.Others"))
|
if ((p.equals("Brand.General") || p.equals("Brand.CAP.Others") || p.equals("Brand.FAP.Others"))
|
||||||
&& record.hasClassificationStartingWith("Brand.")) {
|
&& record.hasClassificationStartingWith("Brand.")) {
|
||||||
|
|
||||||
// Check if the brand matches the business unit XXX
|
// Check if the brand matches the business unit
|
||||||
// if ((p.equals("Brand.General") && record.hasClassificationStartingWith("BusinessUnit.General")) ||
|
if (record.hasClassificationStartingWith("Brand.General")
|
||||||
// (p.equals("Brand.CAP.Others") && record.hasClassificationStartingWith("BusinessUnit.CAP")) ||
|
&& !record.hasClassificationStartingWith("BusinessUnit.General")) {
|
||||||
// (p.equals("Brand.FAP.Others") && record.hasClassificationStartingWith("BusinessUnit.FAP")))
|
log.warn("Classification " + p + " not added, different brand already set");
|
||||||
|
continue;
|
||||||
log.warn("Classification " + p + " not added, different brand already set");
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
record.removeClassificationsStartingWith("Brand.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
record.removeClassificationsStartingWith("Brand.");
|
||||||
|
currentBrand = p.substring(p.lastIndexOf('.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.startsWith("MediaType.")) {
|
if (p.startsWith("MediaType.")) {
|
||||||
@@ -287,16 +286,22 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
record.removeClassificationsStartingWith("Brand.");
|
record.removeClassificationsStartingWith("Brand.");
|
||||||
String brandClassificationId = "Brand." + n.name.trim();
|
String brandClassificationId = "Brand." + n.name.trim();
|
||||||
record.addClassification(brandClassificationId);
|
record.addClassification(brandClassificationId);
|
||||||
|
currentBrand = n.name.trim();
|
||||||
}
|
}
|
||||||
else if (n.action.equals("campaign")) {
|
else if (n.action.equals("campaign")) {
|
||||||
String campaignName = n.name;
|
String campaignName = n.name;
|
||||||
String campaignLabel = n.name;
|
String campaignLabel = n.name;
|
||||||
String campaignYear;
|
String campaignYear;
|
||||||
if (n.parameter != null && !n.parameter.trim().equals("")) {
|
if (n.parameter != null && !n.parameter.trim().equals("")) {
|
||||||
campaignLabel = campaignLabel + " " + n.parameter;
|
|
||||||
campaignYear = n.parameter.substring(1, 5);
|
campaignYear = n.parameter.substring(1, 5);
|
||||||
|
if (currentBrand != null)
|
||||||
|
campaignLabel = currentBrand + " - " + campaignLabel + " " + n.parameter;
|
||||||
|
else
|
||||||
|
campaignLabel = campaignLabel + " " + n.parameter;
|
||||||
} else {
|
} else {
|
||||||
campaignYear = n.name.substring(0, 4);
|
campaignYear = n.name.substring(0, 4);
|
||||||
|
if (currentBrand != null)
|
||||||
|
campaignLabel = currentBrand + " - " + campaignLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -542,8 +547,6 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX E:\71725 wieder herstellen
|
|
||||||
|
|
||||||
filesForUpload.add(masterFile);
|
filesForUpload.add(masterFile);
|
||||||
hrefsForUpload.add(selectedDownload.href);
|
hrefsForUpload.add(selectedDownload.href);
|
||||||
}
|
}
|
||||||
@@ -618,10 +621,9 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
UploadFileRecord fileRecord = new UploadFileRecord();
|
UploadFileRecord fileRecord = new UploadFileRecord();
|
||||||
fileRecord.addFile(reference.token, reference.isMaster);
|
fileRecord.addFile(reference.token, reference.isMaster);
|
||||||
|
|
||||||
log.debug("Attach uploaded file to " + reference.targetRecord);
|
log.debug("Attach " + reference.filename + " to " + reference.targetRecord);
|
||||||
HttpEntity<UploadFileRecord> httpEntity = new HttpEntity<UploadFileRecord>(fileRecord, adamHeaders);
|
HttpEntity<UploadFileRecord> httpEntity = new HttpEntity<UploadFileRecord>(fileRecord, adamHeaders);
|
||||||
|
|
||||||
// TODO E:\56942 wieder herstellen
|
|
||||||
try {
|
try {
|
||||||
ResponseEntity<Void> response = restTemplate.exchange(Definitions.adamHost + reference.targetRecord, HttpMethod.PUT, httpEntity, Void.class);
|
ResponseEntity<Void> response = restTemplate.exchange(Definitions.adamHost + reference.targetRecord, HttpMethod.PUT, httpEntity, Void.class);
|
||||||
log.debug("Response: " + response.toString());
|
log.debug("Response: " + response.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user