Class 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 a ProductTypeQuery for fetching products from a source CTP project with an expansion to the ProductType reference of any NestedType Attribute
      static io.sphere.sdk.producttypes.queries.ProductTypeQuery buildProductTypeQuery​(int maximumSetDepth)
      Builds a ProductTypeQuery for fetching products from a source CTP project with an expansion to the ProductType reference of any NestedType Attribute and also any SetType Attribute that has an elementType of NestedType depending on the given maximumSetDepth 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 an List<ProductTypeDraft> consisting of the results of applying the mapping from ProductType to ProductTypeDraft with considering reference resolution.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 an List<ProductTypeDraft> consisting of the results of applying the mapping from ProductType to ProductTypeDraft 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 supplied productTypes.

        Parameters:
        productTypes - the product types with expanded references.
        Returns:
        a List of ProductTypeDraft built from the supplied List of ProductType.
      • buildProductTypeQuery

        @Nonnull
        public static io.sphere.sdk.producttypes.queries.ProductTypeQuery buildProductTypeQuery()
        Builds a ProductTypeQuery for fetching products from a source CTP project with an expansion to the ProductType reference of any NestedType Attribute

        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.

        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 a ProductTypeQuery for fetching products from a source CTP project with an expansion to the ProductType reference of any NestedType Attribute and also any SetType Attribute that has an elementType of NestedType depending on the given maximumSetDepth will provide an expansion for the nestedType of this set depth and all nested types of smaller depths. For example:

        if maximumSetDepth 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

        if maximumSetDepth 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

        if maximumSetDepth 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.