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/ /bin/
/target/ /target/
/secret.properties /secret.properties
/migration.log
@@ -18,6 +18,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.http.client.BufferingClientHttpRequestFactory; import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@@ -31,16 +32,19 @@ public class MamMigrationSelective implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class); 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}") @Value("${mam.auth}")
private String mamAuth; private String mamAuth;
@Value("${adam.auth}") @Value("${adam.auth}")
private String adamAuth; private String adamAuth;
static int[] selection = { 71048, /* 70778, 70746 ,70142,70361,63924,71263,63201,56942,57641,70745,70440,70340,70288,71725 */ };
RestTemplate restTemplate; RestTemplate restTemplate;
HttpHeaders adamHeaders, mamHeaders; HttpHeaders adamHeaders, mamHeaders;
HttpEntity<String> adamHeadersEntity;
@Override @Override
public void run(String... strings) throws Exception { public void run(String... strings) throws Exception {
@@ -51,6 +55,7 @@ public class MamMigrationSelective implements CommandLineRunner {
restTemplate.setInterceptors(interceptors); restTemplate.setInterceptors(interceptors);
adamHeaders = createAdamHeaders(); adamHeaders = createAdamHeaders();
adamHeadersEntity = new HttpEntity<String>("", adamHeaders);
mamHeaders = createMamHeaders(); mamHeaders = createMamHeaders();
HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders); HttpEntity<String> entity = new HttpEntity<String>("", mamHeaders);
@@ -66,9 +71,7 @@ public class MamMigrationSelective implements CommandLineRunner {
} }
void invalidateAdamToken() { void invalidateAdamToken() {
HttpEntity<String> entity = new HttpEntity<String>("", adamHeaders); ResponseEntity<String> response = restTemplate.exchange(adamHost + "/auth", HttpMethod.DELETE, adamHeadersEntity, String.class);
ResponseEntity<String> response = restTemplate.exchange("https://edam-q.bayer.com:2015/auth", HttpMethod.DELETE,
entity, String.class);
log.info("Logged out from adam API: " + response.toString()); 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); HttpEntity<WriteRecord> httpEntity = new HttpEntity<WriteRecord>(newRecord, adamHeaders);
try { 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); 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) { catch (HttpClientErrorException hcee) {
log.error(hcee.getStatusCode().toString()); log.error(hcee.getStatusCode().toString());