Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.commercetools.sync.services.impl;
import static com.commercetools.sync.commons.utils.CompletableFutureUtils.collectionOfFuturesToFutureOfCollection;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import com.commercetools.api.client.QueryUtils;
import com.commercetools.api.models.DomainResource;
import com.commercetools.api.models.PagedQueryResourceRequest;
import com.commercetools.api.models.ResourcePagedQueryResponse;
import com.commercetools.api.models.graph_ql.GraphQLRequest;
import com.commercetools.api.models.graph_ql.GraphQLRequestBuilder;
import com.commercetools.api.models.graph_ql.GraphQLVariablesMapBuilder;
import com.commercetools.sync.commons.BaseSyncOptions;
import com.commercetools.sync.commons.exceptions.SyncException;
import com.commercetools.sync.commons.models.GraphQlQueryResource;
import com.commercetools.sync.commons.utils.ChunkUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import io.vrap.rmf.base.client.ApiHttpResponse;
import io.vrap.rmf.base.client.ApiMethod;
import io.vrap.rmf.base.client.BodyApiMethod;
import io.vrap.rmf.base.client.Draft;
import io.vrap.rmf.base.client.error.NotFoundException;
import io.vrap.rmf.base.client.utils.json.JsonUtils;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
abstract class BaseService<
SyncOptionsT extends BaseSyncOptions,
ResourceT extends DomainResource,
ResourceDraftT extends Draft,
PagedQueryRequestT extends PagedQueryResourceRequest,
PagedQueryResponseT extends ResourcePagedQueryResponse,
GetOneResourceQueryT extends ApiMethod,
QueryResultT,
PostRequestT extends BodyApiMethod> {
final SyncOptionsT syncOptions;
protected final Cache keyToIdCache;
protected static final int MAXIMUM_ALLOWED_UPDATE_ACTIONS = 500;
static final String CREATE_FAILED = "Failed to create draft with key: '%s'. Reason: %s";
/*
* To be more practical, considering 41 characters as an average for key and sku fields
* (key and sku field doesn't have limit except for ProductType(256)) We chunk them in 250
* (keys or sku) we will have a query around 11.000 characters(also considered some
* conservative space for headers). Above this size it could return - Error 414 (Request-URI Too Large)
*/
static final int CHUNK_SIZE = 250;
BaseService(@Nonnull final SyncOptionsT syncOptions) {
this.syncOptions = syncOptions;
this.keyToIdCache =
Caffeine.newBuilder()
.maximumSize(syncOptions.getCacheSize())
.executor(Runnable::run)
.build();
}
/**
* Given a set of keys this method collects all keys which aren't already contained in the cache
* {@code keyToIdCache}
*
* @param keys {@link Set} of keys
* @return a {@link Set} of keys which aren't already contained in the cache or empty
*/
@Nonnull
protected Set getKeysNotCached(@Nonnull final Set keys) {
return keys.stream()
.filter(StringUtils::isNotBlank)
.filter(key -> !keyToIdCache.asMap().containsKey(key))
.collect(Collectors.toSet());
}
@Nonnull
public CompletionStage