commercetools / commercetools-sdk-java-v2

The e-commerce SDK from commercetools for Java.
https://commercetools.github.io/commercetools-sdk-java-v2/javadoc/index.html
Apache License 2.0
34 stars 15 forks source link

get stores linked to product selections doesn't work #257

Closed andrei-ivanov closed 2 years ago

andrei-ivanov commented 2 years ago
List<AssignedProductSelection> productSelections;
projectApiRoot.stores().get()
    .withWhere("productSelections(active=true and productSelection(id in :productSelectionIds))")
    .withPredicateVar("productSelectionIds", productSelections.stream().map(s -> s.getProductSelection().getId()).toList())
    .executeBlocking()
    .getBody()
    .getResults();
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : results: 2
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : AssignedProductSelectionImpl[createdAt=2022-02-02T09:15:35.001Z,productSelection=ProductSelectionReferenceImpl[id=2e89d89b-bdfb-4339-8e53-7638966a97c2,obj=<null>,typeId=product-selection]]
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : AssignedProductSelectionImpl[createdAt=2022-02-02T11:44:33.841Z,productSelection=ProductSelectionReferenceImpl[id=21a7ebc9-75e4-4be4-b3e7-a9808796ac1c,obj=<null>,typeId=product-selection]]
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : listing stores linked to selections...
DEBUG --- [ForkJoinPool.commonPool-worker-1]                         commercetools.stores.request.queries : io.vrap.rmf.base.client.ApiHttpRequest@29b95c55[method=GET,uri="https://api.europe-west1.gcp.commercetools.com/loylogic-poc/stores?where=productSelections%28active%3Dtrue+and+productSelection%28id+in+%3AproductSelectionIds%29%29&var.productSelectionIds=2e89d89b-bdfb-4339-8e53-7638966a97c2&var.productSelectionIds=21a7ebc9-75e4-4be4-b3e7-a9808796ac1c",headers=[{key=Accept-Encoding, value=gzip}, {key=Authorization, value=**removed from output**}, {key=User-Agent, value=commercetools-sdk-java-v2/7.5.0-SNAPSHOT  Java/17.0.2+8-LTS (Windows 10; amd64)}],textInterpretedBody=empty body]
TRACE --- [ForkJoinPool.commonPool-worker-1]                         commercetools.stores.request.queries : GET https://api.europe-west1.gcp.commercetools.com/loylogic-poc/stores?where=productSelections%28active%3Dtrue+and+productSelection%28id+in+%3AproductSelectionIds%29%29&var.productSelectionIds=2e89d89b-bdfb-4339-8e53-7638966a97c2&var.productSelectionIds=21a7ebc9-75e4-4be4-b3e7-a9808796ac1c <no body>
INFO  --- [    httpclient-dispatch-2]                                commercetools.stores.response : GET https://api.europe-west1.gcp.commercetools.com/loylogic-poc/stores?where=productSelections%28active%3Dtrue+and+productSelection%28id+in+%3AproductSelectionIds%29%29&var.productSelectionIds=2e89d89b-bdfb-4339-8e53-7638966a97c2&var.productSelectionIds=21a7ebc9-75e4-4be4-b3e7-a9808796ac1c 200
DEBUG --- [    httpclient-dispatch-2]                                commercetools.stores.response : io.vrap.rmf.base.client.ApiHttpResponse@1973d7c7[statusCode=200,headers=[{key=date, value=Wed, 02 Feb 2022 13:38:55 GMT}, {key=server, value=istio-envoy}, {key=x-envoy-upstream-service-time, value=4}, {key=content-encoding, value=gzip}, {key=access-control-allow-headers, value=Accept, Authorization, Content-Type, Origin, User-Agent, X-Correlation-ID}, {key=x-correlation-id, value=projects-1e4be2b8-a509-4fe3-a138-cca3ebef2d04}, {key=access-control-allow-methods, value=GET, POST, DELETE, OPTIONS}, {key=via, value=1.1 google}, {key=access-control-expose-headers, value=X-Correlation-ID}, {key=access-control-allow-origin, value=*}, {key=access-control-max-age, value=299}, {key=content-type, value=application/json; charset=utf-8}, {key=server-timing, value=projects;dur=3}, {key=alt-svc, value=clear}],textInterpretedBody={"limit":20,"offset":0,"count":0,"total":0,"results":[]}]
TRACE --- [    httpclient-dispatch-2]                                commercetools.stores.response : 200
{
  "limit" : 20,
  "offset" : 0,
  "count" : 0,
  "total" : 0,
  "results" : [ ]
}
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : stores: 0

Stack information:

It's probably not an SDK issue but a server/platform one.

jenschude commented 2 years ago

Exactly. It's not an SDK issue. Will forward it to the respective team.

jenschude commented 2 years ago

Btw could you try out if the where condition works when directly writing the IDs inside the predicate and not using a predicate variable?

andrei-ivanov commented 2 years ago

I don't really know how, none of these attempts worked, failing with a parse error from the backend:

productSelections(active=true and productSelection(id in [2e89d89b-bdfb-4339-8e53-7638966a97c2,21a7ebc9-75e4-4be4-b3e7-a9808796ac1c]))
productSelections(active=true and productSelection(id in 2e89d89b-bdfb-4339-8e53-7638966a97c2,21a7ebc9-75e4-4be4-b3e7-a9808796ac1c))
productSelections(active=true and productSelection(id in (2e89d89b-bdfb-4339-8e53-7638966a97c2,21a7ebc9-75e4-4be4-b3e7-a9808796ac1c)))
jenschude commented 2 years ago

should be productSelections(active=true and productSelection(id in ("2e89d89b-bdfb-4339-8e53-7638966a97c2","21a7ebc9-75e4-4be4-b3e7-a9808796ac1c")))

See also https://docs.commercetools.com/api/predicates/query

andrei-ivanov commented 2 years ago

I got a 200 result status for GET https://api.europe-west1.gcp.commercetools.com/loylogic-poc/stores?where=productSelections%28active%3Dtrue+and+productSelection%28id+in+%28%222e89d89b-bdfb-4339-8e53-7638966a97c2%22%2C%2221a7ebc9-75e4-4be4-b3e7-a9808796ac1c%22%29%29%29, but still no stores in the result.

jenschude commented 2 years ago

Okay at least we can rule out that it was about the input variables. The team is looking at it. :)

jenschude commented 2 years ago

Could it be that there is no store with these product selections assigned?

andrei-ivanov commented 2 years ago

Damn it.... you're right, I'm embarrassed to say. I've named the selections with the same key as the stores and somehow I forgot to select them at the store level. Sorry for the noise.