use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.
the class CategorySyncer method of.
@Nonnull
public static CategorySyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<CategoryDraft>, Optional<Category>, List<UpdateAction<Category>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "category", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<CategoryDraft>, Optional<Category>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "category", exception, oldResource);
final CategorySyncOptions syncOptions = CategorySyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final CategorySync categorySync = new CategorySync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new CategorySyncer(categorySync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.
the class CustomerSyncer method of.
public static CustomerSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<CustomerDraft>, Optional<Customer>, List<UpdateAction<Customer>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "customer", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<CustomerDraft>, Optional<Customer>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "customer", exception, oldResource);
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final CustomerSync customerSync = new CustomerSync(customerSyncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new CustomerSyncer(customerSync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.
the class CustomObjectSyncer method of.
@Nonnull
public static CustomObjectSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock, @Nullable final String runnerName, final boolean isSyncProjectSyncCustomObjects) {
final QuadConsumer<SyncException, Optional<CustomObjectDraft<JsonNode>>, Optional<CustomObject<JsonNode>>, List<UpdateAction<CustomObject<JsonNode>>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> {
final String resourceIdentifier = getCustomObjectResourceIdentifier(oldResource);
updateActions = updateActions == null ? Collections.emptyList() : updateActions;
logErrorCallback(LOGGER, "customObject", exception, resourceIdentifier, updateActions);
};
final TriConsumer<SyncException, Optional<CustomObjectDraft<JsonNode>>, Optional<CustomObject<JsonNode>>> logWarningCallback = (exception, newResourceDraft, oldResource) -> {
final String resourceIdentifier = getCustomObjectResourceIdentifier(oldResource);
logWarningCallback(LOGGER, "customObject", exception, resourceIdentifier);
};
final CustomObjectSyncOptions syncOptions = CustomObjectSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final CustomObjectSync customObjectSyncer = new CustomObjectSync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new CustomObjectSyncer(customObjectSyncer, sourceClient, targetClient, customObjectService, clock, runnerName, isSyncProjectSyncCustomObjects);
}
use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-project-sync by commercetools.
the class InventoryEntrySyncer method of.
public static InventoryEntrySyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<InventoryEntryDraft>, Optional<InventoryEntry>, List<UpdateAction<InventoryEntry>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "inventory entry", exception, oldResource.map(InventoryEntry::getSku).orElse(IDENTIFIER_NOT_PRESENT), updateActions);
final TriConsumer<SyncException, Optional<InventoryEntryDraft>, Optional<InventoryEntry>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "inventory entry", exception, oldResource.map(InventoryEntry::getSku).orElse(IDENTIFIER_NOT_PRESENT));
final InventorySyncOptions syncOptions = InventorySyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final InventorySync inventorySync = new InventorySync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new InventoryEntrySyncer(inventorySync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-sync-java by commercetools.
the class ProductSyncIT method sync_withMissingPriceChannel_shouldCreateProductDistributionPriceChannel.
@Test
void sync_withMissingPriceChannel_shouldCreateProductDistributionPriceChannel() {
PriceDraftDsl priceDraftWithMissingChannelRef = PriceDraftBuilder.of(MoneyImpl.of("20", "EUR")).channel(ResourceIdentifier.ofKey("missingKey")).build();
ProductVariantDraftDsl masterVariantDraft = ProductVariantDraftBuilder.of(ProductVariantDraftDsl.of().withKey("v2").withSku("1065833").withPrices(Collections.singletonList(priceDraftWithMissingChannelRef))).build();
final ProductDraft productDraft = createProductDraftBuilder(PRODUCT_KEY_2_RESOURCE_PATH, ResourceIdentifier.ofKey(productType.getKey())).masterVariant(masterVariantDraft).taxCategory(null).state(null).build();
final TriConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>> warningCallBack = (exception, newResource, oldResource) -> warningCallBackMessages.add(exception.getMessage());
ProductSyncOptions syncOptions = ProductSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> collectErrors(exception.getMessage(), exception.getCause())).warningCallback(warningCallBack).ensurePriceChannels(true).build();
final ProductSync productSync = new ProductSync(syncOptions);
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(productDraft)));
assertThat(syncStatistics).hasValues(1, 1, 0, 0, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
Product productFromTargetProject = executeBlocking(CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(productDraft.getKey())));
List<Price> prices = productFromTargetProject.getMasterData().getStaged().getMasterVariant().getPrices();
assertThat(prices.size()).isEqualTo(1);
Channel channel = executeBlocking(CTP_TARGET_CLIENT.execute(ChannelByIdGet.of(Objects.requireNonNull(Objects.requireNonNull(prices.get(0).getChannel()).getId()))));
assertThat(channel.getRoles()).containsOnly(ChannelRole.PRODUCT_DISTRIBUTION);
}
Aggregations