Uploads
This commit is contained in:
@@ -2,7 +2,6 @@ package com.bayer.edam.migration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -43,6 +42,7 @@ import com.bayer.edam.migration.adam.Token;
|
||||
import com.bayer.edam.migration.adam.UploadClassification;
|
||||
import com.bayer.edam.migration.adam.UploadRecord;
|
||||
import com.bayer.edam.migration.adam.UploadRecord.WriteClassification;
|
||||
import com.bayer.edam.migration.adam.UploadResult;
|
||||
import com.bayer.edam.migration.interceptors.LoggingRequestInterceptor;
|
||||
import com.bayer.edam.migration.mam.CategoryTree;
|
||||
import com.bayer.edam.migration.mam.CategoryTree.Node;
|
||||
@@ -57,7 +57,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
|
||||
|
||||
static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com";
|
||||
private List<Integer> entrySelection = new ArrayList<Integer>(Arrays.asList( 72048, 60984 /*48147 /* 58443/*, 53787, 32427, 71725, 63080*/ )); // 72048, 60984
|
||||
private List<Integer> entrySelection = new ArrayList<Integer>(Arrays.asList( 71263 /*72048, 60984 /*48147 /* 58443/*, 53787, 32427, 71725, 63080*/ )); // 72048, 60984
|
||||
|
||||
static final String categoryJson = "resources/2017-10-19_categories.json";
|
||||
static final String categoryMapping = "resources/Media_Assistant_Categories_131017_EDITED_without_archive.csv";
|
||||
@@ -90,7 +90,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
public void run(String... strings) throws Exception {
|
||||
|
||||
// XXX
|
||||
readEntryIDsFromFile();
|
||||
// readEntryIDsFromFile();
|
||||
|
||||
log.info("Write log headers for " + entryLog.getAbsolutePath());
|
||||
FileUtils.writeStringToFile(entryLog, "entryId" + fieldSeparator + "Location" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
@@ -127,8 +127,8 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
// XXX
|
||||
// if needed start from a certain ID
|
||||
if (id >= 32935)
|
||||
continue;
|
||||
// if (id > 32348)
|
||||
// continue;
|
||||
|
||||
|
||||
log.info("GET entry " + id);
|
||||
@@ -358,6 +358,9 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
if (entry.creationDate != null)
|
||||
record.addField("byr_ah_deliveryDate", isoDate.format(entry.creationDate));
|
||||
|
||||
if (entry.metaData.get("photographer") != null)
|
||||
record.addField("byr_ah_photographer", entry.metaData.get("photographer"));
|
||||
|
||||
// Project lead
|
||||
if (entry.user != null && entry.user.get("id") != null) {
|
||||
if (Definitions.users.get(entry.user.get("id")) != null) {
|
||||
@@ -437,16 +440,16 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
|
||||
try {
|
||||
|
||||
URI location = restTemplate.postForLocation(Definitions.adamHost + "/records", httpEntity, UploadRecord.class);
|
||||
log.info("RESULT Entry " + entry.id + " migrated to record " + location);
|
||||
// URI location = restTemplate.postForLocation(Definitions.adamHost + "/records", httpEntity, UploadRecord.class);
|
||||
// log.info("RESULT Entry " + entry.id + " migrated to record " + location);
|
||||
|
||||
// XXX
|
||||
// uploadFilesForEntry(entry);
|
||||
uploadFilesForEntry(entry);
|
||||
|
||||
// TODO process file upload errors
|
||||
|
||||
FileUtils.writeStringToFile(entryLog, entry.id + fieldSeparator + location.toString() + fieldSeparator + entryJson + lineSeparator,
|
||||
Charset.forName("utf-8"), true);
|
||||
// FileUtils.writeStringToFile(entryLog, entry.id + fieldSeparator + location.toString() + fieldSeparator + entryJson + lineSeparator,
|
||||
// Charset.forName("utf-8"), true);
|
||||
}
|
||||
catch (HttpStatusCodeException hsce) {
|
||||
log.error("RESULT Skipping entry " + entry.id + ": Error while creating record " + hsce.getStatusCode().toString());
|
||||
@@ -455,7 +458,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
}
|
||||
|
||||
|
||||
private void uploadFilesForEntry(Entry entry) {
|
||||
private void uploadFilesForEntry(Entry entry) throws Exception {
|
||||
|
||||
List<Download> downloadSelection = new ArrayList<Download>();
|
||||
|
||||
@@ -504,18 +507,17 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
if (uploadFile.exists()) {
|
||||
if (uploadFile.length() < 4000000000L) {
|
||||
log.debug("filesize " + uploadFile.length() + " < 4 GB");
|
||||
|
||||
log.info("Uploading file " + filepath);
|
||||
log.info("Uploading file " + filepath + ", size " + uploadFile.length());
|
||||
|
||||
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
|
||||
parameters.add("file", new FileSystemResource(uploadFile));
|
||||
|
||||
String result = restTemplate.postForObject(Definitions.adamHost + "/uploads",
|
||||
new HttpEntity<MultiValueMap<String, Object>>(parameters, adamUploadHeaders), String.class);
|
||||
UploadResult result = restTemplate.exchange(Definitions.adamHost + "/uploads", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, Object>>(parameters, adamUploadHeaders), UploadResult.class).getBody();
|
||||
|
||||
// String answer = restTemplate.exchange(Definitions.adamHost + "/uploads", HttpMethod.POST,
|
||||
// new HttpEntity<MultiValueMap<String, Object>>(parameters, adamUploadHeaders), String.class).getBody();
|
||||
if (result.token != null) {
|
||||
log.debug("Token: " + result.token);
|
||||
}
|
||||
|
||||
log.info("Upload result: " + result);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user