Importing data
WebCmsModule provides infrastructure for easy importing of data using YAML files. The data import services are also the ones used for the default data of WebCmsModule. See the default data section for the YAML version of the default types and assets.
WebCmsDataImportService
The WebCmsDataImportService
allows importing data from Map
structures.
The Map
based data could for example be sourced from YAML, JSON or XML files.
When converting to the domain model, the WebCmsDataImportService
will dispatch to WebCmsDataImporter
beans for handling data items.
The WebCmsDataConversionService
is used to convert from raw values (for example String
) to the actual data type (for example WebCmsPage
).
Yaml yaml = new Yaml();
Map<String, Object> data = (Map<String, Object>) yaml.load( inputStream );
dataImportService.importData( data );
Using an installer
The AbstractWebCmsDataInstaller
is a base class for an installer that imports one or more YAML files using the WebCmsDataImportService
.
The files specified will be imported in registration order.
@Installer(description = "Install some test data", phase = InstallerPhase.AfterContextBootstrap, version = 1)
@RequiredArgsConstructor
public class TestDataInstaller extends AbstractWebCmsDataInstaller
{
@Override
protected void registerResources( List<String> locations ) {
locations.add( "classpath:installers/test-data/my-types.yml" );
locations.add( "classpath:installers/test-data/my-assets.yml" );
}
}