Skip to content

Commit

Permalink
fix intermittent error showing incorrect success or error records
Browse files Browse the repository at this point in the history
fix intermittent error on Windows showing incorrect success or error records. Remove unused method - transferCSVContent().
  • Loading branch information
ashitsalesforce committed Sep 23, 2024
1 parent 24da09c commit 3a92b74
Showing 1 changed file with 5 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -49,7 +45,6 @@
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeSet;
import java.util.stream.Stream;

import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
Expand Down Expand Up @@ -425,39 +420,6 @@ public void flushRemaining() throws OperationException, DataAccessObjectExceptio
}
}

private long transferCSVContent(String fromFileName, String toFileName) throws OperationException {
RandomAccessFile fromFile, toFile;
long contentRowCount = 0;
try {
fromFile = new RandomAccessFile(fromFileName, "rw");
toFile = new RandomAccessFile(toFileName, "rw");
//first line is the header row
fromFile.readLine();
toFile.readLine();

// go to end of to file
while (toFile.readLine() != null) {
contentRowCount++;
}
String contentRow = null;
while ((contentRow = fromFile.readLine()) != null) {
contentRow += System.lineSeparator();
toFile.write(contentRow.getBytes());
contentRowCount++;
}
toFile.close();

// truncate the fromFile
fromFile.setLength(0);
fromFile.close();
return contentRowCount;
} catch (FileNotFoundException e) {
throw new OperationException(e.getMessage());
} catch (IOException e) {
throw new OperationException(e.getMessage());
}
}

private void getBulkV2LoadJobResults() throws AsyncApiException, OperationException, DataAccessObjectException {
this.getSuccessWriter().close();
this.getErrorWriter().close();
Expand All @@ -470,27 +432,12 @@ private void getBulkV2LoadJobResults() throws AsyncApiException, OperationExcept
// String unprocessedRecordsWriterFile = config.getString(Config.OUTPUT_UNPROCESSED_RECORDS);

this.jobUtil.getBulkV2LoadSuccessResults(successWriterFile);
Charset csvCharset = Charset.forName(config.getCsvEncoding(true));
try (Stream<String> lines = Files.lines(Path.of(successWriterFile), csvCharset)) {
// subtract 1 from number of lines to account for the header row
this.setSuccesses(lines.count()-1);
} catch (IOException e) {
CSVFileReader csvReader = new CSVFileReader(new File(successWriterFile), config, true, false);
this.setSuccesses(csvReader.getTotalRows());
}
CSVFileReader csvReader = new CSVFileReader(new File(successWriterFile), config, true, false);
this.setSuccesses(csvReader.getTotalRows());

this.jobUtil.getBulkV2LoadErrorResults(errorWriterFile);
try (Stream<String> lines = Files.lines(Path.of(errorWriterFile), csvCharset)) {
// subtract 1 from number of lines to account for the header row
this.setErrors(lines.count()-1);
} catch (IOException e) {
CSVFileReader csvReader = new CSVFileReader(new File(errorWriterFile), config, true, false);
this.setErrors(csvReader.getTotalRows());
}

// TODO for unprocessed records
// this.jobUtil.getBulkV2LoadUnprocessedRecords(tmpFileName);
// transferCSVContent(tmpFileName, unprocessedRecordsWriterFile);
csvReader = new CSVFileReader(new File(errorWriterFile), config, true, false);
this.setErrors(csvReader.getTotalRows());
}

private void getResults() throws AsyncApiException, OperationException, DataAccessObjectException {
Expand Down

0 comments on commit 3a92b74

Please sign in to comment.