This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • info@ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

Configuration Creator in Liferay 7.2

  • Liferay
  • July 15, 2020

Share On :

Problem : 

While working with the Liferay projects, you may need to create a configuration from the control panel like custom fields, structures, templates, roles, permissions, and many more in order to make portlet/implementation work properly.

Solution : 

You can create the BundleActivator component to create the above configurations programmatically.

Benefits : 
  • We don’t need remember/prepare steps to create configurations from Control Panel.
  • This will remove overhead of creating configurations in all environments (Dev, Test, Production) you have for your project.
Prerequisites
  • Java 
  • Liferay portal 7/7.x
  • Basic knowledge of Liferay
Environment Requirements
  • JDK 8
  • Eclipse
  • MySQL
  • Liferay Portal
  • Gradle

To create BundleActivator for the Liferay project, you need to perform the below steps. In this example, we will explain to you to create custom fields, structure, templates and roles.

1) Create a Liferay module project using the following steps.

  1. Go to Liferay workspace project → modules → new
  2. Select other → Liferay → Liferay Module Project and Click on “Next”.
  3. Enter the project name.
  4. Select “Project Template Name” as “ MVC-portlet” and Click on “Next”.
  5. Enter a Package name and click on “Finish”. The necessary file structure for the MVC-portlet automatically gets created as below.
MVC portlet folder structure in eclipse

2) Create a package with the name com.ignek.action.

3) Create one class with the name ConfigurationCreator into this package.

4) Enter the following line into the bnd.bnd.

				
					// bnd.bnd 
Bundle-Activator: com.ignek.action.ConfigurationCreator.
				
			

5) Enter the following lines into the build.gradle.

				
					// build.gradle
compileOnly group: “org.osgi”, name: “org.osgi.core”
compileOnly group: “com.liferay”, name: “com.liferay.dynamic.data.mapping.api”
compileOnly group: “com.liferay”, name: “com.liferay.journal.api”
compileOnly group: “com.liferay”, name: “com.liferay.petra.string”
				
			

6) Open ConfigurationCreator.java & add the following lines before the declaration of the class name.

				
					// ConfigurationCreator.java
@Component(immediate = true,
	property = { 
		"key=application.startup.events" 
	}, 
	service = BundleActivator.class
)

				
			

7) Implement the BundleActivator in ConfigurationCreator.

				
					// ConfigurationCreator.java
public class ConfigurationCreator implements BundleActivator

				
			

8) Override the following methods inside the class ConfigurationCreator.

				
					// ConfigurationCreator.java
@Override
public void start(BundleContext context) throws Exception {
}

@Override
public void stop(BundleContext context) throws Exception {
}

				
			

Note : Start() method will call automatically when a module is deployed or Liferay server is started. We will add our code to create custom fields, structures, templates, and roles in this method.

1) Create custom fields

Write the below code in the start() method to create custom fields.

				
					//ConfigurationCreator.java
/** Create custom fields **/
/** Fetch default company in Liferay **/
Company defaultCompany = CompanyLocalServiceUtil.getCompanyByMx(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
long companyId = defaultCompany.getCompanyId();
/** Fetch Administrator role id **/
long roleId = roleService.getRole(companyId, RoleConstants.ADMINISTRATOR).getRoleId();
long userId = userLocalService.getRoleUsers(roleId, 0, 1).get(0).getUserId();
try {
	ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, 
		   Group.class.getName(),0 l);
	if (Validator.isNotNull(expandoBridge)) {
		int inputType = 15;
		expandoBridge.addAttribute("Name", inputType, false);
	}
} catch (Exception e) {
	log.error("Error occurred while creating custom field");
}
				
			

ExpandoBridge allows you to add custom fields in Liferay programmatically.

Notes :

1. You can choose different inputType for Custom fields.

For Text and numberint inputType = 15;
For Selectionint inputType = 16;
For Mapint inputType = 21;
For Dateint inputType = 3;
For true/false (boolean)int inputType = 1;

2. You can choose different className to generate custom fields for sites, organizations, roles, users, and several more.

For sitesGroup.class.getName()
For OrganizationOrganization.class.getName()
For RoleRole.class.getName()

3. You can check generated custom fields from control-panel → configuration → custom-fields (refer below image).

Access custom fields in control panel

2) Create Structure

Perform the below steps to create Structure programmatically.

  1. Create a folder inside the src/main/resources with name structures.
  2. Create a file with the name student.json in this folder.
  3. Add the source of structure into this file (You can copy the source from the Liferay control panel).

Add the following code into the start() method to generate structures.

				
					// ConfigurationCreator.java
/** Create structure in global site **/
long groupId = groupService.getCompanyGroup(companyId).getGroupId();
String journalArticleClassName = JournalArticle.class.getName();
long journalArticleClassNameId = classNameService.getClassNameId(journalArticleClassName);
String structureKey = STUDENT;
String content = getFile("structure/student.json");
DDMForm ddmForm = DDMUtil.getDDMForm(content);
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
serviceContext.setCompanyId(companyId);
serviceContext.setUserId(userId);
DDMStructure studentStructure = null;
try {
	studentStructure = structureLocalService.getStructure(groupId, 
		journalArticleClassNameId, structureKey);
} catch (NoSuchStructureException e) {
	log.info("No Structure found Adding new one");
}
if (Validator.isNotNull(studentStructure)) {
	try {
		studentStructure.setDDMForm(ddmForm);
		studentStructure = structureLocalService.updateStructure(userId, 
			studentStructure.getStructureId(),ddmForm, 
			DDMUtil.getDefaultDDMFormLayout(ddmForm), serviceContext);
	} catch (Exception e) {
		log.error("Error while updating structure");
	}
} else {
	try {
		Map<Locale, String> nameMap = new HashMap<Locale, String>();
		nameMap.put(Locale.US, STUDENT);
		Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
		descriptionMap.put(Locale.US, STUDENT);
		studentStructure = structureLocalService.addStructure(userId, groupId, StringPool.BLANK, 
			journalArticleClassNameId, structureKey, nameMap, descriptionMap, ddmForm, 
			DDMUtil.getDefaultDDMFormLayout(ddmForm), StorageType.JSON.toString(), 
			DDMStructureConstants.TYPE_DEFAULT, serviceContext);
	} catch (Exception e) {
		log.error("Error while adding new structure");
	}
}

				
			

Output :

Check list of structures in control panel

3) Create Template

To generate a template for an existing structure, perform below steps.

  1. Create one folder in src/main/resources with the name templates.
  2. Create one file with the name student.ftl in this folder.
  3. Add the source of the template into this file (You can copy the source from the Liferay admin panel).
  4.  Add the following code into the start() method to create a template.
				
					// ConfigurationCreator.java
/** Create template in global site **/
String templateKey = STUDENT;
String script = getFile("template/student.ftl");
String structureClassName = DDMStructure.class.getName();
long structureClassNameId = classNameService.getClassNameId(structureClassName);
DDMTemplate studentTemplate = null;
try {
	studentTemplate = templateService.getTemplate(groupId, structureClassNameId, templateKey);
} catch (Exception e) {
	log.info("No template found Adding new one");
}
if (Validator.isNotNull(studentTemplate)) {
	try {
		studentTemplate.setScript(script);
		studentTemplate = templateService.updateDDMTemplate(studentTemplate);
	} catch (Exception e) {
		log.error("Error while updating template");
	}
} else {
	try {
		Map < Locale, String > nameMap = new HashMap < Locale, String > ();
		nameMap.put(Locale.US, STUDENT);
		Map < Locale, String > descriptionMap = new HashMap < Locale, String > ();
		descriptionMap.put(Locale.US, STUDENT);
		studentTemplate = templateService.addTemplate(userId, groupId, structureClassNameId, 
			studentStructure.getStructureId(), journalArticleClassNameId, 
			templateKey, nameMap, descriptionMap, 
			DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, StringPool.BLANK, 
			"ftl", script, false, false, StringPool.BLANK, null, serviceContext);
	} catch (Exception e) {
		log.error("Error while adding a new template");
	}
}

				
			

Output:

Check list of templates in control panel

4) Create Roles

Write the below code (Inside the start() method) to generate roles in Liferay.

				
					// ConfigurationCreator.java
/** Creating role **/
try {
	Role role = roleService.fetchRole(companyId, "Head of Organization");
	Map < Locale, String > nameMap = new HashMap < > ();
	nameMap.put(Locale.US, HEAD_OF_ORGANIZATION);
	Map < Locale, String > descriptionMap = new HashMap < > ();
	descriptionMap.put(Locale.US, "This role is for organization admin");
	if (Validator.isNull(role)) {
		role = roleService.addRole(userId, Role.class.getName(), 0, HEAD_OF_ORGANIZATION, 
			nameMap, descriptionMap, 1, null, serviceContext);
	}
} catch (Exception e) {
	log.error("Error while adding role");
}

				
			

As you see, the Head of Organization role is created under control-panel → users → roles.

List of regular roles

Now the structure of the Configuration Creator project will look like the structure below.

Configuration Creator project structure visualization

Now build/deploy this using the following command.

blade gw deploy

You can download the source code from the below link.

configuration creator source code

Explore Our Services

Discover how we can help your business thrive, whether you’re running a small startup, an SME, or a large enterprise. We’re here to understand your unique needs and goals, offering the expertise and resources to support your journey to success.

Stay informed about our Liferay services and updates by subscribing to our newsletter—just fill in the details below to subscribe.

Loading
Loading...

Related Blogs

January 3, 2020
How to write ADT with structure and template in Liferay Cover Image
How to write ADT with structure and template in Liferay
March 17, 2020
custom configuration under Instance Settings in Liferay 7.2 Cover Image
Create custom configuration under Instance Settings in Liferay 7.2
December 10, 2020
servlet filter Cover Image
Servlet Filter in Liferay 7.2
Loading...

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@ignek.com
  • info@ignek.com
SALES
  • sales@ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2025 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram