How to get config data from local.properties to impex?
Asked Answered
K

2

7

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!

Kami answered 8/2, 2016 at 9:52 Comment(0)
R
14

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.

Revivalist answered 9/2, 2016 at 8:42 Comment(0)
M
1

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.

Mameluke answered 23/3, 2017 at 14:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.