3333import com .commercetools .importapi .models .productvariants .DateTimeAttribute ;
3434import com .commercetools .importapi .models .productvariants .NumberAttribute ;
3535import io .vrap .rmf .base .client .Builder ;
36-
37- public final class ProductUtil {
38- private static KeyResolverService keyResolverService = new ExpandObjResolverService ();
39-
40- public static ProductDraftImport toProductDraftImport (ProductProjection product ) {
36+ public class ProductUtil {
37+ private final KeyResolverService keyResolverService ;
38+ public ProductUtil () {
39+ keyResolverService = new ExpandObjResolverService ();
40+ }
41+ public ProductUtil (final KeyResolverService resolverService ) {
42+ keyResolverService = resolverService ;
43+ }
44+ public ProductDraftImport toProductDraftImport (ProductProjection product ) {
4145 var draft = ProductDraftImport .builder ()
4246 .key (product .getKey ())
4347 .productType (p -> p .key (keyResolverService .resolveKey (product .getProductType ())))
@@ -69,7 +73,7 @@ private static LocalizedStringBuilder getLocalizedStringBuilder(LocalizedString
6973 return com .commercetools .importapi .models .common .LocalizedString .builder ().values (s .values ());
7074 }
7175
72- private static com .commercetools .importapi .models .common .ProductPriceModeEnum mapPriceModeToImportApi (
76+ private com .commercetools .importapi .models .common .ProductPriceModeEnum mapPriceModeToImportApi (
7377 ProductProjection product ) {
7478 if (product .getPriceMode () == null ) {
7579 return null ;
@@ -80,23 +84,23 @@ private static com.commercetools.importapi.models.common.ProductPriceModeEnum ma
8084 return com .commercetools .importapi .models .common .ProductPriceModeEnum .ProductPriceModeEnumEnum .STANDALONE ;
8185 }
8286
83- private static StateKeyReference getStateKeyReference (ProductProjection product ) {
87+ private StateKeyReference getStateKeyReference (ProductProjection product ) {
8488 var key = keyResolverService .resolveKey (product .getState ());
8589 if (key != null ) {
8690 return StateKeyReference .builder ().key (key ).build ();
8791 }
8892 return null ;
8993 }
9094
91- private static TaxCategoryKeyReference getTaxCategoryKeyReference (ProductProjection product ) {
95+ private TaxCategoryKeyReference getTaxCategoryKeyReference (ProductProjection product ) {
9296 var key = keyResolverService .resolveKey (product .getTaxCategory ());
9397 if (key != null ) {
9498 return TaxCategoryKeyReference .builder ().key (key ).build ();
9599 }
96100 return null ;
97101 }
98102
99- private static List <ProductVariantDraftImport > extractProductVariantDraftImport (ProductProjection product ) {
103+ private List <ProductVariantDraftImport > extractProductVariantDraftImport (ProductProjection product ) {
100104 return product .getVariants ()
101105 .stream ()
102106 .map (ProductUtil ::extractProductVariantDraftImport )
@@ -134,8 +138,8 @@ private static List<PriceDraftImport> mapPricesToImportApi(ProductVariant varian
134138 .collect (Collectors .toList ());
135139 }
136140
137- private static Builder <? extends TypedMoney > importApiTypedMoney (
138- com . commercetools . api . models . common . TypedMoney p , TypedMoneyBuilder v ) {
141+ private static Builder <? extends TypedMoney > importApiTypedMoney (com . commercetools . api . models . common . TypedMoney p ,
142+ TypedMoneyBuilder v ) {
139143 return (p instanceof HighPrecisionMoney ) ?
140144 v .highPrecisionBuilder ()
141145 .centAmount (p .getCentAmount ())
@@ -160,7 +164,7 @@ private static List<com.commercetools.importapi.models.common.Asset> importAsset
160164 .collect (Collectors .toList ());
161165 }
162166
163- private static List <CategoryKeyReference > extractCategoryKeyReference (ProductProjection product ) {
167+ private List <CategoryKeyReference > extractCategoryKeyReference (ProductProjection product ) {
164168 return product .getCategories ()
165169 .stream ()
166170 .map (c -> CategoryKeyReference .builder ().key (keyResolverService .resolveKey (c )).build ())
0 commit comments