cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Aggregation using rule based file parser

Aggregation using rule based file parser

 

Overview

The RuleBasedFileParser is an open-ended Application type that is used to parse non-delimited files, for example mainframe report files. The transformation logic is contained in the FileParsingRule, which is executed once for every record in the file.

 

FileParsingRule

  • The rule receives a BufferedReader (reader) which is used to read in lines from the file
  • It returns a map of names/values from the connected resource, which is used to populate accounts/groups
  • The map will return once for every record, as defined by the logic in the rule. This can be a line or multiple lines
  • The map values must match the attributes of the group and/or account schema
<Source>

       import java.io.BufferedInputStream;

       import java.io.BufferedReader;

       import java.io.BufferedWriter;

       import java.io.File;

       import java.io.FileInputStream;

       import java.io.FileReader;

       import java.io.FileWriter;

       import java.io.IOException;     

       import java.util.*;

     

       HashMap map = new HashMap();     

       String record;     

       // Read a record from file; split that string by spaces

       // parse those records into a map to extract data

       if ( ( record = reader.readLine() ) != null) {

           while (!record.trim().startsWith("$")) {

                record = reader.readLine();

           }

           if(record != null) {  

                    //Tokenize the line by any number of spaces

                    String[] tokens = record.trim().split("\\s+");

                    ArrayList list = new ArrayList(Arrays.asList(tokens));

                 map.put("User ID", list.get(0));

                 map.put("Date Loaded", list.get(1));

                 map.put("Date Referenced", list.get(2));

                 map.put("Days Unused", list.get(3));

                 map.put("Item Class", list.get(4));

                 map.put("Item Name", list.get(5));

           }

        }

     return map;

  </Source>

 

The above rule would parse the following file based on the attributes above:

 

  NEC Entries Referenced within 400 days     Page 0001

 

               Date        Date           Days    Item Item
  User ID Loaded  Referenced Unused Class Name

-------- ------  ---------- ------ -------- --------------------------------------------

$1234567 04.030 2.226 016   PROFILE  XXXXX
$1234567 04.030 2.226 140   USERLIST R47236
$1234567 04.030 2.226 216   DATASET  XXX.XX.
$1234567 04.030 2.226 316   DATASET  XXXX

 

$9876543 04.030 1.072 001   PROFILE  XXXXX
$9876543 04.030 1.072 001   USERLIST R76HGFD
$9876543 04.030 1.072 024   DATASET  XX.XX.
$9876543 04.030 1.072 001   DATASET  XXXXX.XX.XX

 

$9876654 06.037 3.075 002   PROFILE  TEST
$9876654 06.037 3.075 032   USERLIST RSFAS6
$9876654 06.037 4.329 113   DATASET  XXX.
$9876654 06.037 8.075 006   DATASET  XXXX.TEST.

 

$4567654 06.037 15.077 000   PROFILE  TEST
$4567654 06.037 15.077 000   USERLIST 654DG6
$4567654 06.037 15.075 008   DATASET  XXX
$4567654 06.037 15.075 008   DATASET  XXX.TEST
$4567654 06.037 14.332 140   DATASET  XXX.TEST.
$4567654 06.037 15.077 000   DATASET  XXX.TEST.
$4567654 06.037 15.040 087   DATASET  XXX.TEST.*.SYSTEM
$4567654 06.037 14.267 095   DATASET  XXX.TEST
$4567654 06.037 14.267 435   DATASET  XXX.TEST
$4567654 06.037 15.077 010   DATASET  XXX.TEST.SYSTEM
Version history
Revision #:
3 of 3
Last update:
‎Jun 03, 2023 02:05 AM
Updated by:
 
Contributors