Custom Pre-Processing and Post-Processing Blocks
Each processing block class must implement the processFile method. This method is called when there is an import or export file to be processed:
String processFile (String directoryName, String fileName, HashMap args, HashMap inactiveRecords, TreeMap primaryKey, and StringBuffer msgs)
Argument |
Data Type |
Description |
---|---|---|
directoryName |
String |
Fully-qualified path to the directory containing the file to be processed. The file to be returned must also be placed in this same directory. |
fileName |
String |
Name of the file to be processed. |
args |
HashMap |
Map of any pre/post processing arguments defined in the Scheduled Import/Export. |
inactiveRecords |
HashMap |
Map containing the primary keys of any records in the repository having a Status of Inactive. This is only set for imports and only if the Inactive Records flag is set to Reactivate. |
primaryKey |
TreeMap |
The primary key for the repository. |
msgs |
StringBuffer |
Medium for returning error messages to be displayed with the job. |
The method must return either the name of the processed file or null if the processing block failed.
If the processing block class has configurable arguments, there are three methods that must be implemented:
-
String getDescription()
– returns a detailed description of what the processing block does. -
void defineArguments()
– builds the list of arguments that can be configured. Each argument is defined by calling the method:-
void addArgument(String arg, String description)
– adds an argument to the list of arguments/properties that can be set for the class in the Scheduled Import or Scheduled Export record:
-
Argument |
Data Type |
Description |
---|---|---|
arg |
String |
Name of the argument. This name will be used to retrieve the actual value for the argument. Each defined argument must be uniquely named. |
description |
String |
Detailed description for the argument. It should include possible values (if it is a finite set of values) or the range of values, the default if it is left blank, and other information necessary for understanding how to use the argument. |
The BaseCustomProcessFile
class has a set of methods that
help minimize the amount of coding required in a processing block class:
-
void clearBadDate(HashMap parsedLine, String column)
This clears the date value if it is not 10 characters (in mm/dd/yyyy format) or is an invalid date (e.g., 00/00/0000).
-
void closeInput(BufferedReader br)
This closes the opened CSV or TXT file.
-
void closeOutput(PrintWriter output)
This closes the opened CSV or TXT file.
-
void convertToBoolean(HashMap parsedLine, String column)
This converts the values "Y" or "Yes" to 1 and everything else to 0 for the designated column.
-
boolean doesFileExist(String directoryName, String fileName)
This returns true if the specified file in the specified directory exists.
-
void dropLeadingZeros(HashMap parsedLine, String column)
This removes leading zeros from each value containing them.
-
ArrayList extractFiles(String directoryName, String fileName, String fileEncoding, StringBuffer msgs)
This extracts the contents of a zip file and returns a list of unzipped files.
-
void freeQuery(DBQuery dbQuery)
This frees the query connection that was previously obtained with getQuery()
-
String[] getHeaderForImportTemplate(String importTemplateName)
This returns a list of columns based on the mappings in the designated import template.
-
String getHeaderForImportTemplateAsCsvString(String importTemplateName, String delimiter)
This returns a delimited list of columns based on the mappings in the designated import template.
-
String getJobNumber()
This retrieves the identification number of the job being processed.
-
HashMap<String, String> getMapForHeader(String[] header)
This returns a map of columns based on the list of columns for the header.
-
DBQuery getQuery()
This retrieves a query connection that can subsequently be used to query the EPIM database.
-
PrintWriter getReport()
This retrieves the PrintWriter object that is configured to generate the report for the job. Any calls on this object will update that report.
-
void insertDecimal(HashMap parsedLine, String column, int decimalPosition)
This inserts a decimal point character in a value at the designated number of digits from the right.
-
void logDebug(String message)
This generates a message in the log file if debug logging is enabled (debugEnabled=true) in the Enterworks.properties file
-
void logReport(String message)
This adds a line to the import or export report file.
-
void logError(String message)
This adds a line to the EPX BIC log file.
-
void logError(StringBuffer msgs, String message)
This adds a line to the EPX BIC log file and to the Errors attribute for the Scheduled Import Job or Scheduled Export Job record.
-
BufferedReader newInput(String directoryName, String fileName, String charSet)
This opens a CSV or TXT file for reading.
-
PrintWriter newOutput(String directoryName, String fileName, String encoding)
Opens a CSV or TXT file for writing.
-
void outputHeaderLine(PrintWriter output, String[] columns, String delimiter)
This outputs the header line with each column separated using the specified delimiter.
-
void outputHeaderLine(PrintWriter output, String[] columns, char delimiter, char textQualifier)
This outputs the header line with each column separated using the specified delimiter and text qualifier (for when column names include the delimiter or text qualifier character).
-
void outputParsedLine(PrintWriter output, HashMap parsedLine, String[] columns, char delimiter, char textQualifier)
This outputs a line using the parsed values and the designated delimiter and text qualifier.
-
void outputParsedLine(PrintWriter output, HashMap parsedLine, String[] columns, String delimiter)
This outputs a line using the parsed values and the designated delimiter.
-
String[] parseHeader(String headerLine, String delimiter)
This parses the header line using the designated delimiter. If the delimiter is a comma, then special processing is done for commas and quotes embedded in the header names.
-
String[] parseHeader(String headerLine, char delimiter, char textQualifier)
This parses the header line using the designated delimiter. Uses the designated textQualifier to handle values that contain the delimiter or the text qualifier. Assumes the embedded text qualifier is escaped with the same character. For example, if the delimiter is a comma and the text qualifier is a double quote, then the value: ,"3"" x 4"", Rough Cut" would be stored as: 3" x 4", Rough Cut.
-
HashMap parseLine(String line, String[] header, String delimiter)
This parses a line from the file using the defined header and delimiter. Returns a HashMap where each key matches a column name and its value is the corresponding value from the file.
-
HashMap parseLine(String line, String[] header, String delimiter, boolean trimWhiteSpace)
This parses a line from the file using the defined header and delimiter. Returns a HashMap where each key matches a column name and its value is the corresponding value from the file. Trims white space from values if trimWhiteSpace is true.
-
HashMap parseMultiLine(BufferedReader br, String[] header, String delimiter)
This parses a multi-line (where one or more values contains linefeed/carriage return characters and is properly quoted using the header for the map returned. Returns null if end of file or empty line is encountered.
-
HashMap parseMultiLine(BufferedReader br, String[] header, char delimiter, char textQualifier)
This parses a multi-line (where one or more values contains linefeed/carriage return characters and is properly escaped with the designated textQualifier using the header for the map returned. Returns null if end of file or empty line is encountered.
-
void reactivateRecord(HashMap parsedLine, HashMap inactiveRecords, TreeMap primaryKey, String reactivateColumnName)
This reactivates a record that was previously inactivated but is now in the import file.
-
void removeCharacter(HashMap parsedLine, String character)
This removes the designated character from each parsed value.
-
void removeSpaces(HashMap parsedLine)
Removes leading and trailing white space from each parsed value.
-
String[] simpleParseHeader(String headerLine, String delimiter)
This parses the header line using the designated delimiter. Delimiter is passed to the String.split() method.
-
void updateExport(HashMap update)
This updates the specified attributes in the export job with the specified values.
-
void updateExportStatus(String recordsProcessed, String recordsWithErrors, String status, String exportErrors)
This updates the Scheduled Export Job record with the specified details. This call should be made if the post-processing is going to take a considerable amount of time to complete. The call should be made no more than once every several minutes.
-
void updateExportStatus(String recordsProcessed, String recordsWithErrors, String status, String downloadLink, String exportErrors)
This updates the Scheduled Export Job record with the specified details, including a URL for downloading the processed file. This call should be made after processing of the file has completed.
-
void updateImportJob(HashMap update)
This updates the specified attributes in the import job record with the specified values.
-
void updateImportStatus(String recordsProcessed, String recordsUpdated, String recordsCreated, String recordsDeleted, String recordsWithErrors, String status, String importErrors)
This updates the Scheduled Import Job record with the specified details. This call should be made if the pre-processing is going to take a considerable amount of time to complete. The call should be made no more than once every several minutes.