Class ProductTypeReferenceResolutionUtils
- java.lang.Object
-
- com.commercetools.sync.producttypes.utils.ProductTypeReferenceResolutionUtils
-
public final class ProductTypeReferenceResolutionUtils extends java.lang.Object
Util class which provides utilities that can be used when syncing resources from a source commercetools project to a target one.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static io.sphere.sdk.producttypes.queries.ProductTypeQuery
buildProductTypeQuery()
Builds aProductTypeQuery
for fetching products from a source CTP project with an expansion to theProductType
reference of any NestedType Attributestatic io.sphere.sdk.producttypes.queries.ProductTypeQuery
buildProductTypeQuery(int maximumSetDepth)
Builds aProductTypeQuery
for fetching products from a source CTP project with an expansion to theProductType
reference of any NestedType Attribute and also any SetType Attribute that has anelementType
ofNestedType
depending on the givenmaximumSetDepth
will provide an expansion for the nestedType of this set depth and all nested types of smaller depths.static java.util.List<io.sphere.sdk.producttypes.ProductTypeDraft>
mapToProductTypeDrafts(java.util.List<io.sphere.sdk.producttypes.ProductType> productTypes)
Returns anList
<ProductTypeDraft
> consisting of the results of applying the mapping fromProductType
toProductTypeDraft
with considering reference resolution.
-
-
-
Method Detail
-
mapToProductTypeDrafts
@Nonnull public static java.util.List<io.sphere.sdk.producttypes.ProductTypeDraft> mapToProductTypeDrafts(@Nonnull java.util.List<io.sphere.sdk.producttypes.ProductType> productTypes)
Returns anList
<ProductTypeDraft
> consisting of the results of applying the mapping fromProductType
toProductTypeDraft
with considering reference resolution.Mapping of Reference fields for the reference resolution Reference field from to productType references (in case it has NestedType or set of NestedType) Set
<Reference
<ProductType
>>Set
<Reference
<ProductType
>> (with key replaced with id field)Note:If some references are not expanded for an attributeDefinition of a productType, the method will throw a
ReferenceReplacementException
containing the root causes of the exceptions that occurred in any of the suppliedproductTypes
.- Parameters:
productTypes
- the product types with expanded references.- Returns:
- a
List
ofProductTypeDraft
built from the suppliedList
ofProductType
.
-
buildProductTypeQuery
@Nonnull public static io.sphere.sdk.producttypes.queries.ProductTypeQuery buildProductTypeQuery()
Builds aProductTypeQuery
for fetching products from a source CTP project with an expansion to theProductType
reference of any NestedType AttributeNote: Please only use this util if you have nestedType attributes in the productTypes that you will fetch from a source commercetools project. Otherwise, it is more efficient to build the query without expansions, if they are not needed, to avoid unnecessarily bigger payloads fetched from the source project.
- Returns:
- the query for fetching products from the source CTP project with an expansion to the
ProductType
reference of any NestedType Attribute.
-
buildProductTypeQuery
@Nonnull public static io.sphere.sdk.producttypes.queries.ProductTypeQuery buildProductTypeQuery(int maximumSetDepth)
Builds aProductTypeQuery
for fetching products from a source CTP project with an expansion to theProductType
reference of any NestedType Attribute and also any SetType Attribute that has anelementType
ofNestedType
depending on the givenmaximumSetDepth
will provide an expansion for the nestedType of this set depth and all nested types of smaller depths. For example:
ifmaximumSetDepth
is 0, it means there is no atttribute that is a type of set of nestedType. Therefore, the built query will have the following expansion paths:
attributes[*].type.typeReference
ifmaximumSetDepth
is 1, it means the maximum nesting of sets is set of a NestedType. Therefore, the built query will have the following expansion paths:
attributes[*].type.typeReference, attributes[*].type.elementType.typeReference
ifmaximumSetDepth
is 2, it means the maximum nesting of sets is set of set of a NestedType. Therefore, the built query will have the following expansion paths:
attributes[*].type.typeReference, attributes[*].type.elementType.typeReference, attributes[*].type.elementType.elementType.typeReference
and so on..Note: Please only use this util if you have nestedType attributes in the productTypes that you will fetch from a source commercetools project. Otherwise, it is more efficient to build the query without expansions, if they are not needed, to avoid unnecessarily bigger payloads fetched from the source project.
- Parameters:
maximumSetDepth
- defines the maximum nesting of SetType attributes. If there are no setType of NestedType attributes in source productTypes then this number should be 0. If there is an attribute of type setType of a NestedType then this number should be 1. If the maximum nesting is a setType of a setType attribute, then this number should be 2, and so on.- Returns:
- the query for fetching productTypes from the source CTP project with all the aforementioned references expanded.
-
-