EntryDownloader
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
import com.bayer.edam.migration.mam.Entry.Download;
|
||||
import com.bayer.edam.migration.mam.Entrylist;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource("file:secret.properties")
|
||||
public class EntryDownloader implements CommandLineRunner {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(EntryDownloader.class);
|
||||
|
||||
@Value("${mam.auth}")
|
||||
private String mamAuth;
|
||||
|
||||
|
||||
static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com";
|
||||
|
||||
static final String separator = "|~|";
|
||||
|
||||
|
||||
private ObjectMapper jsonMapper = new ObjectMapper();
|
||||
private RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Accept", "application/json");
|
||||
headers.add("Authorization", "Basic " + mamAuth);
|
||||
headers.add("Content-Type", "application/json");
|
||||
headers.add("From", "migration@bayer.com");
|
||||
HttpEntity<String> entity = new HttpEntity<String>("", headers);
|
||||
|
||||
int lastPage = 1;
|
||||
for (int pageNum = 1; pageNum <= lastPage; pageNum++) {
|
||||
Entrylist entrylist = restTemplate.exchange(mamHost + "/rest/migration/entrylist?pagenumber={pagenum}&pagesize=500", HttpMethod.GET, entity, Entrylist.class, pageNum).getBody();
|
||||
lastPage = entrylist.lastPage;
|
||||
|
||||
for (int i = 0; i < entrylist.entries.length; i++) {
|
||||
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);
|
||||
|
||||
long aggregatedFilesize = 0;
|
||||
for (Download download : entry.downloadList) {
|
||||
aggregatedFilesize += download.size;
|
||||
}
|
||||
for (Download download : entry.downloadListPublicFolder) {
|
||||
aggregatedFilesize += download.size;
|
||||
}
|
||||
|
||||
log.info(entry.id + separator + entry.mediaAssistantId + separator + entry.stateId + separator + aggregatedFilesize + separator + entryJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
SpringApplication.run(EntryDownloader.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user