Zwischenstand
This commit is contained in:
@@ -111,11 +111,12 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
// XXX ----------------------------------------------------------------
|
||||
// Option 1: Process all available entries
|
||||
entrySelection = new ArrayList<Long>(entryMap.keySet());
|
||||
// entrySelection = new ArrayList<Long>(entryMap.keySet());
|
||||
|
||||
// Option 2: Process a fixed set of entry IDs
|
||||
// entrySelection = Arrays.asList(71725L, 71537L, 71263L, 71048L, 70778L, 70746L, 70745L,
|
||||
// 70440L, 70361L, 70340L, 70288L, 70161L, 70142L, 63924L, 63201L, 57641L, 56942L);
|
||||
entrySelection = Arrays.asList(34197L);
|
||||
|
||||
// Option 3: Read entry IDs from file
|
||||
// entrySelection = new ArrayList<Long>();
|
||||
@@ -531,12 +532,21 @@ 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);
|
||||
ResponseEntity<String> response = restTemplate.exchange(Definitions.adamHost + "/records", HttpMethod.POST, httpEntity, String.class);
|
||||
|
||||
uploadFilesForEntry(entry, location);
|
||||
|
||||
log.info("FINAL " + entry.id + fieldSeparator + location.toString() + fieldSeparator + entryJson);
|
||||
// XXX
|
||||
if (response.getStatusCodeValue() == 201) {
|
||||
UploadResult result = jsonMapper.readValue(response.getBody(), UploadResult.class);
|
||||
URI location = new URI("/record/" + result.id);
|
||||
log.info("RESULT Entry " + entry.id + " migrated to record " + location);
|
||||
|
||||
uploadFilesForEntry(entry, location);
|
||||
log.info("FINAL " + entry.id + fieldSeparator + location.toString() + fieldSeparator + entryJson);
|
||||
}
|
||||
else {
|
||||
log.error("RESULT Could not create record for entry " + entry.id + ": " + );
|
||||
}
|
||||
}
|
||||
catch (RestClientException rce) {
|
||||
log.error("RESULT Could not create record for entry " + entry.id + ": " + rce.getMessage());
|
||||
@@ -573,65 +583,72 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
// if selected download is a zip that contains a single file, upload extracted file as master
|
||||
if (selectedDownload.fileName.toLowerCase().endsWith(".zip")) {
|
||||
ZipFile zipFile = new ZipFile(masterFile);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FileHeader> fileHeaders = zipFile.getFileHeaders();
|
||||
|
||||
if (fileHeaders.size() == 1) {
|
||||
String extractedMasterFilePath = fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName();
|
||||
|
||||
if (!(new File(extractedMasterFilePath).exists())) {
|
||||
log.info("Extracting single master file " + fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName());
|
||||
zipFile.extractAll(fileCache + entry.id + "\\");
|
||||
}
|
||||
log.info("Using extracted master file " + extractedMasterFilePath);
|
||||
masterFile = new File(extractedMasterFilePath);
|
||||
if (!zipFile.isValidZipFile()) {
|
||||
log.error("Zip file " + masterFile.getAbsolutePath() + " could not be extracted");
|
||||
}
|
||||
else if (entry.mediaType.name.get("en").equals("Logo Folder")) {
|
||||
String destPath = fileCache + entry.id + "\\";
|
||||
log.info("Extracting single 'Logo Folder' files " + destPath);
|
||||
zipFile.extractAll(destPath);
|
||||
else {
|
||||
|
||||
boolean pngFound = false;
|
||||
boolean jpgFound = false;
|
||||
String newMasterFilePath = null;
|
||||
FileHeader newMasterFileHeader = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FileHeader> fileHeaders = zipFile.getFileHeaders();
|
||||
|
||||
for (FileHeader header : fileHeaders) {
|
||||
if (header.getFileName().toLowerCase().endsWith(".png")) {
|
||||
pngFound = true;
|
||||
newMasterFilePath = destPath + header.getFileName();
|
||||
newMasterFileHeader = header;
|
||||
}
|
||||
else if (header.getFileName().toLowerCase().endsWith(".jpg") && !pngFound) {
|
||||
jpgFound = true;
|
||||
newMasterFilePath = destPath + header.getFileName();
|
||||
newMasterFileHeader = header;
|
||||
}
|
||||
else if (!header.isDirectory() && !pngFound && !jpgFound) {
|
||||
newMasterFilePath = destPath + header.getFileName();
|
||||
newMasterFileHeader = header;
|
||||
}
|
||||
}
|
||||
|
||||
if (newMasterFilePath != null) {
|
||||
masterFile = new File(newMasterFilePath);
|
||||
log.info("Using extracted master file " + newMasterFilePath);
|
||||
if (fileHeaders.size() == 1) {
|
||||
String extractedMasterFilePath = fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName();
|
||||
|
||||
if (!(new File(extractedMasterFilePath).exists())) {
|
||||
log.info("Extracting single master file " + fileCache + entry.id + "\\" + fileHeaders.get(0).getFileName());
|
||||
zipFile.extractAll(fileCache + entry.id + "\\");
|
||||
}
|
||||
log.info("Using extracted master file " + extractedMasterFilePath);
|
||||
masterFile = new File(extractedMasterFilePath);
|
||||
}
|
||||
else if (entry.mediaType.name.get("en").equals("Logo Folder")) {
|
||||
String destPath = fileCache + entry.id + "\\";
|
||||
log.info("Extracting single 'Logo Folder' files " + destPath);
|
||||
zipFile.extractAll(destPath);
|
||||
|
||||
boolean pngFound = false;
|
||||
boolean jpgFound = false;
|
||||
String newMasterFilePath = null;
|
||||
FileHeader newMasterFileHeader = null;
|
||||
|
||||
// add remaining extracted files
|
||||
for (FileHeader header : fileHeaders) {
|
||||
if (!header.isDirectory() && header != newMasterFileHeader) {
|
||||
File extractedFile = new File(destPath + header.getFileName());
|
||||
if (extractedFile.exists())
|
||||
filesForUpload.add(extractedFile);
|
||||
else
|
||||
log.error("Could not find extraced file " + destPath + header.getFileName());
|
||||
if (header.getFileName().toLowerCase().endsWith(".png")) {
|
||||
pngFound = true;
|
||||
newMasterFilePath = destPath + header.getFileName();
|
||||
newMasterFileHeader = header;
|
||||
}
|
||||
else if (header.getFileName().toLowerCase().endsWith(".jpg") && !pngFound) {
|
||||
jpgFound = true;
|
||||
newMasterFilePath = destPath + header.getFileName();
|
||||
newMasterFileHeader = header;
|
||||
}
|
||||
else if (!header.isDirectory() && !pngFound && !jpgFound) {
|
||||
newMasterFilePath = destPath + header.getFileName();
|
||||
newMasterFileHeader = header;
|
||||
}
|
||||
}
|
||||
|
||||
if (newMasterFilePath != null) {
|
||||
masterFile = new File(newMasterFilePath);
|
||||
log.info("Using extracted master file " + newMasterFilePath);
|
||||
|
||||
// add remaining extracted files
|
||||
for (FileHeader header : fileHeaders) {
|
||||
if (!header.isDirectory() && header != newMasterFileHeader) {
|
||||
File extractedFile = new File(destPath + header.getFileName());
|
||||
if (extractedFile.exists())
|
||||
filesForUpload.add(extractedFile);
|
||||
else
|
||||
log.error("Could not find extraced file " + destPath + header.getFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.info("No suitable master file found, uploading compressed file " + masterFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
log.info("No suitable master file found, uploading compressed file " + masterFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user