Configuring Liferay for a Custom Feedback Counter Service
Kyle has an idea for a simple application that can help keep track of user feedback by fetching Liferay object data. He created a simple Spring Boot application that can call a Liferay API to achieve this, and now he wants to run it as a custom service in Liferay Cloud.
In the next few exercises, you’ll turn Kyle’s simple application into a custom service that runs in Liferay Cloud. You’ll start by configuring your Liferay instance so that it works with Kyle’s application.
To start this task, you need to
- Install Docker to build Docker images
- Create an account on Docker Hub to publish Docker images
- Have a Liferay workspace ready
- Have an extra service provisioned for your Liferay Cloud project
Creating Object Data
First, import the object definition and use it to create some data for your application.
Import and Publish the Object Definition
In a new folder within a Liferay Workspace, download and unzip Kyle’s feedback counter project:
curl https://resources.learn.liferay.com/courses/latest/en/liferay-administrator/cloud-administrator/cloud-development-lifecycle/w9g6.zip -O
The feedback counter application contains code for a Spring Boot application and an
Object_FeedbackInput.jsonfile with an object definition.
Log into your UAT Liferay instance.
Open the Applications menu ( ) at the top of the screen and navigate to Control Panel → Objects.
Click Actions ( ) at the top of the screen and click Import.
FeedbackInputas the name.
Click Select, and select the
Object_FeedbackInput.jsonfile from your local file system.
Now the object definition is added as a draft. It has a single boolean field for whether the feedback is “helpful.”
Enable it in widgets and fragments and publish it:
Click the Feedback Input object definition from the list.
Enable the Show Widget switch at the bottom of the page.
Click Publish at the top of the page.
The object definition is published and available to use as a form.
Populate Some Data
Next, add a form using the object to a page and submit some values to create usable data.
Navigate back to your site’s home page.
Click Edit ( ) at the top of the page to edit the page.
In the list of fragments on the left side of the screen, drag the Form Container fragment onto the page.
In the Form Container’s drop-down menu, select your new Feedback Input object.
Click Publish at the top of the page.
The form appears on the page with a single “Helpful” checkbox.
Click the Submit button on the new form to submit a false result.
Refresh the page and submit a few more times with the checkbox checked.
Now you have a few true results and a false result submitted for your object.
Configuring Liferay to Authorize Your Service
Next, configure your Liferay instance to allow remote requests and OAuth 2 authorization.
Add and Configure an OAuth 2 Profile
Open the Applications Menu ( ) at the top of the screen and navigate to Control Panel → OAuth 2 Administration.
Click Add ( ) to add a new OAuth 2 profile for your custom service.
Fill in Delectable Bonsai custom services as the OAuth 2 profile’s name.
Deselect the Authorization code checkbox.
Now you have an OAuth 2 profile created, with a client ID and client secret value needed to grant authorization. Copy these values somewhere so that you can use them for your custom service later.
You must also configure the scopes for this profile so that it can be used to retrieve object data.
Click the Scopes tab at the top of the screen.
Click to expand the new scope category named after your object definition (
Select the checkbox for read data on your behalf.
Scroll down to the bottom and click Save.
Next, you’ll create a custom service for your Liferay Cloud environment that retrieves data via the
feedbackinput object’s API.