Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/it/java/io/weaviate/integration/CollectionsITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,32 @@ public void testCrossReferences() throws IOException {
.containsOnly(nsOnlineStores, nsMarkets);
});
}

@Test
public void testListDeleteAll() throws IOException {
var nsA = ns("A");
var nsB = ns("B");
var nsC = ns("C");

client.collections.create(nsA);
client.collections.create(nsB);
client.collections.create(nsC);

Assertions.assertThat(client.collections.exists(nsA)).isTrue();
Assertions.assertThat(client.collections.exists(nsB)).isTrue();
Assertions.assertThat(client.collections.exists(nsC)).isTrue();
Assertions.assertThat(client.collections.exists(ns("X"))).isFalse();

var all = client.collections.list();
Assertions.assertThat(all)
.hasSizeGreaterThanOrEqualTo(3)
.extracting(WeaviateCollection::name)
.contains(nsA, nsB, nsC);

client.collections.deleteAll();

all = client.collections.list();
Assertions.assertThat(all.isEmpty());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.weaviate.client6.v1.api.collections;

import java.util.Collections;
import java.util.List;

import org.apache.hc.core5.http.HttpStatus;

import com.google.gson.reflect.TypeToken;

import io.weaviate.client6.v1.internal.json.JSON;
import io.weaviate.client6.v1.internal.rest.Endpoint;

public record ListCollectionRequest() {
public static final Endpoint<ListCollectionRequest, List<WeaviateCollection>> _ENDPOINT = Endpoint.of(
request -> "GET",
request -> "/schema",
(gson, request) -> null,
request -> Collections.emptyMap(),
code -> code != HttpStatus.SC_SUCCESS,
(gson, response) -> JSON.deserialize(response, ListCollectionResponse.class).collections());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.weaviate.client6.v1.api.collections;

import java.util.List;

import com.google.gson.annotations.SerializedName;

public record ListCollectionResponse(@SerializedName("classes") List<WeaviateCollection> collections) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.weaviate.client6.v1.api.collections;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
Expand Down Expand Up @@ -41,7 +42,21 @@ public Optional<WeaviateCollection> getConfig(String name) throws IOException {
return this.restTransport.performRequest(new GetConfigRequest(name), GetConfigRequest._ENDPOINT);
}

public List<WeaviateCollection> list() throws IOException {
return this.restTransport.performRequest(new ListCollectionRequest(), ListCollectionRequest._ENDPOINT);
}

public void delete(String name) throws IOException {
this.restTransport.performRequest(new DeleteCollectionRequest(name), DeleteCollectionRequest._ENDPOINT);
}

public void deleteAll() throws IOException {
for (var collection : list()) {
delete(collection.name());
}
}

public boolean exists(String name) throws IOException {
return getConfig(name).isPresent();
}
}