creating year classifications, pt. 1
This commit is contained in:
@@ -35,8 +35,9 @@ import com.bayer.edam.migration.adam.Classification;
|
||||
import com.bayer.edam.migration.adam.ClassificationList;
|
||||
import com.bayer.edam.migration.adam.EntityId;
|
||||
import com.bayer.edam.migration.adam.Token;
|
||||
import com.bayer.edam.migration.adam.WriteRecord;
|
||||
import com.bayer.edam.migration.adam.WriteRecord.WriteClassification;
|
||||
import com.bayer.edam.migration.adam.UploadClassification;
|
||||
import com.bayer.edam.migration.adam.UploadRecord;
|
||||
import com.bayer.edam.migration.adam.UploadRecord.WriteClassification;
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
import com.bayer.edam.migration.mam.categories.CategoryTree;
|
||||
import com.bayer.edam.migration.mam.categories.CategoryTree.Node;
|
||||
@@ -76,6 +77,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
private SimpleDateFormat stringDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private ObjectMapper jsonMapper = new ObjectMapper();
|
||||
|
||||
private List<Classification> campaignYears;
|
||||
private List<Campaign> campaigns = new LinkedList<Campaign>();
|
||||
|
||||
private List<String> locations = new ArrayList<String>();
|
||||
@@ -102,18 +104,17 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
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 yearClassification : campaignYears.items) {
|
||||
ClassificationList campaignClassifications = restTemplate.exchange(adamHost + "/classification/" + yearClassification.id + "/children", HttpMethod.GET, httpEntity, ClassificationList.class).getBody();
|
||||
for (Classification campaignClassification : campaignClassifications.items) {
|
||||
campaignYears = restTemplate.exchange(adamHost + "/classification/" + Definitions.campaignRoot + "/children", HttpMethod.GET, httpEntity, 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;
|
||||
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);
|
||||
for (int id : selection) {
|
||||
@@ -149,7 +150,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
}
|
||||
|
||||
void postToAdam(Entry entry) throws Exception {
|
||||
WriteRecord record = new WriteRecord();
|
||||
UploadRecord record = new UploadRecord();
|
||||
String entryJson = jsonMapper.writeValueAsString(entry);
|
||||
|
||||
// globally applicable classifications
|
||||
@@ -206,6 +207,25 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
try {
|
||||
Integer.parseInt(campaignYear);
|
||||
|
||||
// check whether the year classification already exists
|
||||
Classification yearClassification = null;
|
||||
for (Classification c : campaignYears) {
|
||||
if (c.name.equals(campaignYear)) {
|
||||
yearClassification = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (yearClassification == null) {
|
||||
log.info("Create campaign year " + campaignYear);
|
||||
|
||||
UploadClassification newYear = new UploadClassification(campaignYear, campaignYear);
|
||||
|
||||
|
||||
// TODO HIER GEHT'S WEITER
|
||||
|
||||
// (s. Z. 243 ff)
|
||||
}
|
||||
|
||||
// check whether campain already exists
|
||||
String campaignGuid = null;
|
||||
for (Campaign c : campaigns) {
|
||||
@@ -216,7 +236,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
}
|
||||
|
||||
if (campaignGuid == null) {
|
||||
log.info("Create campaign " + campaignName);
|
||||
log.info("Create campaign " + campaignYear + "/" + campaignName);
|
||||
|
||||
Campaign campaign = new Campaign(campaignName, campaignLabel, campaignYear);
|
||||
|
||||
@@ -298,9 +318,9 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
|
||||
// Create record
|
||||
HttpEntity<WriteRecord> httpEntity = new HttpEntity<WriteRecord>(record, adamHeaders);
|
||||
HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
|
||||
try {
|
||||
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, WriteRecord.class);
|
||||
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, UploadRecord.class);
|
||||
log.info("Created " + location);
|
||||
|
||||
FileUtils.writeStringToFile(entryLog, location.toString() + fieldSeparator + entryJson + lineSeparator,
|
||||
|
||||
Reference in New Issue
Block a user