diff --git a/AH MAM Migration/resources/application.properties b/AH MAM Migration/resources/application.properties index 4c2d873..3b6c724 100644 --- a/AH MAM Migration/resources/application.properties +++ b/AH MAM Migration/resources/application.properties @@ -2,4 +2,4 @@ logging.level.com.bayer=DEBUG #logging.level.com.bayer.edam.migration.interceptors=INFO 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 diff --git a/AH MAM Migration/src/com/bayer/edam/migration/EntryDownloader.java b/AH MAM Migration/src/com/bayer/edam/migration/EntryDownloader.java index 161bde3..36306d5 100644 --- a/AH MAM Migration/src/com/bayer/edam/migration/EntryDownloader.java +++ b/AH MAM Migration/src/com/bayer/edam/migration/EntryDownloader.java @@ -12,6 +12,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; @@ -19,7 +20,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.PropertySource; import org.springframework.http.HttpEntity; 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. */ - 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}") @@ -99,8 +99,14 @@ public class EntryDownloader implements CommandLineRunner { if (!downloadFiles) { // only create a list with all IDs try { - FileUtils.writeStringToFile(outputfile, entrylist.entries[i].mediaAssistantId + "\n", Charset.forName("utf-8"), true); - } catch (IOException e) { + log.info("Get " + i + "/" + entrylist.entries.length); + 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(); } } diff --git a/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java b/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java index 224bdc7..80894e1 100644 --- a/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java +++ b/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java @@ -65,7 +65,7 @@ public class MamMigrationSelective implements CommandLineRunner { private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class); static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com"; - private List entrySelection = new ArrayList(Arrays.asList( 71725 /*, 71263, 71048, 70778, 70746, 70745, 70440, 70361, 70340, 70288, 70161, 70142, 63924, 63201, 57641, 56942 */)); + private List entrySelection = new ArrayList(Arrays.asList( /*71725, 71263, 71048, 70778, 70746, 70745, 70440, 70361, 70340, 70288, 70161, 70142, 63924, */63201, 57641, 56942 )); static final String fileCache = "E:\\"; @@ -104,7 +104,6 @@ public class MamMigrationSelective implements CommandLineRunner { log.info("Read categories"); mamCategoryTree = new CategoryTree(categoryJson, categoryMapping); - // XXX SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setBufferRequestBody(false); fileTransferTemplate = new RestTemplate(requestFactory); @@ -126,7 +125,6 @@ public class MamMigrationSelective implements CommandLineRunner { for (Classification yearClassification : campaignYears) { List campaignClassifications = restTemplate.exchange(Definitions.adamHost + "/classification/" + yearClassification.id + "/children", HttpMethod.GET, adamHeadersEntity, ClassificationList.class).getBody().items; 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.guid = campaignClassification.id; campaigns.add(campaign); @@ -142,6 +140,7 @@ public class MamMigrationSelective implements CommandLineRunner { // continue; + log.info("GET entry " + id); 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) { log.debug("Sleeping..."); - TimeUnit.SECONDS.sleep(5); // XXX + TimeUnit.SECONDS.sleep(10); // XXX log.debug("Checking back on open uploads"); attachOpenUploads(); @@ -215,6 +214,7 @@ public class MamMigrationSelective implements CommandLineRunner { List path = new LinkedList(); Node tmpNode = node; + String currentBrand = null; 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() + ")"); @@ -263,17 +263,16 @@ public class MamMigrationSelective implements CommandLineRunner { if ((p.equals("Brand.General") || p.equals("Brand.CAP.Others") || p.equals("Brand.FAP.Others")) && record.hasClassificationStartingWith("Brand.")) { - // Check if the brand matches the business unit XXX -// if ((p.equals("Brand.General") && record.hasClassificationStartingWith("BusinessUnit.General")) || -// (p.equals("Brand.CAP.Others") && record.hasClassificationStartingWith("BusinessUnit.CAP")) || -// (p.equals("Brand.FAP.Others") && record.hasClassificationStartingWith("BusinessUnit.FAP"))) - - log.warn("Classification " + p + " not added, different brand already set"); - continue; - } - else { - record.removeClassificationsStartingWith("Brand."); + // Check if the brand matches the business unit + if (record.hasClassificationStartingWith("Brand.General") + && !record.hasClassificationStartingWith("BusinessUnit.General")) { + log.warn("Classification " + p + " not added, different brand already set"); + continue; + } } + + record.removeClassificationsStartingWith("Brand."); + currentBrand = p.substring(p.lastIndexOf('.')); } if (p.startsWith("MediaType.")) { @@ -287,16 +286,22 @@ public class MamMigrationSelective implements CommandLineRunner { record.removeClassificationsStartingWith("Brand."); String brandClassificationId = "Brand." + n.name.trim(); record.addClassification(brandClassificationId); + currentBrand = n.name.trim(); } else if (n.action.equals("campaign")) { String campaignName = n.name; String campaignLabel = n.name; String campaignYear; if (n.parameter != null && !n.parameter.trim().equals("")) { - campaignLabel = campaignLabel + " " + n.parameter; campaignYear = n.parameter.substring(1, 5); + if (currentBrand != null) + campaignLabel = currentBrand + " - " + campaignLabel + " " + n.parameter; + else + campaignLabel = campaignLabel + " " + n.parameter; } else { campaignYear = n.name.substring(0, 4); + if (currentBrand != null) + campaignLabel = currentBrand + " - " + campaignLabel; } try { @@ -542,8 +547,6 @@ public class MamMigrationSelective implements CommandLineRunner { } } - // XXX E:\71725 wieder herstellen - filesForUpload.add(masterFile); hrefsForUpload.add(selectedDownload.href); } @@ -618,10 +621,9 @@ public class MamMigrationSelective implements CommandLineRunner { UploadFileRecord fileRecord = new UploadFileRecord(); fileRecord.addFile(reference.token, reference.isMaster); - log.debug("Attach uploaded file to " + reference.targetRecord); + log.debug("Attach " + reference.filename + " to " + reference.targetRecord); HttpEntity httpEntity = new HttpEntity(fileRecord, adamHeaders); - // TODO E:\56942 wieder herstellen try { ResponseEntity response = restTemplate.exchange(Definitions.adamHost + reference.targetRecord, HttpMethod.PUT, httpEntity, Void.class); log.debug("Response: " + response.toString());