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