Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ request.setSortBy("Price");
request.setSortAscending(true);
request.getFacets().put("Brand", Arrays.asList("Jif"))

// Add the following paramaters to request for hidden fields or facets
request.getHiddenFields().add("hidden_price_field");
request.getHiddenFacets().add("hidden_brand_facet");

// Create a UserInfo object with the session and unique device identifier (optional)
UserInfo userInfo = new UserInfo(5, "device-id-1123123");
userInfo.setUserSegments(Arrays.asList("Desktop", "Chrome"));
Expand Down Expand Up @@ -205,6 +209,10 @@ request.setSortBy("Price");
request.setSortAscending(true);
request.getFacets().put("Brand", Arrays.asList("Jif"))

// Add the following paramaters to request for hidden fields or facets
request.getHiddenFields().add("hidden_price_field");
request.getHiddenFacets().add("hidden_brand_facet");

// Create a UserInfo object with the session and unique device identifier (optional)
UserInfo userInfo = new UserInfo(5, "device-id-1123123");
userInfo.setUserSegments(Arrays.asList("Desktop", "Chrome"));
Expand Down Expand Up @@ -248,6 +256,10 @@ request.setSortBy("Price");
request.setSortAscending(true);
request.getFacets().put("Brand", Arrays.asList("Jif"))

// Add the following paramaters to request for hidden fields or facets
request.getHiddenFields().add("hidden_price_field");
request.getHiddenFacets().add("hidden_brand_facet");

// Create a UserInfo object with the session and unique device identifier (optional)
UserInfo userInfo = new UserInfo(5, "device-id-1123123");
userInfo.setUserSegments(Arrays.asList("Desktop", "Chrome"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class BrowseItemsRequest {
private boolean sortAscending;
private Map<String, String>formatOptions;
private List<String> hiddenFields;
private List<String> hiddenFacets;

/**
* Creates a browse request
Expand All @@ -39,6 +40,7 @@ public BrowseItemsRequest(List<String> ids) throws IllegalArgumentException {
this.sortAscending = true;
this.formatOptions = new HashMap<String, String>();
this.hiddenFields = new ArrayList<String>();
this.hiddenFacets = new ArrayList<String>();
}

/**
Expand Down Expand Up @@ -171,13 +173,27 @@ public Map<String, String> getFormatOptions() {
* @param hiddenFields the hiddenFields to set
*/
public void setHiddenFields(List<String> hiddenFields) {
this.hiddenFields = hiddenFields;
this.hiddenFields = hiddenFields;
}

/**
* @return the hidden fields
*/
public List<String> getHiddenFields() {
return hiddenFields;
return hiddenFields;
}

/**
* @param hiddenFacets the hiddenFacets to set
*/
public void setHiddenFacets(List<String> hiddenFacets) {
this.hiddenFacets = hiddenFacets;
}

/**
* @return the hidden facets
*/
public List<String> getHiddenFacets() {
return hiddenFacets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BrowseRequest {
private boolean sortAscending;
private Map<String, String>formatOptions;
private List<String> hiddenFields;
private List<String> hiddenFacets;

/**
* Creates a browse request
Expand All @@ -45,6 +46,7 @@ public BrowseRequest(String filterName, String filterValue) throws IllegalArgume
this.sortAscending = true;
this.formatOptions = new HashMap<String, String>();
this.hiddenFields = new ArrayList<String>();
this.hiddenFacets = new ArrayList<String>();
}

/**
Expand Down Expand Up @@ -200,4 +202,18 @@ public void setHiddenFields(List<String> hiddenFields) {
public List<String> getHiddenFields() {
return hiddenFields;
}

/**
* @param hiddenFacets the hiddenFacets to set
*/
public void setHiddenFacets(List<String> hiddenFacets) {
this.hiddenFacets = hiddenFacets;
}

/**
* @return the hidden facets
*/
public List<String> getHiddenFacets() {
return hiddenFacets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,13 @@ protected Request createSearchRequest(SearchRequest req, UserInfo userInfo) thro

for (String hiddenField : req.getHiddenFields()) {
url = url.newBuilder()
.addQueryParameter("hidden_fields", hiddenField)
.addQueryParameter("fmt_options[hidden_fields]", hiddenField)
.build();
}

for (String hiddenFacet : req.getHiddenFacets()) {
url = url.newBuilder()
.addQueryParameter("fmt_options[hidden_facets]", hiddenFacet)
.build();
}

Expand Down Expand Up @@ -638,7 +644,13 @@ protected Request createBrowseRequest(BrowseRequest req, UserInfo userInfo) thro

for (String hiddenField : req.getHiddenFields()) {
url = url.newBuilder()
.addQueryParameter("hidden_fields", hiddenField)
.addQueryParameter("fmt_options[hidden_fields]", hiddenField)
.build();
}

for (String hiddenFacet : req.getHiddenFacets()) {
url = url.newBuilder()
.addQueryParameter("fmt_options[hidden_facets]", hiddenFacet)
.build();
}

Expand Down Expand Up @@ -793,8 +805,14 @@ protected Request createBrowseItemsRequest(BrowseItemsRequest req, UserInfo user

for (String hiddenField : req.getHiddenFields()) {
url = url.newBuilder()
.addQueryParameter("hidden_fields", hiddenField)
.build();
.addQueryParameter("fmt_options[hidden_fields]", hiddenField)
.build();
}

for (String hiddenFacet : req.getHiddenFacets()) {
url = url.newBuilder()
.addQueryParameter("fmt_options[hidden_facets]", hiddenFacet)
.build();
}

Request request = this.makeUserRequestBuilder(userInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class SearchRequest {
private String collectionId;
private Map<String, String>formatOptions;
private List<String> hiddenFields;
private List<String> hiddenFacets;

/**
* Creates a search request
Expand All @@ -40,6 +41,7 @@ public SearchRequest(String query) throws IllegalArgumentException {
this.sortAscending = true;
this.formatOptions = new HashMap<String, String>();
this.hiddenFields = new ArrayList<String>();
this.hiddenFacets = new ArrayList<String>();
}

/**
Expand Down Expand Up @@ -195,4 +197,18 @@ public void setHiddenFields(List<String> hiddenFields) {
public List<String> getHiddenFields() {
return hiddenFields;
}

/**
* @param hiddenFacets the hiddenFacets to set
*/
public void setHiddenFacets(List<String> hiddenFacets) {
this.hiddenFacets = hiddenFacets;
}

/**
* @return the hidden facets
*/
public List<String> getHiddenFacets() {
return hiddenFacets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void settersShouldSet() throws Exception {
Map<String, String> formatOptions = new HashMap<String, String>();
formatOptions.put("groups_start", "top");
List<String> hiddenFields = Arrays.asList("hiddenField1", "hiddenField2");
List<String> hiddenFacets = Arrays.asList("hiddenFacet1", "hiddenFacet2");

request.setIds(newIds);
request.setSection("Browse Suggestions");
Expand All @@ -58,6 +59,7 @@ public void settersShouldSet() throws Exception {
request.setSortAscending(false);
request.setFormatOptions(formatOptions);
request.setHiddenFields(hiddenFields);
request.setHiddenFacets(hiddenFacets);

assertEquals(request.getIds(), newIds);
assertEquals(request.getSection(), "Browse Suggestions");
Expand All @@ -69,5 +71,6 @@ public void settersShouldSet() throws Exception {
assertEquals(request.getSortAscending(), false);
assertEquals(request.getFormatOptions(), formatOptions);
assertEquals(request.getHiddenFields(), hiddenFields);
assertEquals(request.getHiddenFacets(), hiddenFacets);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void settersShouldSet() throws Exception {
Map<String, String> formatOptions = new HashMap<String, String>();
formatOptions.put("groups_start", "top");
List<String> hiddenFields = Arrays.asList("hiddenField1", "hiddenField2");
List<String> hiddenFacets = Arrays.asList("hiddenFacet1", "hiddenFacet2");

request.setFilterName("VacationType");
request.setFilterValue("Air Travel");
Expand All @@ -71,6 +72,7 @@ public void settersShouldSet() throws Exception {
request.setSortAscending(false);
request.setFormatOptions(formatOptions);
request.setHiddenFields(hiddenFields);
request.setHiddenFacets(hiddenFacets);

assertEquals(request.getFilterName(), "VacationType");
assertEquals(request.getFilterValue(), "Air Travel");
Expand All @@ -83,5 +85,7 @@ public void settersShouldSet() throws Exception {
assertEquals(request.getSortAscending(), false);
assertEquals(request.getFormatOptions(), formatOptions);
assertEquals(request.getHiddenFields(), hiddenFields);
assertEquals(request.getHiddenFacets(), hiddenFacets);

}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.constructor.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import io.constructor.client.models.BrowseResponse;
import io.constructor.client.models.FilterFacet;
import io.constructor.client.models.FilterGroup;

public class ConstructorIOBrowseItemsTest {
Expand Down Expand Up @@ -198,4 +201,25 @@ public void BrowseItemsShouldReturnAResultWithHiddenFields() throws Exception {
assertTrue("browse items result id exists", response.getResultId() != null);
assertEquals("browse items [testField] exists", response.getResponse().getResults().get(0).getData().getMetadata().get("testField"), "hiddenFieldValue");
}

@Test
public void BrowseItemsShouldReturnAResultWithHiddenFacets() throws Exception {
ConstructorIO constructor = new ConstructorIO("", apiKey, true, null);
UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie");
List<String> ids = Arrays.asList("10001", "10002");
BrowseItemsRequest request = new BrowseItemsRequest(ids);
request.getHiddenFacets().add("Brand");
BrowseResponse response = constructor.browseItems(request, userInfo);
FilterFacet brandFacet = response.getResponse().getFacets().stream().filter(new Predicate<FilterFacet>() {
@Override
public boolean test(FilterFacet f) {
return f.getName().equals("Brand");
}
}).findAny().orElse(null);

assertTrue("browse items results exist", response.getResponse().getResults().size() > 0);
assertTrue("browse items total results count should be equal to length of supplied ids", (int)response.getResponse().getTotalNumberOfResults() == ids.size());
assertTrue("browse items result id exists", response.getResultId() != null);
assertNotNull("browse facet [Brand] exists", brandFacet);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.constructor.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.function.Predicate;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import io.constructor.client.models.BrowseResponse;
import io.constructor.client.models.FilterGroup;
import io.constructor.client.models.FilterFacet;

public class ConstructorIOBrowseTest {

Expand Down Expand Up @@ -197,4 +200,22 @@ public void BrowseShouldReturnAResultWithHiddenFields() throws Exception {
assertEquals("browse results exist", response.getResponse().getResults().size(), 1);
assertEquals("browse result [testField] exists", response.getResponse().getResults().get(0).getData().getMetadata().get("testField"), "hiddenFieldValue");
}

@Test
public void BrowseShouldReturnAResultWithHiddenFacets() throws Exception {
ConstructorIO constructor = new ConstructorIO("", apiKey, true, null);
UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie");
BrowseRequest request = new BrowseRequest("Brand", "XYZ");
request.getHiddenFacets().add("Brand");
BrowseResponse response = constructor.browse(request, userInfo);
FilterFacet brandFacet = response.getResponse().getFacets().stream().filter(new Predicate<FilterFacet>() {
@Override
public boolean test(FilterFacet f) {
return f.getName().equals("Brand");
}
}).findAny().orElse(null);

assertEquals("browse results exist", response.getResponse().getResults().size(), 1);
assertNotNull("browse facet [Brand] exists", brandFacet);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package io.constructor.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;

import java.util.Arrays;
import java.util.function.Predicate;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import io.constructor.client.models.FilterFacet;
import io.constructor.client.models.FilterGroup;
import io.constructor.client.models.SearchResponse;

Expand Down Expand Up @@ -201,6 +204,25 @@ public void SearchShouldReturnAResultWithHiddenFields() throws Exception {
assertEquals("search result [testField] exists", response.getResponse().getResults().get(0).getData().getMetadata().get("testField"), "hiddenFieldValue");
}

@Test
public void SearchShouldReturnAResultWithHiddenFacets() throws Exception {
ConstructorIO constructor = new ConstructorIO("", apiKey, true, null);
UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie");
SearchRequest request = new SearchRequest("item1");
request.getHiddenFacets().add("Brand");

SearchResponse response = constructor.search(request, userInfo);
FilterFacet brandFacet = response.getResponse().getFacets().stream().filter(new Predicate<FilterFacet>() {
@Override
public boolean test(FilterFacet f) {
return f.getName().equals("Brand");
}
}).findAny().orElse(null);

assertEquals("search results exist", response.getResponse().getResults().size(), 9);
assertNotNull("search facet [Brand] exists", brandFacet);
}

@Test
public void SearchShouldReturnAResultWithResultSources() throws Exception {
ConstructorIO constructor = new ConstructorIO("", apiKey, true, null);
Expand Down
Loading