creating campaigns including campaign years

This commit is contained in:
gexce
2017-10-25 11:17:39 +02:00
parent 47c90fdad4
commit fae7943dc6
@@ -73,7 +73,7 @@ public class MamMigrationSelective implements CommandLineRunner {
HttpHeaders adamHeaders, mamHeaders; HttpHeaders adamHeaders, mamHeaders;
HttpEntity<String> adamHeadersEntity; 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 SimpleDateFormat stringDate = new SimpleDateFormat("yyyy-MM-dd");
private ObjectMapper jsonMapper = new ObjectMapper(); private ObjectMapper jsonMapper = new ObjectMapper();
@@ -103,17 +103,15 @@ public class MamMigrationSelective implements CommandLineRunner {
mamHeaders = createMamHeaders(); mamHeaders = createMamHeaders();
log.info("Read campaigns"); log.info("Read campaigns");
HttpEntity<String> httpEntity = new HttpEntity<String>("parameters", adamHeaders); campaignYears = restTemplate.exchange(adamHost + "/classification/" + Definitions.campaignRoot + "/children", HttpMethod.GET, adamHeadersEntity, ClassificationList.class).getBody().items;
campaignYears = restTemplate.exchange(adamHost + "/classification/" + Definitions.campaignRoot + "/children", HttpMethod.GET, httpEntity, ClassificationList.class).getBody().items;
for (Classification yearClassification : campaignYears) { 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) { for (Classification campaignClassification : campaignClassifications) {
log.debug(yearClassification.name + ": " + campaignClassification.name + ", " + campaignClassification.labels[0].value + ", " + campaignClassification.id); 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 campaign = new Campaign(campaignClassification.name, campaignClassification.labels[0].value, yearClassification.name);
campaign.guid = campaignClassification.id; campaign.guid = campaignClassification.id;
campaigns.add(campaign); campaigns.add(campaign);
} }
} }
HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders); HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
@@ -220,18 +218,30 @@ public class MamMigrationSelective implements CommandLineRunner {
UploadClassification newYear = new UploadClassification(campaignYear, campaignYear); 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;
// TODO HIER GEHT'S WEITER 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());
}
// (s. Z. 243 ff)
} }
// check whether campain already exists // check whether campaign already exists
String campaignGuid = null; String campaignGuid = null;
for (Campaign c : campaigns) { for (Campaign c : campaigns) {
if (c.name.equals(campaignName)) { if (c.name.equals(campaignName)) {
campaignGuid = c.guid;
log.debug("Found already existing campaign '" + campaignName + "' with guid " + campaignGuid); log.debug("Found already existing campaign '" + campaignName + "' with guid " + campaignGuid);
campaignGuid = c.guid;
record.addClassification(new WriteClassification(campaignGuid, 1));
} }
} }
@@ -335,15 +345,6 @@ public class MamMigrationSelective implements CommandLineRunner {
} }
} }
/**
* 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() { private HttpHeaders createMamHeaders() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json"); headers.add("Accept", "application/json");