Skip to content

Commit 2386fcd

Browse files
committed
Initial Commit based on recombee/java-api-client#15
0 parents  commit 2386fcd

File tree

19 files changed

+688
-0
lines changed

19 files changed

+688
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
target/
2+
pom.xml.tag
3+
pom.xml.releaseBackup
4+
pom.xml.versionsBackup
5+
pom.xml.next
6+
.flattened-pom.xml
7+
release.properties
8+
dependency-reduced-pom.xml
9+
buildNumber.properties
10+
.mvn/timing.properties
11+
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
12+
.mvn/wrapper/maven-wrapper.jar
13+
14+
# Eclipse m2e generated files
15+
# Eclipse Core
16+
.project
17+
# JDT-specific (Eclipse Java Development Tools)
18+
.classpath
19+
20+
.settings
21+
22+
.factorypath

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Recombee s.r.o.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Spring Boot Integration for Recombee API Client
2+
3+
Spring Boot 2 and 3 Integration for the [Recombee Java API Client](https://github.com/recombee/java-api-client).
4+
5+
It provides a starter that includes the api-client and an AutoConfiguration to create automatically create a RecombeeClient Bean based on the configuration in the properties.
6+
7+
## Installation and Usage
8+
9+
Add the following `<dependency>` entry to your project's POM. For Spring Boot 2, use the following:
10+
11+
```xml
12+
<dependency>
13+
<groupId>de.125m125.recombee</groupId>
14+
<artifactId>api-client-spring-boot-2-starter</artifactId>
15+
<version>5.0.0</version>
16+
</dependency>
17+
```
18+
19+
For Spring Boot 3, use the following:
20+
21+
```xml
22+
<dependency>
23+
<groupId>de.125m125.recombee</groupId>
24+
<artifactId>api-client-spring-boot-3-starter</artifactId>
25+
<version>5.0.0</version>
26+
</dependency>
27+
```
28+
29+
For the automatic configuration of the bean, you need to add the following properties:
30+
31+
```yaml
32+
com.recombee.client.database-id=my-database-id
33+
com.recombee.client.token=db-private-token
34+
com.recombee.client.region=US_WEST
35+
```
36+
Afterwards, if autoconfiguration is enabled, an instance of RecombeeClient will automatically be created and you can inject it into your components:
37+
```java
38+
import com.recombee.api_client.RecombeeClient;
39+
40+
@Component
41+
public class SampleComponent {
42+
43+
private final RecombeeClient client;
44+
45+
public SampleComponent(RecombeeClient client) {
46+
this.client = client;
47+
}
48+
}
49+
```
50+
51+
See the [Recombee Java API Client](https://github.com/recombee/java-api-client) for detailed usage of the client.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>de.125m125.recombee</groupId>
7+
<artifactId>api-client-parent</artifactId>
8+
<version>${revision}</version>
9+
</parent>
10+
<artifactId>api-client-spring-boot-2-autoconfigure</artifactId>
11+
<name>Recombee API Client Spring Boot 2 Autoconfiguration</name>
12+
13+
<properties>
14+
<dependency.springboot.version>${spring.boot.2.version}</dependency.springboot.version>
15+
</properties>
16+
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-dependencies</artifactId>
22+
<version>${dependency.springboot.version}</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-autoconfigure</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>com.recombee</groupId>
36+
<artifactId>api-client</artifactId>
37+
<optional>true</optional>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-configuration-processor</artifactId>
42+
<optional>true</optional>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-validation</artifactId>
47+
<optional>true</optional>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-test</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package de._125m125.recombee.api_client.spring.boot._2.autoconfiguration;
2+
3+
import org.springframework.boot.autoconfigure.AutoConfiguration;
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7+
import org.springframework.boot.context.properties.ConfigurationProperties;
8+
import org.springframework.context.annotation.Bean;
9+
10+
import com.recombee.api_client.RecombeeClient;
11+
12+
@AutoConfiguration
13+
@ConditionalOnClass(RecombeeClient.class)
14+
@ConditionalOnProperty(prefix = RecombeeClientAutoconfiguration.DEFAULT_RECOMBEE_CLIENT_PROPERTIES_PREFIX, name = "enabled", matchIfMissing = true)
15+
public class RecombeeClientAutoconfiguration {
16+
17+
public static final String DEFAULT_RECOMBEE_CLIENT_PROPERTIES_PREFIX = "com.recombee.client";
18+
19+
@Bean
20+
@ConditionalOnMissingBean
21+
@ConfigurationProperties(DEFAULT_RECOMBEE_CLIENT_PROPERTIES_PREFIX)
22+
RecombeeClientProperties recombeeClientProperties() {
23+
return new RecombeeClientProperties();
24+
}
25+
26+
@Bean
27+
@ConditionalOnMissingBean
28+
RecombeeClient recombeeClient(RecombeeClientProperties recombeeClientProperties) {
29+
return new RecombeeClient(recombeeClientProperties.getDatabaseId(), recombeeClientProperties.getToken())
30+
.setRegion(recombeeClientProperties.getRegion());
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package de._125m125.recombee.api_client.spring.boot._2.autoconfiguration;
2+
3+
import javax.validation.constraints.NotBlank;
4+
import javax.validation.constraints.NotNull;
5+
6+
import org.springframework.validation.annotation.Validated;
7+
8+
import com.recombee.api_client.util.Region;
9+
10+
@Validated
11+
public class RecombeeClientProperties {
12+
@NotBlank
13+
private String databaseId;
14+
@NotBlank
15+
private String token;
16+
@NotNull
17+
private Region region;
18+
19+
public RecombeeClientProperties() {
20+
// empty no-args constructor
21+
}
22+
23+
public RecombeeClientProperties(@NotBlank String databaseId, @NotBlank String token, @NotNull Region region) {
24+
this.databaseId = databaseId;
25+
this.token = token;
26+
this.region = region;
27+
}
28+
29+
public String getDatabaseId() {
30+
return databaseId;
31+
}
32+
33+
public void setDatabaseId(String databaseId) {
34+
this.databaseId = databaseId;
35+
}
36+
37+
public String getToken() {
38+
return token;
39+
}
40+
41+
public void setToken(String token) {
42+
this.token = token;
43+
}
44+
45+
public Region getRegion() {
46+
return region;
47+
}
48+
49+
public void setRegion(Region region) {
50+
this.region = region;
51+
}
52+
53+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2+
de._125m125.recombee.api_client.spring.boot._2.autoconfiguration.RecombeeClientAutoconfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
de._125m125.recombee.api_client.spring.boot._2.autoconfiguration.RecombeeClientAutoconfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de._125m125.recombee.api_client.spring.boot._2.autoconfiguration;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.test.context.ActiveProfiles;
11+
12+
import com.recombee.api_client.RecombeeClient;
13+
14+
import de._125m125.recombee.api_client.spring.boot._2.autoconfiguration.RecombeeClientAutoconfigurationTest.TestConfig;
15+
16+
@SpringBootTest(classes = TestConfig.class)
17+
@ActiveProfiles("test")
18+
public class RecombeeClientAutoconfigurationTest {
19+
20+
@Configuration
21+
@EnableAutoConfiguration
22+
public static class TestConfig {
23+
}
24+
25+
@Autowired
26+
private RecombeeClient client;
27+
28+
@Test
29+
public void testAutoConfigurationExecutes() {
30+
assertThat(client).isNotNull();
31+
}
32+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
com.recombee.client.database-id=my-database-id
2+
com.recombee.client.token=db-private-token
3+
com.recombee.client.region=US_WEST

0 commit comments

Comments
 (0)