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

REST Builder in Liferay 7.x

  • Liferay
  • April 24, 2023

Share On :

Introduction:
  • Rest Builder is Liferay’s tool to build REST and GraphQL APIs.
  • Rest builder is a tool that can help developers generate RESTful web services quickly and easily.
  • REST Builder can be used to create RESTful web services for a wide range of applications, including web applications, mobile applications, and Iot devices.
Benefits : 

The benefits of using REST Builder include:

  1. Development speed:
    • you avoid writing JAX-RS annotations, converters, adding support for multipart or layers to organize your code. Everything is generated.
  2. API scaffolding:
    • pagination, filtering, searching, JSON writers, XML generation, even unit, and integration tests are generated.
  3. GraphQL support out of the box:
    • write your REST API and get a GraphQL endpoint for free.
  4. JSON & XML support:
    •  APIs return whichever format the consumer prefers.
  5. Flexibility:
    • REST Builder allows developers to customize the generated code to meet their specific needs.
Prerequisites :
  • Liferay 7.x
  • Basic understanding of Liferay
  • Knowledge of API
Environmental Requirements :
  • Liferay
  • Eclipse IDE
  • Blade CLI
  • Gradle
Generating APIs with REST Builder
Follow these steps to REST Builder to create a headless REST API for your apps:
  1. Create a project.
    1. Open eclipse IDE. Select the desired workspace which is created for your project and then click on launch.
Step to select Eclipse workspace
    1. Navigate to the File → New → Other.. → Liferay Workspace Project → Enter Project name → Select Build type → Select Product Version → Then click on Finish tab. Open a new project window.
Create new Liferay Workspace Project
Perspective of newly created Liferay Workspace Project
    1. Now create a new REST Builder module project
    2. Navigate to the Project name  → Right click on Modules → New → Liferay Module Project and Click on “Next”
    3. Enter Project name
    4. Select “Build type” as “Gradle”  → Select “Project Template name” as “REST Builder” → Then click on “Next”
Creating Gradle module for REST Builder project
    1. Open a new window. Enter Component class name  → Enter Package name → Click on “Finish”
Defining Component class and package
    1. The necessary file structure for Rest Builder automatically gets created as below.
File structure auto-creation for Rest Builder
  1. In your *-impl module’s root folder, write your OpenAPI profile in “rest-openapi.yaml” file.
    Writing YAML files is tricky, so you can use the swagger editor to do it, which validates the YAML file against YAML syntax and the OpenAPI specification.
Creating API structure in swagger editor
				
					// rest-openapi.yaml
info:
    description: "TestRestUsers REST API"
    license:
        name: "Apache 2.0"
        url: "http://www.apache.org/licenses/LICENSE-2.0.html"
    title: "TestRestUsers"
    version: v1.0
openapi: 3.0.1
paths:
  "/get-user":
    get:
      operationId: getUserById
      parameters:
        - in: query
          name: userId
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/UserObject"
      tags: ["User"]
components:
  schemas:
    UserObject:
      properties:
        userId:
          type: integer
          format: int64
        screenName:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        email:
          type: string
        statusCode:
          type: integer
        statusMessage:
          type: string

				
			
  1. Once you have written your OpenAPI configuration and profile, it’s time to generate your scaffolding for REST and GraphQL.
  2. Now Build the REST Builder module.
    In the terminal, navigate to the root directory of your rest-builder project
    Execute the below command to build the rest-builder module

blade gw buildREST

Or

Build REST Builder module using eclips
  1. The necessary file structure for the rest-builder gets created as below. 
    It’s also generates  the *ResourceImpl class where you can write your business logic for implementation of your each service.
File structure for rest-builder created
  1. After implementing all the business logic for each service, execute below command to deploy your rest-builder module

blade gw deploy

Or

Deploying rest-builder module after implementing logic

Now We have performed the CRUD operation for User in OpenAPI and implemented Business Logic for each service.

Write the OpenAPI profile for the user in “xxx-impl/rest-openapi.yaml” like as below:

				
					// rest-openapi.yaml
info:
    description: "TestRestUsers REST API"
    license:
        name: "Apache 2.0"
        url: "http://www.apache.org/licenses/LICENSE-2.0.html"
    title: "TestRestUsers"
    version: v1.0
openapi: 3.0.1
paths:
  "/get-user":
    get:
      operationId: getUserById
      parameters: 
        - in: query
          name: userId
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                $ref: "#/components/schemas/UserObject"
      tags: ["User"] 
  "/get-users":
    get:
      operationId: getUsers
      parameters: 
        - in: query
          name: page
          schema:
            type: integer
        - in: query
          name: pageSize
          schema:
            type: integer
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/UserObject"
      tags: ["User"] 
  "/update-user":
    post:
      operationId: updateUser
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UserObject"
          application/xml:
            schema:
              $ref: "#/components/schemas/UserObject"   
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                $ref: "#/components/schemas/UserObject"    
      tags: ["User"]
  "/delete-user":
    delete:
      operationId: deleteUserById
      parameters: 
        - in: query
          name: userId
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                $ref: "#/components/schemas/UserObject"
      tags: ["User"]
components:
  schemas:
    UserObject:
      properties:
        userId:
          type: integer
          format: int64
        screenName:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        email:
          type: string
        statusCode:
          type: integer
        statusMessage:
          type: string

				
			

Your APIs are available at this URL:

http://[host]:[port]/o/[APPLICATION_CLASSNAME]/[OPEN_API_VERSION]/

In our case, the API is available at this URL:

http://localhost:8080/o/api

Business Logic for the User:

Write a business logic in “xxx-impl/com.*.portal.restusers.internal.resource.v1_0” file.

1) Add OR Update User

First write the OpenAPI configuration profile to add or update a new User in “rest-openapi.yaml” file

				
					// rest-openapi.yaml
paths:
  "/update-user":
    post:
      operationId: updateUser
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UserObject"
          application/xml:
            schema:
              $ref: "#/components/schemas/UserObject"   
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                $ref: "#/components/schemas/UserObject"    
      tags: ["User"]
components:
  schemas:
    UserObject:
      properties:
        userId:
          type: integer
          format: int64
        screenName:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        email:
          type: string
        statusCode:
          type: integer
        statusMessage:
          type: string

				
			

Write implementation logic for how to add or update User  in “xxx-impl/com.*.portal.restusers.internal.resource.v1_0” file.

Note: If you have passed userId as 0, a new user is created.
If you want to update an existing user then you can pass usedId of existing user for update existing user details.  

Update or add user implementation logic
				
					// xxx-impl/com.*.portal.restusers.internal.resource.v1_0
package com.projectname.portal.restusers.internal.resource.v1_0;

import java.util.Locale;

import javax.ws.rs.core.Response;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ServiceScope;

import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.Validator;
import com.projectname.portal.restusers.dto.v1_0.UserObject;
import com.projectname.portal.restusers.resource.v1_0.UserResource;

/**
 * @author DELL
 */
@Component(properties = "OSGI-INF/liferay/rest/v1_0/user.properties", scope = ServiceScope.PROTOTYPE, service = UserResource.class)
public class UserResourceImpl extends BaseUserResourceImpl {

	@Reference
	private UserLocalService userLocalService;

	@Override
	public UserObject updateUser(UserObject userObject) throws Exception {

		long userId = userObject.getUserId();
		long companyId = contextCompany.getCompanyId();
		Locale locale = contextAcceptLanguage.getPreferredLocale();
		User user = null;
		ServiceContext serviceContext = new ServiceContext();
		serviceContext.setCompanyId(companyId);
		serviceContext.setUserId(contextUser.getUserId());

		String firstName = userObject.getFirstName();
		String lastName = userObject.getLastName();
		String screenName = userObject.getScreenName();
		String primaryEmailAddress = userObject.getEmail();

		try {
			user = Validator.isNotNull(userId) ? userLocalService.updateUser(userId, StringPool.BLANK, StringPool.BLANK,
					StringPool.BLANK, false, StringPool.BLANK, StringPool.BLANK, screenName, primaryEmailAddress, false,
					null, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, firstName,
					StringPool.BLANK, lastName, GetterUtil.DEFAULT_LONG, GetterUtil.DEFAULT_LONG, true, 10, 10, 1980,
					StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK,
					StringPool.BLANK, GetterUtil.DEFAULT_LONG_VALUES, GetterUtil.DEFAULT_LONG_VALUES,
					GetterUtil.DEFAULT_LONG_VALUES, null, GetterUtil.DEFAULT_LONG_VALUES, serviceContext)
					: userLocalService.addUser(contextUser.getUserId(), companyId, true, null, null, false, screenName,
							primaryEmailAddress, locale, firstName, StringPool.BLANK, lastName, GetterUtil.DEFAULT_LONG,
							GetterUtil.DEFAULT_LONG, true, 10, 10, 1980, StringPool.BLANK,
							GetterUtil.DEFAULT_LONG_VALUES, GetterUtil.DEFAULT_LONG_VALUES,
							GetterUtil.DEFAULT_LONG_VALUES, GetterUtil.DEFAULT_LONG_VALUES, true, serviceContext);

			userId = user.getUserId();
			userObject.setUserId(userId);
			userObject.setStatusCode(Response.ok().build().getStatus());
			userObject.setStatusMessage("Added Successfully");
		} catch (Exception e) {
			_log.error(e.getMessage(), e);
			userObject.setStatusCode(Response.serverError().build().getStatus());
			userObject.setStatusMessage(e.getMessage());
		}

		return userObject;
	}

	public static final Log _log = LogFactoryUtil.getLog(UserResourceImpl.class);
}

				
			

Add User

Note: Here you have passed userId as 0 for add new user

Add User json with 0 userId

Update User by userId

Note: Here you have passed the userId of the existing user.

Edit User json with desired userId
2) Get User

First write the OpenAPI configuration profile to get User in “rest-openapi.yaml” file

				
					// rest-openapi.yaml
paths:
  "/get-user":
    get:
      operationId: getUserById
      parameters: 
        - in: query
          name: userId
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                $ref: "#/components/schemas/UserObject"
      tags: ["User"] 
components:
  schemas:
    UserObject:
      properties:
        userId:
          type: integer
          format: int64
        screenName:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        email:
          type: string
        statusCode:
          type: integer
        statusMessage:
          type: string

				
			

Write Implementation logic for how to get User By UserId in  “xxx-impl/com.*.portal.restusers.internal.resource.v1_0” file.

Implement logic for user retrieval
				
					// xxx-impl/com.*.portal.restusers.internal.resource.v1_0
package com.projectname.portal.restusers.internal.resource.v1_0;

import javax.validation.constraints.NotNull;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ServiceScope;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.UserLocalService;
import com.projectname.portal.restusers.dto.v1_0.UserObject;
import com.projectname.portal.restusers.resource.v1_0.UserResource;

/**
 * @author DELL
 */
@Component(properties = "OSGI-INF/liferay/rest/v1_0/user.properties", scope = ServiceScope.PROTOTYPE, service = UserResource.class)
public class UserResourceImpl extends BaseUserResourceImpl {

	@Reference
	private UserLocalService userLocalService;

	@Override
	public UserObject getUserById(@NotNull Long userId) throws Exception {
		User user = userLocalService.getUser(userId);
		UserObject userObject = getUserFromModel(user);
		return userObject;
	}

	private UserObject getUserFromModel(User user) {
		UserObject userObject = new UserObject();
		userObject.setScreenName(user.getScreenName());
		userObject.setFirstName(user.getFirstName());
		userObject.setLastName(user.getLastName());
		userObject.setEmail(user.getEmailAddress());
		return userObject;
	}

	public static final Log _log = LogFactoryUtil.getLog(UserResourceImpl.class);
}

				
			

Get User By userId

Exploring API to get User details By userId
3) Delete User

First write the OpenAPI configuration profile to delete existing User in “rest-openapi.yaml” file

				
					// rest-openapi.yaml
paths:
  "/delete-user":
    delete:
      operationId: deleteUserById
      parameters: 
        - in: query
          name: userId
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                $ref: "#/components/schemas/UserObject"
      tags: ["User"]
components:
  schemas:
    UserObject:
      properties:
        userId:
          type: integer
          format: int64
        screenName:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        email:
          type: string
        statusCode:
          type: integer
        statusMessage:
          type: string

				
			

Write Implementation logic for how to delete User in  “xxx-impl/com.*.portal.restusers.internal.resource.v1_0″ file.

Delete user logic in portal file
				
					// xxx-impl/com.*.portal.restusers.internal.resource.v1_0
package com.projectname.portal.restusers.internal.resource.v1_0;

import javax.validation.constraints.NotNull;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ServiceScope;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.service.UserLocalService;
import com.projectname.portal.restusers.dto.v1_0.UserObject;
import com.projectname.portal.restusers.resource.v1_0.UserResource;

/**
 * @author DELL
 */
@Component(properties = "OSGI-INF/liferay/rest/v1_0/user.properties", scope = ServiceScope.PROTOTYPE, service = UserResource.class)
public class UserResourceImpl extends BaseUserResourceImpl {

	@Reference
	private UserLocalService userLocalService;

	@Override
	public UserObject deleteUserById(@NotNull Long userId) throws Exception {
		UserObject userObject = new UserObject();
		try {
			userLocalService.deleteUser(userId);
			userObject.setStatusCode(200);
			userObject.setStatusMessage("Deleted Successfully");
		} catch (Exception e) {
			_log.error(e.getMessage(), e);
			userObject.setStatusCode(500);
			userObject.setStatusMessage(e.getMessage());
		}
		return userObject;
	}

	public static final Log _log = LogFactoryUtil.getLog(UserResourceImpl.class);
}

				
			

Delete User By userId

Exploring API to delete user by userId
4) Get All Users

First write the OpenAPI configuration profile to get all Users in “rest-openapi.yaml” file

				
					// rest-openapi.yaml
paths:
  "/get-users":
    get:
      operationId: getUsers
      parameters: 
        - in: query
          name: page
          schema:
            type: integer
        - in: query
          name: pageSize
          schema:
            type: integer
      responses:
        200:
          description: "Success Response"
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/UserObject"
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/UserObject"
      tags: ["User"] 
components:
  schemas:
    UserObject:
      properties:
        userId:
          type: integer
          format: int64
        screenName:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        email:
          type: string
        statusCode:
          type: integer
        statusMessage:
          type: string

				
			

Write Implementation logic for how to get all Users in  “xxx-impl/com.*.portal.restusers.internal.resource.v1_0″ file.

Retrieve all Users in implementation logic
				
					// xxx-impl/com.*.portal.restusers.internal.resource.v1_0
package com.projectname.portal.restusers.internal.resource.v1_0;

import java.util.ArrayList;
import java.util.List;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ServiceScope;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.vulcan.pagination.Page;
import com.liferay.portal.vulcan.pagination.Pagination;
import com.projectname.portal.restusers.dto.v1_0.UserObject;
import com.projectname.portal.restusers.resource.v1_0.UserResource;

/**
 * @author DELL
 */
@Component(properties = "OSGI-INF/liferay/rest/v1_0/user.properties", scope = ServiceScope.PROTOTYPE, service = UserResource.class)
public class UserResourceImpl extends BaseUserResourceImpl {

	@Reference
	private UserLocalService userLocalService;

	@Override
	public Page getUsers(Pagination pagination) throws Exception {
		List userObjects = new ArrayList<>();
		List users = userLocalService.getUsers(pagination.getStartPosition(), pagination.getEndPosition());
		for (User user : users) {
			UserObject userObject = getUserFromModel(user);
			userObjects.add(userObject);
		}
		return Page.of(userObjects, pagination, userObjects.size());
	}

	private UserObject getUserFromModel(User user) {
		UserObject userObject = new UserObject();
		userObject.setScreenName(user.getScreenName());
		userObject.setFirstName(user.getFirstName());
		userObject.setLastName(user.getLastName());
		userObject.setEmail(user.getEmailAddress());
		return userObject;
	}

	public static final Log _log = LogFactoryUtil.getLog(UserResourceImpl.class);
}

				
			

Get All Users

Note: Here you have passed page and page-size for getting users.

Exploring API to get user list with pagination

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...
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