File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
commercetools/commercetools-importapi-utils/src/main/java/com/commercetools/sdk Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1+ package com .commercetools .sdk ;
2+
3+ import com .commercetools .api .models .IdentifiableObjHolder ;
4+ import com .commercetools .api .models .WithKey ;
5+
6+ public class ExpandObjResolverService <T extends IdentifiableObjHolder <TResource >, TResource extends WithKey > implements KeyResolverService <T > {
7+
8+ public String resolveKey (T identifiable ) {
9+ return identifiable .getObj ().getKey ();
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ package com .commercetools .sdk ;
2+
3+ public interface KeyResolverService <T > {
4+ public String resolveKey (T identifiable );
5+ }
Original file line number Diff line number Diff line change 1-
21package com .commercetools .sdk ;
32
43import java .time .LocalDate ;
54import java .time .ZonedDateTime ;
65import java .util .*;
76import java .util .stream .Collectors ;
87
8+ import com .commercetools .api .models .category .CategoryReference ;
99import com .commercetools .api .models .common .CentPrecisionMoney ;
1010import com .commercetools .api .models .common .LocalizedString ;
1111import com .commercetools .api .models .common .Money ;
2626import com .commercetools .importapi .models .productvariants .NumberAttribute ;
2727
2828public final class ProductUtil {
29+ private static KeyResolverService <CategoryReference > catKeyResolverService ;
2930
31+ public ProductUtil () {
32+ catKeyResolverService = new ExpandObjResolverService <>();
33+ }
3034 public static ProductDraftImport toProductDraftImport (ProductProjection product ) {
3135 var draft = ProductDraftImport .builder ()
3236 .key (product .getKey ())
@@ -151,7 +155,7 @@ private static List<com.commercetools.importapi.models.common.Asset> importAsset
151155 private static List <CategoryKeyReference > extractCategoryKeyReference (ProductProjection product ) {
152156 return product .getCategories ()
153157 .stream ()
154- .map (c -> CategoryKeyReference .builder ().key (c . getObj (). getKey ( )).build ())
158+ .map (c -> CategoryKeyReference .builder ().key (catKeyResolverService . resolveKey ( c )).build ())
155159 .collect (Collectors .toList ());
156160 }
157161
You can’t perform that action at this time.
0 commit comments