Skip to content

Commit 7183d1e

Browse files
committed
SUPPORT-36587: support custom type resolution in customer's address
1 parent 317d55b commit 7183d1e

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<configuration>
2+
<appender name="JSON-STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3+
<target>System.out</target>
4+
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
5+
<providers>
6+
<!-- Some fields are mapped to camel-case for consistency -->
7+
<timestamp>
8+
<!-- Map default "@timestamp" to "timestamp" -->
9+
<fieldName>timestamp</fieldName>
10+
</timestamp>
11+
<logLevel>
12+
<!-- Map default "logLevel" to "severity" for cloud platforms such as GCP Stackdriver -->
13+
<fieldName>severity</fieldName>
14+
</logLevel>
15+
<loggerName>
16+
<!-- Map default "logger_name" to "loggerName" -->
17+
<fieldName>loggerName</fieldName>
18+
</loggerName>
19+
<message/>
20+
<stackHash>
21+
<!-- Map default "stack_hash" to "stackHash" -->
22+
<fieldName>stackHash</fieldName>
23+
</stackHash>
24+
<stackTrace>
25+
<!-- Map default "stack_trace" to "stackTrace" -->
26+
<fieldName>stackTrace</fieldName>
27+
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
28+
<maxDepthPerThrowable>30</maxDepthPerThrowable>
29+
<maxLength>2048</maxLength>
30+
<shortenedClassNameLength>20</shortenedClassNameLength>
31+
<rootCauseFirst>true</rootCauseFirst>
32+
</throwableConverter>
33+
</stackTrace>
34+
<arguments/>
35+
<logstashMarkers/>
36+
</providers>
37+
</encoder>
38+
</appender>
39+
40+
<root level="INFO">
41+
<appender-ref ref="JSON-STDOUT"/>
42+
</root>
43+
</configuration>

src/main/java/com/commercetools/sync/customers/utils/CustomerReferenceResolutionUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static CustomerDraft mapToCustomerDraft(
111111
.dateOfBirth(customer.getDateOfBirth())
112112
.isEmailVerified(customer.getIsEmailVerified())
113113
.vatId(customer.getVatId())
114-
.addresses(mapToAddressesDraft(customer.getAddresses()))
114+
.addresses(mapToAddressesDraft(customer.getAddresses(), referenceIdToKeyCache))
115115
.defaultBillingAddress(
116116
getAddressIndex(customer.getAddresses(), customer.getDefaultBillingAddressId()))
117117
.billingAddresses(
@@ -143,7 +143,9 @@ private static CustomerGroupResourceIdentifier mapToCustomerGroupResourceIdentif
143143
return null;
144144
}
145145

146-
private static List<BaseAddress> mapToAddressesDraft(@Nonnull List<Address> addresses) {
146+
private static List<BaseAddress> mapToAddressesDraft(
147+
@Nonnull List<Address> addresses,
148+
@Nonnull final ReferenceIdToKeyCache referenceIdToKeyCache) {
147149
if (addresses.isEmpty()) {
148150
return emptyList();
149151
}
@@ -178,8 +180,9 @@ private static List<BaseAddress> mapToAddressesDraft(@Nonnull List<Address> addr
178180
.externalId(address.getExternalId());
179181

180182
if (address.getCustom() != null) {
181-
builder.custom(
182-
CustomFieldsDraftBuilder.of().fields(address.getCustom().getFields()).build());
183+
CustomFieldsDraft draft =
184+
mapToCustomFieldsDraft(address.getCustom(), referenceIdToKeyCache);
185+
builder.custom(draft);
183186
}
184187
return builder.build();
185188
})

src/main/java/com/commercetools/sync/customers/utils/CustomerTransformUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static java.util.stream.Collectors.toSet;
44

55
import com.commercetools.api.client.ProjectApiRoot;
6+
import com.commercetools.api.models.common.Address;
67
import com.commercetools.api.models.common.Reference;
78
import com.commercetools.api.models.customer.Customer;
89
import com.commercetools.api.models.customer.CustomerDraft;
@@ -84,6 +85,17 @@ private CompletableFuture<Void> transformCustomTypeReference(
8485
.map(Reference::getId)
8586
.collect(toSet());
8687

88+
final Set<String> setOfAddressCustomTypeIds =
89+
customers.stream()
90+
.flatMap(c -> c.getAddresses().stream())
91+
.map(Address::getCustom)
92+
.filter(Objects::nonNull)
93+
.map(CustomFields::getType)
94+
.map(Reference::getId)
95+
.collect(toSet());
96+
97+
setOfTypeIds.addAll(setOfAddressCustomTypeIds);
98+
8799
return fetchAndFillReferenceIdToKeyCache(setOfTypeIds, GraphQlQueryResource.TYPES);
88100
}
89101

0 commit comments

Comments
 (0)