From 8d6bad1b982f4939fa9ec032f2eb8999679c304f Mon Sep 17 00:00:00 2001 From: gexce Date: Fri, 17 Nov 2017 16:00:20 +0100 Subject: [PATCH] Special processing for media type "Logo Folder" --- .../resources/application.properties | 2 +- .../edam/migration/MamMigrationSelective.java | 57 +++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/AH MAM Migration/resources/application.properties b/AH MAM Migration/resources/application.properties index e3c2eee..9e284d3 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_2017-11-17.log +logging.file=application_2017-11-17_71537_Logo.log 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 c85870c..5184e37 100644 --- a/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java +++ b/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java @@ -70,7 +70,7 @@ public class MamMigrationSelective implements CommandLineRunner { static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com"; // XXX - static final String fileCache = "E:\\"; + static final String fileCache = "E:\\_TEST\\"; static final String categoryJson = "resources/2017-10-19_categories.json"; static final String categoryMapping = "resources/Media_Assistant_Categories_131017_EDITED_without_archive.csv"; @@ -114,8 +114,10 @@ public class MamMigrationSelective implements CommandLineRunner { // entrySelection = new ArrayList(entryMap.keySet()); // Option 2: Process a fixed set of entry IDs - entrySelection = Arrays.asList(71725L, 71263L, 71048L, 70778L, 70746L, 70745L, 70440L, 70361L, 70340L, 70288L, 70161L, 70142L, - 63924L, 63201L, 57641L, 56942L); +// entrySelection = Arrays.asList(71725L, 71263L, 71048L, 70778L, 70746L, 70745L, 70440L, 70361L, 70340L, 70288L, 70161L, 70142L, +// 63924L, 63201L, 57641L, 56942L); + + entrySelection = Arrays.asList(71537L); // Option 3: Read entry IDs from file // entrySelection = new ArrayList(); @@ -584,6 +586,53 @@ public class MamMigrationSelective implements CommandLineRunner { log.info("Using extracted master file " + extractedMasterFilePath); masterFile = new File(extractedMasterFilePath); } + else if (entry.mediaType.name.get("en").equals("Logo Folder")) { + String destPath = fileCache + entry.id + "\\"; + log.info("Extracting single 'Logo Folder' files " + destPath); + zipFile.extractAll(destPath); + + boolean pngFound = false; + boolean jpgFound = false; + String newMasterFilePath = null; + FileHeader newMasterFileHeader = null; + + for (FileHeader header : fileHeaders) { + if (header.getFileName().toLowerCase().endsWith(".png")) { + pngFound = true; + newMasterFilePath = destPath + header.getFileName(); + newMasterFileHeader = header; + } + else if (header.getFileName().toLowerCase().endsWith(".jpg") && !pngFound) { + jpgFound = true; + newMasterFilePath = destPath + header.getFileName(); + newMasterFileHeader = header; + } + else if (!header.isDirectory() && !pngFound && !jpgFound) { + newMasterFilePath = destPath + header.getFileName(); + newMasterFileHeader = header; + } + } + + if (newMasterFilePath != null) { + masterFile = new File(newMasterFilePath); + log.info("Using extracted master file " + newMasterFilePath); + + // add remaining extracted files + for (FileHeader header : fileHeaders) { + if (!header.isDirectory() && header != newMasterFileHeader) { + File extractedFile = new File(destPath + header.getFileName()); + if (extractedFile.exists()) + filesForUpload.add(extractedFile); + else + log.error("Could not find extraced file " + destPath + header.getFileName()); + } + } + } + else { + log.info("No suitable master file found, uploading compressed file " + masterFile.getAbsolutePath()); + } + + } } filesForUpload.add(masterFile); @@ -707,7 +756,7 @@ public class MamMigrationSelective implements CommandLineRunner { } } catch (RestClientException rce) { - log.error("Failed to check status of " + reference.cachePath + " for " + reference.uri); + log.error("Failed to check status of " + reference.cachePath + " for " + reference.uri + ": " + rce.getMessage()); } } }