adam side
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
2017-09-13 14:48:27.958 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Starting MamMigrationSelective on BY0JGS with PID 11112 (started by gezvf in C:\Users\gezvf\git\mam-migration\AH MAM Migration)
|
||||
2017-09-13 14:48:27.968 DEBUG 11112 --- [main] c.b.e.migration.MamMigrationSelective : Running with Spring Boot v1.5.6.RELEASE, Spring v4.3.10.RELEASE
|
||||
2017-09-13 14:48:27.968 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : No active profile set, falling back to default profiles: default
|
||||
2017-09-13 14:48:28.019 INFO 11112 --- [main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@74294adb: startup date [Wed Sep 13 14:48:28 CEST 2017]; root of context hierarchy
|
||||
2017-09-13 14:48:29.399 INFO 11112 --- [main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
|
||||
2017-09-13 14:48:30.362 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 71048
|
||||
2017-09-13 14:48:30.552 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70778
|
||||
2017-09-13 14:48:30.763 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70746
|
||||
2017-09-13 14:48:33.553 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70142
|
||||
2017-09-13 14:48:33.754 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70361
|
||||
2017-09-13 14:48:33.963 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 63924
|
||||
2017-09-13 14:48:34.153 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 71263
|
||||
2017-09-13 14:48:35.073 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 63201
|
||||
2017-09-13 14:48:35.984 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 56942
|
||||
2017-09-13 14:48:36.834 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 57641
|
||||
2017-09-13 14:48:37.365 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70745
|
||||
2017-09-13 14:48:37.905 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70440
|
||||
2017-09-13 14:48:38.436 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70340
|
||||
2017-09-13 14:48:38.656 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 70288
|
||||
2017-09-13 14:48:38.836 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Migrating entry 71725
|
||||
2017-09-13 14:48:38.836 INFO 11112 --- [main] c.b.e.migration.MamMigrationSelective : Started MamMigrationSelective in 11.24 seconds (JVM running for 11.664)
|
||||
2017-09-13 14:48:38.846 INFO 11112 --- [Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@74294adb: startup date [Wed Sep 13 14:48:28 CEST 2017]; root of context hierarchy
|
||||
2017-09-13 14:48:38.846 INFO 11112 --- [Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
|
||||
@@ -25,8 +25,12 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.hateoas</groupId>
|
||||
<artifactId>spring-hateoas</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
|
||||
logging.level.com.bayer=DEBUG
|
||||
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level- %msg%n
|
||||
logging.file=migration.log
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
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.MediaType;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource("file:secret.properties")
|
||||
public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
|
||||
|
||||
@Value("${mam.auth}")
|
||||
private String mamAuth;
|
||||
|
||||
static int[] selection = {71048,70778,70746/*,70142,70361,63924,71263,63201,56942,57641,70745,70440,70340,70288,71725*/};
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.add("Authorization", "Basic " + mamAuth);
|
||||
headers.add("From", "migration@bayer.com");
|
||||
headers.add("Content-Type", "application/json");
|
||||
HttpEntity<String> entity = new HttpEntity<String>("Parameters", headers);
|
||||
|
||||
for (int id : selection) {
|
||||
Entry entry = restTemplate
|
||||
.exchange("https://service.media-assistant.animalhealth.bayer.com/rest/migration/entry/{id}",
|
||||
HttpMethod.GET, entity, Entry.class, id)
|
||||
.getBody();
|
||||
migrate(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void migrate(Entry entry) {
|
||||
log.info("Migrating entry " + entry.id);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
SpringApplication.run(MamMigrationSelective.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.bayer.edam.migration;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
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;
|
||||
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
|
||||
@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", "XXXXXXXXXX");
|
||||
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());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,12 +3,12 @@ package com.bayer.edam.migration;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
|
||||
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;
|
||||
@@ -16,10 +16,10 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.adam.ReadRecord;
|
||||
import com.bayer.edam.migration.adam.Token;
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MediaAssistantMigrationSimple {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MediaAssistantMigrationSimple.class);
|
||||
@@ -46,14 +46,29 @@ public class MediaAssistantMigrationSimple {
|
||||
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.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/28cadf7f5a504a1f9ef5a76300df3681", HttpMethod.GET, entity, String.class);
|
||||
log.info(r1.toString());
|
||||
|
||||
ResponseEntity<String> r1 = restTemplate.exchange("https://edam-q.bayer.com:2015/record/f46147866c6f49f690ffa7900097b861", 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> newRecord = new HttpEntity<String>("{\"contentType\": \"Record\"}", headers);
|
||||
URI location = restTemplate.postForLocation("https://edam-q.bayer.com:2015/records", newRecord);
|
||||
log.info("Location: " + location);
|
||||
|
||||
// log.info("Entity: " + entity.getBody());
|
||||
|
||||
// ResponseEntity<String> r3 = restTemplate.exchange("https://edam-q.bayer.com:2015/records", HttpMethod.POST, newRecord)
|
||||
|
||||
|
||||
|
||||
headers = new HttpHeaders();
|
||||
headers.add("Registration", "ADAMBAYER");
|
||||
@@ -69,8 +84,8 @@ public class MediaAssistantMigrationSimple {
|
||||
headers.add("From", "migration@bayer.com");
|
||||
headers.add("Content-Type", "application/json");
|
||||
entity = new HttpEntity<String>("Parameters", headers);
|
||||
ResponseEntity<Entry> r2 = restTemplate.exchange("https://service.media-assistant.animalhealth.bayer.com/rest/migration/entry/71948", HttpMethod.GET, entity, Entry.class);
|
||||
log.info(r2.toString());
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.bayer.edam.migration.adam;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ReadRecord {
|
||||
|
||||
public String id;
|
||||
public String contentType;
|
||||
public Date modifiedOn;
|
||||
public Date createdOn;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Record{" + "id=" + id + " contentType=" + contentType + ", modifiedOn=" + modifiedOn + ", createdOn=" + createdOn + "}";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.bayer.edam.migration.adam;
|
||||
|
||||
public class Record {
|
||||
|
||||
String id;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entry{" + "id=" + id + '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.bayer.edam.migration.adam;
|
||||
|
||||
public class WriteRecord {
|
||||
|
||||
|
||||
public static class Classification {
|
||||
public String id;
|
||||
public Integer sortIndex;
|
||||
|
||||
public Classification() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Classifications {
|
||||
public Classification[] addOrUpdate;
|
||||
|
||||
public Classifications() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Field {
|
||||
public String id;
|
||||
|
||||
public Field() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Fields {
|
||||
public Field[] addOrUpdate;
|
||||
|
||||
public Fields() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String contentType = "Record";
|
||||
public Classifications classifications;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.bayer.edam.migration.mam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Category {
|
||||
|
||||
public Long id;
|
||||
public Integer parent;
|
||||
public Map<String, String> name;
|
||||
|
||||
public Category() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,11 +6,11 @@ import java.util.Map;
|
||||
|
||||
public class Entry {
|
||||
|
||||
public static class MediaType {
|
||||
public static class Type {
|
||||
public Long id;
|
||||
public Map<String, String> name;
|
||||
|
||||
public MediaType() {
|
||||
public Type() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,15 +98,15 @@ public class Entry {
|
||||
public Map<String, String> comment;
|
||||
public Map<String, String> user;
|
||||
public Map<String, String> uploader;
|
||||
public String indexer;
|
||||
public Map<String, String> indexer;
|
||||
public Double ratingValue;
|
||||
public Map<String, String> release;
|
||||
public String brandingNet;
|
||||
public MediaType mediaType;
|
||||
public Type mediaType;
|
||||
public Copyright copyright;
|
||||
public String master;
|
||||
public Map<String, String> project;
|
||||
public String imageType;
|
||||
public Type imageType;
|
||||
// public String gpc;
|
||||
public String mediaAssistantId;
|
||||
public Map<String, String> metaData;
|
||||
@@ -121,8 +121,8 @@ public class Entry {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entry{" + "id=" + id + ", fileName=" + fileName + ", creationDate=" + creationDate + ", name="
|
||||
+ name.get("en") + ", user=" + user.get("id") + ", copyright.organization.id=" + copyright.organization.get("id") + '}';
|
||||
return "Entry{" + "id=" + id + ", name=" + name.get("en") + ", creationDate=" + creationDate + ", user="
|
||||
+ user.get("id") + ", copyright.organization.id=" + copyright.organization.get("id") + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.bayer.edam.migration.mam;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class EntrySimple {
|
||||
|
||||
public Long id;
|
||||
public String href;
|
||||
public Long fileSize;
|
||||
public String fileName;
|
||||
public Date creationDate;
|
||||
public Date uploadDate;
|
||||
public Map<String, String> name;
|
||||
public Map<String, String> keyword;
|
||||
public Map<String, String> description;
|
||||
public Map<String, String> comment;
|
||||
public Map<String, String> user;
|
||||
public Map<String, String> uploader;
|
||||
public Map<String, String> indexer;
|
||||
// public Double ratingValue;
|
||||
// public Map<String, String> release;
|
||||
// public String brandingNet;
|
||||
|
||||
public EntrySimple() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entry{" + "id=" + id + ", href=" + href + '}';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootApplication
|
||||
//@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Application.class);
|
||||
@@ -19,12 +19,12 @@ public class Application {
|
||||
SpringApplication.run(Application.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
// @Bean
|
||||
public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
// @Bean
|
||||
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
|
||||
return args -> {
|
||||
Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package hello;
|
||||
|
||||
public class Customer {
|
||||
private long id;
|
||||
private String firstName, lastName;
|
||||
|
||||
public Customer(long id, String firstName, String lastName) {
|
||||
this.id = id;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Customer[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName);
|
||||
}
|
||||
|
||||
// getters & setters omitted for brevity
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package hello;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DatabaseApplication implements CommandLineRunner {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DatabaseApplication.class);
|
||||
|
||||
public static void main(String args[]) {
|
||||
SpringApplication.run(DatabaseApplication.class, args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
|
||||
log.info("Creating tables");
|
||||
|
||||
jdbcTemplate.execute("DROP TABLE customers IF EXISTS");
|
||||
jdbcTemplate.execute("CREATE TABLE customers(" +
|
||||
"id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))");
|
||||
|
||||
// Split up the array of whole names into an array of first/last names
|
||||
List<Object[]> splitUpNames = Arrays.asList("John Woo", "Jeff Dean", "Josh Bloch", "Josh Long").stream()
|
||||
.map(name -> name.split(" "))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Use a Java 8 stream to print out each tuple of the list
|
||||
splitUpNames.forEach(name -> log.info(String.format("Inserting customer record for %s %s", name[0], name[1])));
|
||||
|
||||
// Uses JdbcTemplate's batchUpdate operation to bulk load data
|
||||
jdbcTemplate.batchUpdate("INSERT INTO customers(first_name, last_name) VALUES (?,?)", splitUpNames);
|
||||
|
||||
log.info("Querying for customer records where first_name = 'Josh':");
|
||||
jdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name FROM customers WHERE first_name = ?", new Object[] { "Josh" },
|
||||
(rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name"))
|
||||
).forEach(customer -> log.info(customer.toString()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user