public interface CartByKeyGet extends MetaModelGetDsl<Cart,Cart,CartByKeyGet,CartExpansionModel<Cart>>
withCart(client(), cart -> {
assertThat(cart.getKey()).isNull();
final String key = randomKey();
final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, SetKey.of(key)));
assertThat(updatedCart).isNotNull();
assertThat(updatedCart.getCartState()).isEqualByComparingTo(CartState.ACTIVE);
final Cart fetchedCart = client().executeBlocking(CartByKeyGet.of(key));
assertThat(fetchedCart).isEqualTo(updatedCart);
return updatedCart;
});
See the test code.
Modifier and Type | Method and Description |
---|---|
List<ExpansionPath<Cart>> |
expansionPaths() |
static CartByKeyGet |
of(String key) |
CartByKeyGet |
plusExpansionPaths(ExpansionPath<Cart> expansionPath)
Creates a new object with the properties of the old object but adds
expansionPath to the expansion paths. |
CartByKeyGet |
withExpansionPaths(ExpansionPath<Cart> expansionPath)
Creates a new object with the properties of the old object but replaces all expansion paths with a single
expansionPath . |
CartByKeyGet |
withExpansionPaths(List<ExpansionPath<Cart>> expansionPaths)
Creates a new object with the properties of the old object but replaces all expansion paths with
expansionPaths . |
deserialize
canDeserialize, httpRequestIntent
plusExpansionPaths, withExpansionPaths
plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths
static CartByKeyGet of(String key)
List<ExpansionPath<Cart>> expansionPaths()
expansionPaths
in interface ExpansionPathContainer<Cart>
expansionPaths
in interface ReferenceExpansionSupport<Cart>
CartByKeyGet plusExpansionPaths(ExpansionPath<Cart> expansionPath)
ReferenceExpansionDsl
expansionPath
to the expansion paths.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT);
assertThat(fetch.expansionPaths()).isEmpty();
final ProductProjectionByIdGet fetch2 =
fetch.plusExpansionPaths(ProductProjectionExpansionModel.of().categories());
assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged").isEmpty();
assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("categories[*]")));
assertThat(fetch2).isNotSameAs(fetch);
See the test code.
plusExpansionPaths
in interface ReferenceExpansionDsl<Cart,CartByKeyGet>
expansionPath
- the new expansion path to add to the existing onesCartByKeyGet withExpansionPaths(ExpansionPath<Cart> expansionPath)
ReferenceExpansionDsl
expansionPath
.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT)
.withExpansionPaths(ProductProjectionExpansionModel.of().categories());
assertThat(fetch.expansionPaths())
.isEqualTo(asList(ExpansionPath.of("categories[*]")));
final ProductProjectionByIdGet fetch2 =
fetch.withExpansionPaths(ProductProjectionExpansionModel.of().productType());
assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged")
.isEqualTo(asList(ExpansionPath.of("categories[*]")));
assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType")));
assertThat(fetch2).isNotSameAs(fetch);
See the test code.
This method also can be used to use the same expansions as in another request:
final ProductProjectionQuery query = ProductProjectionQuery.ofCurrent().withExpansionPaths(m -> m.categories());
final ProductProjectionSearch search = ProductProjectionSearch.ofCurrent().withExpansionPaths(query);
assertThat(query.expansionPaths())
.hasSize(1)
.as("reuse expansion spec from other request")
.isEqualTo(search.expansionPaths());
See the test code.
withExpansionPaths
in interface ReferenceExpansionDsl<Cart,CartByKeyGet>
expansionPath
- the new expansion pathsCartByKeyGet withExpansionPaths(List<ExpansionPath<Cart>> expansionPaths)
ReferenceExpansionDsl
expansionPaths
.withExpansionPaths
in interface ReferenceExpansionDsl<Cart,CartByKeyGet>
expansionPaths
- the new expansion paths