use of jgnash.convert.exportantur.ofx.OfxExport in project jgnash by ccavanaugh.
the class OfxExportText method testExport.
@Test
void testExport() throws Exception {
Transaction transaction = TransactionFactory.generateDoubleEntryTransaction(checkingAccount, usdBankAccount, BigDecimal.TEN, LocalDate.now(), "Transfer Test", "Transfer", "");
assertTrue(e.addTransaction(transaction));
Path path = Files.createTempFile("j", ".ofx");
OfxExport ofxExport = new OfxExport(usdBankAccount, LocalDate.now().minusDays(1), LocalDate.now().plusDays(1), path.toFile());
ofxExport.exportAccount();
assertTrue(Files.exists(path));
OfxBank ofxBank = OfxV2Parser.parse(path);
assertNotNull(ofxBank);
assertEquals(0, ofxBank.statusCode);
assertEquals("INFO", ofxBank.statusSeverity);
assertEquals(1, ofxBank.getTransactions().size());
ImportTransaction importTransaction = ofxBank.getTransactions().get(0);
assertEquals("10001-C01", importTransaction.getAccountTo());
Files.delete(path);
}
use of jgnash.convert.exportantur.ofx.OfxExport in project jgnash by ccavanaugh.
the class RegisterActions method exportTransactions.
static void exportTransactions(final Account account, final LocalDate startDate, final LocalDate endDate) {
final ResourceBundle resources = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(RegisterActions.class);
final FileChooser fileChooser = new FileChooser();
final File initialDirectory = new File(pref.get(EXPORT_DIR, System.getProperty("user.home")));
// Protect against an IllegalArgumentException
if (initialDirectory.isDirectory()) {
fileChooser.setInitialDirectory(initialDirectory);
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.CsvFiles") + " (*.csv)", "*.csv"), new FileChooser.ExtensionFilter(resources.getString("Label.OfxFiles") + " (*.ofx)", "*.ofx"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls)", "*.xls"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xlsx)", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
final File exportFile;
if (file != null) {
if (!FileUtils.fileHasExtension(file.getName())) {
// fix up the file name if the user did not specify it
final String fileExtension = fileChooser.getSelectedExtensionFilter().getExtensions().get(0).substring(1);
exportFile = new File(FileUtils.stripFileExtension(file.getAbsolutePath()) + fileExtension);
} else {
exportFile = file;
}
pref.put(EXPORT_DIR, exportFile.getParentFile().getAbsolutePath());
final Task<Void> exportTask = new Task<>() {
@Override
protected Void call() {
updateMessage(resources.getString("Message.PleaseWait"));
updateProgress(-1, Long.MAX_VALUE);
if (OFX.equals(FileUtils.getFileExtension(exportFile.getName()))) {
final OfxExport export = new OfxExport(account, startDate, endDate, exportFile);
export.exportAccount();
} else if (FileUtils.getFileExtension(exportFile.getName()).contains(XLS)) {
final AbstractReportTableModel reportTableModel = AccountRegisterReport.createReportModel(account, startDate, endDate, false, "", "", true);
Workbook.export(reportTableModel, exportFile);
} else {
CsvExport.exportAccount(account, startDate, endDate, exportFile.toPath());
}
return null;
}
};
new Thread(exportTask).start();
StaticUIMethods.displayTaskProgress(exportTask);
}
}
Aggregations