Request a free audit

Specialising in Digital positioning and marketing, we tackle challenging questions that yield tangible value. By the end, you’ll receive actionable tips ready for immediate implementation. Take advantage of our complimentary, no-obligation complete audits.

Social media audit Problem definition workshop ISO/SOC readiness

 

Project configuration in Hybris

Date
July 20, 2017
Hot topics 🔥
Tech Insights
Contributor
Mario Grunitz
Project configuration in Hybris

There are a lot of instances when a number or string should be able to be adjusted in environments outside of your development machine. In these cases, environment variables are a good choice. However, the Hybris platform provides a more convenient approach. Let’s see how.

Global and local properties

The first place of the configuration is in the platform’s project.properties.

This file contains the global properties for the whole Hybris platform. By using it you can configure:

  • tomcat
  • DB access
  • web security settings
  • Hybris cluster
  • Hybris Management Console
  • Hybris Administration Console
  • cockpits
  • cron jobs
  • mail senders
  • logging
  • etc.

A lot of setting entries have some default values. But this file isn’t a good place to make custom changes. For this, the local.properties file inside the config folder exists.

The entries inside this file override the same ones from the project.properties of the platform. So, you need to place everything you need to configure for the platform inside this file.

Extension configuration

Besides global configuration, each Hybris extension has its own configuration file. See below the project.properties file with some configuration items.

How to change properties

You’re able to view all available properties and change them inside Hybris Administration Console. For this, go here.

You can use the search box to find properties you want to change. Please be aware that all changes will be lost after the server reload due to the fact that all changes are stored only in memory (information in the yellow block on the screenshot).

How to read properties

I’ve figured out several ways to read the properties during the Hybris development process. Let’s go through each of them:

Firstly, you can read them in the source code. Hybris offers de.hybris.platform.util.Config which has a pretty straightforward API. For example:

Config.getParameter(“<keyPath>”)
Config.getString(“<keyPath>”)
Config.getChar(“<keyPath>”)
Config.getBoolean(“<keyPath>”)
Config.getInt(“<keyPath>”)
Config.getLong(“<keyPath>”)
Config.getDouble(“<keyPath>”)

If such a key path exists then an appropriate value will be returned. If not, then the method will return a null value.

The second way you can read properties is inside impex files. Impex framework is used inside the Hybris platform to perform import data procedures. You can use defined properties inside an impex file to make your import procedure more flexible and abstract. For example:

# Import modulegen config properties into impex macros

Update

GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
$jarResourceCms=$config-jarResourceCmsValue
$emailPackageName=$config-emailContextPackageName

The code above imports two properties into an impex script: jarResourceCmsValue and emailContextPackageName. Those items, of course, exist in the config section of the HAC.

Conclusions

The Hybris platform provides developers a convenient and flexible approach for configuring applications. The one very interesting feature for me is that you can use properties not only inside Java code, but in the impex scripts as well, which helps us to create very dynamic data imports.

Happy hacking!

Mario Grunitz

Mario is a Strategy Lead and Co-founder of WeAreBrain, bringing over 20 years of rich and diverse experience in the technology sector. His passion for creating meaningful change through technology has positioned him as a thought leader and trusted advisor in the tech community, pushing the boundaries of digital innovation and shaping the future of AI.

Working Machines

An executive’s guide to AI and Intelligent Automation. Working Machines takes a look at how the renewed vigour for the development of Artificial Intelligence and Intelligent Automation technology has begun to change how businesses operate.