Search in sources :

Example 11 with QuadConsumer

use of com.commercetools.sync.commons.utils.QuadConsumer 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);
}
Also used : CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) SyncException(com.commercetools.sync.commons.exceptions.SyncException) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) CustomObject(io.sphere.sdk.customobjects.CustomObject) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) CompletableFuture(java.util.concurrent.CompletableFuture) 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) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomObjectCompositeIdentifier(com.commercetools.sync.customobjects.helpers.CustomObjectCompositeIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) SyncModuleOption(com.commercetools.project.sync.SyncModuleOption) Logger(org.slf4j.Logger) CustomObjectDraft(io.sphere.sdk.customobjects.CustomObjectDraft) IDENTIFIER_NOT_PRESENT(com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) Collectors(java.util.stream.Collectors) CustomObjectSyncOptionsBuilder(com.commercetools.sync.customobjects.CustomObjectSyncOptionsBuilder) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) 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) SyncUtils(com.commercetools.project.sync.util.SyncUtils) CustomObject(io.sphere.sdk.customobjects.CustomObject) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) SyncException(com.commercetools.sync.commons.exceptions.SyncException) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) Nonnull(javax.annotation.Nonnull)

Example 12 with QuadConsumer

use of com.commercetools.sync.commons.utils.QuadConsumer 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);
}
Also used : SyncException(com.commercetools.sync.commons.exceptions.SyncException) InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) LoggerFactory(org.slf4j.LoggerFactory) InventorySyncOptionsBuilder(com.commercetools.sync.inventories.InventorySyncOptionsBuilder) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) InventoryTransformUtils.toInventoryEntryDrafts(com.commercetools.sync.inventories.utils.InventoryTransformUtils.toInventoryEntryDrafts) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) InventoryEntryQuery(io.sphere.sdk.inventory.queries.InventoryEntryQuery) Nonnull(javax.annotation.Nonnull) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) IDENTIFIER_NOT_PRESENT(com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySync(com.commercetools.sync.inventories.InventorySync) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) InventorySyncOptions(com.commercetools.sync.inventories.InventorySyncOptions) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Optional(java.util.Optional) InventorySync(com.commercetools.sync.inventories.InventorySync) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) SyncException(com.commercetools.sync.commons.exceptions.SyncException) InventorySyncOptions(com.commercetools.sync.inventories.InventorySyncOptions)

Aggregations

SyncException (com.commercetools.sync.commons.exceptions.SyncException)12 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)12 UpdateAction (io.sphere.sdk.commands.UpdateAction)12 List (java.util.List)12 Optional (java.util.Optional)12 Nonnull (javax.annotation.Nonnull)12 Syncer (com.commercetools.project.sync.Syncer)11 CustomObjectService (com.commercetools.project.sync.service.CustomObjectService)11 CustomObjectServiceImpl (com.commercetools.project.sync.service.impl.CustomObjectServiceImpl)11 SyncUtils.logErrorCallback (com.commercetools.project.sync.util.SyncUtils.logErrorCallback)11 SyncUtils.logWarningCallback (com.commercetools.project.sync.util.SyncUtils.logWarningCallback)11 TriConsumer (com.commercetools.sync.commons.utils.TriConsumer)11 SphereClient (io.sphere.sdk.client.SphereClient)11 Clock (java.time.Clock)11 CompletionStage (java.util.concurrent.CompletionStage)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 IDENTIFIER_NOT_PRESENT (com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 Collectors (java.util.stream.Collectors)3