-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Ivan Senic
authored
Feb 16, 2023
1 parent
ff24e79
commit 60d5d07
Showing
12 changed files
with
384 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/io/stargate/sgv2/jsonapi/api/model/command/impl/DeleteCollectionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.impl; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import io.stargate.sgv2.jsonapi.api.model.command.NamespaceCommand; | ||
import javax.validation.constraints.NotBlank; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
/** | ||
* Command for deleting a collection. | ||
* | ||
* @param name Name of the collection | ||
*/ | ||
@Schema(description = "Command that deletes a collection if one exists.") | ||
@JsonTypeName("deleteCollection") | ||
public record DeleteCollectionCommand( | ||
@NotBlank | ||
@Schema( | ||
description = "Name of the collection", | ||
implementation = Object.class, | ||
type = SchemaType.OBJECT) | ||
String name) | ||
implements NamespaceCommand {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...java/io/stargate/sgv2/jsonapi/service/operation/model/impl/DeleteCollectionOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.stargate.sgv2.jsonapi.service.operation.model.impl; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
import io.stargate.bridge.proto.QueryOuterClass; | ||
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; | ||
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; | ||
import io.stargate.sgv2.jsonapi.service.bridge.executor.QueryExecutor; | ||
import io.stargate.sgv2.jsonapi.service.operation.model.Operation; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Implementation of the delete collection. | ||
* | ||
* @param context Command context, carries namespace of the collection. | ||
* @param name Collection name. | ||
*/ | ||
public record DeleteCollectionOperation(CommandContext context, String name) implements Operation { | ||
|
||
private static final String DROP_TABLE_CQL = "DROP TABLE IF EXISTS %s.%s;"; | ||
|
||
@Override | ||
public Uni<Supplier<CommandResult>> execute(QueryExecutor queryExecutor) { | ||
String cql = DROP_TABLE_CQL.formatted(context.namespace(), name); | ||
QueryOuterClass.Query query = QueryOuterClass.Query.newBuilder().setCql(cql).build(); | ||
|
||
// execute | ||
return queryExecutor | ||
.executeSchemaChange(query) | ||
|
||
// if we have a result always respond positively | ||
.map(any -> new SchemaChangeResult(true)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...n/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.stargate.sgv2.jsonapi.service.resolver.model.impl; | ||
|
||
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; | ||
import io.stargate.sgv2.jsonapi.api.model.command.impl.DeleteCollectionCommand; | ||
import io.stargate.sgv2.jsonapi.service.operation.model.Operation; | ||
import io.stargate.sgv2.jsonapi.service.operation.model.impl.DeleteCollectionOperation; | ||
import io.stargate.sgv2.jsonapi.service.resolver.model.CommandResolver; | ||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
/** Resolver for the {@link DeleteCollectionCommand}. */ | ||
@ApplicationScoped | ||
public class DeleteCollectionResolver implements CommandResolver<DeleteCollectionCommand> { | ||
@Override | ||
public Class<DeleteCollectionCommand> getCommandClass() { | ||
return DeleteCollectionCommand.class; | ||
} | ||
|
||
@Override | ||
public Operation resolveCommand(CommandContext ctx, DeleteCollectionCommand command) { | ||
return new DeleteCollectionOperation(ctx, command.name()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...est/java/io/stargate/sgv2/jsonapi/api/model/command/impl/DeleteCollectionCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.impl; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.stargate.sgv2.common.testprofiles.NoGlobalResourcesTestProfile; | ||
import java.util.Set; | ||
import javax.inject.Inject; | ||
import javax.validation.ConstraintViolation; | ||
import javax.validation.Validator; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@QuarkusTest | ||
@TestProfile(NoGlobalResourcesTestProfile.Impl.class) | ||
class DeleteCollectionCommandTest { | ||
|
||
@Inject ObjectMapper objectMapper; | ||
|
||
@Inject Validator validator; | ||
|
||
@Nested | ||
class Validation { | ||
|
||
@Test | ||
public void noName() throws Exception { | ||
String json = | ||
""" | ||
{ | ||
"deleteCollection": { | ||
} | ||
} | ||
"""; | ||
|
||
DeleteCollectionCommand command = objectMapper.readValue(json, DeleteCollectionCommand.class); | ||
Set<ConstraintViolation<DeleteCollectionCommand>> result = validator.validate(command); | ||
|
||
assertThat(result) | ||
.isNotEmpty() | ||
.extracting(ConstraintViolation::getMessage) | ||
.contains("must not be blank"); | ||
} | ||
|
||
@Test | ||
public void nameBlank() throws Exception { | ||
String json = | ||
""" | ||
{ | ||
"deleteCollection": { | ||
"name": " " | ||
} | ||
} | ||
"""; | ||
|
||
DeleteCollectionCommand command = objectMapper.readValue(json, DeleteCollectionCommand.class); | ||
Set<ConstraintViolation<DeleteCollectionCommand>> result = validator.validate(command); | ||
|
||
assertThat(result) | ||
.isNotEmpty() | ||
.extracting(ConstraintViolation::getMessage) | ||
.contains("must not be blank"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.