Liferay Tutorial for CTOs
Liferay can be a pretty good way to boost the time to market of your app. Learn how to do that by reading a handy Liferay tutorial.
Join the DZone community and get the full member experience.
Join For FreeMost projects start with a specific business concept, and it wasn’t any different in our case. We needed to develop a system that would allow the client’s employees to display and manage various content (blog posts, newsletters, information about contests, etc.). We also needed to create a user hierarchy structure that would reflect the company’s organization, on the basis of which permissions would be granted for the specific parts of the aforementioned content. Of course, every user would also be required to log in to their account, and the administrator had to have the ability to manage the users, content, and permissions.
The software also had to be integrated with external systems, and last but not least, we needed to pay attention to the general look and feel of the portal, as it would be available for a big audience.
While we could create this system in Java using the Spring framework, like in other projects that we developed, some of the business requirements seemed quite familiar. We thought they could be implemented faster – or even were available out-of-the-box — if we considered using the Liferay technology.
What Is the Liferay Portal?
Liferay is a free (although there is also a paid, enterprise version), open-source tool that allows you to efficiently and quickly deliver a specific system. Liferay (also known as Liferay Portal) was written and developed in Java. It’s a highly configurable (through the administration panel) technology with an intuitive, easy-to-use interface. It offers many built-in Liferay portlet types that you can adapt to your project by using the admin configuration. It also has many management-related functionalities – you can manage users, organizations, and permissions or log in as a different person thanks to the user impersonation function.
In the case of more complex business tasks, Liferay also allows Java developers to override the existing widgets and create their own – for example, the Liferay MVC Portlet (Model-View-Controller) that we constantly use in the project. In addition, the technology provides a Rest Builder to create REST API Interfaces and a Service Builder to create database entities, services, and models (more about that below).
Another important aspect — especially in the case of systems that will be available for a wide audience – is the look and feel. Liferay Themes allows you to customize your website with a combination of CSS, JavaScript, HTML, and FreeMarker templates. It’s also possible to create your own theme using the provided tools.
There are many additional tools available for Java developers. For example, if you want to deploy a web app as a Liferay JSF portlet, there’s a bridge for that. If you’re interested in a Liferay Eclipse plugin, there’s a good chance you’ll find it in the Liferay IDE collection created by the technology’s developers and hosted on GitHub. There’s also an extensive Liferay plugin marketplace that’s full of interesting things and a Liferay plugin project wizard (or portlet project wizard). Long story short, it’s a pretty powerful and flexible solution that might find use in various circumstances.
Liferay Showcase: A Video Tutorial With Additional Information
We've also created a video introduction that shows how to use Liferay Portal to create a web application in your browser really fast and without any coding. You’ll learn how to add the Knowledge Base, Blogs & Webinars, Images, and Documents widgets. The video also shows how to make a dashboard that aggregates details from the other modules and sets up users and permissions.
Liferay Development: 6 Important Functionalities You Can Implement
Here are six functionalities you can implement faster, thanks to Liferay. By doing that, you can accelerate the system’s development and, therefore, improve the time to market.
System Login
The ability to log in to the system is one of the basic functionalities that we had to implement. You can use a ready-made Liferay portlet that allows users to log in to the portal by means of authentication based on an identifier, such as a username or an e-mail address (depending on the configuration).
Additionally, the portlet allows you to change the user’s password and recover or reset it in case it was lost/forgotten. The users can access specific resources only after they log in to the portal. Thanks to this Liferay portlet, developers were able to quickly implement log-in functionality.
Liferay also provides the ability to import and export users to LDAP directories and a single-sign-on (SSO) configuration.
If you want to improve security, it’s also possible to change password policies with the use of the admin panel. There are several options:
- Password change: Allow or disallow the user to change their password
- Syntax checking: For example, change how long and how many special characters the password should have.
- Password expiration time: Define how long the password should be valid
- Lockout: The user can try to log in a certain number of times before their account is blocked
You can assign specific password policies to specific users and whole user groups.
Organizations, Roles, and Permissions
Our next task was to model the organizational structure of our client’s company. Liferay allows you to structure user groups to reflect the organization. In addition, it is possible to manage them – you can add/remove users, create roles for them, and grant them permissions. You’ve got three types of roles to use: Normal, Site, and Organization.
Widgets and Applications
Liferay also allows for the use of widgets/portlets, which are web apps that return data and generate responses with specific content to be displayed on the system page. Widgets can be managed and placed on a page with the use of the admin panel. The cool thing about that is that you don’t need to worry about the arrangement of other elements on the page – it’s handled by the Liferay application. Permissions of the portlet can also be managed by the administrator. In our project, we used the widget and applications mentioned below, with a bit of custom coding to adapt them to the client’s specific business needs:
Asset Publisher
Liferay provides the ability to add many types of resources, such as articles and documents. In most circumstances, you’ll want to present these resources to the end user. This is where the Asset Publisher tool comes in handy. It is a highly customizable application that allows you to search for different types of content on the fly, giving you the ability to control what and how it is displayed in a given place. This helps you create a more dynamic website.
You can search for resources in a variety of ways. You can set the resource selection to either dynamic or manual. With the dynamic setting, the content is displayed automatically based on the specified rules or filters. For example, you can set the Asset Publisher to display only resources of a certain type or resources that have specific tags or categories applied to them.
When you select resources manually, the Asset Publisher only displays resources that have been explicitly chosen by the administrator. You can also configure how the content is displayed by creating new Application Display Templates, which allow portal administrators to override the default settings, removing restrictions on how content is displayed in your application.
Calendar Widget
A standard calendar (as seen on the screen below) that shows events for individual users and sites and allows you to manage them. It’s divided into sections dedicated to the user and the site itself. You can also customize new calendars, add events, and change email notification settings.
Forms App
A module you can use to build your own forms that can be widely configured. For example, you can add field types: Text Field, Single Selection, Multiple Selection, Date, Grid, etc. Such forms are one of the most often used elements in applications. Users can use them to input data (e.g. names or dates of birth) and make various choices in the system.
MVC Portlet
Sometimes, the client’s requirements are more complicated. For example, if you need to display data from a database (or any API), add or modify it – the MVC Portlet is the perfect solution. It’s based on the well-known Model-View-Controller architecture, which is designed to separate each layer of the module’s operation. With it, you can create modules that you will be able to place anywhere in your system using the “drag & drop” functionality. The generated template is configured by default, and ready to be used.
Adding such a portlet requires a few simple steps:
1. Generate the MVC Portlet module template
2. Deploy it by running the blade deploy command
3. Place the portlet on the selected page using the “drag & drop” functionality (just use the mouse, and move it wherever you want it)
As you can see, the template for a working portlet is very easy to obtain. From that moment on, it’s available on the website, and you can start implementing your own business logic.
Service Builder
Service Builder is one of the largest and most frequently used tools for creating new database entities. It uses relational-object mapping, which generates subsequent layers on the basis of a single .xml file:
- model: in which classes corresponding to the created entity are generated
- persistence: downloading and saving data to the database
- service: a clean layer, ready to implement the interface and business logic
After generating the basic service builder, we get two modules – API and service. This configuration file is in the service module under the name service.xml, and in its default version it looks like this:
Now let’s describe what it consists of and what functionalities it has:
- Namespace tag: a unique namespace attached to the name of an entity in the database (protects against conflicts caused by duplicate names)
- Entity tag: it contains information about the name of the given entity
- Column tags: defines columns and the types of their values that will be stored in the database
- Order: the order in which records are stored in the database
- Finder: functionality that allows you to search for data using specific parameters (like objects after the field named “field2” – in the example above).
To build entities and generate classes needed to implement the logic, execute the command blade gw buildService
. After this, you should have the following module structure:
From now on, you can define the behavior of servers related to this entity in the “FooLocalServiceImp” class. After rebuilding the module, you can use these methods.
REST Builder
REST Builder is a powerful tool that consistently generates the code needed to implement and configure the appropriate endpoints (based on the OpenAPI profile) so that they are ready for consumption.
The main advantage of this module is the speed of the REST service development. The programmer does not have to worry about the appropriate endpoint configuration, annotations, or permissions. The code is automatically generated, and everything’s ready to implement the business logic.
This service enables an easy-to-configure ability to use pagination, filtering, or search by declaring the appropriate values in OpenAPI.
Responses are returned in both JSON and XML formats. The end-user can decide in which format he wants to read the answer.
First, you need to build a new module. The process is similar to the previous modules, but in this case, you’ll need to select “rest-builder” from the context menu. This way, two modules – API and IMPL – should be generated. In the latter, you’ll find the rest-openapi.yaml file, which will be the source of your API. We fill it in based on the OpenAPI specification. For example, the file might look like this:
All OpenAPI profiles contain three sections: info, components, and paths. The first one (“info”) contains information about the OpenAPI version, our API version, and the title. The “components” section contains schemas/entities that can be returned or consumed by the API. In this case, an entity named simply “Entity” is created, which contains the fields “name” as a string and “id” as a number. The last section, “paths,” defines the name and structure of the endpoint. In this case, the “entityId” parameter is passed to the GET “/entities” endpoint, and the “Entity” object created in the previous section is returned as a response.
After executing the blade gw buildRest
command, resources, and POJOs of your schemas and JAX-RS application will be generated. After verifying correctness, run the blade deploy
command. That’s it; the endpoint is ready to be consumed.
Real-World Example of Liferay Use: A CMS System for Polish FMCG Chain
We’ve used Liferay to develop a customer portal for one of the leading Polish FMCG companies, which operates over fifteen thousand stores.
The client needed an internal platform where constraints could publish various kinds of information – bulletins, industry news, contests — etc. The key thing was that the system had to be available to people without technical knowledge and without involving software developers each time there was a need to update it. The solution also had to offer users professional tools they could use for collecting statistics, creating financial reports, accessing employee data, and so on.
For these reasons, we decided to create a portal based on Liferay, supported by web and mobile apps and Microsoft Azure cloud infrastructure. The solution gave users a way to easily publish content via an extremely intuitive drag-and-drop interface. The platform also contains a reporting module that fetches information from Microsoft Power BI. People can easily collect and compile data within the system.
The platform has been accepted very warmly and is currently used by over a thousand of our client’s numerous constraints.
Summary
Liferay is a pretty old tool — it was created at the turn of the century, in the year 2000. Because of this, as a CTO, you might be tempted to forgo it in favor of newer solutions. However, this is not a choice that should be made lightly because Liferay is still being developed by its authors and has a lot to offer – both in terms of practical business uses and surprisingly powerful customization options.
It’s a bit hard to start learning this technology, but it has many functionalities that can be used in modern systems. In this article, we’ve only shown you a small part of the possible options, but it should be enough to see how this solution can help you accelerate the development of your application and whether Liferay training is something worth considering.
Published at DZone with permission of Patryk Rutkowski. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments