Initialization and Update hook up


Initialization and Update hook up in hybris

We can configure the impexes to load during Initialization and update process through code.

Hybris has already provided a class called CoreSystemSetup.java and InitialDataSystemSetup.java to achieve the same.

Before understanding this, we should know about Type and Process that we use in the initialization/update hook up process.

type_process_table2


Steps to configure an impex to import during initialization/Update process

Step 1

Create a class and annotate it with @SystemSetup as below

  1. @SystemSetup(extension = TrainingCoreConstants.EXTENSIONNAME)
  2. public class CoreSystemSetup extends AbstractSystemSetup
  3. {
  4.    
  5. }
@SystemSetup(extension = TrainingCoreConstants.EXTENSIONNAME)
public class CoreSystemSetup extends AbstractSystemSetup
{
	
}


Step 2

Create public methods and annotate them with @SystemSetup by specifying “Type” and “Process”.

CoreSystemSetup.java

  1. @SystemSetup(extension = TrainingCoreConstants.EXTENSIONNAME)
  2. public class CoreSystemSetup extends AbstractSystemSetup
  3. {
  4.     public static final String IMPORT_ACCESS_RIGHTS = "accessRights";
  5.  
  6.     @SystemSetup(type = Type.ESSENTIAL, process = Process.ALL)
  7.     public void createEssentialData(final SystemSetupContext context)
  8.     {
  9.         importImpexFile(context, "/trainingcore/import/common/essential-data.impex");
  10.         importImpexFile(context, "/trainingcore/import/common/countries.impex");
  11.         importImpexFile(context, "/trainingcore/import/common/delivery-modes.impex");
  12.         importImpexFile(context, "/trainingcore/import/common/themes.impex");
  13.         importImpexFile(context, "/trainingcore/import/common/user-groups.impex");
  14.     }
  15.  
  16.        @SystemSetup(type = Type.PROJECT, process = Process.ALL)
  17.     public void createProjectData(final SystemSetupContext context)
  18.     {
  19.         final boolean importAccessRights = getBooleanSystemSetupParameter(context,  
  20.                                                                         IMPORT_ACCESS_RIGHTS);
  21.         final List<String> extensionNames = getExtensionNames();
  22.         if (importAccessRights && extensionNames.contains("cmscockpit"))
  23.         {
  24.             importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit
  25.                                                                     /cmscockpit-users.impex");
  26.             importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit
  27.                                                              /cmscockpit-access-rights.impex");
  28.         }
  29.          }
  30. }
@SystemSetup(extension = TrainingCoreConstants.EXTENSIONNAME)
public class CoreSystemSetup extends AbstractSystemSetup
{
	public static final String IMPORT_ACCESS_RIGHTS = "accessRights";

	@SystemSetup(type = Type.ESSENTIAL, process = Process.ALL)
	public void createEssentialData(final SystemSetupContext context)
	{
		importImpexFile(context, "/trainingcore/import/common/essential-data.impex");
		importImpexFile(context, "/trainingcore/import/common/countries.impex");
		importImpexFile(context, "/trainingcore/import/common/delivery-modes.impex");
		importImpexFile(context, "/trainingcore/import/common/themes.impex");
		importImpexFile(context, "/trainingcore/import/common/user-groups.impex");
	}

       @SystemSetup(type = Type.PROJECT, process = Process.ALL)
	public void createProjectData(final SystemSetupContext context)
	{
		final boolean importAccessRights = getBooleanSystemSetupParameter(context,  
                                                                        IMPORT_ACCESS_RIGHTS);
		final List<String> extensionNames = getExtensionNames();
		if (importAccessRights && extensionNames.contains("cmscockpit"))
		{
			importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit
                                                                     /cmscockpit-users.impex");
			importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit
                                                              /cmscockpit-access-rights.impex");
		}
         }
}


We have defined 2 methods in the above class.

Both will be executed during Initialization process but one will be executed during essential data creation process
other will be executed during project data creation process.

We have passed a parameter to a method of type SystemSetupContext which can be used to get some additional details like user selected parameter value.

Step 3

Register the class which is annotated with @SystemSetup as a spring bean
hybris\bin\custom\training\trainingcore\resources\trainingcore-spring.xml

  1. <bean id="acceleratorCoreSystemSetup" class="org.training.core.setup.CoreSystemSetup" parent="abstractCoreSystemSetup"/>
<bean id="acceleratorCoreSystemSetup" class="org.training.core.setup.CoreSystemSetup" parent="abstractCoreSystemSetup"/>

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on