From 07d36cba8cadd66fa539cb922c7667f902354c79 Mon Sep 17 00:00:00 2001 From: Ondrej Fiedler Date: Thu, 29 Dec 2016 22:45:38 +0100 Subject: [PATCH] Added support for user properties. Automatically split Batch with more than 10k requests to multiple Batch requests. Added cascadeCreate parameter to Set item/user values. --- README.md | 39 +++---- pom.xml | 2 +- .../api_client/examples/BasicExample.java | 28 ++--- .../examples/ItemPropertiesExample.java | 5 +- .../recombee/api_client/RecombeeClient.java | 106 +++++++++++++++++- .../api_requests/AddUserProperty.java | 84 ++++++++++++++ .../api_requests/DeleteUserProperty.java | 73 ++++++++++++ .../api_requests/GetUserPropertyInfo.java | 73 ++++++++++++ .../api_requests/GetUserValues.java | 73 ++++++++++++ .../api_requests/ItemBasedRecommendation.java | 18 ++- .../api_requests/ListUserProperties.java | 64 +++++++++++ .../api_requests/SetItemValues.java | 36 ++---- .../api_requests/SetUserValues.java | 56 +++++++++ .../api_client/api_requests/SetValues.java | 84 ++++++++++++++ .../api_requests/UserBasedRecommendation.java | 4 +- .../api_client/AddUserPropertyBatchTest.java | 39 +++++++ .../api_client/AddUserPropertyTest.java | 50 +++++++++ .../com/recombee/api_client/BatchTest.java | 49 ++++++++ .../DeleteUserPropertyBatchTest.java | 37 ++++++ .../api_client/DeleteUserPropertyTest.java | 53 +++++++++ .../GetUserPropertyInfoBatchTest.java | 35 ++++++ .../api_client/GetUserPropertyInfoTest.java | 35 ++++++ .../api_client/GetUserValuesBatchTest.java | 26 +++++ .../api_client/GetUserValuesTest.java | 22 ++++ .../ListUserPropertiesBatchTest.java | 32 ++++++ .../api_client/ListUserPropertiesTest.java | 32 ++++++ .../recombee/api_client/RecombeeTestCase.java | 8 ++ .../api_client/SetItemValuesBatchTest.java | 4 +- .../api_client/SetItemValuesTest.java | 3 + .../api_client/SetUserValuesBatchTest.java | 41 +++++++ .../api_client/SetUserValuesTest.java | 51 +++++++++ 31 files changed, 1177 insertions(+), 85 deletions(-) create mode 100644 src/main/java/com/recombee/api_client/api_requests/AddUserProperty.java create mode 100644 src/main/java/com/recombee/api_client/api_requests/DeleteUserProperty.java create mode 100644 src/main/java/com/recombee/api_client/api_requests/GetUserPropertyInfo.java create mode 100644 src/main/java/com/recombee/api_client/api_requests/GetUserValues.java create mode 100644 src/main/java/com/recombee/api_client/api_requests/ListUserProperties.java create mode 100644 src/main/java/com/recombee/api_client/api_requests/SetUserValues.java create mode 100644 src/main/java/com/recombee/api_client/api_requests/SetValues.java create mode 100644 src/test/java/com/recombee/api_client/AddUserPropertyBatchTest.java create mode 100644 src/test/java/com/recombee/api_client/AddUserPropertyTest.java create mode 100644 src/test/java/com/recombee/api_client/BatchTest.java create mode 100644 src/test/java/com/recombee/api_client/DeleteUserPropertyBatchTest.java create mode 100644 src/test/java/com/recombee/api_client/DeleteUserPropertyTest.java create mode 100644 src/test/java/com/recombee/api_client/GetUserPropertyInfoBatchTest.java create mode 100644 src/test/java/com/recombee/api_client/GetUserPropertyInfoTest.java create mode 100644 src/test/java/com/recombee/api_client/GetUserValuesBatchTest.java create mode 100644 src/test/java/com/recombee/api_client/GetUserValuesTest.java create mode 100644 src/test/java/com/recombee/api_client/ListUserPropertiesBatchTest.java create mode 100644 src/test/java/com/recombee/api_client/ListUserPropertiesTest.java create mode 100644 src/test/java/com/recombee/api_client/SetUserValuesBatchTest.java create mode 100644 src/test/java/com/recombee/api_client/SetUserValuesTest.java diff --git a/README.md b/README.md index 05059e4..791f26e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Recombee API Client -A Java client for easy use of the [Recombee](https://www.recombee.com/) recommendation API. +A Java client (SDK) for easy use of the [Recombee](https://www.recombee.com/) recommendation API. If you don't have an account at Recombee yet, you can create a free account [here](https://www.recombee.com/). @@ -13,7 +13,7 @@ The client is available in the [Maven Central Repository](https://mvnrepository. com.recombee api-client - 1.2.5 + 1.3 ``` @@ -39,32 +39,24 @@ public class BasicExample { RecombeeClient client = new RecombeeClient("client-test", "jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L"); try { + client.send(new ResetDatabase()); final int NUM = 100; - //Create some users and send them to Recombee, use Batch for faster processing - ArrayList addUserRequests = new ArrayList(); - for (int i = 0; i < NUM; i++) addUserRequests.add(new AddUser(String.format("user-%s", i))); - - System.out.println("Send users"); - client.send(new Batch(addUserRequests)); - - //Now create some items - ArrayList addItemRequests = new ArrayList(); - for (int i = 0; i < NUM; i++) addItemRequests.add(new AddItem(String.format("item-%s", i))); - - System.out.println("Send items"); - client.send(new Batch(addItemRequests)); - // Generate some random purchases of items by users - final double PROBABILITY_PURCHASED = 0.01; + final double PROBABILITY_PURCHASED = 0.1; Random r = new Random(); ArrayList addPurchaseRequests = new ArrayList(); for (int i = 0; i < NUM; i++) for (int j = 0; j < NUM; j++) - if (r.nextDouble() < PROBABILITY_PURCHASED) - addPurchaseRequests.add(new AddPurchase(String.format("user-%s", i),String.format("item-%s", j))); + if (r.nextDouble() < PROBABILITY_PURCHASED) { + + AddPurchase request = new AddPurchase(String.format("user-%s", i),String.format("item-%s", j)) + .setCascadeCreate(true); // Use cascadeCreate parameter to create + // the yet non-existing users and items + addPurchaseRequests.add(request); + } System.out.println("Send purchases"); - client.send(new Batch(addPurchaseRequests)); + client.send(new Batch(addPurchaseRequests)); //Use Batch for faster processing of larger data // Get 5 recommendations for user 'user-25' Recommendation[] recommended = client.send(new UserBasedRecommendation("user-25", 5)); @@ -81,6 +73,7 @@ public class BasicExample { ``` ### Using property values + ```java package com.recombee.api_client.examples; @@ -127,10 +120,9 @@ public class ItemPropertiesExample { put("price", 600.0 + 400*rand.nextDouble()); put("num-cores", 1 + rand.nextInt(7)); put("description", "Great computer"); - put("!cascadeCreate", true); // Use !cascadeCreate for creating item - // with given itemId, if it doesn't exist }} - ); + ).setCascadeCreate(true); // Use cascadeCreate for creating item + // with given itemId, if it doesn't exist; requests.add(req); } client.send(new Batch(requests)); // Send catalog to the recommender system @@ -174,7 +166,6 @@ public class ItemPropertiesExample { } } } - ``` ## Exception handling diff --git a/pom.xml b/pom.xml index aa61a6e..6fb2f12 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.recombee api-client - 1.2.5 + 1.3 Recombee API Client A client library for easy use of the Recombee recommendation API http://recombee.com diff --git a/src/examples/java/com/recombee/api_client/examples/BasicExample.java b/src/examples/java/com/recombee/api_client/examples/BasicExample.java index 1eb1023..f1a707b 100644 --- a/src/examples/java/com/recombee/api_client/examples/BasicExample.java +++ b/src/examples/java/com/recombee/api_client/examples/BasicExample.java @@ -13,32 +13,24 @@ public static void main(String[] args) { RecombeeClient client = new RecombeeClient("client-test", "jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L"); try { + client.send(new ResetDatabase()); final int NUM = 100; - //Create some users and send them to Recombee, use Batch for faster processing - ArrayList addUserRequests = new ArrayList(); - for (int i = 0; i < NUM; i++) addUserRequests.add(new AddUser(String.format("user-%s", i))); - - System.out.println("Send users"); - client.send(new Batch(addUserRequests)); - - //Now create some items - ArrayList addItemRequests = new ArrayList(); - for (int i = 0; i < NUM; i++) addItemRequests.add(new AddItem(String.format("item-%s", i))); - - System.out.println("Send items"); - client.send(new Batch(addItemRequests)); - // Generate some random purchases of items by users - final double PROBABILITY_PURCHASED = 0.01; + final double PROBABILITY_PURCHASED = 0.1; Random r = new Random(); ArrayList addPurchaseRequests = new ArrayList(); for (int i = 0; i < NUM; i++) for (int j = 0; j < NUM; j++) - if (r.nextDouble() < PROBABILITY_PURCHASED) - addPurchaseRequests.add(new AddPurchase(String.format("user-%s", i),String.format("item-%s", j))); + if (r.nextDouble() < PROBABILITY_PURCHASED) { + + AddPurchase request = new AddPurchase(String.format("user-%s", i),String.format("item-%s", j)) + .setCascadeCreate(true); // Use cascadeCreate parameter to create + // the yet non-existing users and items + addPurchaseRequests.add(request); + } System.out.println("Send purchases"); - client.send(new Batch(addPurchaseRequests)); + client.send(new Batch(addPurchaseRequests)); //Use Batch for faster processing of larger data // Get 5 recommendations for user 'user-25' Recommendation[] recommended = client.send(new UserBasedRecommendation("user-25", 5)); diff --git a/src/examples/java/com/recombee/api_client/examples/ItemPropertiesExample.java b/src/examples/java/com/recombee/api_client/examples/ItemPropertiesExample.java index 79181bd..3b2ce06 100644 --- a/src/examples/java/com/recombee/api_client/examples/ItemPropertiesExample.java +++ b/src/examples/java/com/recombee/api_client/examples/ItemPropertiesExample.java @@ -43,10 +43,9 @@ public static void main(String[] args) { put("price", 600.0 + 400*rand.nextDouble()); put("num-cores", 1 + rand.nextInt(7)); put("description", "Great computer"); - put("!cascadeCreate", true); // Use !cascadeCreate for creating item - // with given itemId, if it doesn't exist }} - ); + ).setCascadeCreate(true); // Use cascadeCreate for creating item + // with given itemId, if it doesn't exist; requests.add(req); } client.send(new Batch(requests)); // Send catalog to the recommender system diff --git a/src/main/java/com/recombee/api_client/RecombeeClient.java b/src/main/java/com/recombee/api_client/RecombeeClient.java index 1194813..cdfe8ab 100644 --- a/src/main/java/com/recombee/api_client/RecombeeClient.java +++ b/src/main/java/com/recombee/api_client/RecombeeClient.java @@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; @@ -44,7 +45,10 @@ import com.recombee.api_client.api_requests.ListSeriesItems; import com.recombee.api_client.api_requests.ListGroups; import com.recombee.api_client.api_requests.ListGroupItems; +import com.recombee.api_client.api_requests.GetUserValues; import com.recombee.api_client.api_requests.ListUsers; +import com.recombee.api_client.api_requests.GetUserPropertyInfo; +import com.recombee.api_client.api_requests.ListUserProperties; import com.recombee.api_client.api_requests.ListItemDetailViews; import com.recombee.api_client.api_requests.ListUserDetailViews; import com.recombee.api_client.api_requests.ListItemPurchases; @@ -71,6 +75,8 @@ public class RecombeeClient { String baseUri = "rapi.recombee.com"; ObjectMapper mapper; + final int BATCH_MAX_SIZE = 10000; //Maximal number of requests within one batch request + public RecombeeClient(String databaseId, String token) { this.databaseId = databaseId; this.token = token; @@ -170,6 +176,26 @@ public User[] send(ListUsers request) throws ApiException { return null; } + public PropertyInfo send(GetUserPropertyInfo request) throws ApiException { + String responseStr = sendRequest(request); + try { + return this.mapper.readValue(responseStr, PropertyInfo.class); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public PropertyInfo[] send(ListUserProperties request) throws ApiException { + String responseStr = sendRequest(request); + try { + return this.mapper.readValue(responseStr, PropertyInfo[].class); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + public DetailView[] send(ListItemDetailViews request) throws ApiException { String responseStr = sendRequest(request); try { @@ -273,6 +299,11 @@ public Bookmark[] send(ListUserBookmarks request) throws ApiException { /* End of the generated code */ public BatchResponse[] send(Batch batchRequest) throws ApiException { + + if(batchRequest.getRequests().size() > this.BATCH_MAX_SIZE) { + return sendMultipartBatchRequest(batchRequest); + } + String responseStr = sendRequest(batchRequest); try { @@ -376,6 +407,20 @@ else if (request instanceof ListUsers) parsedResponse = ar; } + else if (request instanceof GetUserPropertyInfo) + { + Map obj = (Map) parsedResponse; + parsedResponse = new PropertyInfo(obj); + } + + else if (request instanceof ListUserProperties) + { + ArrayList> array = (ArrayList>) parsedResponse; + PropertyInfo[] ar = new PropertyInfo[array.size()]; + for(int j=0;j> array = (ArrayList>) parsedResponse; @@ -467,7 +512,51 @@ else if (request instanceof ListUserBookmarks) } return null; } - /* End of the generated code */ + + + + private BatchResponse[] sendMultipartBatchRequest(Batch batchRequest) throws ApiException { + + List> requestChunks = getRequestsChunks(batchRequest); + ArrayList responses = new ArrayList(); + + for(List rqs: requestChunks) + responses.add(send(new Batch(rqs))); + + return concatenateResponses(responses); + } + + private List> getRequestsChunks(Batch batchRequest) { + + ArrayList> result = new ArrayList>(); + List requests = batchRequest.getRequests(); + int fullparts = requests.size() / this.BATCH_MAX_SIZE; + + for(int i=0;i responses) + { + int size = 0, i = 0; + + for(BatchResponse[] rsps: responses) { + size += rsps.length; + } + + BatchResponse[] result = new BatchResponse[size]; + + for(BatchResponse[] rsps: responses) { + for(BatchResponse rsp: rsps) + result[i++] = rsp; + } + return result; + } /* End of the generated code */ public Map send(GetItemValues request) throws ApiException { String responseStr = sendRequest(request); @@ -482,6 +571,21 @@ public Map send(GetItemValues request) throws ApiException { return null; } + + public Map send(GetUserValues request) throws ApiException { + String responseStr = sendRequest(request); + + TypeReference> typeRef + = new TypeReference>() {}; + try { + return this.mapper.readValue(responseStr, typeRef); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public Recommendation[] send(UserBasedRecommendation request) throws ApiException { return sendRecomm(request); } diff --git a/src/main/java/com/recombee/api_client/api_requests/AddUserProperty.java b/src/main/java/com/recombee/api_client/api_requests/AddUserProperty.java new file mode 100644 index 0000000..4982397 --- /dev/null +++ b/src/main/java/com/recombee/api_client/api_requests/AddUserProperty.java @@ -0,0 +1,84 @@ +package com.recombee.api_client.api_requests; + +/* + This file is auto-generated, do not edit +*/ + +import java.util.Date; +import java.util.Map; +import java.util.HashMap; + +import com.recombee.api_client.util.HTTPMethod; + +/** + * Adding an user property is somehow equivalent to adding a column to the table of users. The users may be characterized by various properties of different types. + */ +public class AddUserProperty extends Request { + + /** + * Name of the user property to be created. Currently, the following names are reserved:`id`, `userid`, case insensitively. Also, the length of the property name must not exceed 63 characters. + */ + protected String propertyName; + /** + * Value type of the user property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set` + */ + protected String type; + + /** + * Construct the request + * @param propertyName Name of the user property to be created. Currently, the following names are reserved:`id`, `userid`, case insensitively. Also, the length of the property name must not exceed 63 characters. + * @param type Value type of the user property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set` + */ + public AddUserProperty (String propertyName,String type) { + this.propertyName = propertyName; + this.type = type; + this.timeout = 1000; + } + + + public String getPropertyName() { + return this.propertyName; + } + + public String getType() { + return this.type; + } + + /** + * @return Used HTTP method + */ + @Override + public HTTPMethod getHTTPMethod() { + return HTTPMethod.PUT; + } + + /** + * @return URI to the endpoint including path parameters + */ + @Override + public String getPath() { + return String.format("/users/properties/%s", this.propertyName); + } + + /** + * Get query parameters + * @return Values of query parameters (name of parameter: value of the parameter) + */ + @Override + public Map getQueryParameters() { + HashMap params = new HashMap(); + params.put("type", this.type.toString()); + return params; + } + + /** + * Get body parameters + * @return Values of body parameters (name of parameter: value of the parameter) + */ + @Override + public Map getBodyParameters() { + HashMap params = new HashMap(); + return params; + } + +} diff --git a/src/main/java/com/recombee/api_client/api_requests/DeleteUserProperty.java b/src/main/java/com/recombee/api_client/api_requests/DeleteUserProperty.java new file mode 100644 index 0000000..f1d007e --- /dev/null +++ b/src/main/java/com/recombee/api_client/api_requests/DeleteUserProperty.java @@ -0,0 +1,73 @@ +package com.recombee.api_client.api_requests; + +/* + This file is auto-generated, do not edit +*/ + +import java.util.Date; +import java.util.Map; +import java.util.HashMap; + +import com.recombee.api_client.util.HTTPMethod; + +/** + * Deleting an user property is roughly equivalent to removing a column from the table of users. + */ +public class DeleteUserProperty extends Request { + + /** + * Name of the property to be deleted. + */ + protected String propertyName; + + /** + * Construct the request + * @param propertyName Name of the property to be deleted. + */ + public DeleteUserProperty (String propertyName) { + this.propertyName = propertyName; + this.timeout = 1000; + } + + + public String getPropertyName() { + return this.propertyName; + } + + /** + * @return Used HTTP method + */ + @Override + public HTTPMethod getHTTPMethod() { + return HTTPMethod.DELETE; + } + + /** + * @return URI to the endpoint including path parameters + */ + @Override + public String getPath() { + return String.format("/users/properties/%s", this.propertyName); + } + + /** + * Get query parameters + * @return Values of query parameters (name of parameter: value of the parameter) + */ + @Override + public Map getQueryParameters() { + HashMap params = new HashMap(); + return params; + } + + /** + * Get body parameters + * @return Values of body parameters (name of parameter: value of the parameter) + */ + @Override + public Map getBodyParameters() { + HashMap params = new HashMap(); + return params; + } + +} diff --git a/src/main/java/com/recombee/api_client/api_requests/GetUserPropertyInfo.java b/src/main/java/com/recombee/api_client/api_requests/GetUserPropertyInfo.java new file mode 100644 index 0000000..ebf5ac7 --- /dev/null +++ b/src/main/java/com/recombee/api_client/api_requests/GetUserPropertyInfo.java @@ -0,0 +1,73 @@ +package com.recombee.api_client.api_requests; + +/* + This file is auto-generated, do not edit +*/ + +import java.util.Date; +import java.util.Map; +import java.util.HashMap; + +import com.recombee.api_client.util.HTTPMethod; + +/** + * Gets information about specified user property. + */ +public class GetUserPropertyInfo extends Request { + + /** + * Name of the property about which the information is to be retrieved. + */ + protected String propertyName; + + /** + * Construct the request + * @param propertyName Name of the property about which the information is to be retrieved. + */ + public GetUserPropertyInfo (String propertyName) { + this.propertyName = propertyName; + this.timeout = 1000; + } + + + public String getPropertyName() { + return this.propertyName; + } + + /** + * @return Used HTTP method + */ + @Override + public HTTPMethod getHTTPMethod() { + return HTTPMethod.GET; + } + + /** + * @return URI to the endpoint including path parameters + */ + @Override + public String getPath() { + return String.format("/users/properties/%s", this.propertyName); + } + + /** + * Get query parameters + * @return Values of query parameters (name of parameter: value of the parameter) + */ + @Override + public Map getQueryParameters() { + HashMap params = new HashMap(); + return params; + } + + /** + * Get body parameters + * @return Values of body parameters (name of parameter: value of the parameter) + */ + @Override + public Map getBodyParameters() { + HashMap params = new HashMap(); + return params; + } + +} diff --git a/src/main/java/com/recombee/api_client/api_requests/GetUserValues.java b/src/main/java/com/recombee/api_client/api_requests/GetUserValues.java new file mode 100644 index 0000000..47b8196 --- /dev/null +++ b/src/main/java/com/recombee/api_client/api_requests/GetUserValues.java @@ -0,0 +1,73 @@ +package com.recombee.api_client.api_requests; + +/* + This file is auto-generated, do not edit +*/ + +import java.util.Date; +import java.util.Map; +import java.util.HashMap; + +import com.recombee.api_client.util.HTTPMethod; + +/** + * Get all the current property values of a given user. + */ +public class GetUserValues extends Request { + + /** + * ID of the user properties of which are to be obtained. + */ + protected String userId; + + /** + * Construct the request + * @param userId ID of the user properties of which are to be obtained. + */ + public GetUserValues (String userId) { + this.userId = userId; + this.timeout = 1000; + } + + + public String getUserId() { + return this.userId; + } + + /** + * @return Used HTTP method + */ + @Override + public HTTPMethod getHTTPMethod() { + return HTTPMethod.GET; + } + + /** + * @return URI to the endpoint including path parameters + */ + @Override + public String getPath() { + return String.format("/users/%s", this.userId); + } + + /** + * Get query parameters + * @return Values of query parameters (name of parameter: value of the parameter) + */ + @Override + public Map getQueryParameters() { + HashMap params = new HashMap(); + return params; + } + + /** + * Get body parameters + * @return Values of body parameters (name of parameter: value of the parameter) + */ + @Override + public Map getBodyParameters() { + HashMap params = new HashMap(); + return params; + } + +} diff --git a/src/main/java/com/recombee/api_client/api_requests/ItemBasedRecommendation.java b/src/main/java/com/recombee/api_client/api_requests/ItemBasedRecommendation.java index 2277d8b..4e83e73 100644 --- a/src/main/java/com/recombee/api_client/api_requests/ItemBasedRecommendation.java +++ b/src/main/java/com/recombee/api_client/api_requests/ItemBasedRecommendation.java @@ -25,6 +25,9 @@ public class ItemBasedRecommendation extends Request { protected Long count; /** * ID of the user who will see the recommendations. + * Specifying the *targetUserId* is beneficial because: + * * It makes the recommendations personalized + * * Allows calculations of Actions and Conversions in the graphical user interface, as Recombee can pair the user who got recommendations and who afterwards viewed/purchased an item. */ protected String targetUserId; /** @@ -98,15 +101,15 @@ public class ItemBasedRecommendation extends Request { */ protected Double diversity; /** - * **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it. + * **Expert option** If the *targetUserId* is provided: Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it. */ protected String minRelevance; /** - * **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. + * **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. */ protected Double rotationRate; /** - * **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. By example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. + * **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. For example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. */ protected Double rotationTime; @@ -123,6 +126,9 @@ public ItemBasedRecommendation (String itemId,long count) { /** * @param targetUserId ID of the user who will see the recommendations. + * Specifying the *targetUserId* is beneficial because: + * * It makes the recommendations personalized + * * Allows calculations of Actions and Conversions in the graphical user interface, as Recombee can pair the user who got recommendations and who afterwards viewed/purchased an item. */ public ItemBasedRecommendation setTargetUserId(String targetUserId) { this.targetUserId = targetUserId; @@ -236,7 +242,7 @@ public ItemBasedRecommendation setDiversity(double diversity) { } /** - * @param minRelevance **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it. + * @param minRelevance **Expert option** If the *targetUserId* is provided: Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it. */ public ItemBasedRecommendation setMinRelevance(String minRelevance) { this.minRelevance = minRelevance; @@ -244,7 +250,7 @@ public ItemBasedRecommendation setMinRelevance(String minRelevance) { } /** - * @param rotationRate **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. + * @param rotationRate **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. */ public ItemBasedRecommendation setRotationRate(double rotationRate) { this.rotationRate = rotationRate; @@ -252,7 +258,7 @@ public ItemBasedRecommendation setRotationRate(double rotationRate) { } /** - * @param rotationTime **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. By example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. + * @param rotationTime **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. For example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. */ public ItemBasedRecommendation setRotationTime(double rotationTime) { this.rotationTime = rotationTime; diff --git a/src/main/java/com/recombee/api_client/api_requests/ListUserProperties.java b/src/main/java/com/recombee/api_client/api_requests/ListUserProperties.java new file mode 100644 index 0000000..c22a179 --- /dev/null +++ b/src/main/java/com/recombee/api_client/api_requests/ListUserProperties.java @@ -0,0 +1,64 @@ +package com.recombee.api_client.api_requests; + +/* + This file is auto-generated, do not edit +*/ + +import java.util.Date; +import java.util.Map; +import java.util.HashMap; + +import com.recombee.api_client.util.HTTPMethod; + +/** + * Gets the list of all the user properties in your database. + */ +public class ListUserProperties extends Request { + + + /** + * Construct the request + */ + public ListUserProperties () { + this.timeout = 1000; + } + + + + /** + * @return Used HTTP method + */ + @Override + public HTTPMethod getHTTPMethod() { + return HTTPMethod.GET; + } + + /** + * @return URI to the endpoint including path parameters + */ + @Override + public String getPath() { + return "/users/properties/list/"; + } + + /** + * Get query parameters + * @return Values of query parameters (name of parameter: value of the parameter) + */ + @Override + public Map getQueryParameters() { + HashMap params = new HashMap(); + return params; + } + + /** + * Get body parameters + * @return Values of body parameters (name of parameter: value of the parameter) + */ + @Override + public Map getBodyParameters() { + HashMap params = new HashMap(); + return params; + } + +} diff --git a/src/main/java/com/recombee/api_client/api_requests/SetItemValues.java b/src/main/java/com/recombee/api_client/api_requests/SetItemValues.java index 749cc2f..4b77963 100644 --- a/src/main/java/com/recombee/api_client/api_requests/SetItemValues.java +++ b/src/main/java/com/recombee/api_client/api_requests/SetItemValues.java @@ -9,7 +9,7 @@ /** * Set/update (some) property values of a given item. The properties (columns) must be previously created by [Add item property](https://docs.recombee.com/api.html#add-item-property). */ -public class SetItemValues extends Request { +public class SetItemValues extends SetValues { /** * ID of the item which will be modified. @@ -26,28 +26,24 @@ public class SetItemValues extends Request { /** * Construct the request * @param itemId ID of the item which will be modified. - * @param values The values for the individual properties. Key in the Map is the name of the property and value is the value to be set + * @param values The values for the individual properties. Key in the Map is the name of the property and value is the value to be set. */ public SetItemValues (String itemId, Map values) { + super(values); this.itemId = itemId; - this.values = values; } - public String getItemId() { return this.itemId; } - public Map getValues() { - return this.values; - } - /** - * @return Used HTTP method + * @param cascadeCreate Sets whether the entity should be created if not present in the database. */ @Override - public HTTPMethod getHTTPMethod() { - return HTTPMethod.POST; + public SetItemValues setCascadeCreate(boolean cascadeCreate) { + this.cascadeCreate = cascadeCreate; + return this; } /** @@ -57,22 +53,4 @@ public HTTPMethod getHTTPMethod() { public String getPath() { return String.format("/items/%s", this.itemId); } - - /** - * Get query parameters - * @return Values of query parameters (name of parameter: value of the parameter) - */ - @Override - public Map getQueryParameters() { - return new HashMap(); - } - - /** - * Get body parameters - * @return Values of body parameters (name of parameter: value of the parameter) - */ - @Override - public Map getBodyParameters() { - return this.values; - } } diff --git a/src/main/java/com/recombee/api_client/api_requests/SetUserValues.java b/src/main/java/com/recombee/api_client/api_requests/SetUserValues.java new file mode 100644 index 0000000..9f7dda6 --- /dev/null +++ b/src/main/java/com/recombee/api_client/api_requests/SetUserValues.java @@ -0,0 +1,56 @@ +package com.recombee.api_client.api_requests; + +import java.util.Map; + +import java.util.HashMap; + +import com.recombee.api_client.util.HTTPMethod; + +/** + * Set/update (some) property values of a given user. The properties (columns) must be previously created by [Add user property](https://docs.recombee.com/api.html#add-user-property). + */ +public class SetUserValues extends SetValues { + + /** + * ID of the user which will be modified. + */ + protected String userId; + + /** + * The values for the individual properties. + * Key in the Map is the name of the property and value is the value to be set + * Special key "!cascadeCreate" may be used. It indicates that the user of the given userId should be created if it does not exist in the database, as if the corresponding PUT method was used. Note the exclamation mark (!) at the beginning of the parameter's name to distinguish it from user property names. + */ + protected Map values; + + /** + * Construct the request + * @param userId ID of the user which will be modified. + * @param values The values for the individual properties. Key in the Map is the name of the property and value is the value to be set. + */ + public SetUserValues (String userId, Map values) { + super(values); + this.userId = userId; + } + + /** + * @param cascadeCreate Sets whether the entity should be created if not present in the database. + */ + @Override + public SetUserValues setCascadeCreate(boolean cascadeCreate) { + this.cascadeCreate = cascadeCreate; + return this; + } + + public String getuserId() { + return this.userId; + } + + /** + * @return URI to the endpoint including path parameters + */ + @Override + public String getPath() { + return String.format("/users/%s", this.userId); + } +} diff --git a/src/main/java/com/recombee/api_client/api_requests/SetValues.java b/src/main/java/com/recombee/api_client/api_requests/SetValues.java new file mode 100644 index 0000000..e82b38d --- /dev/null +++ b/src/main/java/com/recombee/api_client/api_requests/SetValues.java @@ -0,0 +1,84 @@ +package com.recombee.api_client.api_requests; + +import java.util.Map; + +import java.util.HashMap; + +import com.recombee.api_client.util.HTTPMethod; + +/** + * Set/update (some) property values of an entity. + */ +public abstract class SetValues extends Request { + + /** + * The values for the individual properties. + * Key in the Map is the name of the property and value is the value to be set + * Special key "!cascadeCreate" may be used. It indicates that the entity should be created if it does not exist in the database, as if the corresponding PUT method was used. Note the exclamation mark (!) at the beginning of the parameter's name to distinguish it from the property names. + */ + protected Map values; + + /** + * Sets whether the entity should be created if not present in the database. + */ + protected Boolean cascadeCreate; + + /** + * Construct the request + * @param values The values for the individual properties. Key in the Map is the name of the property and value is the value to be set. + */ + public SetValues (Map values) { + this.values = values; + this.cascadeCreate = false; + } + + public Map getValues() { + return this.values; + } + + /** + * @param cascadeCreate Sets whether the entity should be created if not present in the database. + */ + public SetValues setCascadeCreate(boolean cascadeCreate) { + this.cascadeCreate = cascadeCreate; + return this; + } + + public boolean getCascadeCreate() { + if (this.cascadeCreate==null) return false; + return this.cascadeCreate; + } + + /** + * @return Used HTTP method + */ + @Override + public HTTPMethod getHTTPMethod() { + return HTTPMethod.POST; + } + + /** + * Get query parameters + * @return Values of query parameters (name of parameter: value of the parameter) + */ + @Override + public Map getQueryParameters() { + return new HashMap(); + } + + /** + * Get body parameters + * @return Values of body parameters (name of parameter: value of the parameter) + */ + @Override + public Map getBodyParameters() { + + if(this.cascadeCreate) { + Map values = new HashMap(this.values); + values.put("!cascadeCreate", true); + return values; + } + + return this.values; + } +} diff --git a/src/main/java/com/recombee/api_client/api_requests/UserBasedRecommendation.java b/src/main/java/com/recombee/api_client/api_requests/UserBasedRecommendation.java index c753eea..715f79d 100644 --- a/src/main/java/com/recombee/api_client/api_requests/UserBasedRecommendation.java +++ b/src/main/java/com/recombee/api_client/api_requests/UserBasedRecommendation.java @@ -98,7 +98,7 @@ public class UserBasedRecommendation extends Request { */ protected Double rotationRate; /** - * **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. By example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. + * **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. For example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. */ protected Double rotationTime; @@ -228,7 +228,7 @@ public UserBasedRecommendation setRotationRate(double rotationRate) { } /** - * @param rotationTime **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. By example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. + * @param rotationTime **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. For example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour. */ public UserBasedRecommendation setRotationTime(double rotationTime) { this.rotationTime = rotationTime; diff --git a/src/test/java/com/recombee/api_client/AddUserPropertyBatchTest.java b/src/test/java/com/recombee/api_client/AddUserPropertyBatchTest.java new file mode 100644 index 0000000..2fa87cb --- /dev/null +++ b/src/test/java/com/recombee/api_client/AddUserPropertyBatchTest.java @@ -0,0 +1,39 @@ +package com.recombee.api_client; +/* + This file is auto-generated, do not edit +*/ + + +import com.recombee.api_client.api_requests.*; +import com.recombee.api_client.bindings.*; +import com.recombee.api_client.exceptions.ApiException; +import com.recombee.api_client.exceptions.ResponseException; + +import java.util.HashMap; +import java.util.Date; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +public class AddUserPropertyBatchTest extends RecombeeTestCase { + + @Test + public void testAddUserProperty() throws ApiException { + Request[] requests = new Request[] { + new AddUserProperty("number","int"), + new AddUserProperty("str","string"), + new AddUserProperty("prop","integer"), + new AddUserProperty("number2","int"), + new AddUserProperty("number2","int") + }; + + BatchResponse[] responses = this.client.send(new Batch(requests)); + assertEquals(201,responses[0].getStatusCode()); + assertEquals(201,responses[1].getStatusCode()); + assertEquals(400,responses[2].getStatusCode()); + assertEquals(201,responses[3].getStatusCode()); + assertEquals(409,responses[4].getStatusCode()); + } +} diff --git a/src/test/java/com/recombee/api_client/AddUserPropertyTest.java b/src/test/java/com/recombee/api_client/AddUserPropertyTest.java new file mode 100644 index 0000000..d4704fa --- /dev/null +++ b/src/test/java/com/recombee/api_client/AddUserPropertyTest.java @@ -0,0 +1,50 @@ +package com.recombee.api_client; +/* + This file is auto-generated, do not edit +*/ + + +import com.recombee.api_client.api_requests.*; +import com.recombee.api_client.bindings.*; +import com.recombee.api_client.exceptions.ApiException; +import com.recombee.api_client.exceptions.ResponseException; + +import java.util.HashMap; +import java.util.Date; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +public class AddUserPropertyTest extends RecombeeTestCase { + + @Test + public void testAddUserProperty() throws ApiException { + AddUserProperty req; + Request req2; + String resp; + // it 'does not fail with valid name and type' + req = new AddUserProperty("number","int"); + resp = this.client.send(req); + req = new AddUserProperty("str","string"); + resp = this.client.send(req); + // it 'fails with invalid type' + req = new AddUserProperty("prop","integer"); + try { + this.client.send(req); + fail("No exception thrown"); + } catch (ResponseException ex) { + assertEquals(400,ex.getStatusCode()); + } + // it 'really stores property to the system' + req = new AddUserProperty("number2","int"); + resp = this.client.send(req); + try { + this.client.send(req); + fail("No exception thrown"); + } catch (ResponseException ex) { + assertEquals(409,ex.getStatusCode()); + } + } +} diff --git a/src/test/java/com/recombee/api_client/BatchTest.java b/src/test/java/com/recombee/api_client/BatchTest.java new file mode 100644 index 0000000..531c2b6 --- /dev/null +++ b/src/test/java/com/recombee/api_client/BatchTest.java @@ -0,0 +1,49 @@ +package com.recombee.api_client; + +import com.recombee.api_client.api_requests.*; +import com.recombee.api_client.bindings.*; +import com.recombee.api_client.exceptions.ApiException; +import com.recombee.api_client.exceptions.ResponseException; + + +import java.util.ArrayList; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class BatchTest extends RecombeeTestCase { + + @Test + public void testLargeBatch() throws ApiException { + + this.client.send(new ResetDatabase()); + + final int NUM = 23650; + final int INDEX_LIST = 10005; + final int INDEX_WRONG_REQ = 21121; + + ArrayList requests = new ArrayList(); + for (int i = 0; i < NUM; i++) + requests.add(new AddItem(String.format("item-%s", i))); + + requests.set(INDEX_LIST, new ListItems()); + requests.set(INDEX_WRONG_REQ, new AddUser("žšřč")); + + BatchResponse[] responses = this.client.send(new Batch(requests)); + assertEquals(NUM, responses.length); + + for(int i=0;i) responses[0].getResponse()).get("int_property")); + assertEquals ("hello",((Map) responses[0].getResponse()).get("str_property")); + } +} diff --git a/src/test/java/com/recombee/api_client/GetUserValuesTest.java b/src/test/java/com/recombee/api_client/GetUserValuesTest.java new file mode 100644 index 0000000..b888cb6 --- /dev/null +++ b/src/test/java/com/recombee/api_client/GetUserValuesTest.java @@ -0,0 +1,22 @@ +package com.recombee.api_client; + +import com.recombee.api_client.api_requests.GetUserValues; +import com.recombee.api_client.exceptions.ApiException; +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class GetUserValuesTest extends RecombeeTestCase { + + @Test + public void testGetUserValues() throws ApiException { + GetUserValues req; + // it 'gets values' + req = new GetUserValues("entity_id"); + Map resp = this.client.send(req); + assertEquals (42,resp.get("int_property")); + assertEquals ("hello",resp.get("str_property")); + } +} diff --git a/src/test/java/com/recombee/api_client/ListUserPropertiesBatchTest.java b/src/test/java/com/recombee/api_client/ListUserPropertiesBatchTest.java new file mode 100644 index 0000000..4ce5a46 --- /dev/null +++ b/src/test/java/com/recombee/api_client/ListUserPropertiesBatchTest.java @@ -0,0 +1,32 @@ +package com.recombee.api_client; +/* + This file is auto-generated, do not edit +*/ + + +import com.recombee.api_client.api_requests.*; +import com.recombee.api_client.bindings.*; +import com.recombee.api_client.exceptions.ApiException; +import com.recombee.api_client.exceptions.ResponseException; + +import java.util.HashMap; +import java.util.Date; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +public class ListUserPropertiesBatchTest extends RecombeeTestCase { + + @Test + public void testListUserProperties() throws ApiException { + Request[] requests = new Request[] { + new ListUserProperties() + }; + + BatchResponse[] responses = this.client.send(new Batch(requests)); + assertEquals(200,responses[0].getStatusCode()); + assertEquals(2, ((PropertyInfo []) responses[0].getResponse()).length); + } +} diff --git a/src/test/java/com/recombee/api_client/ListUserPropertiesTest.java b/src/test/java/com/recombee/api_client/ListUserPropertiesTest.java new file mode 100644 index 0000000..556c302 --- /dev/null +++ b/src/test/java/com/recombee/api_client/ListUserPropertiesTest.java @@ -0,0 +1,32 @@ +package com.recombee.api_client; +/* + This file is auto-generated, do not edit +*/ + + +import com.recombee.api_client.api_requests.*; +import com.recombee.api_client.bindings.*; +import com.recombee.api_client.exceptions.ApiException; +import com.recombee.api_client.exceptions.ResponseException; + +import java.util.HashMap; +import java.util.Date; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +public class ListUserPropertiesTest extends RecombeeTestCase { + + @Test + public void testListUserProperties() throws ApiException { + ListUserProperties req; + Request req2; + PropertyInfo [] resp; + // it 'lists properties' + req = new ListUserProperties(); + resp = this.client.send(req); + assertEquals(2, resp.length); + } +} diff --git a/src/test/java/com/recombee/api_client/RecombeeTestCase.java b/src/test/java/com/recombee/api_client/RecombeeTestCase.java index 47c0536..27a68b9 100644 --- a/src/test/java/com/recombee/api_client/RecombeeTestCase.java +++ b/src/test/java/com/recombee/api_client/RecombeeTestCase.java @@ -33,6 +33,14 @@ public void setUp () throws ApiException { put("int_property", 42); put("str_property", "hello"); } + }), + new AddUserProperty("int_property", "int"), + new AddUserProperty("str_property", "string"), + new SetUserValues("entity_id", new HashMap() { + { + put("int_property", 42); + put("str_property", "hello"); + } }) }); diff --git a/src/test/java/com/recombee/api_client/SetItemValuesBatchTest.java b/src/test/java/com/recombee/api_client/SetItemValuesBatchTest.java index c9cbb03..29de2f1 100644 --- a/src/test/java/com/recombee/api_client/SetItemValuesBatchTest.java +++ b/src/test/java/com/recombee/api_client/SetItemValuesBatchTest.java @@ -26,6 +26,7 @@ public void testSetItemValues() throws ApiException { new SetItemValues("entity_id",new HashMap(){{put("str_property","šřžذ的‎");}}), new SetItemValues("entity_id",new HashMap(){{put("int_property",5);put("str_property","test");}}), new SetItemValues("new_entity",new HashMap(){{put("int_property",5);put("str_property","test");put("!cascadeCreate",true);}}), + new SetItemValues("new_entity2",new HashMap(){{put("int_property",5);put("str_property","test");}}).setCascadeCreate(true), new SetItemValues("nonexisting",new HashMap(){{put("int_property",5);}}) }; @@ -34,6 +35,7 @@ public void testSetItemValues() throws ApiException { assertEquals(200,responses[1].getStatusCode()); assertEquals(200,responses[2].getStatusCode()); assertEquals(200,responses[3].getStatusCode()); - assertEquals(404,responses[4].getStatusCode()); + assertEquals(200,responses[4].getStatusCode()); + assertEquals(404,responses[5].getStatusCode()); } } diff --git a/src/test/java/com/recombee/api_client/SetItemValuesTest.java b/src/test/java/com/recombee/api_client/SetItemValuesTest.java index 2161407..97efc0b 100644 --- a/src/test/java/com/recombee/api_client/SetItemValuesTest.java +++ b/src/test/java/com/recombee/api_client/SetItemValuesTest.java @@ -36,6 +36,9 @@ public void testSetItemValues() throws ApiException { // it 'does not fail with !cascadeCreate' req = new SetItemValues("new_entity",new HashMap(){{put("int_property",5);put("str_property","test");put("!cascadeCreate",true);}}); resp = this.client.send(req); + // it 'does not fail with cascadeCreate optional parameter' + req = new SetItemValues("new_entity2",new HashMap(){{put("int_property",5);put("str_property","test");}}).setCascadeCreate(true); + resp = this.client.send(req); // it 'fails with nonexisting entity' req = new SetItemValues("nonexisting",new HashMap(){{put("int_property",5);}}); try { diff --git a/src/test/java/com/recombee/api_client/SetUserValuesBatchTest.java b/src/test/java/com/recombee/api_client/SetUserValuesBatchTest.java new file mode 100644 index 0000000..651f832 --- /dev/null +++ b/src/test/java/com/recombee/api_client/SetUserValuesBatchTest.java @@ -0,0 +1,41 @@ +package com.recombee.api_client; +/* + This file is auto-generated, do not edit +*/ + + +import com.recombee.api_client.api_requests.*; +import com.recombee.api_client.bindings.*; +import com.recombee.api_client.exceptions.ApiException; +import com.recombee.api_client.exceptions.ResponseException; + +import java.util.HashMap; +import java.util.Date; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +public class SetUserValuesBatchTest extends RecombeeTestCase { + + @Test + public void testSetUserValues() throws ApiException { + Request[] requests = new Request[] { + new SetUserValues("entity_id",new HashMap(){{put("int_property",5);}}), + new SetUserValues("entity_id",new HashMap(){{put("str_property","šřžذ的‎");}}), + new SetUserValues("entity_id",new HashMap(){{put("int_property",5);put("str_property","test");}}), + new SetUserValues("new_entity",new HashMap(){{put("int_property",5);put("str_property","test");put("!cascadeCreate",true);}}), + new SetUserValues("new_entity2",new HashMap(){{put("int_property",5);put("str_property","test");}}).setCascadeCreate(true), + new SetUserValues("nonexisting",new HashMap(){{put("int_property",5);}}) + }; + + BatchResponse[] responses = this.client.send(new Batch(requests)); + assertEquals(200,responses[0].getStatusCode()); + assertEquals(200,responses[1].getStatusCode()); + assertEquals(200,responses[2].getStatusCode()); + assertEquals(200,responses[3].getStatusCode()); + assertEquals(200,responses[4].getStatusCode()); + assertEquals(404,responses[5].getStatusCode()); + } +} diff --git a/src/test/java/com/recombee/api_client/SetUserValuesTest.java b/src/test/java/com/recombee/api_client/SetUserValuesTest.java new file mode 100644 index 0000000..8e26473 --- /dev/null +++ b/src/test/java/com/recombee/api_client/SetUserValuesTest.java @@ -0,0 +1,51 @@ +package com.recombee.api_client; +/* + This file is auto-generated, do not edit +*/ + + +import com.recombee.api_client.api_requests.*; +import com.recombee.api_client.bindings.*; +import com.recombee.api_client.exceptions.ApiException; +import com.recombee.api_client.exceptions.ResponseException; + +import java.util.HashMap; +import java.util.Date; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +public class SetUserValuesTest extends RecombeeTestCase { + + @Test + public void testSetUserValues() throws ApiException { + SetUserValues req; + Request req2; + String resp; + // it 'does not fail with existing entity and property' + req = new SetUserValues("entity_id",new HashMap(){{put("int_property",5);}}); + resp = this.client.send(req); + // it 'does not fail with non-ASCII string' + req = new SetUserValues("entity_id",new HashMap(){{put("str_property","šřžذ的‎");}}); + resp = this.client.send(req); + // it 'sets multiple properties' + req = new SetUserValues("entity_id",new HashMap(){{put("int_property",5);put("str_property","test");}}); + resp = this.client.send(req); + // it 'does not fail with !cascadeCreate' + req = new SetUserValues("new_entity",new HashMap(){{put("int_property",5);put("str_property","test");put("!cascadeCreate",true);}}); + resp = this.client.send(req); + // it 'does not fail with cascadeCreate optional parameter' + req = new SetUserValues("new_entity2",new HashMap(){{put("int_property",5);put("str_property","test");}}).setCascadeCreate(true); + resp = this.client.send(req); + // it 'fails with nonexisting entity' + req = new SetUserValues("nonexisting",new HashMap(){{put("int_property",5);}}); + try { + this.client.send(req); + fail("No exception thrown"); + } catch (ResponseException ex) { + assertEquals(404,ex.getStatusCode()); + } + } +}