default values and forced indexing
This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
package com.bayer.edam.migration.attic;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
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.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.LoggingRequestInterceptor;
|
||||
import com.bayer.edam.migration.adam.ReadRecord;
|
||||
import com.bayer.edam.migration.adam.Token;
|
||||
import com.bayer.edam.migration.adam.WriteRecord;
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
|
||||
public class MediaAssistantMigrationSimple {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MediaAssistantMigrationSimple.class);
|
||||
|
||||
public MediaAssistantMigrationSimple() {
|
||||
Properties prop = new Properties();
|
||||
InputStream input = null;
|
||||
try {
|
||||
input = new FileInputStream("secret.properties");
|
||||
prop.load(input);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
|
||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
|
||||
interceptors.add(new LoggingRequestInterceptor());
|
||||
restTemplate.setInterceptors(interceptors);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Registration", "ADAMBAYER");
|
||||
headers.add("API-VERSION", "1");
|
||||
headers.add("Authorization", "Basic " + prop.getProperty("adam.auth"));
|
||||
HttpEntity<String> entity = new HttpEntity<String>("Parameters", headers);
|
||||
Token token = restTemplate.exchange("https://edam-q.bayer.com:2015/auth", HttpMethod.GET, entity, Token.class).getBody();
|
||||
|
||||
headers = new HttpHeaders();
|
||||
// headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.add("Accept", "application/hal+json");
|
||||
headers.add("Registration", "ADAMBAYER");
|
||||
headers.add("API-VERSION", "1");
|
||||
headers.add("Authorization", "Token " + token.getToken());
|
||||
headers.add("Content-Type", "application/json");
|
||||
entity = new HttpEntity<String>("Parameters", headers);
|
||||
|
||||
ResponseEntity<String> r1 = restTemplate.exchange("https://edam-q.bayer.com:2015/record/f5bccf48-6695-4255-8d70-a7e5008e1720", HttpMethod.GET, entity, String.class);
|
||||
log.info(r1.getBody().toString());
|
||||
r1 = restTemplate.exchange("https://edam-q.bayer.com:2015/record/f5bccf48-6695-4255-8d70-a7e5008e1720/fields", HttpMethod.GET, entity, String.class);
|
||||
log.info(r1.getBody().toString());
|
||||
r1 = restTemplate.exchange("https://edam-q.bayer.com:2015/record/f5bccf48-6695-4255-8d70-a7e5008e1720/classifications", HttpMethod.GET, entity, String.class);
|
||||
log.info(r1.getBody().toString());
|
||||
|
||||
ResponseEntity<ReadRecord> r2 = restTemplate.exchange("https://edam-q.bayer.com:2015/record/f46147866c6f49f690ffa7900097b861", HttpMethod.GET, entity, ReadRecord.class);
|
||||
log.info(r2.getBody().toString());
|
||||
|
||||
HttpEntity<String> newRecordString = new HttpEntity<String>("{'contentType': 'Record'}", headers);
|
||||
|
||||
try {
|
||||
URI location = restTemplate.postForLocation("https://edam-q.bayer.com:2015/records", newRecordString);
|
||||
log.info("Location: " + location);
|
||||
}
|
||||
catch (HttpClientErrorException hcee) {
|
||||
log.error(hcee.getStatusCode().toString());
|
||||
log.error(hcee.getResponseBodyAsString());
|
||||
}
|
||||
|
||||
HttpEntity<WriteRecord> newRecord = new HttpEntity<WriteRecord>(new WriteRecord(), headers);
|
||||
|
||||
try {
|
||||
URI location = restTemplate.postForLocation("https://edam-q.bayer.com:2015/records", newRecord, WriteRecord.class);
|
||||
log.info("Location: " + location);
|
||||
}
|
||||
catch (HttpClientErrorException hcee) {
|
||||
log.error(hcee.getStatusCode().toString());
|
||||
log.error(hcee.getResponseBodyAsString());
|
||||
}
|
||||
|
||||
// ResponseEntity<String> r3 = restTemplate.exchange("https://edam-q.bayer.com:2015/records", HttpMethod.POST, newRecord, String.class);
|
||||
// log.info(r3.getBody());
|
||||
|
||||
|
||||
headers = new HttpHeaders();
|
||||
headers.add("Registration", "ADAMBAYER");
|
||||
headers.add("API-VERSION", "1");
|
||||
headers.add("Authorization", "Token " + token.getToken());
|
||||
entity = new HttpEntity<String>("Parameters", headers);
|
||||
ResponseEntity<String> rz = restTemplate.exchange("https://edam-q.bayer.com:2015/auth", HttpMethod.DELETE, entity, String.class);
|
||||
log.info(rz.toString());
|
||||
|
||||
headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.add("Authorization", "Basic " + prop.getProperty("mam.auth"));
|
||||
headers.add("From", "migration@bayer.com");
|
||||
headers.add("Content-Type", "application/json");
|
||||
entity = new HttpEntity<String>("", headers);
|
||||
ResponseEntity<Entry> m1 = restTemplate.exchange("https://service.media-assistant.animalhealth.bayer.com/rest/migration/entry/71948", HttpMethod.GET, entity, Entry.class);
|
||||
log.info(m1.toString());
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
new MediaAssistantMigrationSimple();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.bayer.edam.migration.attic;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.MamMigrationSelective;
|
||||
import com.bayer.edam.migration.adam.Token;
|
||||
|
||||
//@SpringBootApplication
|
||||
@PropertySource("file:secret.properties")
|
||||
public class ShowRecord implements CommandLineRunner {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
|
||||
|
||||
static String adamHost = "https://edam-q.bayer.com:2015";
|
||||
|
||||
@Value("${adam.auth}")
|
||||
private String adamAuth;
|
||||
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
restTemplate = new RestTemplate();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Registration", "ADAMBAYER");
|
||||
headers.add("API-VERSION", "1");
|
||||
headers.add("Accept", "application/hal+json");
|
||||
headers.add("Content-Type", "application/json");
|
||||
headers.add("Authorization", "Basic " + adamAuth);
|
||||
HttpEntity<String> headersEntity = new HttpEntity<String>("", headers);
|
||||
Token token = restTemplate.exchange(adamHost + "/auth", HttpMethod.GET, headersEntity, Token.class).getBody();
|
||||
|
||||
// replace auth header
|
||||
headers.remove("Authorization");
|
||||
headers.add("Authorization", "Token " + token.getToken());
|
||||
|
||||
// replace accept-charset header (in order to declutter log)
|
||||
headers.add("Accept-Charset", "us-ascii, utf-16, utf-8");
|
||||
|
||||
headersEntity = new HttpEntity<String>("", headers);
|
||||
|
||||
|
||||
|
||||
ResponseEntity<String> r1 = restTemplate.exchange(
|
||||
"https://edam-q.bayer.com:2015/record/f5bccf48-6695-4255-8d70-a7e5008e1720", HttpMethod.GET,
|
||||
headersEntity, String.class);
|
||||
log.info(r1.getBody());
|
||||
r1 = restTemplate.exchange("https://edam-q.bayer.com:2015/record/f5bccf48-6695-4255-8d70-a7e5008e1720/fields",
|
||||
HttpMethod.GET, headersEntity, String.class);
|
||||
log.info(r1.getBody());
|
||||
r1 = restTemplate.exchange(
|
||||
"https://edam-q.bayer.com:2015/record/f5bccf48-6695-4255-8d70-a7e5008e1720/classifications",
|
||||
HttpMethod.GET, headersEntity, String.class);
|
||||
log.info(r1.getBody());
|
||||
|
||||
|
||||
// logout
|
||||
ResponseEntity<String> response = restTemplate.exchange(adamHost + "/auth", HttpMethod.DELETE, headersEntity,
|
||||
String.class);
|
||||
log.info("Logged out from adam API: " + response.toString());
|
||||
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
SpringApplication.run(ShowRecord.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user