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
7 changes: 5 additions & 2 deletions src/it/java/io/weaviate/integration/AliasITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ public void test_aliasLifecycle() throws IOException {
.returns(nsColsonBaker, Alias::collection);

// Act: delete Bono alias
client.alias.delete("Bono");
var deleted = client.alias.delete("Bono");
Assertions.assertThat(deleted).as("object was deleted").isTrue();

// Assert
// Act: delete non-existent alias
deleted = client.alias.delete("Bono");
Assertions.assertThat(deleted).as("object wasn't deleted").isFalse();
var paulHewsonAliases = client.alias.list(all -> all.collection(nsPaulHewson));
Assertions.assertThat(paulHewsonAliases)
.as("no aliases once Bono is deleted")
Expand Down
9 changes: 8 additions & 1 deletion src/it/java/io/weaviate/integration/DataITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ public void testCreateGetDelete() throws IOException {
.as("lastUpdateTimeUnix").isNotNull();
});

artists.data.delete(id);
var deleted = artists.data.deleteById(id);
Assertions.assertThat(deleted)
.as("object was deleted").isTrue();
Assertions.assertThat(artists.data.exists(id))
.as("object not exists after deletion").isFalse();

deleted = artists.data.deleteById(id);
// TODO: Change to isFalse() after fixed in Weaviate server
Assertions.assertThat(deleted)
.as("object wasn't deleted").isTrue();
}

@Test
Expand Down
38 changes: 31 additions & 7 deletions src/it/java/io/weaviate/integration/RbacITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,54 @@ public void test_users_db() throws IOException {
.extracting(Role::name)
.doesNotContain(roleName);

client.users.db.activate(userId);
var deactivated = client.users.db.deactivate(userId);
Assertions.assertThat(deactivated)
.as("user was deactivated")
.isTrue();
Assertions.assertThat(client.users.db.byName(userId)).get()
.as("user is deactivated")
.returns(false, DbUser::active);

deactivated = client.users.db.deactivate(userId);
Assertions.assertThat(deactivated)
.as("user was already deactivated")
.isFalse();

var activated = client.users.db.activate(userId);
Assertions.assertThat(activated)
.as("user was activated")
.isTrue();
Assertions.assertThat(client.users.db.byName(userId)).get()
.as("user is activated")
.returns(true, DbUser::active);

activated = client.users.db.activate(userId);
Assertions.assertThat(activated)
.as("user was already active")
.isFalse();

apiKey = client.users.db.rotateKey(userId);
assertValidApiKey(apiKey);

client.users.db.deactivate(userId);
Assertions.assertThat(client.users.db.byName(userId)).get()
.as("user is deactivated")
.returns(false, DbUser::active);

var all = client.users.db.list(users -> users.includeLastUsedAt(true));
Assertions.assertThat(all)
.as("list users include lastUsedTime ")
.allMatch(user -> user.lastUsedAt() != null)
.extracting(DbUser::id)
.contains(userId, ADMIN_USER);

client.users.db.delete(userId);
var deleted = client.users.db.delete(userId);
Assertions.assertThat(deleted)
.as("user was deleted")
.isTrue();
Assertions.assertThat(client.users.db.byName(userId))
.as("user is deleted")
.isEmpty();

deleted = client.users.db.delete(userId);
Assertions.assertThat(deleted)
.as("user was already deleted")
.isFalse();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.util.Collections;

import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
import io.weaviate.client6.v1.internal.rest.Endpoint;
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;

public record DeleteAliasRequest(String alias) {
public final static Endpoint<DeleteAliasRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect(
public final static Endpoint<DeleteAliasRequest, Boolean> _ENDPOINT = BooleanEndpoint.noBody(
__ -> "DELETE",
request -> "/aliases/" + request.alias,
__ -> Collections.emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ public void update(String alias, String newTargetCollection) throws IOException
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*
* @return {@code true} if the alias was deleted, {@code false} if there was no
* alias to delete.
*/
public void delete(String alias) throws IOException {
this.restTransport.performRequest(new DeleteAliasRequest(alias), DeleteAliasRequest._ENDPOINT);
public boolean delete(String alias) throws IOException {
return this.restTransport.performRequest(new DeleteAliasRequest(alias), DeleteAliasRequest._ENDPOINT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public CompletableFuture<Void> update(String alias, String newTargetCollection)
*
* @return A future holding the server's response.
*/
public CompletableFuture<Void> delete(String alias) {
public CompletableFuture<Boolean> delete(String alias) {
return this.restTransport.performRequestAsync(new DeleteAliasRequest(alias), DeleteAliasRequest._ENDPOINT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
import io.weaviate.client6.v1.internal.rest.Endpoint;
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;

public record DeleteObjectRequest(String uuid) {

public static final Endpoint<DeleteObjectRequest, Void> endpoint(
public static final Endpoint<DeleteObjectRequest, Boolean> endpoint(
CollectionDescriptor<?> collection,
CollectionHandleDefaults defaults) {
return SimpleEndpoint.sideEffect(
return BooleanEndpoint.noBody(
request -> "DELETE",
request -> "/objects/" + collection.collectionName() + "/" + request.uuid,
request -> defaults.queryParameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ public void replace(String uuid,
ReplaceObjectRequest.endpoint(collection, defaults));
}

public void delete(String uuid) throws IOException {
this.restTransport.performRequest(new DeleteObjectRequest(uuid),
/**
* Delete an object by its UUID.
*
* @param uuid The UUID of the object to delete.
* @return {@code true} if the object was deleted, {@code false} if there was no object to delete.
* @throws IOException in case the request was not sent successfully.
*/
public boolean deleteById(String uuid) throws IOException {
return this.restTransport.performRequest(new DeleteObjectRequest(uuid),
DeleteObjectRequest.endpoint(collection, defaults));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public CompletableFuture<Void> replace(String uuid,
ReplaceObjectRequest.endpoint(collection, defaults));
}

public CompletableFuture<Void> delete(String uuid) {
public CompletableFuture<Boolean> delete(String uuid) {
return this.restTransport.performRequestAsync(new DeleteObjectRequest(uuid),
DeleteObjectRequest.endpoint(collection, defaults));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.util.Collections;

import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
import io.weaviate.client6.v1.internal.rest.Endpoint;
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
import io.weaviate.client6.v1.internal.rest.UrlEncoder;

public record ActivateDbUserRequest(String userId) {

public static final Endpoint<ActivateDbUserRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect(
public static final Endpoint<ActivateDbUserRequest, Boolean> _ENDPOINT = BooleanEndpoint.noBody(
__ -> "POST",
request -> "/users/db/" + UrlEncoder.encodeValue(((ActivateDbUserRequest) request).userId) + "/activate",
request -> Collections.emptyMap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,45 @@ public String create(String userId) throws IOException {
* Delete a "db" user.
*
* @param userId User ID.
* @return {@code true} if the user was deleted, {@code false} if there was no user to delete.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public void delete(String userId) throws IOException {
this.restTransport.performRequest(new DeleteDbUserRequest(userId), DeleteDbUserRequest._ENDPOINT);
public boolean delete(String userId) throws IOException {
return this.restTransport.performRequest(new DeleteDbUserRequest(userId), DeleteDbUserRequest._ENDPOINT);
}

/**
* Activate a "db" user.
*
* @param userId User ID.
* @return {@code true} if the user was activated, {@code false} if the user was already active.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public void activate(String userId) throws IOException {
this.restTransport.performRequest(new ActivateDbUserRequest(userId), ActivateDbUserRequest._ENDPOINT);
public boolean activate(String userId) throws IOException {
return this.restTransport.performRequest(new ActivateDbUserRequest(userId), ActivateDbUserRequest._ENDPOINT);
}

/**
* Deactivate a "db" user.
*
* @param userId User ID.
* @return {@code true} if the user was deactivated, {@code false} if the user was already deactivated.
* @throws WeaviateApiException in case the server returned with an
* error status code.
* @throws IOException in case the request was not sent successfully
* due to a malformed request, a networking error
* or the server being unavailable.
*/
public void deactivate(String userId) throws IOException {
this.restTransport.performRequest(new DeactivateDbUserRequest(userId), DeactivateDbUserRequest._ENDPOINT);
public boolean deactivate(String userId) throws IOException {
return this.restTransport.performRequest(new DeactivateDbUserRequest(userId), DeactivateDbUserRequest._ENDPOINT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CompletableFuture<String> create(String userId) throws IOException {
*
* @param userId User ID.
*/
public CompletableFuture<Void> delete(String userId) throws IOException {
public CompletableFuture<Boolean> delete(String userId) throws IOException {
return this.restTransport.performRequestAsync(new DeleteDbUserRequest(userId), DeleteDbUserRequest._ENDPOINT);
}

Expand All @@ -39,7 +39,7 @@ public CompletableFuture<Void> delete(String userId) throws IOException {
*
* @param userId User ID.
*/
public CompletableFuture<Void> activate(String userId) throws IOException {
public CompletableFuture<Boolean> activate(String userId) throws IOException {
return this.restTransport.performRequestAsync(new ActivateDbUserRequest(userId), ActivateDbUserRequest._ENDPOINT);
}

Expand All @@ -48,7 +48,7 @@ public CompletableFuture<Void> activate(String userId) throws IOException {
*
* @param userId User ID.
*/
public CompletableFuture<Void> deactivate(String userId) throws IOException {
public CompletableFuture<Boolean> deactivate(String userId) throws IOException {
return this.restTransport.performRequestAsync(new DeactivateDbUserRequest(userId),
DeactivateDbUserRequest._ENDPOINT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.util.Collections;

import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
import io.weaviate.client6.v1.internal.rest.Endpoint;
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
import io.weaviate.client6.v1.internal.rest.UrlEncoder;

public record DeactivateDbUserRequest(String userId) {

public static final Endpoint<DeactivateDbUserRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect(
public static final Endpoint<DeactivateDbUserRequest, Boolean> _ENDPOINT = BooleanEndpoint.noBody(
__ -> "POST",
request -> "/users/db/" + UrlEncoder.encodeValue(((DeactivateDbUserRequest) request).userId) + "/deactivate",
request -> Collections.emptyMap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.util.Collections;

import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
import io.weaviate.client6.v1.internal.rest.Endpoint;
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
import io.weaviate.client6.v1.internal.rest.UrlEncoder;

public record DeleteDbUserRequest(String userId) {

public static final Endpoint<DeleteDbUserRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect(
public static final Endpoint<DeleteDbUserRequest, Boolean> _ENDPOINT = BooleanEndpoint.noBody(
__ -> "DELETE",
request -> "/users/db/" + UrlEncoder.encodeValue(request.userId),
request -> Collections.emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public BooleanEndpoint(
super(method, requestUrl, queryParameters, body);
}

@SuppressWarnings("unchecked")
public <R> BooleanEndpoint<R> allowStatus(Integer... statusCodes) {
super._allowStatusCodes(statusCodes);
return (BooleanEndpoint<R>) this;
}

@Override
public boolean isError(int statusCode) {
return statusCode != 404 && super.isError(statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static Object[][] restTestCases() {
"data::delete by id",
ConsistencyLevel.ONE, Location.QUERY,
"john_doe", Location.QUERY,
(Act) c -> c.data.delete("test-uuid"),
(Act) c -> c.data.deleteById("test-uuid"),
},
{
"data::add reference",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
import io.weaviate.client6.v1.internal.rest.Endpoint;
import io.weaviate.client6.v1.internal.rest.RestTransport;

Expand Down Expand Up @@ -38,10 +39,14 @@ public void assertNext(AssertFunction... assertions) {
}
}

@SuppressWarnings("unchecked")
@Override
public <RequestT, ResponseT, ExceptionT> ResponseT performRequest(RequestT request,
Endpoint<RequestT, ResponseT> endpoint) throws IOException {
requests.add(new Request<>(request, endpoint));
if (endpoint instanceof BooleanEndpoint) {
return (ResponseT) Boolean.TRUE;
}
return null;
}

Expand Down