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