Extending Clarity's Distributor Management App with Client Extensions
To complete the onboarding flow, Clarity wants to enable managers to create business accounts for approved applications easily. Each account should be named after the application’s businessName
and the applicant should be assigned automatically to the account with the Account Administrator role. You can achieve this using an object action client extension.
Exercise: Setting Up the Client Extension
When you deployed the liferay-course-etc-spring-boot
project for your workflow, you also deployed a custom object action.
Before proceeding, ensure the Spring Boot application is running. If it isn’t, navigate to the liferay-course-etc-spring-boot
project folder and run this command:
Then go to http://localhost:58081/ready
to confirm the application started successfully.
Examining the Client Extension Code
This client extension defines a REST controller (ObjectActionAccountRestController
) that handles business account creation for approved distributors. It performs three primary operations:
-
Create a business account using the
businessName
from the approved application. -
Associate the applicant with the account using the
applicantEmailAddress
field. -
Assign the applicant the Account Administrator role.
This Java class automates user account management using Liferay’s headless APIs. These APIs provide programmatic access to Liferay's functionalities, enabling seamless integration and automation. Here are the specific calls this class makes:
-
Account Creation: A POST request to
/o/headless-admin-user/v1.0/accounts
creates the business account. -
User Assignment: A POST request to
/o/headless-admin-user/v1.0/accounts/by-external-reference-code/{accountExternalReferenceCode}/user-accounts/by-email-address/{accountEmailAddress}
associates the user with the account. -
Role Retrieval: A GET request to
/o/headless-admin-user/v1.0/accounts/by-external-reference-code/{accountExternalReferenceCode}/account-roles
retrieves the ID of the "Account Administrator" role. -
Role Assignment: A POST request to
/o/headless-admin-user/v1.0/accounts/by-external-reference-code/{accountExternalReferenceCode}/account-roles/{accountRoleId}/user-accounts/by-email-address/{accountEmailAddress}
assigns the role to the user.
By integrating this client extension with the Distributor Application object, Clarity can automatically create and configure user accounts for approved applicants, eliminating manual steps and ensuring consistency.
Exercise: Adding the Account Setup Action
Clarity has collected valuable information throughout the application process, and they want to leverage that data to streamline the creation of business accounts for approved distributors. Here you’ll add an object action that uses the account setup client extension.
-
Open the Global Menu (
), go to the Control Panel tab, and click Objects. -
Go to the Distributor Management folder and begin editing the Distributor Application object.
-
Go to the Actions tab and click Add (
). -
Enter these values in the Basic Info tab:
Field Value Action Label Set Up Account
Action Name setUpAccount
Description Create a business account for an approved application.
Active Yes -
Go to the Action Builder tab and set these values:
Field Value Trigger Standalone Action object-action-executor[function#liferay-clarity-etc-spring-boot-object-action-account] Description Failed to set up the business account.
-
Click Save.
Once saved, Liferay adds the action as an option in the object’s overview page. This way so you can trigger it manually in the Liferay UI.
Liferay also generates two headless APIs for triggering the standalone action programmatically.
Furthermore, when you use fragments to embed the Distributor Application object in site pages, you can map this action to a button fragment. You’ll learn more about this option in the next module.
With the action defined, you can now assign action permissions to the appropriate user roles. This ensures that only authorized individuals can create business accounts for distributor applications.
Exercise: Assigning the Account Setup Permission
When you define standalone actions, Liferay generates permissions for managing which roles can execute it. Here you’ll assign the account setup permission to the Business Development Manager role.
-
Open the Global
Menu ( ), go to the Control Panel tab, and click Roles. -
Being editing the Business Development Manager role.
-
Go to the Define Permissions tab.
-
In the left menu, go to Applications Menu → Content → Distributor Applications.Enter “Distributor Applications” into the search bar to quickly locate this section.
-
Add this permission:
Section Permissions Resource Permissions Distributor Application > action.setUpAccount -
Click Save.
With this permissions defined, now all business development managers can trigger the account setup action for approved applications.
Exercise: Triggering the Account Setup Action
Here you’ll trigger the account setup for an approved distributor application.
-
Go to the Distributor Applications page.
-
Click Actions (
) for an entry and select Set Up Account. -
Open the Accounts application and verify the account was created.
-
Go to the Users tab and verify the applicant was associated with the account and assigned the Account Administrator role.
Conclusion
Congratulations! You’ve successfully added the business logic necessary for the Distributor Application object. Next, you’ll review what you’ve learned before moving on to the next module.
Capabilities
Product
Education
Contact Us