creating campaigns including campaign years
This commit is contained in:
@@ -73,7 +73,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
HttpHeaders adamHeaders, mamHeaders;
|
||||
HttpEntity<String> adamHeadersEntity;
|
||||
|
||||
private SimpleDateFormat isoDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
|
||||
// private SimpleDateFormat isoDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
|
||||
private SimpleDateFormat stringDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private ObjectMapper jsonMapper = new ObjectMapper();
|
||||
|
||||
@@ -103,17 +103,15 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
mamHeaders = createMamHeaders();
|
||||
|
||||
log.info("Read campaigns");
|
||||
HttpEntity<String> httpEntity = new HttpEntity<String>("parameters", adamHeaders);
|
||||
campaignYears = restTemplate.exchange(adamHost + "/classification/" + Definitions.campaignRoot + "/children", HttpMethod.GET, httpEntity, ClassificationList.class).getBody().items;
|
||||
campaignYears = restTemplate.exchange(adamHost + "/classification/" + Definitions.campaignRoot + "/children", HttpMethod.GET, adamHeadersEntity, ClassificationList.class).getBody().items;
|
||||
for (Classification yearClassification : campaignYears) {
|
||||
List<Classification> campaignClassifications = restTemplate.exchange(adamHost + "/classification/" + yearClassification.id + "/children", HttpMethod.GET, httpEntity, ClassificationList.class).getBody().items;
|
||||
List<Classification> campaignClassifications = restTemplate.exchange(adamHost + "/classification/" + yearClassification.id + "/children", HttpMethod.GET, adamHeadersEntity, ClassificationList.class).getBody().items;
|
||||
for (Classification campaignClassification : campaignClassifications) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
|
||||
@@ -220,18 +218,30 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
UploadClassification newYear = new UploadClassification(campaignYear, campaignYear);
|
||||
|
||||
HttpEntity<UploadClassification> httpEntity = new HttpEntity<UploadClassification>(newYear, adamHeaders);
|
||||
try {
|
||||
EntityId classificationId = restTemplate.exchange(adamHost + "/classifications", HttpMethod.POST, httpEntity, EntityId.class).getBody();
|
||||
newYear.guid = classificationId.id;
|
||||
|
||||
log.info("Created campaign year: " + campaignYear);
|
||||
|
||||
// retrieve the newly created classification back
|
||||
yearClassification = restTemplate.exchange(adamHost + "/classification/" + newYear.guid, HttpMethod.GET, adamHeadersEntity, Classification.class).getBody();
|
||||
campaignYears.add(yearClassification);
|
||||
} catch (HttpStatusCodeException hsce) {
|
||||
log.error("Could not create campaign year '" + campaignYear + "' for entry " + entry.id + ": " + hsce.getStatusCode().toString());
|
||||
log.error(hsce.getResponseBodyAsString());
|
||||
}
|
||||
|
||||
// TODO HIER GEHT'S WEITER
|
||||
|
||||
// (s. Z. 243 ff)
|
||||
}
|
||||
|
||||
// check whether campain already exists
|
||||
// check whether campaign already exists
|
||||
String campaignGuid = null;
|
||||
for (Campaign c : campaigns) {
|
||||
if (c.name.equals(campaignName)) {
|
||||
campaignGuid = c.guid;
|
||||
log.debug("Found already existing campaign '" + campaignName + "' with guid " + campaignGuid);
|
||||
campaignGuid = c.guid;
|
||||
record.addClassification(new WriteClassification(campaignGuid, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,15 +344,6 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
FileUtils.writeStringToFile(problemLog, entry.id + fieldSeparator + entryJson + lineSeparator, Charset.forName("utf-8"), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given campaign already exists and creates it, if not.
|
||||
*
|
||||
* @return the guid of the campaign
|
||||
*/
|
||||
private String getCampaign(int year, String label, String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private HttpHeaders createMamHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
Reference in New Issue
Block a user