Consuming APIs from Clarity's Client Extensions
Client extensions offer a powerful way to handle both frontend and backend processes in Liferay. In this scenario, Clarity's developers want to test two specific client extensions for consuming data from their ticketing app. Through these exercises, you'll learn how to use two types of client extensions—frontend custom elements and object actions—to fetch and interact with Liferay data effectively.
Exercise: Implementing Clarity's Frontend Custom Element
Here, you'll build and deploy Clarity's frontend custom element client extension testing client-to-server API calls.
-
Open a file explorer and navigate to the
exercises/module-1/
folder in your course workspace. -
Extract
clarity-ticketing-custom-element.zip.
-
Move the
clarity-ticketing-custom-element/
folder into theclient-extensions/
folder of your course workspace. -
Open the
clarity-ticketing-custom-element/src/services/request.ts
file with a text editor or IDE. -
Underneath the import line, add this code snippet:
-
Save the file.
-
Open a terminal and navigate to the
client-extensions/clarity-ticketing-custom-element/
folder. -
Run this command to build and deploy the custom element client extension:
-
Verify that the client extension deploys successfully:
Now that you've deployed the custom element client extension, you'll examine the ticketing app's UI.
-
In your Liferay instance, sign in as the Clarity Admin user.
- Username:
admin@clarityvisionsolutions.com
- Password:
learn
- Username:
-
Open the Global Menu (
), go to the Applications tab, and click Client Extensions. Confirm that the Clarity Ticketing Dashboard is present. -
Navigate back to the Home page.
-
Open the Site Menu (
), click Page Tree, and select the Tickets page. -
Click Edit (
) to start editing the page. -
In the Fragments and Widgets search bar, search for
Clarity Ticketing Dashboard
. -
Drag and drop the Clarity Ticketing Dashboard widget to the page.
-
Click Publish.
-
Confirm that the ticket 'How to adjust or tighten my frames?' is in the Open column.
-
In a new browser tab, open the Global Menu (
), go to the Applications tab, and click Tickets. -
Click Actions (
) for the ticket entry with the subject 'How to adjust or tighten my frames?'. -
Click View.
-
Update the Ticket Status to In Progress.
-
Click Save.
-
Return to the tab with the Tickets page and confirm that the 'How to adjust or tighten my frames?' ticket was moved to the In Progress column without requiring a page refresh.
Exercise: Implementing Clarity's Object Action Client Extension
Here, you'll build and deploy Clarity's object action client extension performing an API call.
-
Open a file explorer and navigate to the
client-extensions/clarity-ticketing-action/src/main/java/com/clarityvisionsolutions/ticketing/
folder in your course workspace. -
Open the
TicketActionSuggestionRestController.java
file in a text editor or IDE. -
Replace the code from lines 44 to 50 with the following code snippet:
This adds an authorization header, which ensures this WebClient securely transmits the data between itself and Liferay using the server-generated JWT token.
-
Save the file.
-
Open a terminal and navigate to the
client-extensions/clarity-ticketing-action/
folder. -
Run this command to build and deploy the client extension:
-
Verify it deploys successfully.
- Navigate back to the Home page.
Run this command from the
client-extensions/clarity-ticketing-action/
folder to start the Spring Boot service:Now that you've deployed the spring boot client extension and started the service, configure the object action.
-
In your Liferay instance, open the Global Menu (
), go to the Control Panel tab, and click Objects. -
Go to the Ticketing folder and being editing the Ticket object.
-
Select the Actions tab and click Clarity Ticketing Suggestion Action.
-
Toggle the Active switch on.
-
Go to the Action Builder tab and set these values:
Field Value Trigger On After Add
Condition > Enable Condition Enabled Condition > Expression Builder ticketStatus == 'open'
Action object-action-executor[function#clarity-ticketing-action-object-action-ticket-suggestion]
-
Click Save.
Next, you'll configure the OAuth 2.0 scope to allow the action to update tickets. -
Open the Global Menu (
), go to the Control Panel tab, and click OAuth 2 Administration. -
Click the
Clarity Ticketing Action OAuth Application User Agent
configuration. -
In the Scopes tab, click on
C_TICKET
and selectcreate/update/delete data on your behalf
. -
Click Save.
Next, you'll create a ticket to verify the API is invoked as expected. -
Open the Global Menu (
), go to the Applications tab, and click Tickets. -
Click Add (
). -
Set these values for the fields:
Field Value Priority Minor Account to Tickets Iris Optical User to Tickets Renee Region EMEA Subject Test Client Extension Ticket
Ticket Status Open Type Delivery Issue -
Click Save.
-
Return to the Tickets application menu.
-
Click on the ID of the created Test Client Extension Ticket.
-
Verify the Suggestions field contains the “There are no suggestions for this ticket“ value.
Conclusion
Great! You've implemented two of Clarity's client extensions consuming Liferay's headless APIs. By leveraging functionalities displayed in these client extensions, Clarity's team is better equipped to optimize their organization's performance.
Next, you'll review what you've learned before moving on to the next module.
Capabilities
Product
Education
Contact Us