R
- result type, maybe directly T
or sth. like List<T>
T
- type of the query resultC
- type of the class implementing this classE
- type of the expansion modelpublic abstract class MetaModelGetDslImpl<R,T,C extends MetaModelGetDsl<R,T,C,E>,E> extends Base implements MetaModelGetDsl<R,T,C,E>, MetaModelExpansionDslExpansionModelRead<T,C,E>
Modifier | Constructor and Description |
---|---|
protected |
MetaModelGetDslImpl(com.fasterxml.jackson.databind.JavaType javaType,
String endpoint,
String identifierToSearchFor,
List<ExpansionPath<T>> expansionPaths,
E expansionModel,
Function<MetaModelGetDslBuilder<R,T,C,E>,C> builderFunction,
List<NameValuePair> additionalParameters) |
protected |
MetaModelGetDslImpl(JsonEndpoint<R> endpoint,
String identifierToSearchFor,
E expansionModel,
Function<MetaModelGetDslBuilder<R,T,C,E>,C> builderFunction,
List<NameValuePair> additionalParameters) |
protected |
MetaModelGetDslImpl(MetaModelGetDslBuilder<R,T,C,E> builder) |
protected |
MetaModelGetDslImpl(String identifierToSearchFor,
JsonEndpoint<R> endpoint,
E expansionModel,
Function<MetaModelGetDslBuilder<R,T,C,E>,C> builderFunction) |
Modifier and Type | Method and Description |
---|---|
protected List<NameValuePair> |
additionalQueryParameters() |
boolean |
canDeserialize(HttpResponse httpResponse)
Checks if the response can be handled by
SphereRequest.deserialize(HttpResponse) . |
protected MetaModelGetDslBuilder<R,T,C,E> |
copyBuilder() |
R |
deserialize(HttpResponse httpResponse)
Takes an http response and maps it into a Java object of type T.
|
E |
expansionModel() |
List<ExpansionPath<T>> |
expansionPaths() |
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. |
protected C |
withAdditionalQueryParameters(List<NameValuePair> pairs) |
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 . |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
plusExpansionPaths, withExpansionPaths
protected MetaModelGetDslImpl(JsonEndpoint<R> endpoint, String identifierToSearchFor, E expansionModel, Function<MetaModelGetDslBuilder<R,T,C,E>,C> builderFunction, List<NameValuePair> additionalParameters)
protected MetaModelGetDslImpl(String identifierToSearchFor, JsonEndpoint<R> endpoint, E expansionModel, Function<MetaModelGetDslBuilder<R,T,C,E>,C> builderFunction)
protected MetaModelGetDslImpl(MetaModelGetDslBuilder<R,T,C,E> builder)
protected MetaModelGetDslImpl(com.fasterxml.jackson.databind.JavaType javaType, String endpoint, String identifierToSearchFor, List<ExpansionPath<T>> expansionPaths, E expansionModel, Function<MetaModelGetDslBuilder<R,T,C,E>,C> builderFunction, List<NameValuePair> additionalParameters)
@Nullable public R deserialize(HttpResponse httpResponse)
SphereRequest
SphereRequest.canDeserialize(HttpResponse)
if the response can be consumed.deserialize
in interface SphereRequest<R>
deserialize
in interface Get<R>
httpResponse
- the http response of the APIpublic HttpRequestIntent httpRequestIntent()
SphereRequest
httpRequestIntent
in interface SphereRequest<R>
protected com.fasterxml.jackson.databind.JavaType jacksonJavaType()
protected List<NameValuePair> additionalQueryParameters()
public boolean canDeserialize(HttpResponse httpResponse)
SphereRequest
SphereRequest.deserialize(HttpResponse)
.
Use case 1: A http response returns 404 and the this SphereRequest
can handle this error by returning an empty optional, an empty list or throwing a domain specific exception.canDeserialize
in interface SphereRequest<R>
httpResponse
- the http response which shall be transformedpublic 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 extends MetaModelGetDsl<R,T,C,E>>
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 extends MetaModelGetDsl<R,T,C,E>>
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 extends MetaModelGetDsl<R,T,C,E>,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 extends MetaModelGetDsl<R,T,C,E>>
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 extends MetaModelGetDsl<R,T,C,E>>
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 extends MetaModelGetDsl<R,T,C,E>,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 extends MetaModelGetDsl<R,T,C,E>>
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 extends MetaModelGetDsl<R,T,C,E>>
expansionPath
- the new expansion path to add to the existing onespublic E expansionModel()
expansionModel
in interface MetaModelExpansionDslExpansionModelRead<T,C extends MetaModelGetDsl<R,T,C,E>,E>
protected MetaModelGetDslBuilder<R,T,C,E> copyBuilder()
protected C withAdditionalQueryParameters(List<NameValuePair> pairs)