Class CustomerReferenceResolver

    • Field Detail

      • FAILED_TO_RESOLVE_CUSTOMER_GROUP_REFERENCE

        public static final java.lang.String FAILED_TO_RESOLVE_CUSTOMER_GROUP_REFERENCE
        See Also:
        Constant Field Values
      • FAILED_TO_RESOLVE_STORE_REFERENCE

        public static final java.lang.String FAILED_TO_RESOLVE_STORE_REFERENCE
        See Also:
        Constant Field Values
      • FAILED_TO_RESOLVE_CUSTOM_TYPE

        public static final java.lang.String FAILED_TO_RESOLVE_CUSTOM_TYPE
        See Also:
        Constant Field Values
      • CUSTOMER_GROUP_DOES_NOT_EXIST

        public static final java.lang.String CUSTOMER_GROUP_DOES_NOT_EXIST
        See Also:
        Constant Field Values
    • Constructor Detail

      • CustomerReferenceResolver

        public CustomerReferenceResolver​(@Nonnull
                                         CustomerSyncOptions options,
                                         @Nonnull
                                         TypeService typeService,
                                         @Nonnull
                                         CustomerGroupService customerGroupService)
        Takes a CustomerSyncOptions instance, a TypeService and a CustomerGroupService to instantiate a CustomerReferenceResolver instance that could be used to resolve the customer drafts in the CTP project specified in the injected CustomerSyncOptions instance.
        Parameters:
        options - the container of all the options of the sync process including the CTP project client and/or configuration and other sync-specific options.
        typeService - the service to fetch the custom types for reference resolution.
        customerGroupService - the service to fetch the customer groups for reference resolution.
    • Method Detail

      • resolveReferences

        @Nonnull
        public java.util.concurrent.CompletionStage<io.sphere.sdk.customers.CustomerDraft> resolveReferences​(@Nonnull
                                                                                                             io.sphere.sdk.customers.CustomerDraft customerDraft)
        Given a CustomerDraft this method attempts to resolve the stores, customer group and custom type references to return a CompletionStage which contains a new instance of the draft with the resolved references or, in case an error occurs during reference resolution, a ReferenceResolutionException.
        Specified by:
        resolveReferences in class BaseReferenceResolver<io.sphere.sdk.customers.CustomerDraft,​CustomerSyncOptions>
        Parameters:
        customerDraft - the draft to resolve its references.
        Returns:
        a CompletionStage that contains as a result a new CustomerDraft instance with resolved custom type reference or, in case an error occurs during reference resolution, a ReferenceResolutionException.
      • resolveCustomTypeReference

        protected java.util.concurrent.CompletionStage<io.sphere.sdk.customers.CustomerDraftBuilder> resolveCustomTypeReference​(@Nonnull
                                                                                                                                io.sphere.sdk.customers.CustomerDraftBuilder draftBuilder)
        Description copied from class: CustomReferenceResolver
        Given a draft of D (e.g. CategoryDraft) this method attempts to resolve it's custom type reference to return CompletionStage which contains a new instance of the draft with the resolved custom type reference.

        The method then tries to fetch the key of the custom type, optimistically from a cache. If the key is is not found, the resultant draft would remain exactly the same as the passed draft (without a custom type reference resolution).

        Specified by:
        resolveCustomTypeReference in class CustomReferenceResolver<io.sphere.sdk.customers.CustomerDraft,​io.sphere.sdk.customers.CustomerDraftBuilder,​CustomerSyncOptions>
        Parameters:
        draftBuilder - the draft builder to resolve it's references.
        Returns:
        a CompletionStage that contains as a result a new draft instance with resolved custom type references or, in case an error occurs during reference resolution, a ReferenceResolutionException.
      • resolveCustomerGroupReference

        @Nonnull
        public java.util.concurrent.CompletionStage<io.sphere.sdk.customers.CustomerDraftBuilder> resolveCustomerGroupReference​(@Nonnull
                                                                                                                                io.sphere.sdk.customers.CustomerDraftBuilder draftBuilder)
        Given a CustomerDraftBuilder this method attempts to resolve the customer group to return a CompletionStage which contains a new instance of the builder with the resolved customer group reference.
        Parameters:
        draftBuilder - the customerDraft to resolve its customer group reference.
        Returns:
        a CompletionStage that contains as a result a new builder instance with resolved customer group reference or, in case an error occurs during reference resolution, a ReferenceResolutionException.
      • resolveStoreReferences

        @Nonnull
        public java.util.concurrent.CompletionStage<io.sphere.sdk.customers.CustomerDraftBuilder> resolveStoreReferences​(@Nonnull
                                                                                                                         io.sphere.sdk.customers.CustomerDraftBuilder draftBuilder)
        Given a CustomerDraftBuilder this method attempts to resolve the stores and return a CompletionStage which contains a new instance of the builder with the resolved references.
        Parameters:
        draftBuilder - the customer draft to resolve its store references.
        Returns:
        a CompletionStage that contains as a result a new builder instance with resolved references or, in case an error occurs during reference resolution, a ReferenceResolutionException.
      • populateKeyToIdCachesForReferencedKeys

        @Nonnull
        public java.util.concurrent.CompletableFuture<java.util.List<java.util.Map<java.lang.String,​java.lang.String>>> populateKeyToIdCachesForReferencedKeys​(@Nonnull
                                                                                                                                                                     CustomerBatchValidator.ReferencedKeys referencedKeys)
        Calls the cacheKeysToIds service methods to fetch all the referenced keys (i.e custom type, customer group) from the commercetools to populate caches for the reference resolution.

        Note: This method is meant be only used internally by the library to improve performance.

        Parameters:
        referencedKeys - a wrapper for the product references to fetch and cache the id's for.
        Returns:
        CompletionStage<Map<String>String>> in which the results of it's completions contains a map of requested references keys -> ids of customer references.