Search in sources :

Example 1 with WaitingToBeResolvedCategories

use of com.commercetools.sync.commons.models.WaitingToBeResolvedCategories in project commercetools-sync-java by commercetools.

the class CleanupUnresolvedReferenceCustomObjectsIT method createSampleUnresolvedReferences.

void createSampleUnresolvedReferences() {
    final ProductDraft sampleProductDraft = SphereJsonUtils.readObjectFromResource(PRODUCT_KEY_1_RESOURCE_PATH, ProductDraft.class);
    final CategoryDraft sampleCategoryDraft = SphereJsonUtils.readObjectFromResource(CATEGORY_KEY_1_RESOURCE_PATH, CategoryDraft.class);
    final Set<Reference<State>> sampleTransitions = new HashSet<>(Arrays.asList(State.referenceOfId("id1"), State.referenceOfId("id2")));
    final List<WaitingToBeResolvedProducts> productUnresolvedReferences = new ArrayList<>();
    final List<WaitingToBeResolvedCategories> categoryUnresolvedReferences = new ArrayList<>();
    final List<WaitingToBeResolvedTransitions> transitionUnresolvedReferences = new ArrayList<>();
    for (int i = 1; i <= 5; i++) {
        productUnresolvedReferences.add(new WaitingToBeResolvedProducts(ProductDraftBuilder.of(sampleProductDraft).key(format("productKey%s", i)).build(), asSet("foo", "bar")));
        categoryUnresolvedReferences.add(new WaitingToBeResolvedCategories(CategoryDraftBuilder.of(sampleCategoryDraft).key(format("categoryKey%s", i)).build(), asSet("foo", "bar")));
        transitionUnresolvedReferences.add(new WaitingToBeResolvedTransitions(StateDraftBuilder.of(format("stateKeys%s", i), StateType.LINE_ITEM_STATE).transitions(sampleTransitions).build(), asSet("foo", "bar")));
    }
    CompletableFuture.allOf(CompletableFuture.allOf(productUnresolvedReferences.stream().map(draft -> unresolvedReferencesServiceForProducts.save(draft, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class)).map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new)), CompletableFuture.allOf(categoryUnresolvedReferences.stream().map(draft -> unresolvedReferencesServiceForCategories.save(draft, CUSTOM_OBJECT_CATEGORY_CONTAINER_KEY, WaitingToBeResolvedCategories.class)).map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new)), CompletableFuture.allOf(transitionUnresolvedReferences.stream().map(draft -> unresolvedReferencesServiceForTransitions.save(draft, CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY, WaitingToBeResolvedTransitions.class)).map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new))).join();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY) Arrays(java.util.Arrays) WaitingToBeResolvedProducts(com.commercetools.sync.commons.models.WaitingToBeResolvedProducts) Reference(io.sphere.sdk.models.Reference) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SphereJsonUtils(io.sphere.sdk.json.SphereJsonUtils) CompletableFuture(java.util.concurrent.CompletableFuture) WaitingToBeResolvedCategories(com.commercetools.sync.commons.models.WaitingToBeResolvedCategories) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StateType(io.sphere.sdk.states.StateType) UnresolvedReferencesService(com.commercetools.sync.services.UnresolvedReferencesService) ProductDraft(io.sphere.sdk.products.ProductDraft) PRODUCT_KEY_1_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_RESOURCE_PATH) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) StateDraftBuilder(io.sphere.sdk.states.StateDraftBuilder) UnresolvedReferencesServiceImpl(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl) StateSyncOptionsBuilder(com.commercetools.sync.states.StateSyncOptionsBuilder) Set(java.util.Set) CategorySyncOptionsBuilder(com.commercetools.sync.categories.CategorySyncOptionsBuilder) State(io.sphere.sdk.states.State) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) WaitingToBeResolvedTransitions(com.commercetools.sync.commons.models.WaitingToBeResolvedTransitions) List(java.util.List) CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY) CompletionStage(java.util.concurrent.CompletionStage) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) SphereInternalUtils.asSet(io.sphere.sdk.utils.SphereInternalUtils.asSet) CleanupUnresolvedReferenceCustomObjects(com.commercetools.sync.commons.CleanupUnresolvedReferenceCustomObjects) CATEGORY_KEY_1_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.CATEGORY_KEY_1_RESOURCE_PATH) CUSTOM_OBJECT_CATEGORY_CONTAINER_KEY(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_CATEGORY_CONTAINER_KEY) CustomObjectITUtils.deleteWaitingToBeResolvedCustomObjects(com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.deleteWaitingToBeResolvedCustomObjects) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) Reference(io.sphere.sdk.models.Reference) ArrayList(java.util.ArrayList) WaitingToBeResolvedCategories(com.commercetools.sync.commons.models.WaitingToBeResolvedCategories) CompletableFuture(java.util.concurrent.CompletableFuture) WaitingToBeResolvedTransitions(com.commercetools.sync.commons.models.WaitingToBeResolvedTransitions) ProductDraft(io.sphere.sdk.products.ProductDraft) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) WaitingToBeResolvedProducts(com.commercetools.sync.commons.models.WaitingToBeResolvedProducts) CompletionStage(java.util.concurrent.CompletionStage) HashSet(java.util.HashSet)

Aggregations

CategorySyncOptionsBuilder (com.commercetools.sync.categories.CategorySyncOptionsBuilder)1 CleanupUnresolvedReferenceCustomObjects (com.commercetools.sync.commons.CleanupUnresolvedReferenceCustomObjects)1 WaitingToBeResolvedCategories (com.commercetools.sync.commons.models.WaitingToBeResolvedCategories)1 WaitingToBeResolvedProducts (com.commercetools.sync.commons.models.WaitingToBeResolvedProducts)1 WaitingToBeResolvedTransitions (com.commercetools.sync.commons.models.WaitingToBeResolvedTransitions)1 CustomObjectITUtils.deleteWaitingToBeResolvedCustomObjects (com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.deleteWaitingToBeResolvedCustomObjects)1 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)1 CATEGORY_KEY_1_RESOURCE_PATH (com.commercetools.sync.products.ProductSyncMockUtils.CATEGORY_KEY_1_RESOURCE_PATH)1 PRODUCT_KEY_1_RESOURCE_PATH (com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_RESOURCE_PATH)1 ProductSyncOptionsBuilder (com.commercetools.sync.products.ProductSyncOptionsBuilder)1 UnresolvedReferencesService (com.commercetools.sync.services.UnresolvedReferencesService)1 UnresolvedReferencesServiceImpl (com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl)1 CUSTOM_OBJECT_CATEGORY_CONTAINER_KEY (com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_CATEGORY_CONTAINER_KEY)1 CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY (com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY)1 CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY (com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY)1 StateSyncOptionsBuilder (com.commercetools.sync.states.StateSyncOptionsBuilder)1 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)1 CategoryDraftBuilder (io.sphere.sdk.categories.CategoryDraftBuilder)1 SphereJsonUtils (io.sphere.sdk.json.SphereJsonUtils)1 Reference (io.sphere.sdk.models.Reference)1