Boa noite a todos, estou procurando na internet sobre esse assunto, mas até agora não tive sucesso, há pouca coisa. Gostaria de saber se alguém daqui do fórum já fez algum exemplo ou implementou em seu sistemas? Se por acaso tiver algum exemplo de como leio os dados e listo em um dataTable ou algo assim agradeço.
Achei o seguinte código na internet que faz a leitura, porém como faço para o MultipartFile receber o arquivo .ofx?
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import net.sf.ofx4j.domain.data.MessageSetType;
import net.sf.ofx4j.domain.data.ResponseEnvelope;
import net.sf.ofx4j.domain.data.common.Transaction;
import net.sf.ofx4j.domain.data.creditcard.CreditCardResponseMessageSet;
import net.sf.ofx4j.domain.data.creditcard.CreditCardStatementResponse;
import net.sf.ofx4j.domain.data.creditcard.CreditCardStatementResponseTransaction;
import net.sf.ofx4j.io.AggregateUnmarshaller;
import net.sf.ofx4j.io.OFXParseException;
import org.springframework.web.multipart.MultipartFile;
public class ofxParse implements Serializable {
private static final long serialVersionUID = 5088876124317022485L;
MultipartFile inputStream = null;
public boolean parse() {
//Use ResponseEnvelope to start.
AggregateUnmarshaller<ResponseEnvelope> unmarshaller = new AggregateUnmarshaller<>(
ResponseEnvelope.class);
try {
ResponseEnvelope envelope = unmarshaller.unmarshal(inputStream.getInputStream());
//Assume we are just interested in the credit card info. Make sure to cast.
CreditCardResponseMessageSet messageSet = (CreditCardResponseMessageSet) envelope
.getMessageSet(MessageSetType.creditcard);
List<CreditCardStatementResponseTransaction> responses = messageSet.getStatementResponses();
for (CreditCardStatementResponseTransaction response : responses) {
CreditCardStatementResponse message = response.getMessage();
String currencyCode = message.getCurrencyCode();
List<Transaction> transactions = message.getTransactionList().getTransactions();
for (Transaction transaction : transactions) {
System.out.println(transaction.getName() + " " + transaction.getAmount() + " "
+ currencyCode);
}
}
} catch (OFXParseException | IOException e) {
System.out.println("GEB - Error: " + e);
return false;
}
return true;
}
}
Att
Wagner