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));
}
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);
}
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);
}
Aggregations