
com.commercetools.sync.services.ProductService Maven / Gradle / Ivy
package com.commercetools.sync.services;
import com.commercetools.api.models.product.ProductDraft;
import com.commercetools.api.models.product.ProductProjection;
import com.commercetools.api.models.product.ProductUpdateAction;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletionStage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public interface ProductService {
/**
* Given a {@code key}, if it is blank (null/empty), a completed future with an empty optional is
* returned. This method then checks if the cached map of product keys -> ids contains the key.
* If it does, then an optional containing the mapped id is returned. If the cache doesn't contain
* the key; this method attempts to fetch the id of the key from the CTP project, caches it and
* returns a {@link java.util.concurrent.CompletionStage}<{@link java.util.Optional}<{@link
* String}>> in which the result of it's completion could contain an {@link
* java.util.Optional} with the id inside of it or an empty {@link java.util.Optional} if no
* {@link ProductProjection} was found in the CTP project with this key.
*
* @param key the key by which a {@link ProductProjection} id should be fetched from the CTP
* project.
* @return {@link java.util.concurrent.CompletionStage}<{@link java.util.Optional}<{@link
* String}>> in which the result of it's completion could contain an {@link
* java.util.Optional} with the id inside of it or an empty {@link java.util.Optional} if no
* {@link ProductProjection} was found in the CTP project with this key.
*/
@Nonnull
CompletionStage> getIdFromCacheOrFetch(@Nullable String key);
/**
* Filters out the keys which are already cached and fetches only the not-cached product keys from
* the CTP project defined in an injected {@link com.commercetools.api.client.ProjectApiRoot} and
* stores a mapping for every product to id in the cached map of keys -> ids and returns this
* cached map.
*
* Note: If all the supplied keys are already cached, the cached map is returned right away
* with no request to CTP.
*
* @param productKeys the product keys to fetch and cache the ids for.
* @return {@link java.util.concurrent.CompletionStage}<{@link java.util.Map}> in which the
* result of it's completion contains a map of all product keys -> ids
*/
@Nonnull
CompletionStage
© 2015 - 2025 Weber Informatics LLC | Privacy Policy