|
35 | 35 | import io.vrap.rmf.base.client.Builder; |
36 | 36 |
|
37 | 37 | public final class ProductUtil { |
38 | | - private static KeyResolverService<CategoryReference> catKeyResolverService; |
| 38 | + private static KeyResolverService keyResolverService; |
39 | 39 |
|
40 | 40 | public ProductUtil() { |
41 | | - catKeyResolverService = new ExpandObjResolverService<>(); |
| 41 | + keyResolverService = new ExpandObjResolverService(); |
42 | 42 | } |
43 | 43 |
|
44 | 44 | public static ProductDraftImport toProductDraftImport(ProductProjection product) { |
45 | 45 | var draft = ProductDraftImport.builder() |
46 | 46 | .key(product.getKey()) |
47 | | - .productType(p -> p.key(product.getProductType().getObj().getKey())) |
| 47 | + .productType(p -> p.key(keyResolverService.resolveKey(product.getProductType()))) |
48 | 48 | .name(l -> getLocalizedStringBuilder(product.getName())) |
49 | 49 | .slug(l -> getLocalizedStringBuilder(product.getSlug())) |
50 | 50 | .description(Optional.ofNullable(product.getDescription()) |
@@ -85,18 +85,15 @@ private static com.commercetools.importapi.models.common.ProductPriceModeEnum ma |
85 | 85 | } |
86 | 86 |
|
87 | 87 | private static StateKeyReference getStateKeyReference(ProductProjection product) { |
88 | | - var key = Optional.ofNullable(product.getState()).map(StateReference::getObj).map(State::getKey).orElse(null); |
| 88 | + var key = keyResolverService.resolveKey(product.getState()); |
89 | 89 | if (key != null) { |
90 | 90 | return StateKeyReference.builder().key(key).build(); |
91 | 91 | } |
92 | 92 | return null; |
93 | 93 | } |
94 | 94 |
|
95 | 95 | private static TaxCategoryKeyReference getTaxCategoryKeyReference(ProductProjection product) { |
96 | | - var key = Optional.ofNullable(product.getTaxCategory()) |
97 | | - .map(TaxCategoryReference::getObj) |
98 | | - .map(TaxCategory::getKey) |
99 | | - .orElse(null); |
| 96 | + var key = keyResolverService.resolveKey(product.getTaxCategory()); |
100 | 97 | if (key != null) { |
101 | 98 | return TaxCategoryKeyReference.builder().key(key).build(); |
102 | 99 | } |
@@ -170,7 +167,7 @@ private static List<com.commercetools.importapi.models.common.Asset> importAsset |
170 | 167 | private static List<CategoryKeyReference> extractCategoryKeyReference(ProductProjection product) { |
171 | 168 | return product.getCategories() |
172 | 169 | .stream() |
173 | | - .map(c -> CategoryKeyReference.builder().key(catKeyResolverService.resolveKey(c)).build()) |
| 170 | + .map(c -> CategoryKeyReference.builder().key(keyResolverService.resolveKey(c)).build()) |
174 | 171 | .collect(Collectors.toList()); |
175 | 172 | } |
176 | 173 |
|
|
0 commit comments