Loading Audio...
Exporting and Importing Object Entries
In some cases, migrating object entries between environments is essential for maintaining data consistency across development, testing, and production. While Liferay doesn't currently offer a dedicated UI for importing and exporting object entries, you can leverage Liferay’s batch APIs and client extensions to handle these operations programmatically. This approach provides flexibility but requires careful planning, especially for objects with complex relationships or attachments.
Using Batch APIs and Client Extensions
Liferay’s batch APIs and batch engine enable programmatic export and import of object entries, ensuring data integrity and consistency across environments. Also, using batch client extensions can further automate and streamline migration processes.
- Exporting Object Entries: Use batch APIs to export entries as JSON files. Batch export APIs support the
batchNestedFields
parameter for exporting permissions. Although this parameter may work for exporting other nested fields (like relationships) in some versions, this behavior is not officially supported. To reliably export complex relationship data or Documents and Media attachment references, use separateGET
requests instead. - Importing Object Entries: Use batch APIs to upload JSON files to the target environment. For fields like attachments, leverage nested fields in batch import to handle related data seamlessly.
Handling Related Objects
When importing objects with relationships (e.g., One-to-Many or Many-to-Many), you can choose to import them either together (using nested fields) or individually (object by object). The best approach depends on the logical grouping of the objects and their relationship to each other. For example, consider Clarity’s ticketing solution:
- Tickets have a One-to-Many relationship with Ticket Attachments.
- Tickets have a Many-to-Many relationship with Components.
Importing Related Objects Together
For objects that belong to a unified logic entity (e.g., Tickets and Ticket Attachments), import them together using nested fields:
- Export Tickets with Ticket Attachments using nested fields. Because
batchNestedFields
does not reliably export relationships, you may need to export parent and child data separately and then combine them. - Import the combined payload (i.e., Tickets and their attachments) in a single operation.
Importing Objects Individually
For objects that exist independently (e.g., Components), import them separately. This allows greater flexibility and ensures independent management of the objects:
- Import Components using a batch import.
- Import Tickets, using nested fields to associate Tickets with Components via external reference codes (ERCs).
This method ensures flexibility in managing objects that are logically independent while maintaining consistency in relationships.
Handling Attachments
In Liferay, you can store object entry attachments in the object's private asset folder or link to a media file in the Documents and Media library.
- Private Store: If attachment fields use the private store, you can use nested fields with
field.fileBase64
to export/import attachments in the same payload as their parent objects. - Documents and Media: If attachment fields link to Documents and Media files, it’s generally best to export/import files individually and update field references using the document’s ERC. This method is preferred because documents stored in the Documents and Media library often have broader usage and might be referenced by multiple objects or entities.
Important Considerations
When migrating object entries, keep these points in mind to ensure a smooth and successful process:
- External Reference Codes (ERCs): Always use ERCs to maintain relationships, as IDs differ across environments.
- Attachments: Choose your migration strategy based on the attachment's storage type (private vs. Documents and Media).
- Nested Fields Limitations: The
batchNestedFields
parameter in the export batch APIs only supports permissions. Many-to-many relationships and attachments are not officially supported. If you attempt to export these usingbatchNestedFields
, test thoroughly. For reliable results, use separate GET requests to retrieve related data. - Logical Data Grouping: Import entries for closely related objects together (e.g., Tickets and Ticket Attachments). In contrast, import entries for independent objects individually (e.g., Components).
Best Practices for Object Entries Migration
To ensure smooth and efficient migration of object entries, consider these best practices:
- Group Related Data: Use nested fields for closely related entries, like tickets and their attachments.
- Handle Independent Objects Separately: Import independent object entries individually and then link them during subsequent imports using consistent ERCs.
- Validate Data Before Import: Ensure JSON payloads match the target environment’s schema before importing.
- Automate with Client Extensions: Create client extensions for repetitive tasks, like mapping ERCs or importing attachments.
Conclusion
Migrating object entries is crucial for managing Liferay applications. By understanding how to use batch APIs and client extensions for this process, you can ensure data consistency and application integrity across environments. Next, you’ll review what you’ve learned before moving on to the next module.
Capabilities
Product
Education
Contact Us