DataOption includeCsvImport

Expanders 3.2.1

As of expander version 3.2.1, the dataElement option includeCsvImport option has been added. Using this option will generate the following artifacts:

  1. A <dataElement>ImporterAction class in the control layer.
  2. A <dataElement>ImporterImpl class in the logic layer.
  3. An importFile-method through the stack
  4. A <dataElement>-io-page html and js file in the view layer.

ImporterAction

  • URL: /<application>/<component>/<dataElement>-upload-json
  • method: POST
  • parameters: file, type, parameters

Since a file needs to be uploaded, the parameters should be passed as form-data

The csv-file needs to be attached in the formData as the file parameter. The type refers to the type of the import. In this case, it should always be ‘csv’.

The parameters parameter should be a map with key-value pairs. These are optional values such as:

  • ‘encoding’: the encoding used for the file (default=’UTF-8’)
  • ‘separator’: the separator character used for the CSV (default=’;’)

Upload page

A dedicated page is generated at the url: /<application>/<component>/<dataElement>/data. Here you can manually upload a file and import it.

To add this page to the menu, you need to add <component>-<dataElement>-io-page as a menuItem to the application menu file. This is only available for teh next gen UI.

Default implementation

The default implementation will use the headers of the csv file to match each field in the details of the dataElement with the data in the csv file. This means you don’t need to specify fields that don’t need to be filled in. However, the name field will be used to identify the instance and should always be present. Furthermore, the default implementation will require you to make names unique between different instances of the same dataElement. A second csv row with the same name will result in an update of the first data with the same name. This update also happens with existing data in your database, so make sure all used names are unique in your file and database.

Fields are mapped using dedicated Mapper-classes.

File layout

The file needs to contain the right headers, and as stated previously, the name field should be present. See ImporterAction for encoding and separator.

Custom Implementation

If you add a className (with packageName if it is in a different package than the default one) to the value of the dataElementOption, this custom class will be used. This custom class will need to implement the IImporter interface. Here you need to implement the importFile method yourself.

Custom import type

It is possible to modify the importFile method in the <dataElement>Bean class to handle more import types.

Version

Release Expander version Change
201803 3.2.1 implemented

References