Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kabarret committed Jun 30, 2016
1 parent 37d90c0 commit 815ed6f
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 103,876 deletions.
462 changes: 0 additions & 462 deletions hs_err_pid8483.log

This file was deleted.

39 changes: 27 additions & 12 deletions src/main/java/com/progressSoft/kaue/service/ProcessFileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.progressSoft.kaue.dao.TotalDAO;
import com.progressSoft.kaue.dao.TransactionDAO;
import com.progressSoft.kaue.dao.TransactionErrorDAO;
import com.progressSoft.kaue.entity.Total;
import com.progressSoft.kaue.entity.Transaction;
import com.progressSoft.kaue.entity.TransactionError;
import org.apache.commons.csv.CSVFormat;
Expand All @@ -12,13 +11,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.stereotype.Service;

import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;

/**
Expand All @@ -35,11 +34,13 @@ public class ProcessFileService {
@Autowired
private TotalDAO totalDAO;


@Autowired
private TransactionErrorDAO transactionErrorDAO;

public void processFile(File file) {

private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

public void processFile(final File file) {

try {
final Reader reader = new InputStreamReader(new FileInputStream(file));
Expand All @@ -51,6 +52,7 @@ public void processFile(File file) {
for (CSVRecord csvRecord : parser) {
if (csvRecord.get("id").isEmpty()
|| csvRecord.get("from").isEmpty()
|| csvRecord.get("time").isEmpty()
|| csvRecord.get("to").isEmpty()
|| csvRecord.get("amount").isEmpty()
){
Expand All @@ -61,13 +63,26 @@ public void processFile(File file) {

transactionsErrors.add(transactionError);
}else {
Transaction transaction = new Transaction();
transaction.setId(csvRecord.get("id"));
transaction.setFromCurrency(csvRecord.get("from"));
transaction.setToCurrency(csvRecord.get("to"));
transaction.setAmount(Double.valueOf(csvRecord.get("amount")));
try {
Date time = sdf.parse(csvRecord.get("time"));

Transaction transaction = new Transaction();
transaction.setId(csvRecord.get("id"));
transaction.setFromCurrency(csvRecord.get("from"));
transaction.setToCurrency(csvRecord.get("to"));
transaction.setAmount(Double.valueOf(csvRecord.get("amount")));
transaction.setTime(time);
transactions.add(transaction);

} catch (ParseException e) {
TransactionError transactionError = new TransactionError();
transactionError.setError("Invalid date format, the format should be yyyy-MM-dd'T'HH:mm:ss");
transactionError.setFile(file.getName());
transactionError.setLine(csvRecord.getRecordNumber());
transactionsErrors.add(transactionError);
}


transactions.add(transaction);
}
}

Expand Down
Loading

0 comments on commit 815ed6f

Please sign in to comment.