log in, log out
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
/bin/
|
||||
/target/
|
||||
/secret.properties
|
||||
|
||||
@@ -27,21 +27,12 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.hateoas</groupId>
|
||||
<artifactId>spring-hateoas</artifactId>
|
||||
<version>0.23.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.client.Traverson;
|
||||
|
||||
public class Application {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
public static void main(String args[]) {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("user", 27);
|
||||
|
||||
Traverson traverson;
|
||||
try {
|
||||
traverson = new Traverson(new URI("http://localhost:8080/api/"), MediaTypes.HAL_JSON);
|
||||
String name = traverson.follow("movies", "movie", "actor").withTemplateParameters(parameters).toObject("$.name");
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
public class Entry {
|
||||
|
||||
private Long id;
|
||||
private String href;
|
||||
private Long fileSize;
|
||||
private String fileName;
|
||||
|
||||
public Entry() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public void setHref(String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
public Long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
public void setFileSize(Long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entry{" + "id=" + id + ", fileName=" + fileName + '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MediaAssistantMigration {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MediaAssistantMigration.class);
|
||||
|
||||
public static void main(String args[]) {
|
||||
SpringApplication.run(MediaAssistantMigration.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
builder.basicAuthorization("mam2adam", "B8LzciT.`12YxrJIZ72~X/V'");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
|
||||
return args -> {
|
||||
Entry entry = restTemplate.getForObject("https://qa.service.media-assistant.animalhealth.bayer.com/rest/migration/entry/204", Entry.class);
|
||||
log.info(entry.toString());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
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.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.adam.Token;
|
||||
|
||||
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();
|
||||
|
||||
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());
|
||||
entity = new HttpEntity<String>("Parameters", headers);
|
||||
ResponseEntity<String> r1 = restTemplate.exchange("https://edam-q.bayer.com:2015/record/28cadf7f5a504a1f9ef5a76300df3681", HttpMethod.GET, entity, String.class);
|
||||
log.info(r1.toString());
|
||||
|
||||
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>("Parameters", headers);
|
||||
ResponseEntity<Entry> r2 = restTemplate.exchange("https://qa.service.media-assistant.animalhealth.bayer.com/rest/migration/entry/204", HttpMethod.GET, entity, Entry.class);
|
||||
log.info(r2.getBody().toString());
|
||||
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
new MediaAssistantMigrationSimple();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.bayer.edam.migration.adam;
|
||||
|
||||
public class Record {
|
||||
|
||||
String id;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entry{" + "id=" + id + '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.bayer.edam.migration.adam;
|
||||
|
||||
public class Token {
|
||||
|
||||
private String message;
|
||||
private String token;
|
||||
|
||||
public Token() {
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Token{" + "message=" + message + ", token=" + token + '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,17 +2,34 @@ package hello;
|
||||
|
||||
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.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Application.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
public static void main(String args[]) {
|
||||
SpringApplication.run(Application.class);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
|
||||
restTemplate.
|
||||
log.info(quote.toString());
|
||||
}
|
||||
@Bean
|
||||
public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
|
||||
return args -> {
|
||||
Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
|
||||
log.info(quote.toString());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package hello;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class ApplicationSimple {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ApplicationSimple.class);
|
||||
|
||||
public static void main(String args[]) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
|
||||
log.info(quote.toString());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user