Search in sources :

Example 6 with TriConsumer

use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.

the class ProductSyncer method of.

@Nonnull
public static ProductSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock, @Nullable final ProductSyncCustomRequest productSyncCustomRequest) {
    final QuadConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>, List<UpdateAction<Product>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> {
        final String resourceKey = oldResource.map(WithKey::getKey).orElse(IDENTIFIER_NOT_PRESENT);
        logErrorCallback(LOGGER, "product", exception, resourceKey, updateActions);
    };
    final TriConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "product", exception, oldResource);
    final ProductSyncOptions syncOptions = ProductSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final ProductSync productSync = new ProductSync(syncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new ProductSyncer(productSync, sourceClient, targetClient, customObjectService, clock, productSyncCustomRequest);
}
Also used : ProductTransformUtils.toProductDrafts(com.commercetools.sync.products.utils.ProductTransformUtils.toProductDrafts) ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) SyncException(com.commercetools.sync.commons.exceptions.SyncException) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) ProductSync(com.commercetools.sync.products.ProductSync) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ProductSyncCustomRequest(com.commercetools.project.sync.model.ProductSyncCustomRequest) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) WithKey(io.sphere.sdk.models.WithKey) Logger(org.slf4j.Logger) QueryPredicate(io.sphere.sdk.queries.QueryPredicate) IDENTIFIER_NOT_PRESENT(com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CompletionException(java.util.concurrent.CompletionException) Product(io.sphere.sdk.products.Product) List(java.util.List) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CompletionStage(java.util.concurrent.CompletionStage) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) Collections(java.util.Collections) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) Optional(java.util.Optional) WithKey(io.sphere.sdk.models.WithKey) Product(io.sphere.sdk.products.Product) ProductSync(com.commercetools.sync.products.ProductSync) SyncException(com.commercetools.sync.commons.exceptions.SyncException) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) Nonnull(javax.annotation.Nonnull)

Example 7 with TriConsumer

use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.

the class ProductTypeSyncer method of.

@Nonnull
public static ProductTypeSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
    final QuadConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>, List<UpdateAction<ProductType>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "product type", exception, oldResource, updateActions);
    final TriConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "product type", exception, oldResource);
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new ProductTypeSyncer(productTypeSync, sourceClient, targetClient, customObjectService, clock);
}
Also used : SyncException(com.commercetools.sync.commons.exceptions.SyncException) ProductType(io.sphere.sdk.producttypes.ProductType) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) SphereClient(io.sphere.sdk.client.SphereClient) ProductTypeTransformUtils(com.commercetools.sync.producttypes.utils.ProductTypeTransformUtils) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) Nonnull(javax.annotation.Nonnull) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) ProductTypeSync(com.commercetools.sync.producttypes.ProductTypeSync) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) ProductTypeSyncStatistics(com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Optional(java.util.Optional) ProductTypeSync(com.commercetools.sync.producttypes.ProductTypeSync) ProductType(io.sphere.sdk.producttypes.ProductType) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) SyncException(com.commercetools.sync.commons.exceptions.SyncException) Nonnull(javax.annotation.Nonnull)

Example 8 with TriConsumer

use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.

the class StateSyncer method of.

public static StateSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
    final QuadConsumer<SyncException, Optional<StateDraft>, Optional<State>, List<UpdateAction<State>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "state", exception, oldResource, updateActions);
    final TriConsumer<SyncException, Optional<StateDraft>, Optional<State>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "state", exception, oldResource);
    StateSyncOptions syncOptions = StateSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    StateSync stateSync = new StateSync(syncOptions);
    CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new StateSyncer(stateSync, sourceClient, targetClient, customObjectService, clock);
}
Also used : StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) SyncException(com.commercetools.sync.commons.exceptions.SyncException) StateQuery(io.sphere.sdk.states.queries.StateQuery) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) Nonnull(javax.annotation.Nonnull) StateSyncOptionsBuilder(com.commercetools.sync.states.StateSyncOptionsBuilder) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) StateSync(com.commercetools.sync.states.StateSync) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) State(io.sphere.sdk.states.State) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Syncer(com.commercetools.project.sync.Syncer) StateTransformUtils.toStateDrafts(com.commercetools.sync.states.utils.StateTransformUtils.toStateDrafts) Clock(java.time.Clock) Optional(java.util.Optional) StateDraft(io.sphere.sdk.states.StateDraft) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) StateSync(com.commercetools.sync.states.StateSync) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Optional(java.util.Optional) State(io.sphere.sdk.states.State) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) SyncException(com.commercetools.sync.commons.exceptions.SyncException) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions)

Example 9 with TriConsumer

use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.

the class TaxCategorySyncer method of.

@Nonnull
public static TaxCategorySyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
    final QuadConsumer<SyncException, Optional<TaxCategoryDraft>, Optional<TaxCategory>, List<UpdateAction<TaxCategory>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "tax category", exception, oldResource, updateActions);
    final TriConsumer<SyncException, Optional<TaxCategoryDraft>, Optional<TaxCategory>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "tax category", exception, oldResource);
    final TaxCategorySyncOptions syncOptions = TaxCategorySyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final TaxCategorySync taxCategorySync = new TaxCategorySync(syncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new TaxCategorySyncer(taxCategorySync, sourceClient, targetClient, customObjectService, clock);
}
Also used : TaxCategorySync(com.commercetools.sync.taxcategories.TaxCategorySync) TaxCategorySyncStatistics(com.commercetools.sync.taxcategories.helpers.TaxCategorySyncStatistics) SyncException(com.commercetools.sync.commons.exceptions.SyncException) TaxCategoryDraft(io.sphere.sdk.taxcategories.TaxCategoryDraft) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) TaxCategoryQuery(io.sphere.sdk.taxcategories.queries.TaxCategoryQuery) CompletableFuture(java.util.concurrent.CompletableFuture) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) TaxRateDraft(io.sphere.sdk.taxcategories.TaxRateDraft) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) Nonnull(javax.annotation.Nonnull) TaxCategoryDraftBuilder(io.sphere.sdk.taxcategories.TaxCategoryDraftBuilder) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) TaxRate(io.sphere.sdk.taxcategories.TaxRate) Logger(org.slf4j.Logger) TaxCategorySyncOptionsBuilder(com.commercetools.sync.taxcategories.TaxCategorySyncOptionsBuilder) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Collectors(java.util.stream.Collectors) List(java.util.List) TaxCategorySyncOptions(com.commercetools.sync.taxcategories.TaxCategorySyncOptions) CompletionStage(java.util.concurrent.CompletionStage) Syncer(com.commercetools.project.sync.Syncer) TaxRateDraftBuilder(io.sphere.sdk.taxcategories.TaxRateDraftBuilder) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) TaxCategorySync(com.commercetools.sync.taxcategories.TaxCategorySync) Optional(java.util.Optional) TaxCategorySyncOptions(com.commercetools.sync.taxcategories.TaxCategorySyncOptions) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) SyncException(com.commercetools.sync.commons.exceptions.SyncException) Nonnull(javax.annotation.Nonnull)

Example 10 with TriConsumer

use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.

the class TypeSyncer method of.

@Nonnull
public static TypeSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
    final QuadConsumer<SyncException, Optional<TypeDraft>, Optional<Type>, List<UpdateAction<Type>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "type", exception, oldResource, updateActions);
    final TriConsumer<SyncException, Optional<TypeDraft>, Optional<Type>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "type", exception, oldResource);
    final TypeSyncOptions syncOptions = TypeSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final TypeSync typeSync = new TypeSync(syncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new TypeSyncer(typeSync, sourceClient, targetClient, customObjectService, clock);
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) SyncException(com.commercetools.sync.commons.exceptions.SyncException) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) CompletableFuture(java.util.concurrent.CompletableFuture) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) SphereClient(io.sphere.sdk.client.SphereClient) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) Nonnull(javax.annotation.Nonnull) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeSync(com.commercetools.sync.types.TypeSync) Collectors(java.util.stream.Collectors) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) Type(io.sphere.sdk.types.Type) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Type(io.sphere.sdk.types.Type) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) SyncException(com.commercetools.sync.commons.exceptions.SyncException) TypeSync(com.commercetools.sync.types.TypeSync) Nonnull(javax.annotation.Nonnull)

Aggregations

SyncException (com.commercetools.sync.commons.exceptions.SyncException)17 TriConsumer (com.commercetools.sync.commons.utils.TriConsumer)17 SphereClient (io.sphere.sdk.client.SphereClient)17 UpdateAction (io.sphere.sdk.commands.UpdateAction)17 Optional (java.util.Optional)17 Syncer (com.commercetools.project.sync.Syncer)11 CustomObjectService (com.commercetools.project.sync.service.CustomObjectService)11 List (java.util.List)11 Nonnull (javax.annotation.Nonnull)11 CustomObjectServiceImpl (com.commercetools.project.sync.service.impl.CustomObjectServiceImpl)9 SyncUtils.logErrorCallback (com.commercetools.project.sync.util.SyncUtils.logErrorCallback)9 SyncUtils.logWarningCallback (com.commercetools.project.sync.util.SyncUtils.logWarningCallback)9 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)9 Clock (java.time.Clock)9 CompletionStage (java.util.concurrent.CompletionStage)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 Category (io.sphere.sdk.categories.Category)7 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)7 LocalizedString (io.sphere.sdk.models.LocalizedString)6