EntryDownloader - download all entry IDs
This commit is contained in:
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -8,10 +8,12 @@ import java.net.PasswordAuthentication;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -29,12 +31,20 @@ import com.bayer.edam.migration.mam.Entry.Download;
|
|||||||
import com.bayer.edam.migration.mam.Entrylist;
|
import com.bayer.edam.migration.mam.Entrylist;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
//@SpringBootApplication
|
@SpringBootApplication
|
||||||
@PropertySource("file:secret.properties")
|
@PropertySource("file:secret.properties")
|
||||||
public class EntryDownloader implements CommandLineRunner {
|
public class EntryDownloader implements CommandLineRunner {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(EntryDownloader.class);
|
private static final Logger log = LoggerFactory.getLogger(EntryDownloader.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, files are downloaded. If false, only the IDs are written into the outputfile.
|
||||||
|
*/
|
||||||
|
private final boolean downloadFiles = false;
|
||||||
|
|
||||||
|
File outputfile = new File("C:\\Temp\\Migration AH\\files\\entrylist_2017-10-25.txt");
|
||||||
|
|
||||||
|
|
||||||
@Value("${mam.auth}")
|
@Value("${mam.auth}")
|
||||||
private String mamAuth;
|
private String mamAuth;
|
||||||
|
|
||||||
@@ -82,9 +92,21 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
for (int pageNum = 1; pageNum <= lastPage; pageNum++) {
|
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();
|
Entrylist entrylist = restTemplate.exchange(mamHost + "/rest/migration/entrylist?pagenumber={pagenum}&pagesize=500", HttpMethod.GET, entity, Entrylist.class, pageNum).getBody();
|
||||||
lastPage = entrylist.lastPage;
|
lastPage = entrylist.lastPage;
|
||||||
|
log.debug("processing page " + pageNum + " of " + lastPage);
|
||||||
|
|
||||||
for (int i = 0; i < entrylist.entries.length; i++) {
|
for (int i = 0; i < entrylist.entries.length; i++) {
|
||||||
|
|
||||||
|
|
||||||
|
if (!downloadFiles) {
|
||||||
|
// only create a list with all IDs
|
||||||
|
try {
|
||||||
|
FileUtils.writeStringToFile(outputfile, entrylist.entries[i].mediaAssistantId + "\n", Charset.forName("utf-8"), true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
Integer entryId = Integer.parseInt(entrylist.entries[i].mediaAssistantId);
|
Integer entryId = Integer.parseInt(entrylist.entries[i].mediaAssistantId);
|
||||||
File targetDir = new File("E:\\" + entryId);
|
File targetDir = new File("E:\\" + entryId);
|
||||||
if (targetDir.exists()) {
|
if (targetDir.exists()) {
|
||||||
@@ -161,6 +183,7 @@ public class EntryDownloader implements CommandLineRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
SpringApplication.run(EntryDownloader.class, args);
|
SpringApplication.run(EntryDownloader.class, args);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import com.bayer.edam.migration.mam.categories.CategoryTree;
|
|||||||
import com.bayer.edam.migration.mam.categories.CategoryTree.Node;
|
import com.bayer.edam.migration.mam.categories.CategoryTree.Node;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
@SpringBootApplication
|
//@SpringBootApplication
|
||||||
@PropertySource("file:secret.properties")
|
@PropertySource("file:secret.properties")
|
||||||
public class MamMigrationSelective implements CommandLineRunner {
|
public class MamMigrationSelective implements CommandLineRunner {
|
||||||
|
|
||||||
@@ -79,15 +79,14 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
|
|
||||||
private List<Classification> campaignYears;
|
private List<Classification> campaignYears;
|
||||||
private List<Campaign> campaigns = new LinkedList<Campaign>();
|
private List<Campaign> campaigns = new LinkedList<Campaign>();
|
||||||
|
|
||||||
private List<String> locations = new ArrayList<String>();
|
|
||||||
private CategoryTree mamCategoryTree;
|
private CategoryTree mamCategoryTree;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... strings) throws Exception {
|
public void run(String... strings) throws Exception {
|
||||||
|
|
||||||
log.info("Write log headers");
|
log.info("Write log headers for " + entryLog.getAbsolutePath());
|
||||||
FileUtils.writeStringToFile(entryLog, "Location" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
FileUtils.writeStringToFile(entryLog, "Location" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||||
|
log.info("Write log headers for " + problemLog.getAbsolutePath());
|
||||||
FileUtils.writeStringToFile(problemLog, "entryId" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
FileUtils.writeStringToFile(problemLog, "entryId" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||||
|
|
||||||
log.info("Read categories");
|
log.info("Read categories");
|
||||||
@@ -137,13 +136,6 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
postToAdam(entry);
|
postToAdam(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // delete all created records
|
|
||||||
// for (String location : locations) {
|
|
||||||
// ResponseEntity<String> response = restTemplate.exchange(adamHost + location, HttpMethod.DELETE, adamHeadersEntity,
|
|
||||||
// String.class);
|
|
||||||
// log.info("Deleted " + location + ": " + response.toString());
|
|
||||||
// }
|
|
||||||
|
|
||||||
invalidateAdamToken();
|
invalidateAdamToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,14 +323,12 @@ public class MamMigrationSelective implements CommandLineRunner {
|
|||||||
HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
|
HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
|
||||||
try {
|
try {
|
||||||
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, UploadRecord.class);
|
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, UploadRecord.class);
|
||||||
log.info("Created " + location);
|
log.info("Entry " + entry.id + " migrated to record " + location);
|
||||||
|
|
||||||
FileUtils.writeStringToFile(entryLog, location.toString() + fieldSeparator + entryJson + lineSeparator,
|
FileUtils.writeStringToFile(entryLog, location.toString() + fieldSeparator + entryJson + lineSeparator,
|
||||||
Charset.forName("utf-8"), true);
|
Charset.forName("utf-8"), true);
|
||||||
|
}
|
||||||
locations.add(location.toString());
|
catch (HttpStatusCodeException hsce) {
|
||||||
|
|
||||||
} catch (HttpStatusCodeException hsce) {
|
|
||||||
log.error("Skipping entry " + entry.id + ": Error while creating record " + hsce.getStatusCode().toString());
|
log.error("Skipping entry " + entry.id + ": Error while creating record " + hsce.getStatusCode().toString());
|
||||||
log.error(hsce.getResponseBodyAsString());
|
log.error(hsce.getResponseBodyAsString());
|
||||||
FileUtils.writeStringToFile(problemLog, entry.id + fieldSeparator + entryJson + lineSeparator, Charset.forName("utf-8"), true);
|
FileUtils.writeStringToFile(problemLog, entry.id + fieldSeparator + entryJson + lineSeparator, Charset.forName("utf-8"), true);
|
||||||
|
|||||||
Reference in New Issue
Block a user