All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.commercetools.sync.services.impl.CustomerGroupServiceImpl Maven / Gradle / Ivy

Go to download

Java Library used to import and/or sync (taking care of changes) data into one or more commercetools projects from external sources such as CSV, XML, JSON, etc.. or even from an already existing commercetools project.

The newest version!
package com.commercetools.sync.services.impl;

import com.commercetools.api.client.ByProjectKeyCustomerGroupsGet;
import com.commercetools.api.client.ByProjectKeyCustomerGroupsKeyByKeyGet;
import com.commercetools.api.client.ByProjectKeyCustomerGroupsPost;
import com.commercetools.api.models.customer_group.CustomerGroup;
import com.commercetools.api.models.customer_group.CustomerGroupDraft;
import com.commercetools.api.models.customer_group.CustomerGroupPagedQueryResponse;
import com.commercetools.api.predicates.query.customer_group.CustomerGroupQueryBuilderDsl;
import com.commercetools.sync.commons.BaseSyncOptions;
import com.commercetools.sync.commons.models.GraphQlQueryResource;
import com.commercetools.sync.services.CustomerGroupService;
import java.util.Collections;
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;

// todo: reuse duplicated code between TypeService and CustomerService
public final class CustomerGroupServiceImpl
    extends BaseService<
        BaseSyncOptions,
        CustomerGroup,
        CustomerGroupDraft,
        ByProjectKeyCustomerGroupsGet,
        CustomerGroupPagedQueryResponse,
        ByProjectKeyCustomerGroupsKeyByKeyGet,
        CustomerGroup,
        CustomerGroupQueryBuilderDsl,
        ByProjectKeyCustomerGroupsPost>
    implements CustomerGroupService {

  public CustomerGroupServiceImpl(@Nonnull final BaseSyncOptions syncOptions) {
    super(syncOptions);
  }

  @Nonnull
  @Override
  public CompletionStage> cacheKeysToIds(
      @Nonnull final Set customerGroupKeys) {
    return super.cacheKeysToIdsUsingGraphQl(
        customerGroupKeys, GraphQlQueryResource.CUSTOMER_GROUPS);
  }

  @Nonnull
  @Override
  public CompletionStage> fetchCachedCustomerGroupId(@Nonnull final String key) {
    ByProjectKeyCustomerGroupsGet query =
        syncOptions
            .getCtpClient()
            .customerGroups()
            .get()
            .withWhere("key in :keys")
            .withPredicateVar("keys", Collections.singletonList(key));

    return fetchCachedResourceId(key, query);
  }

  @Nonnull
  CompletionStage> fetchCachedResourceId(
      @Nullable final String key, @Nonnull final ByProjectKeyCustomerGroupsGet query) {
    return super.fetchCachedResourceId(key, resource -> resource.getKey(), query);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy