Skip to Main Content

Java User Groups

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Java - if records are invalid records, write to a excel file

4281104Jul 2 2020 — edited Sep 17 2020

My code validates if the file has valid records or invalid records**(see invalidApplicantTypeRecords)** if the records are invalid, I need to write it to a file. how do I do that in this code

public class EdcCebaProcessor {

  
public void startProcessing()
  
{
  
List<String> fileNames = inputFileHandler.fetchInputFileNames();
  
for (String fileName : fileNames) {
  
OutputRecords outputRecords = generateOutputRecords(fileName);
  
List<EDCOutputRecord> listOfEdcOutputRecords = outputRecords.getValidOutputRecords();
  
List<EDCOutputRecord> listOfInvalidApplicantTypeRecords = outputRecords.getInvalidApplicantTypeRecord();
  outputFileWriter
.writeIntoFile(listOfEdcOutputRecords);
  inputFileHandler
.moveInputFileToProcessedDirectory(fileName);
  
}
  
}
  
private OutputRecords generateOutputRecords(
  
String fileLocation)
  
{
  
ArrayList<CSVRecord> csvRecords;
  
List<EDCOutputRecord> outputRecords = new ArrayList<>();
  
List<EDCOutputRecord> invalidApplicantTypeRecords = new ArrayList<>();
  
try {
  
EDCOutputRecord outputRecord = null;
  csvRecords
= (ArrayList<CSVRecord>) this.csvRecordsParser.getCSVRecordsFromFile(fileLocation);
  
for (CSVRecord record : csvRecords) {
  
try {
  edcRecordValidator
.validateRecord(record);
  outputRecord
= edcOutputRecordCreator.buildValidRecord(new EDCInputRecord(record));
  
} catch (FieldValidationException e) {
  
if (e.getFailedValidationField().equals(EDCRecordField.APPLICANT_TYPE)) {
  log
.error("Invalid Applicant Type for the record number: " + record.getRecordNumber());
  outputRecord
= edcOutputRecordCreator.buildInvalidBNFormatRecord(new EDCInputRecord(record));
  
// Object to keep track of the Invalid Applicant Type Values.
  invalidApplicantTypeRecords
  
.add(edcOutputRecordCreator.buildInvalidBNFormatRecord(new EDCInputRecord(record)));
  
}
  
}
  outputRecords
.add(outputRecord);
  
}
  
}
  
return new OutputRecords(outputRecords, invalidApplicantTypeRecords);
  
}
}

Comments

Processing

Post Details

Added on Jul 2 2020
1 comment
266 views