dynamically create campaigns
This commit is contained in:
@@ -76,19 +76,20 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
private SimpleDateFormat stringDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private ObjectMapper jsonMapper = new ObjectMapper();
|
||||
|
||||
private List<String[]> campaigns;
|
||||
private List<Campaign> campaigns = new LinkedList<Campaign>();
|
||||
|
||||
private List<String> locations = new ArrayList<String>();
|
||||
private CategoryTree mamCategoryTree;
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
|
||||
// log.info("Write log headers");
|
||||
// FileUtils.writeStringToFile(entryLog, "Location" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
// FileUtils.writeStringToFile(problemLog, "entryId" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
//
|
||||
// log.info("Read categories");
|
||||
// mamCategoryTree = new CategoryTree(categoryJson, categoryMapping);
|
||||
log.info("Write log headers");
|
||||
FileUtils.writeStringToFile(entryLog, "Location" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
FileUtils.writeStringToFile(problemLog, "entryId" + fieldSeparator + "Entry" + lineSeparator, Charset.forName("utf-8"));
|
||||
|
||||
log.info("Read categories");
|
||||
mamCategoryTree = new CategoryTree(categoryJson, categoryMapping);
|
||||
|
||||
restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
|
||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
|
||||
@@ -97,27 +98,23 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
adamHeaders = createAdamHeaders();
|
||||
adamHeadersEntity = new HttpEntity<String>("", adamHeaders);
|
||||
// mamHeaders = createMamHeaders();
|
||||
|
||||
|
||||
|
||||
mamHeaders = createMamHeaders();
|
||||
|
||||
log.info("Read campaigns");
|
||||
HttpEntity<String> httpEntity = new HttpEntity<String>("parameters", adamHeaders);
|
||||
ClassificationList campaignYears = restTemplate.exchange(adamHost + "/classification/" + Definitions.campaignRoot + "/children", HttpMethod.GET, httpEntity, ClassificationList.class).getBody();
|
||||
for (Classification c : campaignYears.items) {
|
||||
log.info(c.name + ", " + c.labels[0].value + ", " + c.id);
|
||||
for (Classification yearClassification : campaignYears.items) {
|
||||
ClassificationList campaignClassifications = restTemplate.exchange(adamHost + "/classification/" + yearClassification.id + "/children", HttpMethod.GET, httpEntity, ClassificationList.class).getBody();
|
||||
for (Classification campaignClassification : campaignClassifications.items) {
|
||||
log.debug(yearClassification.name + ": " + campaignClassification.name + ", " + campaignClassification.labels[0].value + ", " + campaignClassification.id);
|
||||
Campaign campaign = new Campaign(campaignClassification.name, campaignClassification.labels[0].value, yearClassification.name);
|
||||
campaign.guid = campaignClassification.id;
|
||||
campaigns.add(campaign);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
invalidateAdamToken();
|
||||
System.exit(1);
|
||||
|
||||
// TODO HIER GEHT'S WEITER - die vorhandenen Campaigns per REST aufrufen und in campaigns speichern
|
||||
|
||||
|
||||
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
|
||||
for (int id : selection) {
|
||||
log.info("GET entry " + id);
|
||||
@@ -211,9 +208,9 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
// check whether campain already exists
|
||||
String campaignGuid = null;
|
||||
for (String[] line : campaigns) {
|
||||
if (line[0].equals(campaignName)) {
|
||||
campaignGuid = line[2];
|
||||
for (Campaign c : campaigns) {
|
||||
if (c.name.equals(campaignName)) {
|
||||
campaignGuid = c.guid;
|
||||
log.debug("Found already existing campaign '" + campaignName + "' with guid " + campaignGuid);
|
||||
}
|
||||
}
|
||||
@@ -226,13 +223,12 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
HttpEntity<Campaign> httpEntity = new HttpEntity<Campaign>(campaign, adamHeaders);
|
||||
try {
|
||||
EntityId campaignId = restTemplate.exchange(adamHost + "/classifications", HttpMethod.POST, httpEntity, EntityId.class).getBody();
|
||||
campaignGuid = campaignId.id;
|
||||
campaign.guid = campaignId.id;
|
||||
|
||||
log.info("Created campaign: " + campaignName + ";" + campaignLabel + ";" + campaignGuid);
|
||||
record.addClassification(new WriteClassification(campaignGuid, 1));
|
||||
log.info("Created campaign: " + campaignName + ";" + campaignLabel + ";" + campaign.guid);
|
||||
record.addClassification(new WriteClassification(campaign.guid, 1));
|
||||
|
||||
// TODO better write campaign to file right away?
|
||||
campaigns.add(new String[] { campaignName, campaignLabel, campaignGuid });
|
||||
campaigns.add(campaign);
|
||||
|
||||
} catch (HttpStatusCodeException hsce) {
|
||||
log.error("Could not create campaign '" + campaignName + "' for entry " + entry.id + ": " + hsce.getStatusCode().toString());
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import com.bayer.edam.migration.adam.WriteRecord.Field;
|
||||
import com.bayer.edam.migration.adam.WriteRecord.Fields;
|
||||
import com.bayer.edam.migration.adam.WriteRecord.LocalizedValue;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
public class Campaign {
|
||||
|
||||
@@ -17,6 +18,9 @@ public class Campaign {
|
||||
public Integer sortIndex = 1;
|
||||
public LocalizedValue[] labels;
|
||||
|
||||
@JsonIgnore
|
||||
public String guid;
|
||||
|
||||
public Fields fields = new Fields();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user