Skip to content

Commit

Permalink
Merge pull request #388 from FgForrest/387-evita-client-fails-to-quer…
Browse files Browse the repository at this point in the history
…y-custom-entity-contract-without-specifying-collection-in-query

fix(#387): Evita Client fails to query custom entity contract without…
  • Loading branch information
novoj authored Jan 2, 2024
2 parents fbefaf4 + 098a3d2 commit 1d5c9c9
Show file tree
Hide file tree
Showing 13 changed files with 584 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* | __/\ V /| | || (_| | |_| | |_) |
* \___| \_/ |_|\__\__,_|____/|____/
*
* Copyright (c) 2023
* Copyright (c) 2023-2024
*
* Licensed under the Business Source License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -446,12 +446,15 @@ public <S extends Serializable, T extends EvitaResponse<S>> T query(@Nonnull Que
assertActive();
assertRequestMakesSense(query, expectedType);
final String entityTypeByExpectedType = extractEntityTypeFromClass(expectedType, reflectionLookup)
.orElse(null);
.orElseGet(() -> ofNullable(query.getCollection())
.map(io.evitadb.api.query.head.Collection::getEntityType)
.orElseThrow(() -> new CollectionNotFoundException(expectedType)));

final StringWithParameters stringWithParameters = query.normalizeQuery().toStringWithParameterExtraction();
final GrpcQueryResponse grpcResponse = executeWithEvitaSessionService(evitaSessionService ->
evitaSessionService.query(
GrpcQueryRequest.newBuilder()
.setCollection(entityTypeByExpectedType)
.setQuery(stringWithParameters.query())
.addAllPositionalQueryParams(
stringWithParameters.parameters()
Expand Down Expand Up @@ -1398,11 +1401,16 @@ private <S extends Serializable> List<S> queryListInternal(
) {
assertActive();
assertRequestMakesSense(query, expectedType);
final String entityTypeByExpectedType = extractEntityTypeFromClass(expectedType, reflectionLookup)
.orElseGet(() -> ofNullable(query.getCollection())
.map(io.evitadb.api.query.head.Collection::getEntityType)
.orElseThrow(() -> new CollectionNotFoundException(expectedType)));

final StringWithParameters stringWithParameters = query.normalizeQuery().toStringWithParameterExtraction();
final GrpcQueryListResponse grpcResponse = executeWithEvitaSessionService(evitaSessionService ->
evitaSessionService.queryList(
GrpcQueryRequest.newBuilder()
.setCollection(entityTypeByExpectedType)
.setQuery(stringWithParameters.query())
.addAllPositionalQueryParams(
stringWithParameters.parameters()
Expand Down Expand Up @@ -1507,11 +1515,16 @@ private <S extends Serializable> Optional<S> queryOneInternal(
) {
assertActive();
assertRequestMakesSense(query, expectedType);
final String entityTypeByExpectedType = extractEntityTypeFromClass(expectedType, reflectionLookup)
.orElseGet(() -> ofNullable(query.getCollection())
.map(io.evitadb.api.query.head.Collection::getEntityType)
.orElseThrow(() -> new CollectionNotFoundException(expectedType)));

final StringWithParameters stringWithParameters = query.normalizeQuery().toStringWithParameterExtraction();
final GrpcQueryOneResponse grpcResponse = executeWithEvitaSessionService(evitaSessionService ->
evitaSessionService.queryOne(
GrpcQueryRequest.newBuilder()
.setCollection(entityTypeByExpectedType)
.setQuery(stringWithParameters.query())
.addAllPositionalQueryParams(
stringWithParameters.parameters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* | __/\ V /| | || (_| | |_| | |_) |
* \___| \_/ |_|\__\__,_|____/|____/
*
* Copyright (c) 2023
* Copyright (c) 2023-2024
*
* Licensed under the Business Source License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -580,7 +580,7 @@ public void query(@Nonnull GrpcQueryRequest request, @Nonnull StreamObserver<Grp
query.normalizeQuery(),
OffsetDateTime.now(),
EntityClassifier.class,
null,
request.getCollection(),
EvitaRequest.CONVERSION_NOT_SUPPORTED
);

Expand Down Expand Up @@ -670,8 +670,16 @@ public void queryOne(@Nonnull GrpcQueryRequest request, @Nonnull StreamObserver<
);

if (query != null) {
final EvitaRequest evitaRequest = new EvitaRequest(
query,
OffsetDateTime.now(),
EntityClassifier.class,
request.getCollection(),
EvitaRequest.CONVERSION_NOT_SUPPORTED
);

final GrpcQueryOneResponse.Builder responseBuilder = GrpcQueryOneResponse.newBuilder();
session.queryOne(query, EntityClassifier.class).ifPresent(responseEntity -> {
session.queryOne(evitaRequest).ifPresent(responseEntity -> {
if (responseEntity instanceof final EntityReference entityReference) {
responseBuilder.setEntityReference(GrpcEntityReference.newBuilder()
.setEntityType(entityReference.getType())
Expand Down Expand Up @@ -712,7 +720,7 @@ public void queryList(@Nonnull GrpcQueryRequest request, @Nonnull StreamObserver
query,
OffsetDateTime.now(),
EntityClassifier.class,
null,
request.getCollection(),
EvitaRequest.CONVERSION_NOT_SUPPORTED
);
final List<EntityClassifier> responseEntities = session.queryList(evitaRequest);
Expand Down
Loading

0 comments on commit 1d5c9c9

Please sign in to comment.