How to get config data from local.properties to impex?

青春壹個敷衍的年華 提交于 2019-12-09 18:36:00

问题


Is it possible to get a value from the environment variables defined at local.properties configuration file and access it via the impex file?

Ex.

$someMacro=<some variable from config>

Thank you!


回答1:


You can add this to your impex:

# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]

All your configurations from local.properties, etc. are now loaded and can be used via $config- prefix, say for example:

local.properties

your.config.property=322

So your impex would look something like:

# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]

$variable=$config-your.config.property

INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$variable

# OR you can just directly use the config macro
INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$config-your.config.property

Hope this works for you.

EDIT: Please also note that if there was no such property found, the value stored on the sample above shall be exactly: $config-your.config.property.




回答2:


To complete @Atsusa Kai answer, the line with a header alone can be avoided.

It's quite ugly to have this line just to load the properties... but that's actually what is mentionned in the ConfigPropertyImportProcessor class comment :

  /**
   * Impex ImportProcessor that injects all config properties as impex definitions.
   * All defined configuration properties are added as impex macro definitions with
   * the prefix of "config-". For example the config key <tt>mail.smtp.server</tt>
   * can be accessed via the macro <tt>$config-mail.smtp.server</tt>.
   * In order to use this import processor and to load the configuration properties
   * the following must be added to the top of the impex file:
   *
   * <tt>UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]</tt>
   */

The alternative is to used a beanshell command that are tailored for this kind of action.

You can replace the UPDATE GenericItem line by

#%new de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor().init(impex)

but you need to enable code execution.



来源:https://stackoverflow.com/questions/35266593/how-to-get-config-data-from-local-properties-to-impex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!