Exemplo n.º 1
0
 private static void startServer() {
   try {
     if (!FileUtils.isFileLocked(serverFile.getAbsolutePath())) {
       JpaNetworkServer networkServer = new JpaNetworkServer();
       networkServer.startServer(serverFile.getAbsolutePath(), port, password);
       Arrays.fill(password, (char) 0); // clear the password to protect against malicious code
     } else {
       System.err.println(ResourceUtils.getString("Message.FileIsLocked"));
     }
   } catch (final FileNotFoundException e) {
     Logger.getLogger(jGnashFx.class.getName()).log(Level.SEVERE, e.toString(), e);
     System.err.println("File " + serverFile.getAbsolutePath() + " was not found");
   } catch (final Exception e) {
     Logger.getLogger(jGnashFx.class.getName()).log(Level.SEVERE, e.toString(), e);
   }
 }
Exemplo n.º 2
0
  private void runHsqldbServer(final String fileName, final int port, final char[] password) {
    org.hsqldb.server.Server hsqlServer = new org.hsqldb.server.Server();

    hsqlServer.setPort(port);
    hsqlServer.setDatabaseName(0, "jgnash"); // the alias
    hsqlServer.setDatabasePath(0, "file:" + FileUtils.stripFileExtension(fileName));

    hsqlServer.start();

    // Start the message server and engine, this should block until closed
    if (!run(DataStoreType.HSQL_DATABASE, fileName, port, password)) {
      Logger.getLogger(JpaNetworkServer.class.getName()).severe("Failed to start the server");
    }

    hsqlServer.stop();
  }
Exemplo n.º 3
0
  public void exportAccount() {

    final Date exportDate = new Date();

    if (account == null || startDate == null || endDate == null || file == null) {
      throw new RuntimeException();
    }

    // force a correct file extension
    final String fileName = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".ofx";

    try (IndentedPrintWriter writer =
        new IndentedPrintWriter(
            new BufferedWriter(
                new OutputStreamWriter(
                    new FileOutputStream(fileName), Charset.forName("windows-1252"))))) {

      indentedWriter = writer;

      // write the required header
      for (String line : OFXHEADER) {
        writer.println(line, indentLevel);
      }
      writer.println();

      // start of data
      writer.println(wrapOpen(OFX), indentLevel++);

      // write sign-on response
      writer.println(wrapOpen(SIGNONMSGSRSV1), indentLevel++);
      writer.println(wrapOpen(SONRS), indentLevel++);
      writer.println(wrapOpen(STATUS), indentLevel++);
      writer.println(wrapOpen(CODE) + "0", indentLevel);
      writer.println(wrapOpen(SEVERITY) + "INFO", indentLevel);
      writer.println(wrapClose(STATUS), --indentLevel);
      writer.println(wrapOpen(DTSERVER) + encodeDate(exportDate), indentLevel);
      writer.println(wrapOpen(LANGUAGE) + "ENG", indentLevel);
      writer.println(wrapClose(SONRS), --indentLevel);
      writer.println(wrapClose(SIGNONMSGSRSV1), --indentLevel);

      writer.println(wrapOpen(getBankingMessageSetAggregate(account)), indentLevel++);
      writer.println(wrapOpen(getResponse(account)), indentLevel++);
      writer.println(wrapOpen(TRNUID) + "1", indentLevel);
      writer.println(wrapOpen(STATUS), indentLevel++);
      writer.println(wrapOpen(CODE) + "0", indentLevel);
      writer.println(wrapOpen(SEVERITY) + "INFO", indentLevel);
      writer.println(wrapClose(STATUS), --indentLevel);

      // begin start of statement response
      writer.println(wrapOpen(getStatementResponse(account)), indentLevel++);
      writer.println(wrapOpen(CURDEF) + account.getCurrencyNode().getSymbol(), indentLevel);

      // write account identification
      writer.println(wrapOpen(getAccountFromAggregate(account)), indentLevel++);

      switch (account.getAccountType()) {
        case INVEST:
        case MUTUAL:
          writer.println(
              wrapOpen(BROKERID),
              indentLevel); //  required for investment accounts, but jGnash does not manage a
                            // broker ID, normally a web URL
          break;
        default:
          writer.println(
              wrapOpen(BANKID) + account.getBankId(), indentLevel); // savings and checking only
          break;
      }

      writer.println(wrapOpen(ACCTID) + account.getAccountNumber(), indentLevel);

      // write the required account type
      switch (account.getAccountType()) {
        case CHECKING:
          writer.println(wrapOpen(ACCTTYPE) + CHECKING, indentLevel);
          break;
        case ASSET:
        case BANK:
        case CASH:
          writer.println(wrapOpen(ACCTTYPE) + SAVINGS, indentLevel);
          break;
        case CREDIT:
        case LIABILITY:
          writer.println(wrapOpen(ACCTTYPE) + CREDITLINE, indentLevel);
          break;
        case SIMPLEINVEST:
          writer.println(wrapOpen(ACCTTYPE) + MONEYMRKT, indentLevel);
          break;
        default:
          break;
      }

      writer.println(wrapClose(getAccountFromAggregate(account)), --indentLevel);

      // begin start of transaction list
      writer.println(wrapOpen(getTransactionList(account)), indentLevel++);
      writer.println(wrapOpen(DTSTART) + encodeDate(startDate), indentLevel);
      writer.println(wrapOpen(DTEND) + encodeDate(endDate), indentLevel);

      // write the transaction list
      if (account.getAccountType() == AccountType.INVEST
          || account.getAccountType() == AccountType.MUTUAL) {
        writeInvestmentTransactions();
      } else {
        writeBankTransactions();
      }

      // end of transaction list
      writer.println(wrapClose(getTransactionList(account)), --indentLevel);

      // write ledger balance
      writer.println(wrapOpen(LEDGERBAL), indentLevel++);
      writer.println(wrapOpen(BALAMT) + account.getBalance(endDate).toPlainString(), indentLevel);
      writer.println(wrapOpen(DTASOF) + encodeDate(exportDate), indentLevel);
      writer.println(wrapClose(LEDGERBAL), --indentLevel);

      // end of statement response
      writer.println(wrapClose(getStatementResponse(account)), --indentLevel);
      writer.println(wrapClose(getResponse(account)), --indentLevel);
      writer.println(wrapClose(getBankingMessageSetAggregate(account)), --indentLevel);

      // finished
      writer.println(wrapClose(OFX), --indentLevel);
    } catch (IOException e) {
      Logger.getLogger(OfxExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }