adam CRUD

This commit is contained in:
gezvf
2017-09-14 14:01:59 +02:00
parent fbbdbdb779
commit e982628d75
2 changed files with 12 additions and 5 deletions
+1
View File
@@ -1,3 +1,4 @@
/bin/
/target/
/secret.properties
/migration.log
@@ -18,6 +18,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
@@ -31,16 +32,19 @@ public class MamMigrationSelective implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
static String adamHost = "https://edam-q.bayer.com:2015";
static int[] selection = { 71048, /* 70778, 70746 ,70142,70361,63924,71263,63201,56942,57641,70745,70440,70340,70288,71725 */ };
@Value("${mam.auth}")
private String mamAuth;
@Value("${adam.auth}")
private String adamAuth;
static int[] selection = { 71048, /* 70778, 70746 ,70142,70361,63924,71263,63201,56942,57641,70745,70440,70340,70288,71725 */ };
RestTemplate restTemplate;
HttpHeaders adamHeaders, mamHeaders;
HttpEntity<String> adamHeadersEntity;
@Override
public void run(String... strings) throws Exception {
@@ -51,6 +55,7 @@ public class MamMigrationSelective implements CommandLineRunner {
restTemplate.setInterceptors(interceptors);
adamHeaders = createAdamHeaders();
adamHeadersEntity = new HttpEntity<String>("", adamHeaders);
mamHeaders = createMamHeaders();
HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
@@ -66,9 +71,7 @@ public class MamMigrationSelective implements CommandLineRunner {
}
void invalidateAdamToken() {
HttpEntity<String> entity = new HttpEntity<String>("", adamHeaders);
ResponseEntity<String> response = restTemplate.exchange("https://edam-q.bayer.com:2015/auth", HttpMethod.DELETE,
entity, String.class);
ResponseEntity<String> response = restTemplate.exchange(adamHost + "/auth", HttpMethod.DELETE, adamHeadersEntity, String.class);
log.info("Logged out from adam API: " + response.toString());
}
@@ -79,8 +82,11 @@ public class MamMigrationSelective implements CommandLineRunner {
HttpEntity<WriteRecord> httpEntity = new HttpEntity<WriteRecord>(newRecord, adamHeaders);
try {
URI location = restTemplate.postForLocation("https://edam-q.bayer.com:2015/records", httpEntity, WriteRecord.class);
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, WriteRecord.class);
log.info("Location: " + location);
ResponseEntity<String> response = restTemplate.exchange(adamHost + location, HttpMethod.DELETE, adamHeadersEntity, String.class);
log.info("Deleted record: " + response.toString());
}
catch (HttpClientErrorException hcee) {
log.error(hcee.getStatusCode().toString());