Definitions for QA and PROD

This commit is contained in:
gexce
2017-11-02 13:41:09 +01:00
parent 1585c9e29a
commit 5b2b5c7a83
2 changed files with 191 additions and 27 deletions
@@ -56,7 +56,6 @@ public class MamMigrationSelective implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
static final String adamHost = "https://edam-q.bayer.com:2015";
static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com";
private List<Integer> entrySelection = new ArrayList<Integer>(Arrays.asList( 48147 /* 58443/*, 53787, 32427, 71725, 63080*/ )); // 72048, 60984
@@ -112,9 +111,9 @@ public class MamMigrationSelective implements CommandLineRunner {
mamHeaders = createMamHeaders();
log.info("Read campaigns");
campaignYears = restTemplate.exchange(adamHost + "/classification/" + Definitions.campaignRoot + "/children", HttpMethod.GET, adamHeadersEntity, ClassificationList.class).getBody().items;
campaignYears = restTemplate.exchange(Definitions.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, adamHeadersEntity, ClassificationList.class).getBody().items;
List<Classification> campaignClassifications = restTemplate.exchange(Definitions.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);
@@ -288,11 +287,11 @@ public class MamMigrationSelective implements CommandLineRunner {
HttpEntity<UploadClassification> httpEntity = new HttpEntity<UploadClassification>(newYear, adamHeaders);
try {
EntityId classificationId = restTemplate.exchange(adamHost + "/classifications", HttpMethod.POST, httpEntity, EntityId.class).getBody();
EntityId classificationId = restTemplate.exchange(Definitions.adamHost + "/classifications", HttpMethod.POST, httpEntity, EntityId.class).getBody();
newYear.guid = classificationId.id;
// retrieve the newly created classification back
yearClassification = restTemplate.exchange(adamHost + "/classification/" + newYear.guid, HttpMethod.GET, adamHeadersEntity, Classification.class).getBody();
yearClassification = restTemplate.exchange(Definitions.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());
@@ -318,7 +317,7 @@ 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();
EntityId campaignId = restTemplate.exchange(Definitions.adamHost + "/classifications", HttpMethod.POST, httpEntity, EntityId.class).getBody();
campaign.guid = campaignId.id;
record.addClassification(new WriteClassification(campaign.guid, 1));
campaigns.add(campaign);
@@ -438,7 +437,7 @@ public class MamMigrationSelective implements CommandLineRunner {
HttpEntity<UploadRecord> httpEntity = new HttpEntity<UploadRecord>(record, adamHeaders);
try {
// URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, UploadRecord.class);
// URI location = restTemplate.postForLocation(Definitions.adamHost + "/records", httpEntity, UploadRecord.class);
// log.info("RESULT Entry " + entry.id + " migrated to record " + location);
// XXX
@@ -512,10 +511,10 @@ public class MamMigrationSelective implements CommandLineRunner {
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
parameters.add("file", new FileSystemResource(uploadFile));
String result = restTemplate.postForObject(adamHost + "/uploads",
String result = restTemplate.postForObject(Definitions.adamHost + "/uploads",
new HttpEntity<MultiValueMap<String, Object>>(parameters, adamUploadHeaders), String.class);
// String answer = restTemplate.exchange(adamHost + "/uploads", HttpMethod.POST,
// String answer = restTemplate.exchange(Definitions.adamHost + "/uploads", HttpMethod.POST,
// new HttpEntity<MultiValueMap<String, Object>>(parameters, adamUploadHeaders), String.class).getBody();
log.info("Upload result: " + result);
@@ -565,7 +564,7 @@ public class MamMigrationSelective implements CommandLineRunner {
headers.add("Authorization", "Basic " + adamAuth);
headers.add("set-immediateSearchIndexUpdate", "true"); // see https://edam.bayer.com:2015/docs/resources/record#example-records-direct-push
HttpEntity<String> entity = new HttpEntity<String>("", headers);
Token token = restTemplate.exchange(adamHost + "/auth", HttpMethod.GET, entity, Token.class).getBody();
Token token = restTemplate.exchange(Definitions.adamHost + "/auth", HttpMethod.GET, entity, Token.class).getBody();
// replace auth header
headers.remove("Authorization");
@@ -578,7 +577,7 @@ public class MamMigrationSelective implements CommandLineRunner {
}
private void invalidateAdamToken() {
ResponseEntity<String> response = restTemplate.exchange(adamHost + "/auth", HttpMethod.DELETE, adamHeadersEntity, String.class);
ResponseEntity<String> response = restTemplate.exchange(Definitions.adamHost + "/auth", HttpMethod.DELETE, adamHeadersEntity, String.class);
log.info("Logged out from adam API: " + response.toString());
}