Skip to content

Commit 7f26fa1

Browse files
committed
Add collection update API.
1 parent a70db00 commit 7f26fa1

File tree

5 files changed

+169
-6
lines changed

5 files changed

+169
-6
lines changed

src/main/java/org/typesense/api/ApiCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ <T, R> T put(String endpoint, R body, Class<T> resourceClass) throws Exception {
171171
return makeRequest(endpoint, r, resourceClass);
172172
}
173173

174-
<T, R> T patch(String endpoint, R body) throws Exception {
174+
<T, R> T patch(String endpoint, R body, Class<T> resourceClass) throws Exception {
175175

176176
RequestHandler r = (String REST_URI) -> this.client.target(REST_URI)
177177
.request(MediaType.APPLICATION_JSON)
178178
.header(API_KEY_HEADER, apiKey)
179179
.build("PATCH", Entity.entity(body, MediaType.APPLICATION_JSON))
180180
.invoke();
181181

182-
return makeRequest(endpoint, r, null);
182+
return makeRequest(endpoint, r, resourceClass);
183183
}
184184

185185

src/main/java/org/typesense/api/Collection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.typesense.api.exceptions.TypesenseError;
44
import org.typesense.model.CollectionResponse;
5+
import org.typesense.model.CollectionUpdateSchema;
56

67
import java.util.HashMap;
78

@@ -41,6 +42,10 @@ public CollectionResponse retrieve() throws Exception {
4142
return this.apiCall.get(endpoint, CollectionResponse.class);
4243
}
4344

45+
public CollectionUpdateSchema update(CollectionUpdateSchema c) throws Exception {
46+
return this.apiCall.patch(endpoint, c, CollectionUpdateSchema.class);
47+
}
48+
4449
public CollectionResponse delete() throws Exception {
4550
return this.apiCall.delete(endpoint,CollectionResponse.class);
4651
}

src/main/java/org/typesense/api/Document.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ public class Document {
1818
this.endpoint = Collections.RESOURCE_PATH + "/" + this.collectionName + Documents.RESOURCE_PATH + "/" + this.documentId;
1919
}
2020

21-
HashMap<String,Object> retrieve() throws Exception {
21+
public HashMap<String,Object> retrieve() throws Exception {
2222
return this.apiCall.get(endpoint);
2323
}
2424

25-
HashMap<String, Object> delete() throws Exception {
25+
public HashMap<String, Object> delete() throws Exception {
2626
return this.apiCall.delete(this.endpoint);
2727
}
2828

29-
HashMap<String , Object> update(HashMap<String, Object> document) throws Exception {
30-
return this.apiCall.patch(this.endpoint, document);
29+
public HashMap<String , Object> update(HashMap<String, Object> document) throws Exception {
30+
return this.apiCall.patch(this.endpoint, document, HashMap.class);
3131
}
3232

3333
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.typesense.model;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.typesense.model.Field;
6+
7+
import io.swagger.v3.oas.annotations.media.Schema;
8+
import javax.xml.bind.annotation.XmlElement;
9+
import javax.xml.bind.annotation.XmlRootElement;
10+
import javax.xml.bind.annotation.XmlAccessType;
11+
import javax.xml.bind.annotation.XmlAccessorType;
12+
import javax.xml.bind.annotation.XmlType;
13+
import javax.xml.bind.annotation.XmlEnum;
14+
import javax.xml.bind.annotation.XmlEnumValue;
15+
import com.fasterxml.jackson.annotation.JsonProperty;
16+
import com.fasterxml.jackson.annotation.JsonValue;
17+
import com.fasterxml.jackson.annotation.JsonCreator;
18+
19+
public class CollectionUpdateSchema {
20+
21+
@Schema(example = "[{\"name\":\"company_name\",\"type\":\"string\",\"facet\":false},{\"name\":\"num_employees\",\"type\":\"int32\",\"facet\":false},{\"name\":\"country\",\"type\":\"string\",\"facet\":true}]", required = true, description = "A list of fields for querying, filtering and faceting")
22+
/**
23+
* A list of fields for querying, filtering and faceting
24+
**/
25+
private List<Field> fields = new ArrayList<Field>();
26+
/**
27+
* A list of fields for querying, filtering and faceting
28+
* @return fields
29+
**/
30+
@JsonProperty("fields")
31+
public List<Field> getFields() {
32+
return fields;
33+
}
34+
35+
public void setFields(List<Field> fields) {
36+
this.fields = fields;
37+
}
38+
39+
public CollectionUpdateSchema fields(List<Field> fields) {
40+
this.fields = fields;
41+
return this;
42+
}
43+
44+
public CollectionUpdateSchema addFieldsItem(Field fieldsItem) {
45+
this.fields.add(fieldsItem);
46+
return this;
47+
}
48+
49+
50+
@Override
51+
public String toString() {
52+
StringBuilder sb = new StringBuilder();
53+
sb.append("class CollectionUpdateSchema {\n");
54+
55+
sb.append(" fields: ").append(toIndentedString(fields)).append("\n");
56+
sb.append("}");
57+
return sb.toString();
58+
}
59+
60+
/**
61+
* Convert the given object to string with each line indented by 4 spaces
62+
* (except the first line).
63+
*/
64+
private static String toIndentedString(java.lang.Object o) {
65+
if (o == null) {
66+
return "null";
67+
}
68+
return o.toString().replace("\n", "\n ");
69+
}
70+
}

src/main/java/org/typesense/model/Field.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public class Field {
2929

3030
@Schema(example = "true", description = "")
3131
private Boolean index = true;
32+
33+
@Schema(example = "el", description = "")
34+
private String locale = null;
35+
36+
@Schema(example = "true", description = "")
37+
private Boolean sort = false;
38+
39+
@Schema(example = "true", description = "")
40+
private Boolean infix = false;
41+
42+
@Schema(example = "true", description = "")
43+
private Boolean drop = null;
3244
/**
3345
* Get name
3446
* @return name
@@ -119,6 +131,78 @@ public Field index(Boolean index) {
119131
return this;
120132
}
121133

134+
/**
135+
* Get locale
136+
* @return locale
137+
**/
138+
@JsonProperty("locale")
139+
public String getLocale() {
140+
return locale;
141+
}
142+
143+
public void setLocale(String locale) {
144+
this.locale = locale;
145+
}
146+
147+
public Field locale(String locale) {
148+
this.locale = locale;
149+
return this;
150+
}
151+
152+
/**
153+
* Get sort
154+
* @return sort
155+
**/
156+
@JsonProperty("sort")
157+
public Boolean isSort() {
158+
return sort;
159+
}
160+
161+
public void setSort(Boolean sort) {
162+
this.sort = sort;
163+
}
164+
165+
public Field sort(Boolean sort) {
166+
this.sort = sort;
167+
return this;
168+
}
169+
170+
/**
171+
* Get infix
172+
* @return infix
173+
**/
174+
@JsonProperty("infix")
175+
public Boolean isInfix() {
176+
return infix;
177+
}
178+
179+
public void setInfix(Boolean infix) {
180+
this.infix = infix;
181+
}
182+
183+
public Field infix(Boolean infix) {
184+
this.infix = infix;
185+
return this;
186+
}
187+
188+
/**
189+
* Get drop
190+
* @return drop
191+
**/
192+
@JsonProperty("drop")
193+
public Boolean isDrop() {
194+
return drop;
195+
}
196+
197+
public void setDrop(Boolean drop) {
198+
this.drop = drop;
199+
}
200+
201+
public Field drop(Boolean drop) {
202+
this.drop = drop;
203+
return this;
204+
}
205+
122206

123207
@Override
124208
public String toString() {
@@ -130,6 +214,10 @@ public String toString() {
130214
sb.append(" optional: ").append(toIndentedString(optional)).append("\n");
131215
sb.append(" facet: ").append(toIndentedString(facet)).append("\n");
132216
sb.append(" index: ").append(toIndentedString(index)).append("\n");
217+
sb.append(" locale: ").append(toIndentedString(locale)).append("\n");
218+
sb.append(" sort: ").append(toIndentedString(sort)).append("\n");
219+
sb.append(" infix: ").append(toIndentedString(infix)).append("\n");
220+
sb.append(" drop: ").append(toIndentedString(drop)).append("\n");
133221
sb.append("}");
134222
return sb.toString();
135223
}

0 commit comments

Comments
 (0)