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
2
3
4
5
@SystemSetup(extension = TrainingCoreConstants.EXTENSIONNAME)
public class CoreSystemSetup extends AbstractSystemSetup
{
    
}
@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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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");
        }
         }
}
@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

Karibasappa G C (KB)
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