Skip to content

Commit d5e4e28

Browse files
committed
Added distinctRecomms parameter to batch request
1 parent 97c877d commit d5e4e28

15 files changed

+158
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The client is available in the [Maven Central Repository](https://mvnrepository.
1313
<dependency>
1414
<groupId>com.recombee</groupId>
1515
<artifactId>api-client</artifactId>
16-
<version>1.2.3</version>
16+
<version>1.2.4</version>
1717
</dependency>
1818
```
1919

@@ -181,4 +181,4 @@ public class ItemPropertiesExample {
181181

182182
Various errors can occur while processing request, for example because of adding an already existing item or submitting interaction of nonexistent user without *setCascadeCreate(true)*. These errors lead to throwing the *ResponseException* by the *send* method of the client. Another reason for throwing an exception is a timeout. *ApiException* is the base class of both *ResponseException* and *ApiTimeoutException*.
183183

184-
We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.
184+
We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.

pom.xml

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
<groupId>com.recombee</groupId>
88
<artifactId>api-client</artifactId>
9-
<version>1.2.3</version>
10-
9+
<version>1.2.4</version>
1110
<name>Recombee API Client</name>
1211
<description>A client library for easy use of the Recombee recommendation API</description>
1312
<url>http://recombee.com</url>
@@ -28,12 +27,12 @@
2827

2928
<developers>
3029
<developer>
31-
<id>ondra_fiedler</id>
32-
<name>Ondrej Fiedler</name>
33-
<email>[email protected]</email>
34-
<url>https://github.com/OndraFiedler</url>
35-
<organization>Recombee</organization>
36-
<organizationUrl>http://recombee.com</organizationUrl>
30+
<id>ondra_fiedler</id>
31+
<name>Ondrej Fiedler</name>
32+
<email>[email protected]</email>
33+
<url>https://github.com/OndraFiedler</url>
34+
<organization>Recombee</organization>
35+
<organizationUrl>http://recombee.com</organizationUrl>
3736
</developer>
3837
</developers>
3938

@@ -64,4 +63,81 @@
6463
<version>2.6</version>
6564
</dependency>
6665
</dependencies>
66+
67+
68+
<distributionManagement>
69+
<snapshotRepository>
70+
<id>ossrh</id>
71+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
72+
</snapshotRepository>
73+
</distributionManagement>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.5.1</version>
81+
<configuration>
82+
<source>1.7</source>
83+
<target>1.7</target>
84+
</configuration>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-source-plugin</artifactId>
89+
<version>2.2.1</version>
90+
<executions>
91+
<execution>
92+
<id>attach-sources</id>
93+
<goals>
94+
<goal>jar-no-fork</goal>
95+
</goals>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-javadoc-plugin</artifactId>
102+
<version>2.9.1</version>
103+
<executions>
104+
<execution>
105+
<id>attach-javadocs</id>
106+
<goals>
107+
<goal>jar</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-gpg-plugin</artifactId>
116+
<version>1.6</version>
117+
<executions>
118+
<execution>
119+
<id>sign-artifacts</id>
120+
<phase>verify</phase>
121+
<goals>
122+
<goal>sign</goal>
123+
</goals>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
128+
<plugin>
129+
<groupId>org.sonatype.plugins</groupId>
130+
<artifactId>nexus-staging-maven-plugin</artifactId>
131+
<version>1.6.7</version>
132+
<extensions>true</extensions>
133+
<configuration>
134+
<serverId>ossrh</serverId>
135+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
136+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
137+
</configuration>
138+
</plugin>
139+
140+
</plugins>
141+
</build>
142+
67143
</project>

src/main/java/com/recombee/api_client/api_requests/Batch.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.recombee.api_client.util.HTTPMethod;
1010

1111
/**
12-
* In many cases, it may be desirable to execute multiple requests at once. By example, when synchronizing the catalog of items in periodical manner, you would have to execute a sequence of thousands of separate POST requests, which is very ineffective and may take a very long time to complete. Most notably, network latencies can make execution of such a sequence very slow and even if executed in multiple parallel threads, there will still be unreasonable overhead caused by the HTTP(s). To avoid the problems mentioned, batch processing may be used, encapsulating a sequence of requests into a single HTTP request.
12+
* In many cases, it may be desirable to execute multiple requests at once. For example, when synchronizing the catalog of items in periodical manner, you would have to execute a sequence of thousands of separate POST requests, which is very ineffective and may take a very long time to complete. Most notably, network latencies can make execution of such a sequence very slow and even if executed in multiple parallel threads, there will still be unreasonable overhead caused by the HTTP(s). To avoid the problems mentioned, batch processing may be used, encapsulating a sequence of requests into a single HTTP request.
1313
* Batch processing allows you to submit arbitrary sequence of requests in form of JSON array. Any type of request from the above documentation may be used in the batch, and the batch may combine different types of requests arbitrarily as well.
1414
* Note that:
1515
* - executing the requests in a batch is equivalent as if they were executed one-by-one individually; there are, however, many optimizations to make batch execution as fast as possible,
@@ -23,6 +23,7 @@ public class Batch extends Request {
2323
* Requests contained in the batch
2424
*/
2525
protected List<Request> requests;
26+
protected boolean distinctRecomms;
2627

2728
/**
2829
* Construct the request
@@ -44,6 +45,7 @@ public Batch(Request[] requests)
4445
private void initialize(List<Request> requests)
4546
{
4647
this.requests = requests;
48+
this.distinctRecomms = false;
4749
this.timeout = 0;
4850
for(Request r: this.requests)
4951
this.timeout += r.getTimeout();
@@ -53,6 +55,18 @@ public List<Request> getRequests() {
5355
return this.requests;
5456
}
5557

58+
/**
59+
* @param distinctRecomms Makes all the recommended items for a certain user distinct among multiple recommendation requests in the batch
60+
*/
61+
public Batch setDistinctRecomms(boolean distinctRecomms) {
62+
this.distinctRecomms = distinctRecomms;
63+
return this;
64+
}
65+
66+
public boolean getDistinctRecomms() {
67+
return this.distinctRecomms;
68+
}
69+
5670
/**
5771
* @return Used HTTP method
5872
*/
@@ -91,6 +105,7 @@ public Map<String, Object> getBodyParameters() {
91105

92106
HashMap<String, Object> result = new HashMap<String, Object>();
93107
result.put("requests", requestMaps);
108+
result.put("distinctRecomms", this.distinctRecomms);
94109
return result;
95110
}
96111

src/main/java/com/recombee/api_client/api_requests/ListGroups.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ListGroups extends Request {
2020
* Construct the request
2121
*/
2222
public ListGroups () {
23-
this.timeout = 1000;
23+
this.timeout = 30000;
2424
}
2525

2626

src/main/java/com/recombee/api_client/api_requests/ListItems.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ListItems extends Request {
2424
* Construct the request
2525
*/
2626
public ListItems () {
27-
this.timeout = 1000;
27+
this.timeout = 30000;
2828
}
2929

3030
/**

src/main/java/com/recombee/api_client/api_requests/ListSeries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ListSeries extends Request {
2020
* Construct the request
2121
*/
2222
public ListSeries () {
23-
this.timeout = 1000;
23+
this.timeout = 30000;
2424
}
2525

2626

src/main/java/com/recombee/api_client/api_requests/ListUsers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ListUsers extends Request {
2020
* Construct the request
2121
*/
2222
public ListUsers () {
23-
this.timeout = 1000;
23+
this.timeout = 30000;
2424
}
2525

2626

src/test/java/com/recombee/api_client/AddBookmarkBatchTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void testAddBookmark() throws ApiException {
2525
new AddBookmark("u_id","i_id").setCascadeCreate(true),
2626
new AddBookmark("entity_id","entity_id"),
2727
new AddBookmark("entity_id","entity_id").setTimestamp(parseDate("2013-10-29T09:38:41.341Z")),
28+
new AddBookmark("entity_id","nonex_id"),
2829
new AddBookmark("nonex_id","entity_id"),
2930
new AddBookmark("entity_id","entity_id").setTimestamp(new Date(-15)),
3031
new AddBookmark("u_id2","i_id2").setCascadeCreate(true).setTimestamp(new Date(5)),
@@ -36,8 +37,9 @@ public void testAddBookmark() throws ApiException {
3637
assertEquals(200,responses[1].getStatusCode());
3738
assertEquals(200,responses[2].getStatusCode());
3839
assertEquals(404,responses[3].getStatusCode());
39-
assertEquals(400,responses[4].getStatusCode());
40-
assertEquals(200,responses[5].getStatusCode());
41-
assertEquals(409,responses[6].getStatusCode());
40+
assertEquals(404,responses[4].getStatusCode());
41+
assertEquals(400,responses[5].getStatusCode());
42+
assertEquals(200,responses[6].getStatusCode());
43+
assertEquals(409,responses[7].getStatusCode());
4244
}
4345
}

src/test/java/com/recombee/api_client/AddBookmarkTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public void testAddBookmark() throws ApiException {
3434
req = new AddBookmark("entity_id","entity_id").setTimestamp(parseDate("2013-10-29T09:38:41.341Z"));
3535
resp = this.client.send(req);
3636
// it 'fails with nonexisting item id'
37+
req = new AddBookmark("entity_id","nonex_id");
38+
try {
39+
this.client.send(req);
40+
fail("No exception thrown");
41+
} catch (ResponseException ex) {
42+
assertEquals(404,ex.getStatusCode());
43+
}
44+
// it 'fails with nonexisting user id'
3745
req = new AddBookmark("nonex_id","entity_id");
3846
try {
3947
this.client.send(req);

src/test/java/com/recombee/api_client/AddCartAdditionBatchTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void testAddCartAddition() throws ApiException {
2525
new AddCartAddition("u_id","i_id").setCascadeCreate(true),
2626
new AddCartAddition("entity_id","entity_id"),
2727
new AddCartAddition("entity_id","entity_id").setTimestamp(parseDate("2013-10-29T09:38:41.341Z")),
28+
new AddCartAddition("entity_id","nonex_id"),
2829
new AddCartAddition("nonex_id","entity_id"),
2930
new AddCartAddition("entity_id","entity_id").setTimestamp(new Date(-15)),
3031
new AddCartAddition("u_id2","i_id2").setCascadeCreate(true).setTimestamp(new Date(5)),
@@ -36,8 +37,9 @@ public void testAddCartAddition() throws ApiException {
3637
assertEquals(200,responses[1].getStatusCode());
3738
assertEquals(200,responses[2].getStatusCode());
3839
assertEquals(404,responses[3].getStatusCode());
39-
assertEquals(400,responses[4].getStatusCode());
40-
assertEquals(200,responses[5].getStatusCode());
41-
assertEquals(409,responses[6].getStatusCode());
40+
assertEquals(404,responses[4].getStatusCode());
41+
assertEquals(400,responses[5].getStatusCode());
42+
assertEquals(200,responses[6].getStatusCode());
43+
assertEquals(409,responses[7].getStatusCode());
4244
}
4345
}

0 commit comments

Comments
 (0)