Search in sources :

Example 1 with ProductSyncCustomRequest

use of com.commercetools.project.sync.model.ProductSyncCustomRequest in project commercetools-project-sync by commercetools.

the class ProductSyncerTest method getQuery_ShouldBuildProductQueryWithCustomQueryAndLimitSize.

@Test
void getQuery_ShouldBuildProductQueryWithCustomQueryAndLimitSize() {
    // preparation
    final Long limit = 100L;
    final String customQuery = "published=true AND masterData(masterVariant(attributes(name= \"abc\" AND value=123)))";
    final ProductSyncCustomRequest productSyncCustomRequest = new ProductSyncCustomRequest();
    productSyncCustomRequest.setWhere(customQuery);
    productSyncCustomRequest.setLimit(limit);
    final ProductSyncer productSyncer = ProductSyncer.of(mock(SphereClient.class), mock(SphereClient.class), getMockedClock(), productSyncCustomRequest);
    // test
    final ProductProjectionQuery query = productSyncer.getQuery();
    // assertion
    assertThat(query.limit()).isEqualTo(100);
    assertThat(query.predicates()).contains(QueryPredicate.of(customQuery));
}
Also used : ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) SphereClient(io.sphere.sdk.client.SphereClient) ProductSyncCustomRequest(com.commercetools.project.sync.model.ProductSyncCustomRequest) Test(org.junit.jupiter.api.Test)

Example 2 with ProductSyncCustomRequest

use of com.commercetools.project.sync.model.ProductSyncCustomRequest in project commercetools-project-sync by commercetools.

the class CliRunner method processSyncOptionAndExecute.

@Nonnull
private static CompletionStage<Void> processSyncOptionAndExecute(@Nonnull final CommandLine commandLine, @Nonnull final SyncerFactory syncerFactory) {
    final String[] syncOptionValues = commandLine.getOptionValues(SYNC_MODULE_OPTION_SHORT);
    final String runnerNameValue = commandLine.getOptionValue(RUNNER_NAME_OPTION_SHORT);
    final boolean isFullSync = commandLine.hasOption(FULL_SYNC_OPTION_SHORT);
    final boolean isSyncProjectSyncCustomObjects = commandLine.hasOption(SYNC_PROJECT_SYNC_CUSTOM_OBJECTS_OPTION_LONG);
    final boolean isProductQueryParametersOptionPresent = commandLine.hasOption(PRODUCT_QUERY_PARAMETERS_OPTION);
    final ProductSyncCustomRequest productSyncCustomRequest;
    try {
        productSyncCustomRequest = isProductQueryParametersOptionPresent ? parseProductQueryParametersOption(commandLine.getOptionValue(PRODUCT_QUERY_PARAMETERS_OPTION)) : null;
    } catch (CliException e) {
        return exceptionallyCompletedFuture(e);
    }
    return syncerFactory.sync(syncOptionValues, runnerNameValue, isFullSync, isSyncProjectSyncCustomObjects, productSyncCustomRequest);
}
Also used : CliException(com.commercetools.project.sync.exception.CliException) ProductSyncCustomRequest(com.commercetools.project.sync.model.ProductSyncCustomRequest) Nonnull(javax.annotation.Nonnull)

Example 3 with ProductSyncCustomRequest

use of com.commercetools.project.sync.model.ProductSyncCustomRequest 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)

Aggregations

ProductSyncCustomRequest (com.commercetools.project.sync.model.ProductSyncCustomRequest)3 SphereClient (io.sphere.sdk.client.SphereClient)2 ProductProjectionQuery (io.sphere.sdk.products.queries.ProductProjectionQuery)2 Nonnull (javax.annotation.Nonnull)2 Syncer (com.commercetools.project.sync.Syncer)1 CliException (com.commercetools.project.sync.exception.CliException)1 CustomObjectService (com.commercetools.project.sync.service.CustomObjectService)1 CustomObjectServiceImpl (com.commercetools.project.sync.service.impl.CustomObjectServiceImpl)1 IDENTIFIER_NOT_PRESENT (com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT)1 SyncUtils.logErrorCallback (com.commercetools.project.sync.util.SyncUtils.logErrorCallback)1 SyncUtils.logWarningCallback (com.commercetools.project.sync.util.SyncUtils.logWarningCallback)1 SyncException (com.commercetools.sync.commons.exceptions.SyncException)1 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)1 TriConsumer (com.commercetools.sync.commons.utils.TriConsumer)1 ProductSync (com.commercetools.sync.products.ProductSync)1 ProductSyncOptions (com.commercetools.sync.products.ProductSyncOptions)1 ProductSyncOptionsBuilder (com.commercetools.sync.products.ProductSyncOptionsBuilder)1 ProductSyncStatistics (com.commercetools.sync.products.helpers.ProductSyncStatistics)1 ProductTransformUtils.toProductDrafts (com.commercetools.sync.products.utils.ProductTransformUtils.toProductDrafts)1 UpdateAction (io.sphere.sdk.commands.UpdateAction)1