Skip to content

Commit 292270c

Browse files
esezenclaudeCopilot
authored
[CDX-286] Add active field to ConstructorItem and ConstructorVariation (#171)
* Add active field to ConstructorItem and ConstructorVariation Add Boolean active field to ConstructorItem and ConstructorVariation classes to support marking items and variations as active/inactive. Include getter/setter methods and ensure the field is properly serialized in the toMap() method. Add comprehensive tests verifying that: - Active field is included in serialized output when set - Active field defaults to null when not set - Getter/setter methods work correctly for both true and false values 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update constructorio-client/src/main/java/io/constructor/client/ConstructorVariation.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update constructorio-client/src/main/java/io/constructor/client/ConstructorVariation.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Lint * Update version tests --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 83b0cef commit 292270c

7 files changed

Lines changed: 104 additions & 16 deletions

File tree

constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ConstructorItem {
1414
private String imageUrl;
1515
private String id;
1616
private String description;
17+
private Boolean active;
1718
private Map<String, List<Object>> facets;
1819
private Map<String, Object> metadata;
1920
private List<String> groupIds;
@@ -37,6 +38,7 @@ public ConstructorItem(String id, String name) throws IllegalArgumentException {
3738
this.url = null;
3839
this.imageUrl = null;
3940
this.description = null;
41+
this.active = null;
4042
this.facets = null;
4143
this.metadata = null;
4244
this.groupIds = null;
@@ -54,6 +56,7 @@ public ConstructorItem(String id) throws IllegalArgumentException {
5456
this.url = null;
5557
this.imageUrl = null;
5658
this.description = null;
59+
this.active = null;
5760
this.facets = null;
5861
this.metadata = null;
5962
this.groupIds = null;
@@ -82,6 +85,7 @@ public Map<String, Object> toMap() {
8285
dataMap.put("facets", this.facets);
8386
dataMap.put("group_ids", this.groupIds);
8487
dataMap.put("description", this.description);
88+
dataMap.put("active", this.active);
8589
params.put("data", dataMap);
8690

8791
return params;
@@ -171,6 +175,20 @@ public void setDescription(String description) {
171175
this.description = description;
172176
}
173177

178+
/**
179+
* @return the active status of the item
180+
*/
181+
public Boolean getActive() {
182+
return active;
183+
}
184+
185+
/**
186+
* @param active the active status to set for the item
187+
*/
188+
public void setActive(Boolean active) {
189+
this.active = active;
190+
}
191+
174192
/**
175193
* @return the id
176194
*/

constructorio-client/src/main/java/io/constructor/client/ConstructorVariation.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ public class ConstructorVariation {
1515
private String id;
1616
private String itemId;
1717
private String description;
18+
private Boolean active;
1819
private Map<String, List<Object>> facets;
1920
private Map<String, Object> metadata;
2021
private List<String> groupIds;
2122

2223
/**
2324
* Creates a variation. Optional public fields are in the <a
24-
* href="https://docs.constructor.com/docs/integrating-with-constructor-product-catalog-items-variations">API documentation</a>
25+
* href="https://docs.constructor.com/docs/integrating-with-constructor-product-catalog-items-variations">API
26+
* documentation</a>
2527
*
2628
* @param id the id of the variation that you are adding.
2729
* @param itemId the id of the item this variation is attached to.
@@ -45,6 +47,7 @@ public ConstructorVariation(String id, String itemId, String name)
4547
this.url = null;
4648
this.imageUrl = null;
4749
this.description = null;
50+
this.active = null;
4851
this.facets = null;
4952
this.metadata = null;
5053
this.groupIds = null;
@@ -67,6 +70,7 @@ public ConstructorVariation(String id, String itemId) throws IllegalArgumentExce
6770
this.url = null;
6871
this.imageUrl = null;
6972
this.description = null;
73+
this.active = null;
7074
this.facets = null;
7175
this.metadata = null;
7276
this.groupIds = null;
@@ -85,6 +89,7 @@ public ConstructorVariation(String id) throws IllegalArgumentException {
8589
this.url = null;
8690
this.imageUrl = null;
8791
this.description = null;
92+
this.active = null;
8893
this.facets = null;
8994
this.metadata = null;
9095
this.groupIds = null;
@@ -114,6 +119,7 @@ public Map<String, Object> toMap() {
114119
dataMap.put("facets", this.facets);
115120
dataMap.put("group_ids", this.groupIds);
116121
dataMap.put("description", this.description);
122+
dataMap.put("active", this.active);
117123
params.put("data", dataMap);
118124

119125
return params;
@@ -203,6 +209,20 @@ public void setDescription(String description) {
203209
this.description = description;
204210
}
205211

212+
/**
213+
* @return the active status of the variation
214+
*/
215+
public Boolean getActive() {
216+
return active;
217+
}
218+
219+
/**
220+
* @param active the active status to set for the variation
221+
*/
222+
public void setActive(Boolean active) {
223+
this.active = active;
224+
}
225+
206226
/**
207227
* @return the id
208228
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void AutocompleteWithPlusShouldBeEncodedInUrl() throws Exception {
4242

4343
RecordedRequest recordedRequest = mockServer.takeRequest();
4444
String expectedPath =
45-
String.format("/autocomplete/r%%2Bco?key=%s&c=ciojava-7.0.0", apiKey);
45+
String.format("/autocomplete/r%%2Bco?key=%s&c=ciojava-7.1.0", apiKey);
4646
String actualPath = recordedRequest.getPath();
4747
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
4848
}
@@ -60,7 +60,7 @@ public void AutocompleteWithSpaceShouldBeEncodedInUrl() throws Exception {
6060

6161
RecordedRequest recordedRequest = mockServer.takeRequest();
6262
String expectedPath =
63-
String.format("/autocomplete/r%%20co?key=%s&c=ciojava-7.0.0", apiKey);
63+
String.format("/autocomplete/r%%20co?key=%s&c=ciojava-7.1.0", apiKey);
6464
String actualPath = recordedRequest.getPath();
6565
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
6666
}
@@ -78,7 +78,7 @@ public void AutocompleteWithSlashShouldBeEncodedInUrl() throws Exception {
7878

7979
RecordedRequest recordedRequest = mockServer.takeRequest();
8080
String expectedPath =
81-
String.format("/autocomplete/r%%2Fco?key=%s&c=ciojava-7.0.0", apiKey);
81+
String.format("/autocomplete/r%%2Fco?key=%s&c=ciojava-7.1.0", apiKey);
8282
String actualPath = recordedRequest.getPath();
8383
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
8484
}
@@ -95,7 +95,7 @@ public void AutocompleteWithSingleQuoteShouldBeAllowedInUrl() throws Exception {
9595
constructor.autocomplete(request, null);
9696

9797
RecordedRequest recordedRequest = mockServer.takeRequest();
98-
String expectedPath = String.format("/autocomplete/r'co?key=%s&c=ciojava-7.0.0", apiKey);
98+
String expectedPath = String.format("/autocomplete/r'co?key=%s&c=ciojava-7.1.0", apiKey);
9999
String actualPath = recordedRequest.getPath();
100100
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
101101
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void makeUrlShouldReturnAUrl() throws Exception {
143143
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"));
144144
assertEquals("host is set", url.host(), "ac.cnstrc.com");
145145
assertEquals("protocol is set", url.scheme(), "https");
146-
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
146+
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
147147
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
148148
}
149149

@@ -160,7 +160,7 @@ public void makeUrlWithBasePathShouldReturnAUrl() throws Exception {
160160
assertEquals("Path is correct", url.encodedPath(), "/123/2345/getitUuuurl");
161161
assertEquals("host is set", url.host(), "ac.cnstrc.com");
162162
assertEquals("protocol is set", url.scheme(), "https");
163-
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
163+
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
164164
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
165165
}
166166

@@ -179,7 +179,7 @@ public void makeUrlWithBasePathAndUserInfoShouldReturnAUrl() throws Exception {
179179
assertEquals("Path is correct", url.encodedPath(), "/123/2345/getitUuuurl");
180180
assertEquals("host is set", url.host(), "ac.cnstrc.com");
181181
assertEquals("protocol is set", url.scheme(), "https");
182-
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
182+
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
183183
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
184184
}
185185

@@ -190,7 +190,7 @@ public void makeUrlWithUserIdShouldReturnAUrl() throws Exception {
190190
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"), info);
191191
assertEquals("host is set", url.host(), "ac.cnstrc.com");
192192
assertEquals("protocol is set", url.scheme(), "https");
193-
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
193+
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
194194
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
195195
assertEquals("session id is set", url.queryParameter("s"), "2");
196196
assertEquals("client id is set", url.queryParameter("i"), "sideshow bob");
@@ -205,7 +205,7 @@ public void makeUrlWithUserInfoShouldReturnAUrl() throws Exception {
205205
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"), info);
206206
assertEquals("host is set", url.host(), "ac.cnstrc.com");
207207
assertEquals("protocol is set", url.scheme(), "https");
208-
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
208+
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
209209
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
210210
assertEquals("session id is set", url.queryParameter("s"), "2");
211211
assertEquals("client id is set", url.queryParameter("i"), "sideshow bob");
@@ -220,7 +220,7 @@ public void makeUrlWithUserSegmentsShouldReturnAUrl() throws Exception {
220220
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"), info);
221221
assertEquals("host is set", url.host(), "ac.cnstrc.com");
222222
assertEquals("protocol is set", url.scheme(), "https");
223-
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
223+
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
224224
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
225225
assertEquals("session id is set", url.queryParameter("s"), "2");
226226
assertEquals("client id is set", url.queryParameter("i"), "sideshow bob");
@@ -238,7 +238,7 @@ public void verifyShouldReturnTrueWithValidKeyTokenPair() throws Exception {
238238
@Test
239239
public void getVersionShouldReturnClientVersion() throws Exception {
240240
ConstructorIO constructor = new ConstructorIO(token, apiKey, true, null);
241-
assertEquals("grabs version from pom.xml", constructor.getVersion(), "ciojava-7.0.0");
241+
assertEquals("grabs version from pom.xml", constructor.getVersion(), "ciojava-7.1.0");
242242
}
243243

244244
@Test

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void SearchWithPlusShouldBeEncodedInUrl() throws Exception {
4343
RecordedRequest recordedRequest = mockServer.takeRequest();
4444
String expectedPath =
4545
String.format(
46-
"/search/r%%2Bco?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
46+
"/search/r%%2Bco?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
4747
apiKey);
4848
String actualPath = recordedRequest.getPath();
4949
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
@@ -63,7 +63,7 @@ public void SearchWithSpaceShouldBeEncodedInUrl() throws Exception {
6363
RecordedRequest recordedRequest = mockServer.takeRequest();
6464
String expectedPath =
6565
String.format(
66-
"/search/r%%20co?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
66+
"/search/r%%20co?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
6767
apiKey);
6868
String actualPath = recordedRequest.getPath();
6969
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
@@ -83,7 +83,7 @@ public void SearchWithSlashShouldBeEncodedInUrl() throws Exception {
8383
RecordedRequest recordedRequest = mockServer.takeRequest();
8484
String expectedPath =
8585
String.format(
86-
"/search/r%%2Fco?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
86+
"/search/r%%2Fco?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
8787
apiKey);
8888
String actualPath = recordedRequest.getPath();
8989
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
@@ -103,7 +103,7 @@ public void SearchWithSingleQuoteShouldBeAllowedInUrl() throws Exception {
103103
RecordedRequest recordedRequest = mockServer.takeRequest();
104104
String expectedPath =
105105
String.format(
106-
"/search/r'co?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
106+
"/search/r'co?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
107107
apiKey);
108108
String actualPath = recordedRequest.getPath();
109109
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void newShouldReturnDefaultProperties() throws Exception {
4343
assertEquals(item.getUrl(), null);
4444
assertEquals(item.getImageUrl(), null);
4545
assertEquals(item.getDescription(), null);
46+
assertEquals(item.getActive(), null);
4647
assertEquals(item.getId(), itemName);
4748
assertEquals(item.getFacets(), null);
4849
assertEquals(item.getGroupIds(), null);
@@ -60,6 +61,7 @@ public void settersShouldSet() throws Exception {
6061
item.setUrl("https://constructor.io/test");
6162
item.setImageUrl("https://constructor.io/test.png");
6263
item.setDescription("See the world!");
64+
item.setActive(true);
6365
item.setId("TICK-007");
6466
item.setGroupIds(Arrays.asList("Lucky Tickets", "Special Tickets", "Fancy Tickets"));
6567

@@ -69,6 +71,7 @@ public void settersShouldSet() throws Exception {
6971
assertEquals(item.getUrl(), "https://constructor.io/test");
7072
assertEquals(item.getImageUrl(), "https://constructor.io/test.png");
7173
assertEquals(item.getDescription(), "See the world!");
74+
assertEquals(item.getActive(), true);
7275
assertEquals(item.getId(), "TICK-007");
7376
assertEquals(item.getFacets(), null);
7477
assertEquals(item.getMetadata(), null);
@@ -97,4 +100,25 @@ public void toMapShouldHaveADataObject() throws Exception {
97100
assertEquals(metadataFields.get("image_url"), "https://constructor.io/test.png");
98101
assertEquals(metadataFields.get("test_field"), "test");
99102
}
103+
104+
@Test
105+
public void toMapShouldIncludeActiveWhenSet() throws Exception {
106+
String itemName = this.getRandomProductName();
107+
String itemId = itemName;
108+
ConstructorItem item = new ConstructorItem(itemId, itemName);
109+
item.setActive(true);
110+
111+
Map<String, Object> dataFields = (Map<String, Object>) item.toMap().get("data");
112+
assertEquals(dataFields.get("active"), true);
113+
}
114+
115+
@Test
116+
public void toMapShouldIncludeActiveAsNullWhenNotSet() throws Exception {
117+
String itemName = this.getRandomProductName();
118+
String itemId = itemName;
119+
ConstructorItem item = new ConstructorItem(itemId, itemName);
120+
121+
Map<String, Object> dataFields = (Map<String, Object>) item.toMap().get("data");
122+
assertEquals(dataFields.get("active"), null);
123+
}
100124
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void newShouldReturnDefaultProperties() throws Exception {
4747
assertEquals(variation.getUrl(), null);
4848
assertEquals(variation.getImageUrl(), null);
4949
assertEquals(variation.getDescription(), null);
50+
assertEquals(variation.getActive(), null);
5051
assertEquals(variation.getId(), variationName);
5152
assertEquals(variation.getItemId(), itemId);
5253
assertEquals(variation.getFacets(), null);
@@ -67,6 +68,7 @@ public void settersShouldSet() throws Exception {
6768
variation.setUrl("https://constructor.io/test");
6869
variation.setImageUrl("https://constructor.io/test.png");
6970
variation.setDescription("See the world!");
71+
variation.setActive(false);
7072
variation.setId("TICK-007");
7173
variation.setItemId("TICK");
7274
variation.setGroupIds(Arrays.asList("Lucky Tickets", "Special Tickets", "Fancy Tickets"));
@@ -77,6 +79,7 @@ public void settersShouldSet() throws Exception {
7779
assertEquals(variation.getUrl(), "https://constructor.io/test");
7880
assertEquals(variation.getImageUrl(), "https://constructor.io/test.png");
7981
assertEquals(variation.getDescription(), "See the world!");
82+
assertEquals(variation.getActive(), false);
8083
assertEquals(variation.getId(), "TICK-007");
8184
assertEquals(variation.getItemId(), "TICK");
8285
assertEquals(variation.getFacets(), null);
@@ -108,4 +111,27 @@ public void toMapShouldHaveADataObject() throws Exception {
108111
assertEquals(metadataFields.get("image_url"), "https://constructor.io/test.png");
109112
assertEquals(metadataFields.get("test_field"), "test");
110113
}
114+
115+
@Test
116+
public void toMapShouldIncludeActiveWhenSet() throws Exception {
117+
String variationName = this.getRandomProductName();
118+
String itemId = this.getRandomProductName();
119+
ConstructorVariation variation =
120+
new ConstructorVariation(variationName, itemId, variationName);
121+
variation.setActive(false);
122+
123+
Map<String, Object> dataFields = (Map<String, Object>) variation.toMap().get("data");
124+
assertEquals(dataFields.get("active"), false);
125+
}
126+
127+
@Test
128+
public void toMapShouldIncludeActiveAsNullWhenNotSet() throws Exception {
129+
String variationName = this.getRandomProductName();
130+
String itemId = this.getRandomProductName();
131+
ConstructorVariation variation =
132+
new ConstructorVariation(variationName, itemId, variationName);
133+
134+
Map<String, Object> dataFields = (Map<String, Object>) variation.toMap().get("data");
135+
assertEquals(dataFields.get("active"), null);
136+
}
111137
}

0 commit comments

Comments
 (0)