Importing and Exporting Clarity's Bulk Data
Batch engine APIs provide a high-performance approach to interacting with large data sets. Clarity’s developers want to test importing and exporting with batch APIs to understand how they can interact with their object data and populate dashboards with historic data sets.
In these exercises, you’ll export Clarity’s object entries and import JSON data with batch endpoints.
Exercise: Exporting Clarity’s Existing Tickets
Here, you’ll leverage the export-task endpoint to create a batch export of Clarity’s existing Ticket object entries.
-
Sign in as the Clarity Admin user.
-
Username:
admin@clarityvisionsolutions.com
-
Password:
learn
-
-
Navigate to the API Explorer at http://localhost:8080/o/api.
-
In the upper right, click the REST Applications drop-down menu and select
headless-batch-engine/v1.0
. -
Under the ExportTask section, expand the
postExportTask
endpoint.
-
Enter these parameters and click Execute:
Parameter Value className com.liferay.object.rest.dto.v1_0.ObjectEntry contentType JSON fieldNames description,priority,resolution,subject,suggestions,ticketStatus,type
taskItemDelegateName C_Ticket -
Verify in the Response body that the batch process was submitted:
The current executeStatus should listSTARTED
, confirming submission of the batch engine task. -
Copy the ID value for a future step. In this case:
18
. -
Within the Headless Batch Engine API, expand the
getExportTask
endpoint. -
Paste in the previously copied ID to the
exportTaskId
parameter and click Execute. -
Verify that the batch job now lists COMPLETED for the executeStatus:
Batch jobs can include thousands of data entries, extending the required time to complete tasks. You can use this endpoint to check in on a batch job’s progress while it’s being processed. -
Within the Headless Batch Engine API, expand the
getExportTaskContent
endpoint. -
Enter the same previously copied ID for the
exportTaskId
and click Execute.
-
Verify that the request's status code is 200 and the Response body includes a “Download file” link.
The downloaded file contains a JSON array containing all of Clarity’s existing Ticket entries, including only the filtered fields specified within the batch export job.
Exercise: Importing Clarity’s New Ticket Object Entries
While you can also create import jobs with the Headless Batch Engine API’s import-task
endpoints, Clarity would like to test leveraging the Ticket object’s batch
endpoint to import a historic data set. Here, you’ll create a batch import to populate additional ticket object entries.
-
Navigate to the API Explorer at http://localhost:8080/o/api.
-
In the upper right, click the REST Applications drop-down menu and select
c/tickets
. -
Under the Ticket section, expand the
postTicketBatch
endpoint. -
Replace the placeholder curly brackets in the Request body with two square brackets.
This prepares your payload to include a JSON array. -
In your course workspace, navigate to the
exercises/module-3/historic_ticket_data.json
file and copy its contents. -
In API Explorer, paste the JSON contents between the square brackets and click Execute.
-
Examine the Request body to verify that the import started:
The executeStatus of INITIAL indicates that the batch job has started. -
From the Response body, copy the job’s externalReferenceCode.
-
In the upper right, click the REST Applications drop-down menu and select headless-batch-engine/v1.0.
-
Under the ImportTask section, expand the getImportTaskByExternalReferenceCode endpoint.
-
Paste the copied externalReferenceCode and click Execute.
-
Verify that the Response body lists COMPLETED with 10 total items imported:
While you can also create import jobs with the Headless Batch Engine API’s import-task endpoints, Clarity would like to test leveraging the Ticket object’s batch endpoint to import a historic data set. Here, you’ll create a batch import to populate additional ticket object entries.If theexecuteStatus
showsFAILED
, check theerrorMessage
field to understand what issue was encountered. -
Navigate to the Clarity home page
-
Open the Site Menu (
), click Page Tree, and navigate to the Tickets page.
You should see 10 additional tickets included on Clarity’s dashboard, including historic, closed tickets.
Conclusion
Excellent! You’ve successfully leveraged batch engine APIs to export batch data from Liferay and import a set of object entries. This provides the foundation to migrate large data sets within your Liferay environment using APIs.
Next, you’ll review what you've learned before completing the course.
Capabilities
Product
Education
Contact Us