This commit is contained in:
gexce
2017-11-16 15:37:35 +01:00
parent bb1a81ad3a
commit 909f34d062
3 changed files with 30 additions and 22 deletions
@@ -39,6 +39,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import com.bayer.edam.migration.adam.Campaign;
@@ -69,7 +70,8 @@ public class MamMigrationSelective implements CommandLineRunner {
static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com";
static final String fileCache = "E:\\";
// XXX
static final String fileCache = "E:\\_TEST\\";
static final String categoryJson = "resources/2017-10-19_categories.json";
static final String categoryMapping = "resources/Media_Assistant_Categories_131017_EDITED_without_archive.csv";
@@ -153,7 +155,7 @@ public class MamMigrationSelective implements CommandLineRunner {
}
int entryCounter = 1;
HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
// HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
for (long id : entrySelection) {
// XXX
@@ -163,7 +165,7 @@ public class MamMigrationSelective implements CommandLineRunner {
log.info("GET entry " + id + " (" + entryCounter++ + ")");
log.info("GET entry " + id + " (" + entryCounter++ + "/" + entrySelection.size() + ")");
// Entry entry = restTemplate.exchange(mamHost + "/rest/migration/entry/{id}", HttpMethod.GET, entity, Entry.class, id).getBody();
Entry entry = entryMap.get(id);
@@ -641,9 +643,9 @@ public class MamMigrationSelective implements CommandLineRunner {
}
}
catch (ResourceAccessException rae) {
log.error("Could not upload " + file.getAbsolutePath() + " (" + isMaster + ") for " + recordLocation + " from entry " + entry.id + ": " + rae.getMessage());
rae.printStackTrace();
catch (RestClientException rce) {
log.error("FILE RESULT Could not upload " + file.getAbsolutePath() + " (" + isMaster + ") for " + recordLocation + " from entry " + entry.id + ": " + rce.getMessage());
rce.printStackTrace();
}
}
@@ -679,27 +681,33 @@ public class MamMigrationSelective implements CommandLineRunner {
ResponseEntity<Void> response = restTemplate.exchange(Definitions.adamHost + reference.targetRecord, HttpMethod.PUT, httpEntity, Void.class);
log.debug("Response: " + response.toString());
}
catch (Exception e) {
log.error("Exception while attaching file to record " + e.getMessage());
e.printStackTrace();
catch (RestClientException rce) {
log.error("ATTACH RESULT Exception while attaching file " + reference.cachePath + " (" + reference.isMaster + ") for " + reference.targetRecord + ": " + rce.getMessage());
rce.printStackTrace();
}
log.debug("ATTACH RESULT Attached " + reference.cachePath + " (" + reference.isMaster + ") to " + reference.targetRecord);
processedReferences.add(reference);
}
else {
log.debug("Checking status of " + reference.cachePath + " for " + reference.uri);
UploadResult result = restTemplate.exchange(Definitions.adamHost + reference.uri, HttpMethod.GET, adamHeadersEntity, UploadResult.class).getBody();
log.debug("Result: " + result);
if (result.token != null) {
log.debug("Storing upload token " + result.token);
reference.token = result.token;
}
else if (result.status != null) {
if (result.status.equals("Error")) {
log.error("System could not process file " + reference.cachePath + " for " + reference.targetRecord);
processedReferences.add(reference);
try {
UploadResult result = restTemplate.exchange(Definitions.adamHost + reference.uri, HttpMethod.GET, adamHeadersEntity, UploadResult.class).getBody();
log.debug("Result: " + result);
if (result.token != null) {
log.debug("Storing upload token " + result.token);
reference.token = result.token;
}
else if (result.status != null) {
if (result.status.equals("Error")) {
log.error("System could not process file " + reference.cachePath + " for " + reference.targetRecord);
processedReferences.add(reference);
}
}
}
catch (RestClientException rce) {
log.error("Failed to check status of " + reference.cachePath + " for " + reference.uri);
}
}
}