Fixed MAM download
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user