Skip to content

Commit fe511b1

Browse files
committed
adds support for getting and deleting tenants
1 parent c46333c commit fe511b1

File tree

7 files changed

+331
-152
lines changed

7 files changed

+331
-152
lines changed

src/main/java/io/weaviate/client/v1/schema/Schema.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import io.weaviate.client.v1.schema.api.ShardUpdater;
1313
import io.weaviate.client.v1.schema.api.ShardsGetter;
1414
import io.weaviate.client.v1.schema.api.ShardsUpdater;
15-
import io.weaviate.client.v1.schema.api.TenantCreator;
15+
import io.weaviate.client.v1.schema.api.TenantsCreator;
16+
import io.weaviate.client.v1.schema.api.TenantsDeleter;
17+
import io.weaviate.client.v1.schema.api.TenantsGetter;
1618

1719
public class Schema {
1820
private final Config config;
@@ -63,7 +65,15 @@ public ShardsUpdater shardsUpdater() {
6365
return new ShardsUpdater(httpClient, config);
6466
}
6567

66-
public TenantCreator tenantCreator() {
67-
return new TenantCreator(httpClient, config);
68+
public TenantsCreator tenantsCreator() {
69+
return new TenantsCreator(httpClient, config);
70+
}
71+
72+
public TenantsDeleter tenantsDeleter() {
73+
return new TenantsDeleter(httpClient, config);
74+
}
75+
76+
public TenantsGetter tenantsGetter() {
77+
return new TenantsGetter(httpClient, config);
6878
}
6979
}

src/main/java/io/weaviate/client/v1/schema/api/TenantCreator.java renamed to src/main/java/io/weaviate/client/v1/schema/api/TenantsCreator.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,33 @@
66
import io.weaviate.client.base.Response;
77
import io.weaviate.client.base.Result;
88
import io.weaviate.client.base.http.HttpClient;
9+
import io.weaviate.client.base.util.UrlEncoder;
910
import io.weaviate.client.v1.schema.model.Tenant;
1011
import org.apache.http.HttpStatus;
1112

12-
import java.io.UnsupportedEncodingException;
13-
import java.net.URLEncoder;
14-
import java.nio.charset.StandardCharsets;
15-
16-
public class TenantCreator extends BaseClient<Tenant[]> implements ClientResult<Boolean> {
13+
public class TenantsCreator extends BaseClient<Tenant[]> implements ClientResult<Boolean> {
1714

1815
private String className;
1916
private Tenant[] tenants;
2017

21-
public TenantCreator(HttpClient httpClient, Config config) {
18+
public TenantsCreator(HttpClient httpClient, Config config) {
2219
super(httpClient, config);
2320
}
2421

25-
public TenantCreator withClassName(String className) {
22+
public TenantsCreator withClassName(String className) {
2623
this.className = className;
2724
return this;
2825
}
2926

30-
public TenantCreator withTenants(Tenant... tenants) {
27+
public TenantsCreator withTenants(Tenant... tenants) {
3128
this.tenants = tenants;
3229
return this;
3330
}
3431

3532
@Override
3633
public Result<Boolean> run() {
37-
String path = String.format("/schema/%s/tenants", encode(className));
34+
String path = String.format("/schema/%s/tenants", UrlEncoder.encodePathParam(className));
3835
Response<Tenant[]> resp = sendPostRequest(path, tenants, Tenant[].class);
3936
return new Result<>(resp.getStatusCode(), resp.getStatusCode() == HttpStatus.SC_OK, resp.getErrors());
4037
}
41-
42-
private String encode(String value) {
43-
try {
44-
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
45-
} catch (UnsupportedEncodingException e) {
46-
return null;
47-
}
48-
}
4938
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.weaviate.client.v1.schema.api;
2+
3+
import io.weaviate.client.Config;
4+
import io.weaviate.client.base.BaseClient;
5+
import io.weaviate.client.base.ClientResult;
6+
import io.weaviate.client.base.Response;
7+
import io.weaviate.client.base.Result;
8+
import io.weaviate.client.base.http.HttpClient;
9+
import io.weaviate.client.base.util.UrlEncoder;
10+
import org.apache.http.HttpStatus;
11+
12+
public class TenantsDeleter extends BaseClient<Object> implements ClientResult<Boolean> {
13+
14+
private String className;
15+
private String[] tenants;
16+
17+
public TenantsDeleter(HttpClient httpClient, Config config) {
18+
super(httpClient, config);
19+
}
20+
21+
public TenantsDeleter withClassName(String className) {
22+
this.className = className;
23+
return this;
24+
}
25+
26+
public TenantsDeleter withTenants(String... tenants) {
27+
this.tenants = tenants;
28+
return this;
29+
}
30+
31+
@Override
32+
public Result<Boolean> run() {
33+
String path = String.format("/schema/%s/tenants", UrlEncoder.encodePathParam(className));
34+
Response<Object> resp = sendDeleteRequest(path, tenants, Object.class);
35+
return new Result<>(resp.getStatusCode(), resp.getStatusCode() == HttpStatus.SC_OK, resp.getErrors());
36+
}
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.weaviate.client.v1.schema.api;
2+
3+
import io.weaviate.client.Config;
4+
import io.weaviate.client.base.BaseClient;
5+
import io.weaviate.client.base.ClientResult;
6+
import io.weaviate.client.base.Response;
7+
import io.weaviate.client.base.Result;
8+
import io.weaviate.client.base.http.HttpClient;
9+
import io.weaviate.client.base.util.UrlEncoder;
10+
import io.weaviate.client.v1.schema.model.Tenant;
11+
12+
import java.util.Arrays;
13+
import java.util.List;
14+
import java.util.Optional;
15+
16+
public class TenantsGetter extends BaseClient<Tenant[]> implements ClientResult<List<Tenant>> {
17+
18+
private String className;
19+
20+
public TenantsGetter(HttpClient httpClient, Config config) {
21+
super(httpClient, config);
22+
}
23+
24+
public TenantsGetter withClassName(String className) {
25+
this.className = className;
26+
return this;
27+
}
28+
29+
@Override
30+
public Result<List<Tenant>> run() {
31+
String path = String.format("/schema/%s/tenants", UrlEncoder.encodePathParam(className));
32+
Response<Tenant[]> resp = sendGetRequest(path, Tenant[].class);
33+
34+
List<Tenant> tenants = Optional.ofNullable(resp.getBody())
35+
.map(Arrays::asList)
36+
.orElse(null);
37+
return new Result<>(resp.getStatusCode(), tenants, resp.getErrors());
38+
}
39+
}

src/test/java/io/weaviate/integration/client/WeaviateTestGenerics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ private void createTenants(WeaviateClient client, String className, String[] ten
386386
.map(tenant -> Tenant.builder().name(tenant).build())
387387
.toArray(Tenant[]::new);
388388

389-
Result<Boolean> createStatus = client.schema().tenantCreator()
389+
Result<Boolean> createStatus = client.schema().tenantsCreator()
390390
.withClassName(className)
391391
.withTenants(t)
392392
.run();

0 commit comments

Comments
 (0)