尝试通过 impex 将 defaltValue 插入到列中,但出现无法在 null 位置插入默认值的错误

Trying to insert defaltValue to a column through impex but getting error unable to insert default value in the place of null

第二列中的空值(传入的 csv 文件):->
输入 CSV: 10512, 10513,12345,

impex:

INSERT_UPDATE Product;code[unique=true];vendors(code)[translator=ca.batch.converter.StiboSetDefaultVendorIfNullTranslator];...

代码:

正在扩展 de.hybris.platform.impex.jalo.translators.AbstractValueTranslator;

private final String defaultVendorCode = "000000";

@Override
public Object importValue(String valueExpr, final Item item)
        throws JaloInvalidParameterException {

    if (valueExpr == null || StringUtils.isEmpty(valueExpr)) {

        LOG.debug("Current attribute value is null so inserting "
                + defaultVendorCode);
        valueExpr = defaultVendorCode;

    }

    return valueExpr;
}

12345 也出现以下错误,但最终 impex conveterd 行的编号为 (impex row -> 10153;12345)

由于试图为属性 de.hybris.platform.jalo.product.Product.vendors 设置值“000000”的参数不匹配(得到 java.lang.String,预期 de.h ybris.platform.jalo.product.Product).,

(impex 行 -> 10153;;)

我认为这个错误信息很清楚:

(got java.lang.String, expected de.h ybris.platform.jalo.product.Product).,

对于翻译器,您必须查找实际的默认供应商对象,而不是返回默认供应商代码。

我认为最简单的解决方案是,如果您使用 Decorator 而不是 returns 您的 "vendors" 属性的代码值。 您可以在此处找到详细说明: https://wiki.hybris.com/display/release5/ImpEx+API#ImpExAPI-WritingOwnCellDecorator

但基本上是这样的:

public class MyDecorator implements CSVCellDecorator
{
   public String decorate( int position, Map<Integer, String> srcLine )
   {
      // here add your custom logic to check and if applies return your default vendor code, otherwise return the given input value
      //String parsedValue=srcLine.get(position);
      //return parsedValue+"modified"; // some decoration stuff
   }
}

希望有点帮助:)

你应该试试这个:[allownull=true] 属性修饰符; 您的 impex 应如下所示:

INSERT_UPDATE Product;code[unique=true];vendors(code)[allownull=true]

仅导入 真假 默认值:假 如果设置为 true,则此修饰符明确允许列值的空值。如果没有阻止空值的业务代码,该修饰符甚至允许在强制属性中使用空值,例如 Media 类型的 catalogVersion 属性。 例子: [allownull=true] 提示 在Service Layer模式下,如果设置了allownull,可能会导入失败。从hybris Commerce Suite 5.1.1版本开始,import遇到这个参数会动态切换到legacy模式。处理给定行后,导入将切换回 SL 模式。