Skip to content

Commit 3ebceaa

Browse files
authored
Add options (#158)
1 parent 736b732 commit 3ebceaa

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

constructorio-client/src/main/java/io/constructor/client/models/FilterFacetOption.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.constructor.client.models;
22

33
import com.google.gson.annotations.SerializedName;
4+
5+
import java.util.List;
46
import java.util.Map;
57

68
/** Constructor.io Filter Facet Option ... uses Gson/Reflection to load data in */
@@ -24,6 +26,9 @@ public class FilterFacetOption {
2426
@SerializedName("range")
2527
private Object[] range; // Array to hold two values of either Number or "inf", "-inf"
2628

29+
@SerializedName("options")
30+
private List<FilterFacetOption> options;
31+
2732
/**
2833
* @return the counts
2934
*/
@@ -66,6 +71,13 @@ public Object[] getRange() {
6671
return range;
6772
}
6873

74+
/**
75+
* @return the options
76+
*/
77+
public List<FilterFacetOption> getOptions() {
78+
return options;
79+
}
80+
6981
public void setCount(Integer count) {
7082
this.count = count;
7183
}
@@ -89,4 +101,8 @@ public void setValue(String value) {
89101
public void setRange(Object[] range) {
90102
this.range = range;
91103
}
104+
105+
public void setOptions(List<FilterFacetOption> options) {
106+
this.options = options;
107+
}
92108
}

constructorio-client/src/test/java/io/constructor/client/FiltersTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public void rangeFacet() throws Exception {
5757
assertEquals(facet.getStatus().size(), 0);
5858
}
5959

60+
@Test
61+
public void hierarchicalFacet() throws Exception {
62+
String string = Utils.getTestResource("facet.hierarchical.json");
63+
FilterFacet facet = new Gson().fromJson(string, FilterFacet.class);
64+
assertEquals(facet.getDisplayName(), "Size");
65+
assertEquals(facet.getName(), "Size");
66+
assertEquals(facet.getType(), "hierarchical");
67+
assertEquals(facet.getOptions().get(0).getValue(), "Mens");
68+
assertEquals(facet.getOptions().get(0).getOptions().get(0), "Mens/Small");
69+
assertNull(facet.getMax());
70+
assertNull(facet.getMin());
71+
assertNull(facet.getStatus());
72+
}
73+
6074
@Test
6175
public void rangeFacetSelected() throws Exception {
6276
String string = Utils.getTestResource("facet.range.selected.json");
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"display_name": "Size",
3+
"name": "Size",
4+
"options": [
5+
{
6+
"count": 5,
7+
"data": {},
8+
"display_name": "Mens",
9+
"status": "",
10+
"value": "Mens",
11+
"options": [
12+
{
13+
"count": 5,
14+
"data": {},
15+
"display_name": "Small",
16+
"status": "",
17+
"value": "Mens/Small"
18+
}
19+
]
20+
},
21+
{
22+
"count": 4,
23+
"data": {},
24+
"display_name": "Womens",
25+
"status": "",
26+
"value": "Womens",
27+
"options": [
28+
{
29+
"count": 4,
30+
"data": {},
31+
"display_name": "Medium",
32+
"status": "",
33+
"value": "Womens/Medium"
34+
}
35+
]
36+
}
37+
],
38+
"type": "hierarchical"
39+
}

0 commit comments

Comments
 (0)