You might often want to provision a Nuxeo server with an existing set of data. For instance, you might want the same set of data between several environments or maybe you just want to import the data set while setting up your server. Today, I will explain how we can build a data set for import using our plugin nuxeo-showcase-content-importer, just like we handle it in Nuxeo Showcase Content containing a bunch of basic Nuxeo Documents or in Nuxeo Getting Started.
Create your Data
The first thing we have to do is import data in a running Nuxeo server. To do that, you can use the
import button in the JSF UI, or the
+ button in Web UI. If you need something more, in case you have a lot of documents, the REST API or any other importers should do the trick but it will require a little more work.
Optimize your Export
Now, your Nuxeo server contains all the documents/files you imported in the previous step. It has a lot of documents and you would like to export them. But before you use our
export zip, I would like to warn you that the
showcase-content-importer re-triggers all the generated stuff, which will prevent you from exporting a huge zip containing all picture views, video encodings, etc.
So, let's remove all those generated documents before exporting and ensure that all trashed documents have been cleared because we do not want them to be a part of the export. The easiest way to reduce useless documents is to stop your server, then execute the following SQL query in your database.
delete from hierarchy where primarytype = 'view' or primarytype = 'storyboarditem' or primarytype = 'transcodedVideoItem';
Bundle the Data
Now that we have exported our
zip file without any useless technical document, we are going to package the zip in a Nuxeo Package to deploy it everywhere.
Prepare the Package
To prepare the package, we will use the Nuxeo Generator. It helps bootstrapping an empty Nuxeo Package in one command.
$ yo nuxeo --type="ressources" single-module package create Generating Multi module (Your project parent POM) info Parameters: Use a parent artifact, Parent group, Parent artifact, Parent version, Import nuxeo in the `dependency management`, Nuxeo version, Project group, Project artifact, Project version, Project description ? Use a parent artifact (for instance your company's BOM or the org.nuxeo.ecm.distribution:nuxeo-distribution POM)? Yes ? Parent Group id: org.nuxeo.ecm.distribution ? Parent Artifact id: nuxeo-distribution ? Parent Version: 8.10 ? Project Group id: org.nuxeo.provisioning ? Project Artifact id: easy-provisioning-parent ? Project Version: 1.0-SNAPSHOT ? Project Description: create Generate Module: easy-provisioning-ressources create Generating Single module info Parameters: Nuxeo version, Project group, Project artifact, Project version, Project description ? Project Group id: org.nuxeo.provisioning ? Project Artifact id: easy-provisioning-ressources ? Project version: 1.0-SNAPSHOT ? Project description: create Generate Module: easy-provisioning-package create Generating Package info Parameters: Package artifact, Package version, Package name, Company name ? Package Artifact id: easy-provisioning-package ? Package Version: 1.0-SNAPSHOT ? Package name: easy-provisioning ? Company name:
Your folder should look like:
$ tree -d . ├── easy-provisioning-package │ └── src │ └── main │ ├── assemble │ └── resources │ └── install │ └── templates │ └── easy-provisioning └── easy-provisioning-ressources └── src ├── main │ ├── java │ │ └── org │ │ └── nuxeo │ │ └── provisioning │ └── resources │ ├── META-INF │ └── OSGI-INF └── test ├── java │ └── org │ └── nuxeo │ └── provisioning └── resources
Add Dependency to the nuxeo-showcase-content-importer plugin
Our Nuxeo Package is ready to be deployed but we have to depend on
nuxeo-showcase-content-importer to let it import your exported zip.
We have to ensure that the
assembly.xml file will copy the expected bundles during the build process. To do that, simply add a direct dependency to
org.nuxeo.ecm.platform:nuxeo-showcase-content-importer in the
<dependencies> <!-- Additional bundles to be deployed by the MP --> .. <dependency> <groupId>org.nuxeo.ecm.platform</groupId> <artifactId>nuxeo-showcase-content-importer</artifactId> </dependency> </dependencies>
Add the Exported File
We just finished preparing a Nuxeo Package using the generator. It contains everything we need except our exported
zip file. Copy it to the
easy-provisioning-ressources/src/main/resources folder named
easy-provisioning.zip. Add a contribution to declare it (
"1.0" encoding="UTF-8" xml version=<component name="org.nuxeo.provisioning"> <extension target="org.nuxeo.ecm.showcase.content" point="contents"> <content name="easy-provisioning"> <!-- Use the name of your zip file --> <filename>easy-provisioning.zip</filename> </content> </extension> </component>
Next, add this contribution to
Deploy your Package
Now you just have to build your package and install it:
mvn install cd $NUXEO_HOME ./bin/nuxeoctl mp-install easy-provisioning-package/target/easy-provisioning-package-1.0-SNAPSHOT.zip
That’s all. Your content is imported only once, and all converters are going to work hard to recreate all picture views, videos storyboards and encoded videos!