Sample for integrating drafts & submissions component with database

Sample overview

AEM Forms portal drafts and submissions component allows users to save their forms as drafts and submit later from any device. Also, users can view their submitted forms on portal. To enable this functionality, AEM Forms provides data and metadata services to store the data filled in by a user in the form and the form metadata associated with drafts and submitted forms. This data is stored in the CRX repository, by default. However, as users interact with forms through AEM publish instance, which is generally outside the enterprise firewall, organizations may want to customize data storage for it to be more secure and reliable.

The sample, discussed in this document, is a reference implementation of customized data and metadata services to integrate drafts and submissions component with a database. The database used in the sample implementation is
MySQL 5.6.24
. However, you can integrate the drafts and submissions component with any database of your choice.

The examples and configurations explained in this document are according to MySQL 5.6.24 and you must substitute them appropriately for your database system.

Ensure that you have installed latest version of AEM Forms add-on package. For the list of available packages, see the
AEM Forms releases
article.

The sample package works only with Adaptive Forms submit actions.

Set up and configure the sample

Perform the following steps, on all the author and publish instances, to install and configure the sample :

Download the following
aem-fp-db-integration-sample-pkg-6.1.2.zip
package to your file system.

For Apache Sling connection, find and click to open
Apache Sling Connection Pooled DataSource
in edit mode in the Web Console Configuration. Specify the values for properties as described in the following table:

Property

Value

Datasource name

A datasource name for filtering drivers from the data source pool

Note:
The sample implementation uses FormsPortal as the datasource name.

The sample implementation is now configured, which you can use to list your drafts and submissions while storing all data and metadata in a database. Let’s now see how data and metadata services are configured in the sample.

Install mysql-connector-java-5.1.39-bin.jar file

Perform the following steps,on all the author and publish instances, to install the mysql-connector-java-5.1.39-bin.jar file:

Navigate to
https://[server]:[port]/system/console/depfinder
and search for com.mysql.jdbc package.

In the Exported by column, check if the package is exported by any bundle.

(
Windows only
) Turn off the system firewall for your operating system.

Sample code for forms portal data and metadata service

The following zip contains
FormsPortalSampleDataServiceImpl
and
FormsPortalSampleMetadataServiceImpl
(implementation classes) for data and metadata service interfaces. Additionally, it contains all the classes required for compilation of above mentioned implementation classes.

Verify length of the file name

Database implementation of Forms Portal uses additional metadata table. The table has a composite primary key based on Key and id columns of the table. MySQL allows primary keys up to the length of 255 characters. You can use the following client-side validation script to verify the length of filename attached to the file widget. The validation is run when a file is attached. The script provided in the following procedure displays a message, when the filename is larger than 150 (including extension). You can modify the script to check it for a different number of characters.

The script is for out of the box (OOTB) attachment widget component. If you have customized the OOTB attachment widget then change the above script to incorporate respective changes.

Add the following property to the folder created in step 2 and click
Save All
.

Name:
categories

Type:
String

Value:
fp.validation

multi option:
Enabled

Navigate to
/libs/fd/af/runtime/clientlibs/guideRuntime
and append the
fp.validation
value to the
embed
property.

Navigate to /libs/fd/af/runtime/clientlibs/guideRuntimeWithXFA and append the
fp.validation
value to
embed
property.

If you are using custom client libraries instead of of the guideRuntime and guideRuntimeWithXfa client libraries, use the category name to embed the client library created in this procedure to your custom libraries loaded at runtime.

Click
Save All.
Now, when the filename is larger than 150 (including extension) characters a message is displayed.