Martini Data Files Flat File Editor
The Flat File Editor in Martini consists of three tabs: Design, Preview, and Source.
Design Tab
The Design tab is where you define the structure of the flat file.
The fields visible in the editor depend on the type of descriptor configured to handle the flat file, whether it's character-delimited or fixed-width delimitation.
Common Configuration Fields
The following fields are present in both character-delimited and fixed-width flat file services:
-
Type: The type of the descriptor.
-
Input First Data Row: Specifies the row number where reading of data should start. Useful if the data contains header rows with column names that need to be skipped.
-
Encoding: The text-encoding method used in the flat file.
-
Output Header Type: Determines the presence of headers in the data when writing it.
Option | Description |
---|---|
Column Names | Acknowledge the first row of entries as property names |
Data | No headers; data is displayed immediately in the first row |
Character-delimited
The following fields are specific to character-delimited flat file services only:
-
Column Delimiter: The character used to separate fields in an entry.
-
Text Delimiter: The character used to quote text, defaults to double quotes (
"
). -
Escape Character: The character used to escape special characters.
-
Comment Maker: The character used to mark data as a comment.
-
Record Separator: The character(s) used to separate records.
-
Null String: The string used for
null
values. -
Quote Mode: Indicates how values are quoted in the flat file.
Option | Description |
---|---|
All |
Quote all columns. |
Minimal |
Quote only fields containing special characters. |
Non-Numeric |
Quote only non-numeric fields. |
None |
Do not quote; delimiter within a field must be preceded by the escape character. |
-
Allow Missing Column Names: Specifies whether missing column names are allowed when parsing the header.
-
Ignore Empty Lines: Specifies whether to ignore empty lines.
-
Ignore Surrounding Spaces: Specifies whether leading or trailing spaces around values are ignored.
-
Property: Used to design the model representing the flat-file data.
Fixed width
The following fields are specific to fixed-width flat file services only:
-
Record Separator: The character(s) used to separate records.
-
Padding Character: The character used to pad fields in a record.
-
Left Justified: Specifies whether the columns are left-justified.
-
Property: Used to design the model representing the flat-file data.
Spreadsheet (Excel)
The following fields are specific to spreadsheet (Excel) flat file services only:
- Sheet Number: The sheet in the spreadsheet to process data from. Set to 0 to process all sheets.
Preview Tab
The Preview tab allows you to test the flat file service with sample data. It parses the data and displays the results in a table.
Source Tab
The Source tab displays the source code of the flat file service, written in JSON format.
Flat File Services
Flat file services define the structure of a particular flat file, whether it's delimited, has fixed-width columns, or is an Excel spreadsheet. These services are used to determine how data should be parsed (read) from or serialized (written) to the file.
Once a flat file service is configured and saved, Martini generates a data model and a service. The model contains the properties specified in the service, while the service can be used to access your data for processing by Martini. The generated service returns a model array, which is then used to read or write the flat file data.
Creating a Flat File Service
To create a flat file service:
-
Right-click anywhere under a package's
code
folder and select New > Flat File Service. The folder you right-clicked on will be the default location for your new flat file service. -
In the wizard that appears, fill in the following fields:
- Location: Where the flat file service will be stored. By default, this is populated with the location you right-clicked on.
- Name: The name of the descriptor.
- Type: Specifies how fields in the flat file are identified. Choose from Delimited, Fixed Width, or Spreadsheet (Excel).
-
If the chosen type is Excel and you have a file to generate the flat file service from, click Next. Otherwise, click Finish.
-
If you're on the Excel-specific screen in the wizard, choose an Excel file and specify the sheet and first data rows. This will use the spreadsheet to create the flat file service.
Using a Flat File Service in a Service
To integrate a flat file service into your service:
-
Add the generated flat file service to your service.
-
Once added, configure the necessary arguments:
flatFileData
: Represents the flat file to read from or write to. It can be aFile
,InputStream
,OutputStream
,Reader
, orWriter
.type
: Indicates whether to read or write data. Set toInput
for reading orOutput
for writing.
The output of the generated service is a cursor. If reading, the cursor contains the entries in the flat file. If writing, the cursor receives the entries to write to the file. In both scenarios, you need to iterate over the cursor.
-
To read each entry, create an iteration process and set the cursor as the input data.
-
To write entries, create an iteration process where the input data holds the items to serialize, and the output data is set to the cursor.