Fixed MAM download

This commit is contained in:
gexce
2017-11-17 11:28:46 +01:00
parent 9649cdb153
commit d5866ac48c
4 changed files with 39 additions and 28 deletions
@@ -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:\\_TEST\\";
static final String fileCache = "E:\\";
static final String categoryJson = "resources/2017-10-19_categories.json";
static final String categoryMapping = "resources/Media_Assistant_Categories_131017_EDITED_without_archive.csv";
@@ -602,6 +602,8 @@ public class MamMigrationSelective implements CommandLineRunner {
File file = getFileForEntry(download, entry.id);
if (file != null)
filesForUpload.add(file);
else
log.error("File " + download.fileName + " not available");
}
}
@@ -725,14 +727,20 @@ 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 url = new URL(download.href);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestProperty("Authorization", mamAuth);
ReadableByteChannel rbc = Channels.newChannel(httpConn.getInputStream());
FileOutputStream fos = new FileOutputStream(fileCache + id + "\\" + filenameToUse);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
try {
log.debug("Downloading missing file " + filenameToUse + " for entry " + id + " at " + download.href);
URL url = new URL(download.href);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestProperty("Authorization", "Basic " + mamAuth);
ReadableByteChannel rbc = Channels.newChannel(httpConn.getInputStream());
FileOutputStream fos = new FileOutputStream(fileCache + id + "\\" + filenameToUse);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
}
catch (IOException ioe) {
log.error("Could not download file " + filenameToUse + " for entry " + id + ": " + ioe.getMessage());
return null;
}
}
else {
log.debug("Using existing file " + filenameToUse + " for entry " + id);