Custom parameters during initialization and update


How to add custom parameters in HAC during initialization and update?


Some times it is required to add custom parameters in HAC during initialization and update time so that we can import appropriate impex files based on user selection.

How to add such custom parameters in HAC ?


We should add a method annotated with @SystemSetupParameterMethod inside a SystemSetup annotated class.

This method returns a list of parameters to be added

Let us see an Example


Add below method in the CoreSystemSetup class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@SystemSetupParameterMethod
    public List<SystemSetupParameter> getCustomSystemSetupParameters()
    {
        final List<SystemSetupParameter> params = new ArrayList<SystemSetupParameter>();
//Adding boolean field
        final SystemSetupParameter customDataParameter = new 
                                                        SystemSetupParameter("createCustomData");
        customDataParameter.setLabel("Do you want to create custom data?");
        customDataParameter.addValue("true");
        customDataParameter.addValue("false", true);
        params.add(customDataParameter);
//Adding multi select drop down box
        final SystemSetupParameter imports = new SystemSetupParameter("imports");
        imports.setMultiSelect(true);
        imports.setLabel("Custom data to import : ");
        imports.addValues(new String[]
        { "marketingGroups", "specialUsers" });
        params.add(imports);
 
        return params;
    }
@SystemSetupParameterMethod
	public List<SystemSetupParameter> getCustomSystemSetupParameters()
	{
		final List<SystemSetupParameter> params = new ArrayList<SystemSetupParameter>();
//Adding boolean field
		final SystemSetupParameter customDataParameter = new 
                                                        SystemSetupParameter("createCustomData");
		customDataParameter.setLabel("Do you want to create custom data?");
		customDataParameter.addValue("true");
		customDataParameter.addValue("false", true);
		params.add(customDataParameter);
//Adding multi select drop down box
		final SystemSetupParameter imports = new SystemSetupParameter("imports");
		imports.setMultiSelect(true);
		imports.setLabel("Custom data to import : ");
		imports.addValues(new String[]
		{ "marketingGroups", "specialUsers" });
		params.add(imports);

		return params;
	}

we have added 2 different types of custom parameters , one is single selection list box and other one is multiple selection list box.

After this, Do Build, start the server and access Initialization or Update option in HAC using below URLs

http://localhost:9001/platform/update

http://localhost:9001/platform/init

custom_param_init_update_process

we can see that custom parameters are appeared during the initialization process.

Users can select the options from these custom parameters and accordingly we can import the corresponding impex files.


How to access the options selected by user ?

We can access the values selected by user using below code and import the appropriate impex during initialization and update process.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 @SystemSetup(type = Type.PROJECT, process = Process.ALL)
public void createProjectData(final SystemSetupContext context) throws Exception
{
    String createCustomData = context.getParameter(CoreConstants.EXTENSIONNAME +
        "_createCustomData"));
    
    if(createCustomData!=null)
    {
    importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit/"+createCustomData+".impex");
    }
    for (final String selectedParam : context.getParameters(CoreConstants.EXTENSIONNAME +
        "_imports"))
    {
        importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit/"+selectedParam+".impex");
    }
}
 @SystemSetup(type = Type.PROJECT, process = Process.ALL)
public void createProjectData(final SystemSetupContext context) throws Exception
{
    String createCustomData = context.getParameter(CoreConstants.EXTENSIONNAME +
        "_createCustomData"));
    
	if(createCustomData!=null)
	{
	importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit/"+createCustomData+".impex");
	}
    for (final String selectedParam : context.getParameters(CoreConstants.EXTENSIONNAME +
        "_imports"))
    {
        importImpexFile(context, "/trainingcore/import/cockpits/cmscockpit/"+selectedParam+".impex");
    }
}



The parameters are stored in the map with the prefix < extension>_ to avoid duplicate parameters

SystemSetupContext.getParameters(key) method returns a String[] with all the selected options

SystemSetupContext.getParameter(key) method returns a String with a single selected option

Points to Remember


@SystemSetup annotation should be used only for public methods

If the annotation is defined at the class level, then those values acts as a default values for all the annotated methods within that class.

Annotation @SystemSetup has an attribute called extension, if it is not defined then annotation code will not be executed at all.

For both process and type attributes of annotation, default value is “ALL”

We can define any number of annotated methods inside the annotated class.

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