Skip to content

Commit 2e874a8

Browse files
committed
fix: pass new defaults to aggregate client
1 parent 6948c9c commit 2e874a8

8 files changed

Lines changed: 126 additions & 10 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandle.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public CollectionHandle(
4040

4141
/** Copy constructor that sets new defaults. */
4242
private CollectionHandle(CollectionHandle<PropertiesT> c, CollectionHandleDefaults defaults) {
43-
this.aggregate = c.aggregate;
44-
this.tenants = c.tenants;
45-
4643
this.config = new WeaviateConfigClient(c.config, defaults);
44+
this.aggregate = new WeaviateAggregateClient(c.aggregate, defaults);
4745
this.query = new WeaviateQueryClient<>(c.query, defaults);
4846
this.data = new WeaviateDataClient<>(c.data, defaults);
4947
this.defaults = defaults;
48+
49+
this.tenants = c.tenants;
5050
}
5151

5252
public Paginator<PropertiesT> paginate() {

src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public CollectionHandleAsync(
4343

4444
/** Copy constructor that sets new defaults. */
4545
private CollectionHandleAsync(CollectionHandleAsync<PropertiesT> c, CollectionHandleDefaults defaults) {
46-
this.aggregate = c.aggregate;
47-
this.tenants = c.tenants;
48-
4946
this.config = new WeaviateConfigClientAsync(c.config, defaults);
47+
this.aggregate = new WeaviateAggregateClientAsync(c.aggregate, defaults);
5048
this.query = new WeaviateQueryClientAsync<>(c.query, defaults);
5149
this.data = new WeaviateDataClientAsync<>(c.data, defaults);
5250
this.defaults = defaults;
51+
52+
this.tenants = c.tenants;
5353
}
5454

5555
public AsyncPaginator<PropertiesT> paginate() {

src/main/java/io/weaviate/client6/v1/api/collections/aggregate/AbstractAggregateClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ abstract class AbstractAggregateClient<ResponseT, GroupedResponseT> {
3232
this.defaults = defaults;
3333
}
3434

35+
AbstractAggregateClient(
36+
AbstractAggregateClient<ResponseT, GroupedResponseT> c,
37+
CollectionHandleDefaults defaults) {
38+
this(c.collection, c.transport, defaults);
39+
}
40+
3541
protected abstract ResponseT performRequest(Aggregation aggregation);
3642

3743
protected abstract GroupedResponseT performRequest(Aggregation aggregation, GroupBy groupBy);

src/main/java/io/weaviate/client6/v1/api/collections/aggregate/WeaviateAggregateClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public WeaviateAggregateClient(
1313
super(collection, transport, defaults);
1414
}
1515

16+
/** Copy constructor that sets new defaults. */
17+
public WeaviateAggregateClient(WeaviateAggregateClient c, CollectionHandleDefaults defaults) {
18+
super(c, defaults);
19+
}
20+
1621
protected final AggregateResponse performRequest(Aggregation aggregation) {
1722
var request = new AggregateRequest(aggregation, null);
1823
return this.transport.performRequest(request, AggregateRequest.rpc(collection, defaults));

src/main/java/io/weaviate/client6/v1/api/collections/aggregate/WeaviateAggregateClientAsync.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public WeaviateAggregateClientAsync(
1616
super(collection, transport, defaults);
1717
}
1818

19+
/** Copy constructor that sets new defaults. */
20+
public WeaviateAggregateClientAsync(WeaviateAggregateClientAsync c, CollectionHandleDefaults defaults) {
21+
super(c, defaults);
22+
}
23+
1924
protected final CompletableFuture<AggregateResponse> performRequest(Aggregation aggregation) {
2025
var request = new AggregateRequest(aggregation, null);
2126
return this.transport.performRequestAsync(request, AggregateRequest.rpc(collection, defaults));

src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ abstract class AbstractQueryClient<PropertiesT, SingleT, ResponseT, GroupedRespo
2323
}
2424

2525
/** Copy constructor that sets new defaults. */
26-
AbstractQueryClient(AbstractQueryClient<PropertiesT, SingleT, ResponseT, GroupedResponseT> qc,
26+
AbstractQueryClient(
27+
AbstractQueryClient<PropertiesT, SingleT, ResponseT, GroupedResponseT> c,
2728
CollectionHandleDefaults defaults) {
28-
this(qc.collection, qc.grpcTransport, defaults);
29+
this(c.collection, c.grpcTransport, defaults);
2930
}
3031

3132
protected abstract SingleT byId(ById byId);

src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public WeaviateQueryClient(
1919
}
2020

2121
/** Copy constructor that sets new defaults. */
22-
public WeaviateQueryClient(WeaviateQueryClient<T> qc, CollectionHandleDefaults defaults) {
23-
super(qc, defaults);
22+
public WeaviateQueryClient(WeaviateQueryClient<T> c, CollectionHandleDefaults defaults) {
23+
super(c, defaults);
2424
}
2525

2626
@Override
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package io.weaviate.client6.v1.api.collections.tenants;
2+
3+
import java.io.IOException;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.Optional;
7+
import java.util.concurrent.CompletableFuture;
8+
9+
import io.weaviate.client6.v1.internal.grpc.GrpcTransport;
10+
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
11+
import io.weaviate.client6.v1.internal.rest.RestTransport;
12+
13+
public class WeaviateTenantsClientAsync {
14+
private final CollectionDescriptor<?> collection;
15+
private final RestTransport restTransport;
16+
private final GrpcTransport grpcTransport;
17+
18+
public WeaviateTenantsClientAsync(
19+
CollectionDescriptor<?> collection,
20+
RestTransport restTransport,
21+
GrpcTransport grpcTransport) {
22+
this.collection = collection;
23+
this.restTransport = restTransport;
24+
this.grpcTransport = grpcTransport;
25+
}
26+
27+
public CompletableFuture<Void> create(Tenant... tenants) throws IOException {
28+
return create(Arrays.asList(tenants));
29+
}
30+
31+
public CompletableFuture<Void> create(List<Tenant> tenants) throws IOException {
32+
return this.restTransport.performRequestAsync(new CreateTenantsRequest(tenants),
33+
CreateTenantsRequest.endpoint(collection));
34+
}
35+
36+
public CompletableFuture<Optional<Tenant>> get(String tenant) {
37+
var tenants = get(List.of(tenant));
38+
return tenants.thenApply(result -> result.isEmpty() ? Optional.empty() : Optional.ofNullable(result.get(0)));
39+
}
40+
41+
public CompletableFuture<List<Tenant>> list() {
42+
return get();
43+
}
44+
45+
public CompletableFuture<List<Tenant>> get(String... tenants) {
46+
return get(Arrays.asList(tenants));
47+
}
48+
49+
public CompletableFuture<List<Tenant>> get(List<String> tenants) {
50+
return this.grpcTransport.performRequestAsync(new GetTenantsRequest(tenants), GetTenantsRequest.rpc(collection));
51+
}
52+
53+
public CompletableFuture<Void> update(Tenant... tenants) throws IOException {
54+
return update(Arrays.asList(tenants));
55+
}
56+
57+
public CompletableFuture<Void> update(List<Tenant> tenants) throws IOException {
58+
return this.restTransport.performRequestAsync(new UpdateTenantsRequest(tenants),
59+
UpdateTenantsRequest.endpoint(collection));
60+
}
61+
62+
public CompletableFuture<Void> delete(String... tenants) throws IOException {
63+
return delete(Arrays.asList(tenants));
64+
}
65+
66+
public CompletableFuture<Void> delete(List<String> tenants) throws IOException {
67+
return this.restTransport.performRequestAsync(new DeleteTenantsRequest(tenants),
68+
DeleteTenantsRequest.endpoint(collection));
69+
}
70+
71+
public CompletableFuture<Boolean> exists(String tenant) throws IOException {
72+
return this.restTransport.performRequestAsync(new TenantExistsRequest(tenant),
73+
TenantExistsRequest.endpoint(collection));
74+
}
75+
76+
public CompletableFuture<Void> activate(String... tenants) throws IOException {
77+
return activate(Arrays.asList(tenants));
78+
}
79+
80+
public CompletableFuture<Void> activate(List<String> tenants) throws IOException {
81+
return update(tenants.stream().map(Tenant::active).toList());
82+
}
83+
84+
public CompletableFuture<Void> deactivate(String... tenants) throws IOException {
85+
return deactivate(Arrays.asList(tenants));
86+
}
87+
88+
public CompletableFuture<Void> deactivate(List<String> tenants) throws IOException {
89+
return update(tenants.stream().map(Tenant::inactive).toList());
90+
}
91+
92+
public CompletableFuture<Void> offload(String... tenants) throws IOException {
93+
return offload(Arrays.asList(tenants));
94+
}
95+
96+
public CompletableFuture<Void> offload(List<String> tenants) throws IOException {
97+
return update(tenants.stream().map(t -> new Tenant(t, TenantStatus.OFFLOADED)).toList());
98+
}
99+
}

0 commit comments

Comments
 (0)