Mastering Data Modeling with Liferay Objects

Course Overview

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. Note that batch APIs do not currently support exporting nested fields. Therefore, you must handle fields like attachments and many-to-many relationships separately using standard GET methods.

  • 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.

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 app:

  • Tickets have a One-to-Many relationship with Ticket Attachments.

  • Tickets have a Many-to-Many relationship with Components.

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 as a nested field.

  • Import both 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. Document and Media).

  • Nested Fields Limitations: Export batch APIs do not support nested fields for many-to-many relationships or attachments. In these cases, use standard GET methods to retrieve the necessary 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.

  • Using Batch APIs and Client Extensions

  • Handling Related Objects

  • Handling Attachments

  • Important Considerations

  • Best Practices for Object Entries Migration

  • Conclusion

Loading Knowledge

Capabilities

Product

Education

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy