Skip to content

Commit

Permalink
feat(adapter) Create an adpater to use RestTemplate (#7)
Browse files Browse the repository at this point in the history
* feat(adapter) Create an adpater to use RestTemplate
---------

Co-authored-by: Arnaud THOREL<arnaud.thorel@ouest-france.fr>
  • Loading branch information
anthony-frage-ouest-france authored and arnaud-thorel-of committed Jan 17, 2024
1 parent 680a69c commit d3e0f47
Show file tree
Hide file tree
Showing 101 changed files with 1,345 additions and 245 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
/.idea
*.iml
.gitlab-ci.yml

**/target/
50 changes: 47 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ and provides class and annotation to improve your developer experience using Pos
Add the following dependency to your Maven project:

```xml

<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl-postgrest</artifactId>
Expand All @@ -51,7 +50,16 @@ implementing `PostgrestClient` interface.
You can also specify authenticators, interceptors (retry, transform) and every configuration (timeout, default headers,
cookies, ...) you need to deploy.

**Webclient configuration example**
#### WebClient configuration example

Add the dependency :
```xml
<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl-postgrest-webclient-adapter</artifactId>
<version>${querydsl-postgrest.version}</version>
</dependency>
```

```java
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -77,6 +85,42 @@ public class PostgrestConfiguration {
}
```

#### RestTemplate configuration example

Add the dependency :
```xml
<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl-postgrest-resttemplate-adapter</artifactId>
<version>${querydsl-postgrest.version}</version>
</dependency>
```

```java
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.ouestfrance.querydsl.postgrest.PostgrestClient;
import fr.ouestfrance.querydsl.postgrest.PostgrestRestTemplate;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;

@Configuration
public class PostgrestConfiguration {

@Bean
public PostgrestClient podstgrestClient() {
String serviceUrl = "http://localhost:9000";
RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(serviceUrl));
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault()));
return PostgrestRestTemplate.of(webclient);
}
}
```

### Create your first repository

#### Specify your first search criteria
Expand Down Expand Up @@ -334,4 +378,4 @@ The QueryDSL is licensed under [MIT License](https://opensource.org/license/mit/

[sonar-image]: https://sonarcloud.io/api/project_badges/measure?project=Ouest-France_querydsl-postgrest&metric=alert_status

[sonar-url]: https://sonarcloud.io/summary/new_code?id=Ouest-France_querydsl-postgrest
[sonar-url]: https://sonarcloud.io/summary/new_code?id=Ouest-France_querydsl-postgrest
62 changes: 10 additions & 52 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<modelVersion>4.0.0</modelVersion>

<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl-postgrest</artifactId>
<version>1.2.2-SNAPSHOT</version>
<name>querydsl-postgrest</name>
<artifactId>querydsl-postgrest-bom</artifactId>
<version>1.2.3-SNAPSHOT</version>
<packaging>pom</packaging>
<name>querydsl-postgrest-bom</name>
<description>Implementation of unified queryDSL for postgRest API</description>
<url>https://github.com/ouest-france/querydsl-postgrest</url>

Expand All @@ -23,6 +24,11 @@
<organizationUrl>https://www.ouest-france.fr/qui-sommes-nous</organizationUrl>
</developer>
</developers>
<modules>
<module>querydsl-postgrest</module>
<module>querydsl-postgrest-webclient-adapter</module>
<module>querydsl-postgrest-resttemplate-adapter</module>
</modules>


<properties>
Expand Down Expand Up @@ -50,34 +56,13 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
<version>6.1.1</version>
</dependency>
<!-- test dependencies -->

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -130,33 +115,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand Down Expand Up @@ -193,4 +151,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
104 changes: 104 additions & 0 deletions querydsl-postgrest-resttemplate-adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<div align="center" style="text-align:center;padding-top: 15px">
<img alt="logo-ouest-france" src="https://sipaui.sipaof.fr/downloads/logotheque/ouest-france-couleur.svg" height="100"/>
<h1 style="margin: 0;padding: 0">PostgRest-RestTemplate-Adapter</h1>
</div>
<div align="center" style="text-align: center">

[![Build Status][maven-build-image]][maven-build-url]
[![Coverage][coverage-image]][coverage-url]
[![Quality Gate Status][sonar-image]][sonar-url]
[![Download][maven-central-image]][maven-central-url]

</div>

**QueryDSL-PostgRest-RestTemplate-Adapter** is a httpclient adapter of [QueryDSL-Postgrest](https://github.com/Ouest-France/querydsl-postgrest).

**PostgREST** is an open source project that provides a fully RESTful API from any existing PostgreSQL database

## Getting Started

### Maven integration

Add the following dependency to your Maven project:

```xml
<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl-postgrest-resttemplate-adapter</artifactId>
<version>${querydsl-postgrest.version}</version>
</dependency>
```

### Gradle integration

Add the following dependency to your gradle project:

```groovy
implementation 'fr.ouestfrance.querydsl:querydsl-postgrest-resttemplate-adapter:${querydsl-postgrest.version}'
```

### Configure PostgrestClient
QueryDsl postgrest need implementation of PostgrestClient with a specific HttpAdapter.

It's really easy to create your own HttpClientAdapter (RestTemplate, OkHttpClient, HttpConnexion, ...) by
implementing `PostgrestClient` interface.

You can also specify authenticators, interceptors (retry, transform) and every configuration (timeout, default headers,
cookies, ...) you need to deploy.

#### Configuration example

```java
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.ouestfrance.querydsl.postgrest.PostgrestClient;
import fr.ouestfrance.querydsl.postgrest.PostgrestRestTemplate;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;

@Configuration
public class PostgrestConfiguration {

@Bean
public PostgrestClient podstgrestClient() {
String serviceUrl = "http://localhost:9000";
RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(serviceUrl));
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault()));
return PostgrestRestTemplate.of(webclient);
}
}
```

## Need Help ?

If you need help with the library please start a new thread QA / Issue on github

## Contributing

If you want to request a feature or report a bug, please create a GitHub Issue

If you want to make a contribution to the project, please create a PR

## License

The QueryDSL is licensed under [MIT License](https://opensource.org/license/mit/)

[maven-build-image]: https://github.com/Ouest-France/querydsl-postgrest/actions/workflows/build.yml/badge.svg

[maven-build-url]: https://github.com/Ouest-France/querydsl-postgrest/actions/workflows/build.yml

[coverage-image]: https://codecov.io/gh/ouest-france/querydsl-postgrest/graph/badge.svg

[coverage-url]: https://codecov.io/gh/ouest-france/querydsl-postgrest

[maven-central-image]: https://maven-badges.herokuapp.com/maven-central/fr.ouestfrance.querydsl/querydsl-postgrest/badge.svg

[maven-central-url]: https://mvnrepository.com/artifact/fr.ouestfrance.querydsl/querydsl-postgrest

[sonar-image]: https://sonarcloud.io/api/project_badges/measure?project=Ouest-France_querydsl-postgrest&metric=alert_status

[sonar-url]: https://sonarcloud.io/summary/new_code?id=Ouest-France_querydsl-postgrest
73 changes: 73 additions & 0 deletions querydsl-postgrest-resttemplate-adapter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl-postgrest-bom</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.3-SNAPSHOT</version>
</parent>

<artifactId>querydsl-postgrest-resttemplate-adapter</artifactId>

<dependencies>
<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl-postgrest</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>deploy</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit d3e0f47

Please sign in to comment.