Skip to content

Commit 5a31f5a

Browse files
author
salander85
committed
Merge branch 'master' into DEVX-291_Sync-producttypes-with-reference-set
2 parents 16a763a + c340210 commit 5a31f5a

File tree

17 files changed

+192
-103
lines changed

17 files changed

+192
-103
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
id: vars
4444
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
4545
- name: Set up Java
46-
uses: actions/setup-java@v3
46+
uses: actions/setup-java@v4
4747
with:
4848
java-version: 11
4949
distribution: 'zulu'

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- uses: actions/checkout@v4
29-
- uses: actions/setup-java@v3
29+
- uses: actions/setup-java@v4
3030
with:
3131
java-version: 11
3232
distribution: 'zulu'

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ plugins {
22
id 'org.ajoberstar.git-publish' version '4.2.1'
33
id 'com.adarshr.test-logger' version '4.0.0'
44
id 'org.ajoberstar.grgit' version '5.2.1'
5-
id "com.github.ben-manes.versions" version '0.49.0'
5+
id "com.github.ben-manes.versions" version '0.50.0'
66
id 'ru.vyarus.mkdocs' version '3.0.0'
7-
id "com.github.spotbugs" version "5.2.3"
8-
id 'com.diffplug.spotless' version '6.22.0'
7+
id "com.github.spotbugs" version "6.0.1"
8+
id 'com.diffplug.spotless' version '6.23.3'
99
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
1010
}
1111

1212
ext{
1313
commercetoolsJavaSdkV2Version = '17.2.0'
14-
mockitoJunitJupiterVersion = '5.7.0'
14+
mockitoJunitJupiterVersion = '5.8.0'
1515
jupiterApiVersion = '5.10.1'
1616
assertjVersion = '3.24.2'
1717
pmdVersion = '6.55.0'
@@ -47,15 +47,15 @@ dependencies {
4747
implementation "com.github.ben-manes.caffeine:caffeine:${caffeineVersion}"
4848
implementation "org.apache.commons:commons-text:${commonTextVersion}"
4949
api "com.commercetools.sdk:commercetools-sdk-java-api:${commercetoolsJavaSdkV2Version}"
50-
api 'commons-io:commons-io:2.11.0'
50+
api 'commons-io:commons-io:2.15.1'
5151
api 'commons-codec:commons-codec:1.16.0'
5252
api 'com.google.code.findbugs:annotations:3.0.1'
53-
api 'com.neovisionaries:nv-i18n:1.28'
53+
api 'com.neovisionaries:nv-i18n:1.29'
5454
testImplementation "org.mockito:mockito-junit-jupiter:${mockitoJunitJupiterVersion}"
5555
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterApiVersion}"
5656
testImplementation "org.junit.jupiter:junit-jupiter-params:${jupiterApiVersion}"
5757
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterApiVersion}"
5858
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${jupiterApiVersion}"
5959
testImplementation "org.assertj:assertj-core:${assertjVersion}"
60-
testImplementation 'com.github.spotbugs:spotbugs-annotations:4.8.1'
60+
testImplementation 'com.github.spotbugs:spotbugs-annotations:4.8.2'
6161
}

gradle/wrapper/gradle-wrapper.jar

-19.8 KB
Binary file not shown.

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.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/com/commercetools/sync/categories/utils/CategoryReferenceResolutionUtils.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,7 @@ private static CategoryDraft mapToCategoryDraft(
8383
getResourceIdentifierWithKey(
8484
category.getParent(),
8585
referenceIdToKeyCache,
86-
(id, key) -> {
87-
final CategoryResourceIdentifierBuilder builder =
88-
CategoryResourceIdentifierBuilder.of();
89-
if (id == null) {
90-
return builder.key(key).build();
91-
} else {
92-
return builder.id(id).build();
93-
}
94-
});
86+
(id, key) -> CategoryResourceIdentifierBuilder.of().key(key).id(id).build());
9587
return CategoryDraftBuilder.of()
9688
.key(category.getKey())
9789
.slug(category.getSlug())

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,11 @@ public static CustomFieldsDraft mapToCustomFieldsDraft(
7070
SyncUtils.getResourceIdentifierWithKey(
7171
typeReference,
7272
referenceIdToKeyCache,
73-
(id, key) -> {
74-
final TypeResourceIdentifierBuilder builder =
75-
TypeResourceIdentifierBuilder.of();
76-
if (id == null) {
77-
78-
return builder.key(key).build();
79-
} else {
80-
return builder.id(id).build();
81-
}
82-
}))
73+
(id, key) ->
74+
TypeResourceIdentifierBuilder.of()
75+
.key(key)
76+
.id(id)
77+
.build()))
8378
.orElse(null))
8479
.build())
8580
.orElse(null);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ResourceIdentifierT getResourceIdentifierWithKey(
7070
@Nullable final String key,
7171
final BiFunction<String, String, ResourceIdentifierT> toResourceIdentifier) {
7272

73-
if (!StringUtils.isEmpty(key)) {
73+
if (!StringUtils.isBlank(key)) {
7474
return toResourceIdentifier.apply(null, key);
7575
}
7676
return toResourceIdentifier.apply(id, null);

src/main/java/com/commercetools/sync/inventories/utils/InventoryReferenceResolutionUtils.java

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import com.commercetools.api.models.inventory.InventoryEntry;
1212
import com.commercetools.api.models.inventory.InventoryEntryDraft;
1313
import com.commercetools.api.models.inventory.InventoryEntryDraftBuilder;
14+
import com.commercetools.api.models.type.CustomFieldsDraft;
1415
import com.commercetools.api.models.type.Type;
1516
import com.commercetools.api.models.type.TypeReference;
1617
import com.commercetools.api.models.type.TypeResourceIdentifier;
1718
import com.commercetools.sync.commons.utils.ReferenceIdToKeyCache;
1819
import java.util.List;
1920
import javax.annotation.Nonnull;
21+
import javax.annotation.Nullable;
2022

2123
/**
2224
* Util class which provides utilities that can be used when syncing resources from a source
@@ -81,24 +83,41 @@ private static InventoryEntryDraft mapToInventoryEntryDraft(
8183
getResourceIdentifierWithKey(
8284
inventoryEntry.getSupplyChannel(),
8385
referenceIdToKeyCache,
84-
(id, key) -> {
85-
final ChannelResourceIdentifierBuilder builder =
86-
ChannelResourceIdentifierBuilder.of();
87-
if (id == null) {
88-
return builder.key(key).build();
89-
} else {
90-
return builder.id(id).build();
91-
}
92-
});
93-
return InventoryEntryDraftBuilder.of()
94-
.sku(inventoryEntry.getSku())
95-
.quantityOnStock(inventoryEntry.getQuantityOnStock())
96-
.expectedDelivery(inventoryEntry.getExpectedDelivery())
97-
.restockableInDays(inventoryEntry.getRestockableInDays())
98-
.key(inventoryEntry.getKey())
99-
.custom(mapToCustomFieldsDraft(inventoryEntry, referenceIdToKeyCache))
100-
.supplyChannel(channelResourceIdentifier)
101-
.build();
86+
(id, key) -> ChannelResourceIdentifierBuilder.of().key(key).id(id).build());
87+
final CustomFieldsDraft customFieldsDraft =
88+
mapToCustomFieldsDraft(inventoryEntry, referenceIdToKeyCache);
89+
return getInventoryEntryDraft(inventoryEntry, customFieldsDraft, channelResourceIdentifier);
90+
}
91+
92+
/**
93+
* Creates a new {@link InventoryEntryDraft} from given {@link InventoryEntry}, already mapped
94+
* {@link CustomFieldsDraft} and channel as {@link ChannelResourceIdentifier}.
95+
*
96+
* @param inventoryEntry - a template inventoryEntry to build the draft from
97+
* @param mappedCustomFields - a customFieldsDraft or null
98+
* @param channel - a resource identifier representing the supply channel or null
99+
* @return a new {@link InventoryEntryDraft} with all fields copied from the {@param
100+
* inventoryEntry} and custom fields set {@param mappedCustomFields} and supply channel with
101+
* {@param channel} resource identifier - it will return empty InventoryEntryDraft if sku or
102+
* quantityOnStock are missing.
103+
*/
104+
private static InventoryEntryDraft getInventoryEntryDraft(
105+
@Nonnull final InventoryEntry inventoryEntry,
106+
@Nullable final CustomFieldsDraft mappedCustomFields,
107+
@Nullable final ChannelResourceIdentifier channel) {
108+
if (inventoryEntry.getSku() != null && inventoryEntry.getQuantityOnStock() != null) {
109+
return InventoryEntryDraftBuilder.of()
110+
.sku(inventoryEntry.getSku())
111+
.quantityOnStock(inventoryEntry.getQuantityOnStock())
112+
.expectedDelivery(inventoryEntry.getExpectedDelivery())
113+
.restockableInDays(inventoryEntry.getRestockableInDays())
114+
.key(inventoryEntry.getKey())
115+
.custom(mappedCustomFields)
116+
.supplyChannel(channel)
117+
.build();
118+
} else {
119+
return InventoryEntryDraft.of();
120+
}
102121
}
103122

104123
private InventoryReferenceResolutionUtils() {}

src/main/java/com/commercetools/sync/products/ProductSync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private CompletionStage<Void> syncOrKeepTrack(
258258
final Set<String> missingReferencedProductKeys =
259259
getMissingReferencedProductKeys(newDraft, keyToIdCache);
260260

261-
boolean selfReferenceExists =
261+
final boolean selfReferenceExists =
262262
missingReferencedProductKeys.remove(newDraft.getKey());
263263

264264
if (!missingReferencedProductKeys.isEmpty()) {

0 commit comments

Comments
 (0)