Class CustomReferenceResolver<D,​B extends io.sphere.sdk.models.Builder<? extends D>,​S extends BaseSyncOptions>

    • Field Detail

      • TYPE_DOES_NOT_EXIST

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

      • CustomReferenceResolver

        protected CustomReferenceResolver​(@Nonnull
                                          S options,
                                          @Nonnull
                                          TypeService typeService)
    • Method Detail

      • resolveCustomTypeReference

        protected abstract java.util.concurrent.CompletionStage<B> resolveCustomTypeReference​(@Nonnull
                                                                                              B draftBuilder)
        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).

        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.
      • resolveCustomTypeReference

        @Nonnull
        protected java.util.concurrent.CompletionStage<B> resolveCustomTypeReference​(@Nonnull
                                                                                     B draftBuilder,
                                                                                     @Nonnull
                                                                                     java.util.function.Function<B,​io.sphere.sdk.types.CustomFieldsDraft> customGetter,
                                                                                     @Nonnull
                                                                                     java.util.function.BiFunction<B,​io.sphere.sdk.types.CustomFieldsDraft,​B> customSetter,
                                                                                     @Nonnull
                                                                                     java.lang.String errorMessage)
        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).

        Note: If the id field is set, then it is an evidence of resource existence on commercetools, so we can issue an update/create API request right away without reference resolution.

        Parameters:
        draftBuilder - the draft builder to resolve it's references.
        customGetter - a function to return the CustomFieldsDraft instance of the draft builder.
        customSetter - a function to set the CustomFieldsDraft instance of the builder and return this builder.
        errorMessage - the error message to inject in the ReferenceResolutionException if it occurs.
        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.