Skip to content

Commit

Permalink
Merge branch 'sync-java-migration-v10' into DEVX-276_add_retry_to_ITs
Browse files Browse the repository at this point in the history
  • Loading branch information
lojzatran committed Nov 2, 2023
2 parents 7463e7a + 37470ba commit 92c243b
Show file tree
Hide file tree
Showing 19 changed files with 552 additions and 310 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ ext {
assertjVersion = '3.24.2'
pmdVersion = '6.55.0'
jacocoVersion = '0.8.10'
commercetoolsSyncJava = '10.0.0-beta.3'
httpClientVersion = '14.7.0'
commercetoolsSyncJava = '10.0.0-beta.4'
httpClientVersion = '17.0.0'
apacheCliVersion = '1.5.0'
jupiterApiVersion = '5.10.0'
logbackVersion = '1.4.11'
Expand Down Expand Up @@ -65,7 +65,7 @@ tasks.withType(SpotlessTask) {

dependencies {
implementation "com.commercetools:commercetools-sync-java:${commercetoolsSyncJava}"
implementation "com.commercetools.sdk:commercetools-http-client:${httpClientVersion}"
implementation "com.commercetools.sdk:commercetools-okhttp-client4:${httpClientVersion}"
implementation "commons-cli:commons-cli:${apacheCliVersion}"
implementation "ch.qos.logback:logback-classic:${logbackVersion}"
implementation "ch.qos.logback:logback-core:${logbackVersion}"
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/commercetools/project/sync/Syncer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import static com.commercetools.project.sync.util.SyncUtils.getSyncModuleName;
import static java.lang.String.format;

import com.commercetools.api.client.PagedQueryResourceRequest;
import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.models.DomainResource;
import com.commercetools.api.models.PagedQueryResourceRequest;
import com.commercetools.api.models.ResourcePagedQueryResponse;
import com.commercetools.api.models.ResourceUpdateAction;
import com.commercetools.api.models.category.Category;
Expand Down Expand Up @@ -45,6 +45,8 @@
* com.commercetools.api.models.product.ProductUpdateAction})
* @param <ResourceDraftT> The type of the resource draft (e.g. {@link ProductDraft}, {@link
* CategoryDraft}, etc..)
* @param <QueryBuilderDslT> The type of the query builder dsl class (e.g. {@link
* com.commercetools.api.predicates.query.state.StateQueryBuilderDsl})
* @param <SyncStatisticsT> The type of the sync statistics resulting from the sync process (e.g.
* {@link com.commercetools.sync.products.helpers.ProductSyncStatistics}, {@link
* com.commercetools.sync.categories.helpers.CategorySyncStatistics}, etc..)
Expand All @@ -62,9 +64,11 @@ public abstract class Syncer<
ResourceT extends BaseResource & DomainResource<ResourceT>,
ResourceUpdateActionT extends ResourceUpdateAction<ResourceUpdateActionT>,
ResourceDraftT,
QueryBuilderDslT,
SyncStatisticsT extends BaseSyncStatistics,
SyncOptionsT extends BaseSyncOptions<ResourceT, ResourceDraftT, ResourceUpdateActionT>,
PagedQueryT extends PagedQueryResourceRequest<PagedQueryT, PagedQueryResponseT>,
PagedQueryT extends
PagedQueryResourceRequest<PagedQueryT, PagedQueryResponseT, QueryBuilderDslT>,
PagedQueryResponseT extends ResourcePagedQueryResponse<ResourceT>,
BaseSyncT extends
BaseSync<ResourceT, ResourceDraftT, ResourceUpdateActionT, SyncStatisticsT, SyncOptionsT>> {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/commercetools/project/sync/SyncerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import static java.lang.String.format;
import static org.apache.commons.lang3.StringUtils.isBlank;

import com.commercetools.api.client.PagedQueryResourceRequest;
import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.models.PagedQueryResourceRequest;
import com.commercetools.api.models.ResourcePagedQueryResponse;
import com.commercetools.api.models.ResourceUpdateAction;
import com.commercetools.api.models.common.BaseResource;
Expand Down Expand Up @@ -131,9 +131,10 @@ private CompletableFuture<Void> chainSyncExecution(
? extends BaseResource,
? extends ResourceUpdateAction<?>,
?,
?,
? extends BaseSyncStatistics,
? extends BaseSyncOptions<?, ?, ?>,
? extends PagedQueryResourceRequest<?, ?>,
? extends PagedQueryResourceRequest<?, ?, ?>,
? extends ResourcePagedQueryResponse<?>,
? extends BaseSync<?, ?, ?, ?, ?>>
syncer =
Expand Down Expand Up @@ -290,9 +291,10 @@ private void closeClients() {
? extends BaseResource,
? extends ResourceUpdateAction<?>,
?,
?,
? extends BaseSyncStatistics,
? extends BaseSyncOptions<?, ?, ?>,
? extends PagedQueryResourceRequest<?, ?>,
? extends PagedQueryResourceRequest<?, ?, ?>,
? extends ResourcePagedQueryResponse<?>,
? extends BaseSync<?, ?, ?, ?, ?>>
buildSyncer(
Expand All @@ -305,9 +307,10 @@ private void closeClients() {
? extends BaseResource,
? extends ResourceUpdateAction<?>,
?,
?,
? extends BaseSyncStatistics,
? extends BaseSyncOptions<?, ?, ?>,
? extends PagedQueryResourceRequest<?, ?>,
? extends PagedQueryResourceRequest<?, ?, ?>,
? extends ResourcePagedQueryResponse<?>,
? extends BaseSync<?, ?, ?, ?, ?>>
syncer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.commercetools.api.models.cart_discount.CartDiscountDraft;
import com.commercetools.api.models.cart_discount.CartDiscountPagedQueryResponse;
import com.commercetools.api.models.cart_discount.CartDiscountUpdateAction;
import com.commercetools.api.predicates.query.cart_discount.CartDiscountQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -33,6 +34,7 @@ public final class CartDiscountSyncer
CartDiscount,
CartDiscountUpdateAction,
CartDiscountDraft,
CartDiscountQueryBuilderDsl,
CartDiscountSyncStatistics,
CartDiscountSyncOptions,
ByProjectKeyCartDiscountsGet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.commercetools.api.models.category.CategoryDraft;
import com.commercetools.api.models.category.CategoryPagedQueryResponse;
import com.commercetools.api.models.category.CategoryUpdateAction;
import com.commercetools.api.predicates.query.category.CategoryQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -33,6 +34,7 @@ public final class CategorySyncer
Category,
CategoryUpdateAction,
CategoryDraft,
CategoryQueryBuilderDsl,
CategorySyncStatistics,
CategorySyncOptions,
ByProjectKeyCategoriesGet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.commercetools.api.models.customer.CustomerDraft;
import com.commercetools.api.models.customer.CustomerPagedQueryResponse;
import com.commercetools.api.models.customer.CustomerUpdateAction;
import com.commercetools.api.predicates.query.customer.CustomerQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -33,6 +34,7 @@ public final class CustomerSyncer
Customer,
CustomerUpdateAction,
CustomerDraft,
CustomerQueryBuilderDsl,
CustomerSyncStatistics,
CustomerSyncOptions,
ByProjectKeyCustomersGet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.commercetools.api.models.custom_object.CustomObjectDraft;
import com.commercetools.api.models.custom_object.CustomObjectDraftBuilder;
import com.commercetools.api.models.custom_object.CustomObjectPagedQueryResponse;
import com.commercetools.api.predicates.query.custom_object.CustomObjectQueryBuilderDsl;
import com.commercetools.project.sync.SyncModuleOption;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
Expand Down Expand Up @@ -41,6 +42,7 @@ public final class CustomObjectSyncer
CustomObject,
NoopResourceUpdateAction,
CustomObjectDraft,
CustomObjectQueryBuilderDsl,
CustomObjectSyncStatistics,
CustomObjectSyncOptions,
ByProjectKeyCustomObjectsGet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.commercetools.api.models.inventory.InventoryEntryDraft;
import com.commercetools.api.models.inventory.InventoryEntryUpdateAction;
import com.commercetools.api.models.inventory.InventoryPagedQueryResponse;
import com.commercetools.api.predicates.query.inventory.InventoryEntryQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -34,6 +35,7 @@ public final class InventoryEntrySyncer
InventoryEntry,
InventoryEntryUpdateAction,
InventoryEntryDraft,
InventoryEntryQueryBuilderDsl,
InventorySyncStatistics,
InventorySyncOptions,
ByProjectKeyInventoryGet,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.commercetools.project.sync.product;

import static com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT;
import static com.commercetools.project.sync.util.SyncUtils.getCompletionExceptionCause;
import static com.commercetools.project.sync.util.SyncUtils.logErrorCallback;
import static com.commercetools.project.sync.util.SyncUtils.logWarningCallback;
import static com.commercetools.sync.products.utils.ProductTransformUtils.toProductDrafts;
Expand All @@ -18,6 +19,7 @@
import com.commercetools.api.models.product.ProductUpdateAction;
import com.commercetools.api.models.product.ProductVariantDraft;
import com.commercetools.api.models.product.ProductVariantDraftBuilder;
import com.commercetools.api.predicates.query.product.ProductProjectionQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.model.ProductSyncCustomRequest;
import com.commercetools.project.sync.service.CustomObjectService;
Expand All @@ -33,7 +35,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand All @@ -46,6 +47,7 @@ public final class ProductSyncer
ProductProjection,
ProductUpdateAction,
ProductDraft,
ProductProjectionQueryBuilderDsl,
ProductSyncStatistics,
ProductSyncOptions,
ByProjectKeyProductProjectionsGet,
Expand Down Expand Up @@ -171,14 +173,6 @@ private ProductVariantDraft createProductVariantDraftWithoutDiscounted(
return ProductVariantDraftBuilder.of(productVariantDraft).prices(priceDrafts).build();
}

@Nonnull
private static Throwable getCompletionExceptionCause(@Nonnull final Throwable exception) {
if (exception instanceof CompletionException) {
return getCompletionExceptionCause(exception.getCause());
}
return exception;
}

@Nonnull
@Override
protected ByProjectKeyProductProjectionsGet getQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.commercetools.api.models.product_type.ProductTypeDraft;
import com.commercetools.api.models.product_type.ProductTypePagedQueryResponse;
import com.commercetools.api.models.product_type.ProductTypeUpdateAction;
import com.commercetools.api.predicates.query.product_type.ProductTypeQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -33,6 +34,7 @@ public final class ProductTypeSyncer
ProductType,
ProductTypeUpdateAction,
ProductTypeDraft,
ProductTypeQueryBuilderDsl,
ProductTypeSyncStatistics,
ProductTypeSyncOptions,
ByProjectKeyProductTypesGet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.commercetools.api.models.shopping_list.ShoppingListDraft;
import com.commercetools.api.models.shopping_list.ShoppingListPagedQueryResponse;
import com.commercetools.api.models.shopping_list.ShoppingListUpdateAction;
import com.commercetools.api.predicates.query.shopping_list.ShoppingListQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -34,6 +35,7 @@ public final class ShoppingListSyncer
ShoppingList,
ShoppingListUpdateAction,
ShoppingListDraft,
ShoppingListQueryBuilderDsl,
ShoppingListSyncStatistics,
ShoppingListSyncOptions,
ByProjectKeyShoppingListsGet,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.commercetools.project.sync.state;

import static com.commercetools.project.sync.util.SyncUtils.getCompletionExceptionCause;
import static com.commercetools.project.sync.util.SyncUtils.logErrorCallback;
import static com.commercetools.project.sync.util.SyncUtils.logWarningCallback;
import static com.commercetools.sync.states.utils.StateTransformUtils.toStateDrafts;
Expand All @@ -10,6 +11,7 @@
import com.commercetools.api.models.state.StateDraft;
import com.commercetools.api.models.state.StatePagedQueryResponse;
import com.commercetools.api.models.state.StateUpdateAction;
import com.commercetools.api.predicates.query.state.StateQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -28,13 +30,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// This class compiles but not tested yet
// TODO: Test class and adjust logic if needed
public final class StateSyncer
extends Syncer<
State,
StateUpdateAction,
StateDraft,
StateQueryBuilderDsl,
StateSyncStatistics,
StateSyncOptions,
ByProjectKeyStatesGet,
Expand Down Expand Up @@ -77,7 +78,17 @@ public static StateSyncer of(
@Nonnull
@Override
protected CompletionStage<List<StateDraft>> transform(@Nonnull List<State> states) {
return toStateDrafts(getSourceClient(), referenceIdToKeyCache, states);
return toStateDrafts(getSourceClient(), referenceIdToKeyCache, states)
.handle(
(stateDrafts, throwable) -> {
if (throwable != null) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn(throwable.getMessage(), getCompletionExceptionCause(throwable));
}
return List.of();
}
return stateDrafts;
});
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.commercetools.api.models.tax_category.TaxRate;
import com.commercetools.api.models.tax_category.TaxRateDraft;
import com.commercetools.api.models.tax_category.TaxRateDraftBuilder;
import com.commercetools.api.predicates.query.tax_category.TaxCategoryQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -33,13 +34,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// This class compiles but not tested yet
// TODO: Test class and adjust logic if needed
public final class TaxCategorySyncer
extends Syncer<
TaxCategory,
TaxCategoryUpdateAction,
TaxCategoryDraft,
TaxCategoryQueryBuilderDsl,
TaxCategorySyncStatistics,
TaxCategorySyncOptions,
ByProjectKeyTaxCategoriesGet,
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/commercetools/project/sync/type/TypeSyncer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.commercetools.project.sync.type;

import static com.commercetools.project.sync.util.SyncUtils.getCompletionExceptionCause;
import static com.commercetools.project.sync.util.SyncUtils.logErrorCallback;
import static com.commercetools.project.sync.util.SyncUtils.logWarningCallback;

Expand All @@ -10,6 +11,7 @@
import com.commercetools.api.models.type.TypeDraftBuilder;
import com.commercetools.api.models.type.TypePagedQueryResponse;
import com.commercetools.api.models.type.TypeUpdateAction;
import com.commercetools.api.predicates.query.type.TypeQueryBuilderDsl;
import com.commercetools.project.sync.Syncer;
import com.commercetools.project.sync.service.CustomObjectService;
import com.commercetools.project.sync.service.impl.CustomObjectServiceImpl;
Expand All @@ -27,6 +29,7 @@
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,6 +40,7 @@ public final class TypeSyncer
Type,
TypeUpdateAction,
TypeDraft,
TypeQueryBuilderDsl,
TypeSyncStatistics,
TypeSyncOptions,
ByProjectKeyTypesGet,
Expand Down Expand Up @@ -96,11 +100,21 @@ protected Logger getLoggerInstance() {
@Nonnull
@Override
protected CompletionStage<List<TypeDraft>> transform(@Nonnull final List<Type> page) {
return CompletableFuture.completedFuture(
page.stream().map(TypeSyncer::typeToDraft).collect(Collectors.toList()));
return CompletableFuture.supplyAsync(
() -> page.stream().map(TypeSyncer::typeToDraft).collect(Collectors.toList()))
.handle(
((typeDrafts, throwable) -> {
if (throwable != null) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn(throwable.getMessage(), getCompletionExceptionCause(throwable));
}
return List.of();
}
return typeDrafts;
}));
}

@Nonnull
@Nullable
private static TypeDraft typeToDraft(@Nonnull final Type type) {
return TypeDraftBuilder.of()
.key(type.getKey())
Expand Down
Loading

0 comments on commit 92c243b

Please sign in to comment.