T
- the type of the result of the commandC
- class which will serialized as JSON command body, most likely a templateD
- type of the draft objectE
- type of the expansion modelpublic abstract class MetaModelCreateCommandImpl<T,C,D,E> extends CommandImpl<T> implements DraftBasedCreateCommand<T,D>, MetaModelExpansionDslExpansionModelRead<T,C,E>
Modifier | Constructor and Description |
---|---|
protected |
MetaModelCreateCommandImpl(D draft,
com.fasterxml.jackson.databind.JavaType javaType,
String endpoint,
List<ExpansionPath<T>> expansionPaths,
E expansionModel,
Function<MetaModelCreateCommandBuilder<T,C,D,E>,C> creationFunction) |
protected |
MetaModelCreateCommandImpl(D draft,
JsonEndpoint<T> endpoint,
E expansionModel,
Function<MetaModelCreateCommandBuilder<T,C,D,E>,C> creationFunction) |
protected |
MetaModelCreateCommandImpl(MetaModelCreateCommandBuilder<T,C,D,E> builder) |
Modifier and Type | Method and Description |
---|---|
protected MetaModelCreateCommandBuilder<T,C,D,E> |
copyBuilder() |
E |
expansionModel() |
List<ExpansionPath<T>> |
expansionPaths() |
D |
getDraft() |
protected String |
httpBody() |
protected HttpMethod |
httpMethod() |
HttpRequestIntent |
httpRequestIntent()
Provides an http request intent, this does not include the execution of it.
|
protected com.fasterxml.jackson.databind.JavaType |
jacksonJavaType() |
C |
plusExpansionPaths(ExpansionPath<T> expansionPath)
Creates a new object with the properties of the old object but adds
expansionPath to the expansion paths. |
C |
plusExpansionPaths(Function<E,ExpansionPathContainer<T>> m)
Creates a new object with the properties of the old object but adds a new expansion path to it by using meta models.
|
C |
plusExpansionPaths(List<ExpansionPath<T>> expansionPaths)
Creates a new object with the properties of the old object but adds
expansionPaths to the expansion paths. |
C |
plusExpansionPaths(String expansionPath)
Creates a new object with the properties of the old object but adds
expansionPath to the expansion paths. |
C |
withExpansionPaths(ExpansionPath<T> expansionPath)
Creates a new object with the properties of the old object but replaces all expansion paths with a single
expansionPath . |
C |
withExpansionPaths(Function<E,ExpansionPathContainer<T>> m)
Creates a new object with the properties of the old object but replaces all expansion paths with a single
expansionPath by using meta models. |
C |
withExpansionPaths(List<ExpansionPath<T>> expansionPaths)
Creates a new object with the properties of the old object but replaces all expansion paths with
expansionPaths . |
C |
withExpansionPaths(String expansionPath)
Creates a new object with the properties of the old object but replaces all expansion paths with a single
expansionPath . |
deserialize
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
canDeserialize, deserialize
plusExpansionPaths, withExpansionPaths
protected MetaModelCreateCommandImpl(D draft, com.fasterxml.jackson.databind.JavaType javaType, String endpoint, List<ExpansionPath<T>> expansionPaths, E expansionModel, Function<MetaModelCreateCommandBuilder<T,C,D,E>,C> creationFunction)
protected MetaModelCreateCommandImpl(MetaModelCreateCommandBuilder<T,C,D,E> builder)
public HttpRequestIntent httpRequestIntent()
SphereRequest
httpRequestIntent
in interface SphereRequest<T>
protected HttpMethod httpMethod()
protected String httpBody()
protected com.fasterxml.jackson.databind.JavaType jacksonJavaType()
jacksonJavaType
in class CommandImpl<T>
public List<ExpansionPath<T>> expansionPaths()
expansionPaths
in interface ExpansionPathContainer<T>
expansionPaths
in interface ReferenceExpansionSupport<T>
public final C withExpansionPaths(List<ExpansionPath<T>> expansionPaths)
ReferenceExpansionDsl
expansionPaths
.withExpansionPaths
in interface ReferenceExpansionDsl<T,C>
expansionPaths
- the new expansion pathspublic C withExpansionPaths(ExpansionPath<T> 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<T,C>
expansionPath
- the new expansion pathspublic C withExpansionPaths(Function<E,ExpansionPathContainer<T>> m)
MetaModelReferenceExpansionDsl
expansionPath
by using meta models.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .plusExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch.withExpansionPaths(m -> m.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.
withExpansionPaths
in interface MetaModelReferenceExpansionDsl<T,C,E>
m
- function to use the meta model for expansions to create an expansion pathpublic C plusExpansionPaths(List<ExpansionPath<T>> expansionPaths)
ReferenceExpansionDsl
expansionPaths
to the expansion paths.plusExpansionPaths
in interface ReferenceExpansionDsl<T,C>
expansionPaths
- the new expansion paths to add to the existing onespublic C plusExpansionPaths(ExpansionPath<T> 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<T,C>
expansionPath
- the new expansion path to add to the existing onespublic C plusExpansionPaths(Function<E,ExpansionPathContainer<T>> m)
MetaModelReferenceExpansionDsl
An example in the product projection context:
final ProductProjectionByIdGet fetch1 = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .plusExpansionPaths(m -> m.categories()); assertThat(fetch1.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch1.plusExpansionPaths(m -> m.productType()); assertThat(fetch2.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"), ExpansionPath.of("productType"))) .isEqualTo(listOf(fetch1.expansionPaths(), ExpansionPath.of("productType"))); //this is equivalent to final ExpansionPath<ProductProjection> categoryExpand = ProductProjectionExpansionModel.of().categories().expansionPaths().get(0); final ExpansionPath<ProductProjection> productTypeExpand = ProductProjectionExpansionModel.of().productType().expansionPaths().get(0); final ProductProjectionByIdGet fetchB = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .withExpansionPaths(asList(categoryExpand, productTypeExpand)); assertThat(fetchB.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"), ExpansionPath.of("productType")));
See the test code.
plusExpansionPaths
in interface MetaModelReferenceExpansionDsl<T,C,E>
m
- function to use the meta model for expansions to create an expansion pathpublic C withExpansionPaths(String 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<T,C>
expansionPath
- the new expansion pathspublic C plusExpansionPaths(String 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<T,C>
expansionPath
- the new expansion path to add to the existing onespublic E expansionModel()
expansionModel
in interface MetaModelExpansionDslExpansionModelRead<T,C,E>
public D getDraft()
getDraft
in interface DraftBasedCreateCommand<T,D>
protected MetaModelCreateCommandBuilder<T,C,D,E> copyBuilder()