hardened EntryDownloader
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.http.HttpHeaders;
|
|||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import com.bayer.edam.migration.mam.Entry;
|
import com.bayer.edam.migration.mam.Entry;
|
||||||
@@ -65,6 +66,12 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
String entryJson = restTemplate.exchange(mamHost + "/rest/migration/entry/{id}", HttpMethod.GET, entity, String.class, entrylist.entries[i].mediaAssistantId).getBody();
|
String entryJson = restTemplate.exchange(mamHost + "/rest/migration/entry/{id}", HttpMethod.GET, entity, String.class, entrylist.entries[i].mediaAssistantId).getBody();
|
||||||
Entry entry = jsonMapper.readValue(entryJson, Entry.class);
|
Entry entry = jsonMapper.readValue(entryJson, Entry.class);
|
||||||
|
|
||||||
|
File targetDir = new File("E:\\" + entry.id);
|
||||||
|
if (targetDir.exists()) {
|
||||||
|
log.info("Skip " + entry.id + ", target directory already present");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
List<Download> downloadSelection = new ArrayList<Download>();
|
List<Download> downloadSelection = new ArrayList<Download>();
|
||||||
|
|
||||||
// Select download: Download original only. If original is not available, download largest file
|
// Select download: Download original only. If original is not available, download largest file
|
||||||
@@ -86,7 +93,7 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
if (selectedDownload != null)
|
if (selectedDownload != null)
|
||||||
downloadSelection.add(selectedDownload);
|
downloadSelection.add(selectedDownload);
|
||||||
|
|
||||||
// TODO extract, if zip --> postponed
|
// TODO extract, if zip --> postponed until upload
|
||||||
|
|
||||||
for (Download download : entry.downloadListPublicFolder) {
|
for (Download download : entry.downloadListPublicFolder) {
|
||||||
downloadSelection.add(download);
|
downloadSelection.add(download);
|
||||||
@@ -108,7 +115,7 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
|
|
||||||
log.info(entry.id + separator + entry.mediaAssistantId + separator + entry.stateId + separator + aggregatedFilesize + separator + entryJson);
|
log.info(entry.id + separator + entry.mediaAssistantId + separator + entry.stateId + separator + aggregatedFilesize + separator + entryJson);
|
||||||
|
|
||||||
new File("E:\\" + entry.id).mkdir();
|
targetDir.mkdir();
|
||||||
|
|
||||||
for (Download download : cleanedDownloads) {
|
for (Download download : cleanedDownloads) {
|
||||||
String filenameToUse;
|
String filenameToUse;
|
||||||
@@ -117,6 +124,7 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
else
|
else
|
||||||
filenameToUse = download.fileName;
|
filenameToUse = download.fileName;
|
||||||
|
|
||||||
|
try {
|
||||||
ResponseEntity<byte[]> response = restTemplate.exchange(download.href, HttpMethod.GET, entity, byte[].class);
|
ResponseEntity<byte[]> response = restTemplate.exchange(download.href, HttpMethod.GET, entity, byte[].class);
|
||||||
|
|
||||||
if (response.getStatusCode() == HttpStatus.OK) {
|
if (response.getStatusCode() == HttpStatus.OK) {
|
||||||
@@ -126,9 +134,15 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
log.error(entry.id + ", " + response.getStatusCodeValue() + ", " + download.href);
|
log.error(entry.id + ", " + response.getStatusCodeValue() + ", " + download.href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (HttpClientErrorException hcee) {
|
||||||
|
log.error(hcee.getMessage());
|
||||||
|
hcee.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ioe) {
|
catch (IOException ioe) {
|
||||||
log.error(ioe.toString());
|
log.error(ioe.getMessage());
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user