Liferay DXP’s Staging and Export/Import features are the building blocks for creating, managing, and publishing a site. These features can be accessed in your Portal’s Publishing Tools menu. You can also, however, start these processes programatically. This lets you provide new interfaces or mimic the functionality of these features in your own application.
Providing the ability to stage your application’s assets makes using your application much more site administrator-friendly. Your new assets no longer have to be saved somewhere off-site until they’re ready to be published. You can publish them to a staging environment, test their usability, and save them to a page. Once the time is right for publishing, you can publish your application’s assets to the live site with one mouse click. The export/import feature offers similar conveniences: if you want to export your application’s assets to use in another place or you need to clear its data but save a copy you can implement the export feature. Implementing the import feature lets you bring your assets/data back into your application.
To initiate a export/import or staging process, you must pass in an
ExportImportConfiguration
object. This object encapsulates many parameters and
settings that are required while the export/import is running. Having one single
object with all your necessary data makes executing these frameworks quick and
easy.
When you want to implement, for example, export, you must call services offered
by the ExportImportService
interface. All the methods in this interface
require an ExportImportConfiguration
object. Liferay DXP provides a way to
generate these configuration objects, so you can easily pass them in your
service methods.
It’s also important to know that ExportImportConfiguration
is a Portal
entity, similar to User
or Group
. This means that the
ExportImportConfiguration
framework offers local and remote services, models,
persistence classes, and more.
In this tutorial, you’ll learn about the ExportImportConfiguration
framework
and how you can take advantage of provided services and factories to create
these controller obects. Once they’re created, you can easily impment whatever
import/export functionality you need.
Your first step is to create an ExportImportConfiguration
object and use it to
initiate your custom export/import or staging process.
-
Use the Export Import Configuration factory classes to build your
ExportImportConfiguration
object. Below is a common way to do it:Map<String, Serializable> exportLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory. buildExportLayoutSettingsMap(...); ExportImportConfiguration exportImportConfiguration = exportImportConfigurationLocalService. addDraftExportImportConfiguration( user.getUserId(), ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT, exportLayoutSettingsMap);
This example uses the ExportImportConfigurationSettingsMapFactory to create a layout export settings map. Then this map is used as a parameter to create an
ExportImportConfiguration
by calling an add method in the entity’s local service interface. The ExportImportConfigurationLocalService provides several useful methods to create and modify your customExportImportConfiguration
.The
ExportImportConfigurationSettingsMapFactory
provides manybuild
methods to create settings maps for various scenarios, like importing, exporting, and publishing layouts and portlets. For examples of this particular scenario, you can reference UserGroupLocalServiceImpl.exportLayouts(…) and GroupLocalServiceImpl.addDefaultGuestPublicLayoutsByLAR(…).There are two other important factories provided by this framework that are useful during the creation of
ExportImportConfiguration
objects:- ExportImportConfigurationFactory:
This factory is used to build
ExportImportConfiguration
objects used for default local/remote publishing. - ExportImportConfigurationParameterMapFactory: This factory is used to build parameter maps, which are required during export/import and publishing.
- ExportImportConfigurationFactory:
This factory is used to build
-
Call the appropriate service to initiate the export/import or staging process. There are two important service interfaces that you can use in the cases of exporting, importing, and staging: ExportImportLocalService and StagingLocalService. In the previous step’s example code snippet, you created an
ExportImportConfiguration
object intended for exporting layouts. Here’s how to initiate that process:files[0] = exportImportLocalService.exportLayoutsAsFile( exportImportConfiguration);
By calling this interface’s method, you’re exporting layouts from Portal into a
java.io.File
array. Notice that yourExportImportConfiguration
object is the only needed parameter in the method. Your configuration object holds all the required parameters and settings necessary to export your layouts from Portal. Although this example code resides in Liferay DXP, you could easily use this framework from your own plugin or module.
It’s that easy! To start your own export/import or staging process, you must
create an ExportImportConfiguration
object using a combination of the three
provided ExportImportConfiguration
factories. Once you have your configuration
object, provide it as a parameter in one of the many service methods available to
you by the Export/Import or Staging interfaces to begin your desired process.