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 cad1464..23f4902 100644 --- a/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java +++ b/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java @@ -1,12 +1,8 @@ package com.bayer.edam.migration; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.URI; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -74,8 +70,8 @@ public class MamMigrationSelective implements CommandLineRunner { static final String categoryMapping = "resources/Media_Assistant_Categories_131017_EDITED_without_archive.csv"; // XXX - static final String entryListPath = "resources/entrylist_2017-10-25.txt"; -// static final String entryListPath = "resources/lottery.txt"; +// static final String entryListPath = "resources/entrylist_2017-10-25.txt"; + static final String entryListPath = "resources/lottery.txt"; @Value("${mam.auth}") private String mamAuth; @@ -191,7 +187,7 @@ public class MamMigrationSelective implements CommandLineRunner { HashSet campaignGuids = new HashSet(); // XXX -// record.addClassification("Migration.Test"); + record.addClassification("Migration.Test"); // globally applicable classifications record.addClassification("Migration"); @@ -523,7 +519,7 @@ public class MamMigrationSelective implements CommandLineRunner { private void uploadFilesForEntry(Entry entry, URI recordLocation) throws Exception { HashSet hrefsForUpload = new HashSet(); - List filesForUpload = new ArrayList(); + ArrayList filesForUpload = new ArrayList(); // Select download: Download original only. If original is not available, download largest file Download selectedDownload = null; @@ -545,26 +541,31 @@ public class MamMigrationSelective implements CommandLineRunner { File masterFile = getFileForEntry(selectedDownload, entry.id); - // if selected download is a zip that contains a single file, upload extracted file as master - if (selectedDownload.fileName.toLowerCase().endsWith(".zip")) { - ZipFile zipFile = new ZipFile(masterFile); - @SuppressWarnings("unchecked") - List fileHeaders = zipFile.getFileHeaders(); - - if (fileHeaders.size() == 1) { - String extractedMasterFilePath = fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName(); + if (masterFile != null) { + // if selected download is a zip that contains a single file, upload extracted file as master + if (selectedDownload.fileName.toLowerCase().endsWith(".zip")) { + ZipFile zipFile = new ZipFile(masterFile); + @SuppressWarnings("unchecked") + List fileHeaders = zipFile.getFileHeaders(); - if (!(new File(extractedMasterFilePath).exists())) { - log.info("Extracting single master file " + fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName()); - zipFile.extractAll(fileCache + entry.id + "\\"); + if (fileHeaders.size() == 1) { + String extractedMasterFilePath = fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName(); + + if (!(new File(extractedMasterFilePath).exists())) { + log.info("Extracting single master file " + fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName()); + zipFile.extractAll(fileCache + entry.id + "\\"); + } + log.info("Using extracted master file " + extractedMasterFilePath); + masterFile = new File(extractedMasterFilePath); } - log.info("Using extracted master file " + extractedMasterFilePath); - masterFile = new File(extractedMasterFilePath); } + + filesForUpload.add(masterFile); + hrefsForUpload.add(selectedDownload.href); + } + else { + log.error("Master file " + selectedDownload.fileName + " not available"); } - - filesForUpload.add(masterFile); - hrefsForUpload.add(selectedDownload.href); } else { log.warn("Could not identify master file for entry " + entry.id); @@ -572,7 +573,9 @@ public class MamMigrationSelective implements CommandLineRunner { for (Download download : entry.downloadListPublicFolder) { if (hrefsForUpload.add(download.href)) { - filesForUpload.add(getFileForEntry(download, entry.id)); + File file = getFileForEntry(download, entry.id); + if (file != null) + filesForUpload.add(file); } } @@ -691,12 +694,16 @@ public class MamMigrationSelective implements CommandLineRunner { // check whether file is in cache, download if it's not there if (!file.exists()) { - log.debug("Downloading missing file " + filenameToUse + " for entry " + id); - URL fileLink = new URL(download.href); - ReadableByteChannel rbc = Channels.newChannel(fileLink.openStream()); - FileOutputStream fos = new FileOutputStream(fileCache + id + "\\" + filenameToUse); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); + log.error("Missing file " + filenameToUse + " for entry " + id); + return null; + +// FIXME +// log.debug("Downloading missing file " + filenameToUse + " for entry " + id); +// URL fileLink = new URL(download.href); +// ReadableByteChannel rbc = Channels.newChannel(fileLink.openStream()); +// FileOutputStream fos = new FileOutputStream(fileCache + id + "\\" + filenameToUse); +// fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); +// fos.close(); } else { log.debug("Using existing file " + filenameToUse + " for entry " + id);