Skip to content

Commit 9ed387c

Browse files
committed
Merge branch 'master' into cleanup-project-after-sdk-v2-migration
# Conflicts: # build.gradle
2 parents e298f18 + 8f922fb commit 9ed387c

52 files changed

Lines changed: 331 additions & 111 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
plugins {
2-
id 'org.ajoberstar.git-publish' version '4.2.0'
3-
id 'com.adarshr.test-logger' version '3.2.0'
4-
id 'org.ajoberstar.grgit' version '5.2.0'
5-
id "com.github.ben-manes.versions" version '0.48.0'
2+
id 'org.ajoberstar.git-publish' version '4.2.1'
3+
id 'com.adarshr.test-logger' version '4.0.0'
4+
id 'org.ajoberstar.grgit' version '5.2.1'
5+
id "com.github.ben-manes.versions" version '0.49.0'
66
id 'ru.vyarus.mkdocs' version '3.0.0'
7-
id "com.github.spotbugs" version "5.1.3"
8-
id 'com.diffplug.spotless' version '6.21.0'
7+
id "com.github.spotbugs" version "5.2.1"
8+
id 'com.diffplug.spotless' version '6.22.0'
99
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
1010
}
1111

1212
ext{
13-
commercetoolsJavaSdkV2Version = '14.7.0'
14-
mockitoJunitJupiterVersion = '5.5.0'
15-
jupiterApiVersion = '5.10.0'
13+
commercetoolsJavaSdkV2Version = '17.1.0'
14+
mockitoJunitJupiterVersion = '5.7.0'
15+
jupiterApiVersion = '5.10.1'
1616
assertjVersion = '3.24.2'
1717
pmdVersion = '6.55.0'
18-
jacocoVersion = '0.8.10'
18+
jacocoVersion = '0.8.11'
1919
caffeineVersion = '3.1.8'
2020
nexusStagingPluginVersion = '0.22.0'
21-
commonTextVersion = '1.9'
21+
commonTextVersion = '1.11.0'
2222
}
2323

2424
apply from: "$rootDir/gradle-scripts/repositories.gradle"
@@ -43,21 +43,18 @@ apply from: "$rootDir/gradle-scripts/mkdocs.gradle"
4343
apply from: "$rootDir/gradle-scripts/spotless.gradle"
4444

4545
dependencies {
46-
implementation "com.commercetools.sdk:commercetools-http-client:${commercetoolsJavaSdkV2Version}"
47-
implementation "com.commercetools.sdk:commercetools-sdk-java-api:${commercetoolsJavaSdkV2Version}"
46+
implementation "com.commercetools.sdk:commercetools-http-client:${commercetoolsJavaSDK2Version}"
47+
implementation "com.commercetools.sdk:commercetools-sdk-java-api:${commercetoolsJavaSDK2Version}"
48+
4849
implementation "com.github.ben-manes.caffeine:caffeine:${caffeineVersion}"
4950
implementation "org.apache.commons:commons-text:${commonTextVersion}"
50-
api 'commons-io:commons-io:2.11.0'
51-
api 'commons-codec:commons-codec:1.16.0'
52-
api 'com.google.code.findbugs:annotations:3.0.1'
53-
api 'com.neovisionaries:nv-i18n:1.28'
51+
api "com.commercetools.sdk:commercetools-sdk-compat-v1:${commercetoolsJavaSdkV2Version}"
52+
api "com.commercetools.sdk:commercetools-apachehttp-client:${commercetoolsJavaSdkV2Version}"
5453
testImplementation "org.mockito:mockito-junit-jupiter:${mockitoJunitJupiterVersion}"
5554
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterApiVersion}"
5655
testImplementation "org.junit.jupiter:junit-jupiter-params:${jupiterApiVersion}"
5756
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterApiVersion}"
5857
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${jupiterApiVersion}"
5958
testImplementation "org.assertj:assertj-core:${assertjVersion}"
60-
testImplementation 'com.github.spotbugs:spotbugs-annotations:4.7.3'
61-
62-
59+
testImplementation 'com.github.spotbugs:spotbugs-annotations:4.8.0'
6360
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/integration-test/java/com/commercetools/sync/integration/services/impl/ProductServiceImplIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ void cacheKeysToIds_WithAlreadyCachedKeys_ShouldNotMakeRequestsAndReturnCurrentC
259259
spyProductService.cacheKeysToIds(singleton(product.getKey())).toCompletableFuture().join();
260260
assertThat(cache).hasSize(2);
261261
assertThat(cache).containsKeys(product.getKey(), product2.getKey());
262+
cache = spyProductService.cacheKeysToIds(singleton(null)).toCompletableFuture().join();
263+
assertThat(cache).hasSize(2);
262264

263265
// verify only 1 request was made to fetch id the first time, but not second time since it's
264266
// already in cache.

src/main/java/com/commercetools/sync/cartdiscounts/helpers/CartDiscountSyncStatistics.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import com.commercetools.sync.commons.helpers.BaseSyncStatistics;
44

5-
public final class CartDiscountSyncStatistics extends BaseSyncStatistics {
5+
public final class CartDiscountSyncStatistics
6+
extends BaseSyncStatistics<CartDiscountSyncStatistics> {
67

78
/**
89
* Builds a summary of the cart discount sync statistics instance that looks like the following
@@ -17,4 +18,9 @@ public final class CartDiscountSyncStatistics extends BaseSyncStatistics {
1718
public String getReportMessage() {
1819
return getDefaultReportMessageForResource("cart discounts");
1920
}
21+
22+
@Override
23+
protected CartDiscountSyncStatistics getThis() {
24+
return this;
25+
}
2026
}

src/main/java/com/commercetools/sync/categories/helpers/CategorySyncStatistics.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import javax.annotation.Nonnull;
1111
import javax.annotation.Nullable;
1212

13-
public class CategorySyncStatistics extends BaseSyncStatistics {
13+
public class CategorySyncStatistics extends BaseSyncStatistics<CategorySyncStatistics> {
1414

1515
/**
1616
* The following {@link java.util.Map} ({@code categoryKeysWithMissingParents}) represents
@@ -52,6 +52,11 @@ public String getReportMessage() {
5252
getNumberOfCategoriesWithMissingParents());
5353
}
5454

55+
@Override
56+
protected CategorySyncStatistics getThis() {
57+
return this;
58+
}
59+
5560
/**
5661
* Returns the total number of categories with missing parents.
5762
*

src/main/java/com/commercetools/sync/commons/BaseSync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public abstract class BaseSync<
1515
ResourceT extends BaseResource,
1616
ResourceDraftT,
1717
ResourceUpdateActionT extends ResourceUpdateAction<ResourceUpdateActionT>,
18-
SyncStatisticsT extends BaseSyncStatistics,
19-
SyncOptionsT extends BaseSyncOptions> {
18+
SyncStatisticsT extends BaseSyncStatistics<SyncStatisticsT>,
19+
SyncOptionsT extends BaseSyncOptions<ResourceT, ResourceDraftT, ResourceUpdateActionT>> {
2020
protected final SyncStatisticsT statistics;
2121
protected final SyncOptionsT syncOptions;
2222

src/main/java/com/commercetools/sync/commons/helpers/BaseBatchValidator.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.apache.commons.lang3.StringUtils.isBlank;
44

55
import com.commercetools.api.models.common.AssetDraft;
6-
import com.commercetools.api.models.common.Reference;
76
import com.commercetools.api.models.common.ResourceIdentifier;
87
import com.commercetools.api.models.customer.CustomerDraft;
98
import com.commercetools.api.models.type.CustomFieldsDraft;
@@ -70,14 +69,6 @@ protected void collectReferencedKeysFromAssetDrafts(
7069
}
7170
}
7271

73-
protected <T> void collectReferencedKeyFromReference(
74-
@Nullable final Reference reference, @Nonnull final Consumer<String> keyInReferenceSupplier) {
75-
76-
if (reference != null && !isBlank(reference.getId())) {
77-
keyInReferenceSupplier.accept(reference.getId());
78-
}
79-
}
80-
8172
protected void handleError(@Nonnull final SyncException syncException) {
8273
this.syncOptions.applyErrorCallback(syncException);
8374
this.syncStatistics.incrementFailed();

src/main/java/com/commercetools/sync/commons/helpers/BaseSyncStatistics.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.concurrent.atomic.AtomicInteger;
77
import javax.annotation.Nonnull;
88

9-
public abstract class BaseSyncStatistics {
9+
public abstract class BaseSyncStatistics<SyncStatisticsT extends BaseSyncStatistics> {
1010
private AtomicInteger updated;
1111
private AtomicInteger created;
1212
private AtomicInteger failed;
@@ -280,6 +280,29 @@ public long getLatestBatchProcessingTimeInMillis() {
280280
*/
281281
public abstract String getReportMessage();
282282

283+
/**
284+
* Gets the name of the implementation class extending this abstract class. This name is then
285+
* serialized into JSON and stored in the custom object of the last sync statistics. Later we
286+
* could use this name to deserialize the custom object into the correct implementation class.
287+
*
288+
* @return name of the implementation class extending this abstract class.
289+
*/
290+
public String getSyncStatisticsClassName() {
291+
return getThis().getClass().getName();
292+
}
293+
294+
/**
295+
* Returns {@code this} instance of {@code T}, which extends {@link
296+
* com.commercetools.sync.commons.helpers.BaseSyncStatistics}. The purpose of this method is to
297+
* make sure that {@code this} is an instance of a class which extends {@link
298+
* com.commercetools.sync.commons.helpers.BaseSyncStatistics} in order to be used in the generic
299+
* methods of the class. Otherwise, without this method, the methods above would need to cast
300+
* {@code this to T} which could lead to a runtime error of the class was extended in a wrong way.
301+
*
302+
* @return an instance of the class that overrides this method.
303+
*/
304+
protected abstract SyncStatisticsT getThis();
305+
283306
/**
284307
* Builds a proper summary message of the statistics report of a given {@code resourceString} in
285308
* following format:

src/main/java/com/commercetools/sync/commons/utils/ChunkUtils.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import static com.commercetools.sync.commons.utils.CompletableFutureUtils.collectionOfFuturesToFutureOfCollection;
44
import static java.util.stream.Collectors.toList;
55

6+
import com.commercetools.api.client.PagedQueryResourceRequest;
67
import com.commercetools.api.client.ProjectApiRoot;
7-
import com.commercetools.api.models.PagedQueryResourceRequest;
88
import com.commercetools.api.models.graph_ql.GraphQLRequest;
99
import com.commercetools.api.models.graph_ql.GraphQLResponse;
1010
import io.vrap.rmf.base.client.ApiHttpResponse;
@@ -24,16 +24,21 @@ public class ChunkUtils {
2424
*
2525
* @param requests A list of {@link PagedQueryResourceRequest} implementation to allow {@link
2626
* ProjectApiRoot} to execute queries on CTP.
27-
* @param <ResourceT> the type of the underlying model.
28-
* @param <QueryT> the type of the request model.
27+
* @param <ResourceT> the type of the request model.
28+
* @param <ResultT> the type of the underlying model.
29+
* @param <QueryBuilderDslT> the type of the query builder dsl class (e.g.
30+
* CartDiscountQueryBuilderDsl, CustomerQueryBuilderDsl, ...).
2931
* @return a list of lists where each list represents the results of passed {@link
3032
* PagedQueryResourceRequest}.
3133
*/
32-
public static <QueryT extends PagedQueryResourceRequest<QueryT, ResourceT>, ResourceT>
33-
CompletableFuture<List<ApiHttpResponse<ResourceT>>> executeChunks(
34-
@Nonnull final List<QueryT> requests) {
34+
public static <
35+
ResourceT extends PagedQueryResourceRequest<ResourceT, ResultT, QueryBuilderDslT>,
36+
ResultT,
37+
QueryBuilderDslT>
38+
CompletableFuture<List<ApiHttpResponse<ResultT>>> executeChunks(
39+
@Nonnull final List<ResourceT> requests) {
3540

36-
final List<CompletableFuture<ApiHttpResponse<ResourceT>>> futures =
41+
final List<CompletableFuture<ApiHttpResponse<ResultT>>> futures =
3742
requests.stream().map(request -> request.execute()).collect(toList());
3843

3944
return collectionOfFuturesToFutureOfCollection(futures, toList());

0 commit comments

Comments
 (0)