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

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



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

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