Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the Optional handling where its not needed #40

Merged
merged 1 commit into from
Jan 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public record Options(
description = "Maximum number of document that can be fetched for the command.",
type = SchemaType.INTEGER,
implementation = Integer.class)
int limit,
Integer limit,
@Valid
@Schema(
description = "Next page state for pagination.",
Expand All @@ -37,5 +37,5 @@ public record Options(
description = "Number of document needed per page.",
type = SchemaType.INTEGER,
implementation = Integer.class)
int pageSize) {}
Integer pageSize) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public QueryExecutor(
* @return proto result set
*/
public Uni<QueryOuterClass.ResultSet> executeRead(
QueryOuterClass.Query query, Optional<String> pagingState, Optional<Integer> pageSize) {
QueryOuterClass.Query query, Optional<String> pagingState, int pageSize) {
QueryOuterClass.Consistency consistency = queriesConfig.consistency().reads();
QueryOuterClass.ConsistencyValue.Builder consistencyValue =
QueryOuterClass.ConsistencyValue.newBuilder().setValue(consistency);
Expand All @@ -51,12 +51,8 @@ public Uni<QueryOuterClass.ResultSet> executeRead(
params.setPagingState(BytesValue.of(ByteString.copyFrom(decodeBase64(pagingState.get()))));
}

if (pageSize.isPresent()) {
int page = Math.min(pageSize.get(), documentConfig.maxPageSize());
params.setPageSize(Int32Value.of(page));
} else {
params.setPageSize(Int32Value.of(documentConfig.defaultPageSize()));
}
int page = Math.min(pageSize, documentConfig.maxPageSize());
params.setPageSize(Int32Value.of(page));
return queryBridge(
QueryOuterClass.Query.newBuilder(query).setParameters(params).buildPartial());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ default Uni<FindResponse> findDocument(
boolean readDocument,
ObjectMapper objectMapper) {
return queryExecutor
.executeRead(query, Optional.ofNullable(pagingState), Optional.of(pageSize))
.executeRead(query, Optional.ofNullable(pagingState), pageSize)
.onItem()
.transform(
rSet -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.stargate.sgv3.docsapi.service.operation.model.impl.DeleteOperation;
import io.stargate.sgv3.docsapi.service.resolver.model.CommandResolver;
import io.stargate.sgv3.docsapi.service.resolver.model.impl.matcher.FilterableResolver;
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

Expand Down Expand Up @@ -37,7 +36,7 @@ public Class<DeleteOneCommand> getCommandClass() {
}

@Override
protected Optional<FilteringOptions> getFilteringOption(DeleteOneCommand command) {
return Optional.of(new FilteringOptions(1, null, 1));
protected FilteringOptions getFilteringOption(DeleteOneCommand command) {
return new FilteringOptions(1, null, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.stargate.sgv3.docsapi.service.operation.model.Operation;
import io.stargate.sgv3.docsapi.service.resolver.model.CommandResolver;
import io.stargate.sgv3.docsapi.service.resolver.model.impl.matcher.FilterableResolver;
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

Expand Down Expand Up @@ -40,16 +39,16 @@ public Operation resolveCommand(CommandContext ctx, FindCommand command) {
}

@Override
protected Optional<FilteringOptions> getFilteringOption(FindCommand command) {
protected FilteringOptions getFilteringOption(FindCommand command) {
int limit =
command.options() != null && command.options().limit() != 0
command.options() != null && command.options().limit() != null
? command.options().limit()
: documentConfig.maxLimit();
int pageSize =
command.options() != null && command.options().pageSize() != 0
command.options() != null && command.options().pageSize() != null
? command.options().pageSize()
: documentConfig.defaultPageSize();
String pagingState = command.options() != null ? command.options().pagingState() : null;
return Optional.of(new FilteringOptions(limit, pagingState, pageSize));
return new FilteringOptions(limit, pagingState, pageSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.stargate.sgv3.docsapi.service.operation.model.Operation;
import io.stargate.sgv3.docsapi.service.resolver.model.CommandResolver;
import io.stargate.sgv3.docsapi.service.resolver.model.impl.matcher.FilterableResolver;
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

Expand All @@ -31,7 +30,7 @@ public Operation resolveCommand(CommandContext ctx, FindOneCommand command) {
}

@Override
protected Optional<FilteringOptions> getFilteringOption(FindOneCommand command) {
return Optional.of(new FilteringOptions(1, null, 1));
protected FilteringOptions getFilteringOption(FindOneCommand command) {
return new FilteringOptions(1, null, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
import io.stargate.sgv3.docsapi.api.model.command.Filterable;
import io.stargate.sgv3.docsapi.api.model.command.clause.filter.JsonType;
import io.stargate.sgv3.docsapi.api.model.command.clause.filter.ValueComparisonOperator;
import io.stargate.sgv3.docsapi.exception.DocsException;
import io.stargate.sgv3.docsapi.exception.ErrorCode;
import io.stargate.sgv3.docsapi.service.operation.model.ReadOperation;
import io.stargate.sgv3.docsapi.service.operation.model.impl.FindOperation;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;

/**
Expand Down Expand Up @@ -81,7 +78,7 @@ protected ReadOperation resolve(CommandContext commandContext, T command) {

public record FilteringOptions(int limit, String pagingState, int pageSize) {}

protected abstract Optional<FilteringOptions> getFilteringOption(T command);
protected abstract FilteringOptions getFilteringOption(T command);

private ReadOperation findById(CommandContext commandContext, CaptureGroups<T> captures) {
List<FindOperation.DBFilterBase> filters = new ArrayList<>();
Expand All @@ -95,34 +92,27 @@ private ReadOperation findById(CommandContext commandContext, CaptureGroups<T> c
new FindOperation.IDFilter(
FindOperation.IDFilter.Operator.EQ, expression.value())));
}
Optional<FilteringOptions> filteringOptions = getFilteringOption(captures.command());
if (filteringOptions.isPresent()) {
return new FindOperation(
commandContext,
filters,
filteringOptions.get().pagingState(),
filteringOptions.get().limit(),
filteringOptions.get().pageSize(),
readDocument,
objectMapper);
}
throw new DocsException(ErrorCode.FILTER_UNRESOLVABLE);
FilteringOptions filteringOptions = getFilteringOption(captures.command());
return new FindOperation(
commandContext,
filters,
filteringOptions.pagingState(),
filteringOptions.limit(),
filteringOptions.pageSize(),
readDocument,
objectMapper);
}

private ReadOperation findNoFilter(CommandContext commandContext, CaptureGroups<T> captures) {
Optional<FilteringOptions> filteringOptions = getFilteringOption(captures.command());
if (filteringOptions.isPresent()) {
return new FindOperation(
commandContext,
List.of(),
filteringOptions.get().pagingState(),
filteringOptions.get().limit(),
filteringOptions.get().pageSize(),
readDocument,
objectMapper);
}
throw new DocsException(
ErrorCode.FILTER_UNRESOLVABLE, "Options need to be returned for filterable of non findOne");
FilteringOptions filteringOptions = getFilteringOption(captures.command());
return new FindOperation(
commandContext,
List.of(),
filteringOptions.pagingState(),
filteringOptions.limit(),
filteringOptions.pageSize(),
readDocument,
objectMapper);
}

private ReadOperation findDynamic(CommandContext commandContext, CaptureGroups<T> captures) {
Expand Down Expand Up @@ -181,18 +171,14 @@ private ReadOperation findDynamic(CommandContext commandContext, CaptureGroups<T
expression -> filters.add(new FindOperation.IsNullFilter(expression.path())));
}

Optional<FilteringOptions> filteringOptions = getFilteringOption(captures.command());
if (filteringOptions.isPresent()) {
return new FindOperation(
commandContext,
filters,
filteringOptions.get().pagingState(),
filteringOptions.get().limit(),
filteringOptions.get().pageSize(),
readDocument,
objectMapper);
}
throw new DocsException(
ErrorCode.FILTER_UNRESOLVABLE, "Options need to be returned for filterable of non findOne");
FilteringOptions filteringOptions = getFilteringOption(captures.command());
return new FindOperation(
commandContext,
filters,
filteringOptions.pagingState(),
filteringOptions.limit(),
filteringOptions.pageSize(),
readDocument,
objectMapper);
}
}