public ServerSolution() { accountMap = new HashMap<String, Account>(); File file = new File(fileName); ObjectInputStream in = null; try { if (file.exists()) { System.out.println("Reading from file " + fileName + "..."); in = new ObjectInputStream(new FileInputStream(file)); Integer sizeI = (Integer) in.readObject(); int size = sizeI.intValue(); for (int i = 0; i < size; i++) { Account acc = (Account) in.readObject(); if (acc != null) accountMap.put(acc.getName(), acc); } } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Throwable t) { t.printStackTrace(); } } } }
public void printAllAccounts(String customerID) { // Sorts the customer based on ID, then prints the accounts information // change the withdrawal funcitons and deposit functions too ajf.dispose(); ajf = new AdminRunningFrame(this); Collections.sort(cust, Customer.CompareIDs); String searchString = ajf.getCustomerID(); StringBuilder stringResults = new StringBuilder(); String header = header(); stringResults.append(header); for (Customer customer : cust) { String id = customer.returnID(); String name = customer.getName().toUpperCase(); String pin = customer.returnPin(); if (searchString.equals(id)) { ArrayList<Account> accounts = customer.getAccounts(); if (!accounts.isEmpty()) { for (Account account : accounts) { if (account.checkActive()) { String accountNumber = account.returnNumber(); double balance = account.returnBalance(); String balanceAsString = formatter.format(balance); String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString); stringResults.append(customerInfo); } } } } } String resultsAsString = stringResults.toString(); ajf.printInfo(resultsAsString); }
/** Creates a new instance of AccountPicker */ public AccountSelect(Display display, boolean enableQuit) { super(); // this.display=display; setTitleItem(new Title(SR.MS_ACCOUNTS)); accountList = new Vector(); Account a; int index = 0; activeAccount = Config.getInstance().accountIndex; do { a = Account.createFromStorage(index); if (a != null) { accountList.addElement(a); a.active = (activeAccount == index); index++; } } while (a != null); if (accountList.isEmpty()) { a = Account.createFromJad(); if (a != null) { // a.updateJidCache(); accountList.addElement(a); rmsUpdate(); } } attachDisplay(display); addCommand(cmdAdd); if (enableQuit) addCommand(cmdQuit); commandState(); setCommandListener(this); }
public boolean closeAccount(String name) { Account acc = accountMap.get(name); if (acc == null) { return false; } acc.setState(State.CLOSED); return true; }
public List<Account> getActiveAccounts() { List<Account> result = new ArrayList<Account>(); for (Account acc : accountMap.values()) { if (acc.getState() != State.CLOSED) { result.add(acc); } } return result; }
/* update title string */ public static void updateAccountString( Account account, String stringID, String description, String singular, String plural) throws DBException { /* valid account? */ if (account == null) { throw new DBException("Account not specified."); } /* delete? */ // delete if both singular/plural values are empty/null if (((singular == null) || singular.equals("")) && ((plural == null) || plural.equals(""))) { String acctID = account.getAccountID(); AccountString.Key key = new AccountString.Key(acctID, stringID); key.delete(true); // also delete dependencies (if any) return; } /* get/create AccountString */ AccountString str = AccountString.getAccountString(account, stringID); if (str == null) { str = AccountString.getAccountString(account, stringID, true); } /* insert/update */ str.setDescription(description); str.setSingularTitle(singular); str.setPluralTitle((plural != null) ? plural : singular); str.save(); }
/** Writes all investment account transactions within the date range */ private void writeInvestmentTransactions() { for (Transaction transaction : account.getTransactions(startDate, endDate)) { if (transaction instanceof InvestmentTransaction) { InvestmentTransaction invTransaction = (InvestmentTransaction) transaction; switch (invTransaction.getTransactionType()) { case ADDSHARE: case BUYSHARE: writeBuyStockTransaction(invTransaction); break; case REMOVESHARE: case SELLSHARE: writeSellStockTransaction(invTransaction); break; case DIVIDEND: writeDividendTransaction(invTransaction); break; case REINVESTDIV: writeReinvestStockTransaction(invTransaction); break; default: break; } } else { // bank transaction, write it indentedWriter.println(wrapOpen(INVBANKTRAN), indentLevel++); writeBankTransaction(transaction); indentedWriter.println(wrapClose(INVBANKTRAN), --indentLevel); } } }
/* overridden to set default values */ public void setCreationDefaultValues() { BasicPrivateLabel privateLabel = Account.getPrivateLabel(this.getAccount()); StatusCodes.Code code = StatusCodes.GetCode(this.getStatusCode(), privateLabel); this.setStatusName((code != null) ? code.getName() : ""); this.setDescription((code != null) ? code.getDescription(null) : ""); this.setIconSelector(""); // super.setRuntimeDefaultValues(); }
private void switchAccount(boolean login) { if (!login) parentView = StaticData.getInstance().roster; destroyView(); Config cf = Config.getInstance(); cf.accountIndex = cursor; cf.saveToStorage(); Account.loadAccount(login); }
private static String getTransactionList(final Account account) { switch (account.getAccountType()) { case INVEST: case MUTUAL: return INVTRANLIST; default: return BANKTRANLIST; } }
@Test public void manyToOne_setAccount() { SavedSearch many = new SavedSearch(); // init Account one = new Account(); one.setId(ValueGenerator.getUniqueString(36)); many.setAccount(one); // make sure it is propagated properly assertThat(many.getAccount()).isEqualTo(one); // now set it to back to null many.setAccount(null); // make sure null is propagated properly assertThat(many.getAccount()).isNull(); }
/* Return specified StatusCode, create if specified */ private static StatusCode _getStatusCode( String accountID, Account account, String deviceID, int code, boolean createOK) throws DBException { // does not return null if 'createOK' is true /* account-id specified? */ if (StringTools.isBlank(accountID)) { if (account == null) { throw new DBException("Account not specified."); } else { accountID = account.getAccountID(); } } else if ((account != null) && !account.getAccountID().equals(accountID)) { throw new DBException("Account does not match specified AccountID."); } /* device-id specified? */ if (StringTools.isBlank(deviceID)) { // throw new DBException("Device-ID not specified."); deviceID = ALL_DEVICES; } /* get/create entity */ StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, code); if (scKey.exists()) { // may throw DBException StatusCode sc = scKey.getDBRecord(true); if (account != null) { sc.setAccount(account); } return sc; } else if (createOK) { StatusCode sc = scKey.getDBRecord(); if (account != null) { sc.setAccount(account); } sc.setCreationDefaultValues(); return sc; // not yet saved! } else { // record doesn't exist, and caller doesn't want us to create it return null; } }
private boolean newAccountFactory(String type, String name, float balance) throws IllegalArgumentException { Account acc; if ("Checking".equals(type)) { acc = new Checking(name, balance); } else if ("Savings".equals(type)) { acc = new Savings(name, balance); } else { throw new IllegalArgumentException("Bad account type:" + type); } try { accountMap.put(acc.getName(), acc); } catch (Exception exc) { return false; } return true; }
public void printByCustomerName() { // Prints the database info by customer's name in ascending order Collections.sort(cust, Customer.CompareName); ajf.dispose(); ajf = new AdminRunningFrame(this); StringBuilder stringResults = new StringBuilder(); String header = header(); stringResults.append(header); if (!cust.isEmpty()) { for (Customer customer : cust) { String id = customer.returnID(); String name = customer.getName().toUpperCase(); String pin = customer.returnPin(); ArrayList<Account> accounts = customer.getAccounts(); if (!accounts.isEmpty()) { for (Account account : accounts) { if (account.checkActive()) { String accountNumber = account.returnNumber(); double balance = account.returnBalance(); String balanceAsString = formatter.format(balance); String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString); stringResults.append(customerInfo); } } } else { // Still prints customers who have created customer accounts but not set up any // checking/savings String noAccounts = String.format("%-20s %-9s %-10s\n", name, id, pin); stringResults.append(noAccounts); } } } String resultsAsString = stringResults.toString(); ajf.printInfo(resultsAsString); }
public void printHighestBalance() { // prints the accounts from highest amount to lowest, with those who have empty accounts last ajf.dispose(); ajf = new AdminRunningFrame(this); StringBuilder stringResults = new StringBuilder(); String header = header(); stringResults.append(header); if (!cust.isEmpty()) { ArrayList<Account> allAccounts = new ArrayList<Account>(); ArrayList<Customer> CustomersNoAccounts = new ArrayList<Customer>(); for (Customer c : cust) { ArrayList<Account> accounts = c.getAccounts(); if (!accounts.isEmpty()) { // Concatenates all the accounts together for easy sorting allAccounts.addAll(accounts); } // Adds customers without accounts to a separate list to be printed at the end of all the // others else { CustomersNoAccounts.add(c); } } if (!allAccounts.isEmpty()) { Collections.sort(allAccounts, Account.CompareBalances); for (Account a : allAccounts) { if (a.checkActive()) { String id = a.getID(); String name = a.getName().toUpperCase(); String pin = a.getPin(); String accountNumber = a.returnNumber(); double balance = a.returnBalance(); String balanceAsString = formatter.format(balance); String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString); stringResults.append(customerInfo); } } } if (!CustomersNoAccounts.isEmpty()) { Collections.sort(CustomersNoAccounts, Customer.CompareName); for (Customer c : CustomersNoAccounts) { String id = c.returnID(); String name = c.getName().toUpperCase(); String pin = c.returnPin(); String noAccounts = String.format("%-20s %-9s %-10s\n", name, id, pin); stringResults.append(noAccounts); } } String resultsAsString = stringResults.toString(); ajf.printInfo(resultsAsString); } }
public static DBFactory<AccountString> getFactory() { if (factory == null) { factory = DBFactory.createDBFactory( AccountString.TABLE_NAME(), AccountString.FieldInfo, DBFactory.KeyType.PRIMARY, AccountString.class, AccountString.Key.class, true /*editable*/, true /*viewable*/); factory.addParentTable(Account.TABLE_NAME()); } return factory; }
/* get string */ public static AccountString getAccountString(Account account, String strID) throws DBException { if ((account != null) && (strID != null)) { String acctID = account.getAccountID(); AccountString.Key key = new AccountString.Key(acctID, strID); if (key.exists()) { AccountString str = key.getDBRecord(true); str.setAccount(account); return str; } else { // AccountString does not exist return null; } } else { return null; // just say it doesn't exist } }
public static DBFactory<RoleAcl> getFactory() { if (factory == null) { EnumTools.registerEnumClass(AccessLevel.class); factory = DBFactory.createDBFactory( RoleAcl.TABLE_NAME(), RoleAcl.FieldInfo, DBFactory.KeyType.PRIMARY, RoleAcl.class, RoleAcl.Key.class, true /*editable*/, true /*viewable*/); factory.addParentTable(Account.TABLE_NAME()); factory.addParentTable(Role.TABLE_NAME()); } return factory; }
public static DBFactory<StatusCode> getFactory() { if (factory == null) { factory = DBFactory.createDBFactory( StatusCode.TABLE_NAME(), StatusCode.FieldInfo, DBFactory.KeyType.PRIMARY, StatusCode.class, StatusCode.Key.class, true /*editable*/, true /*viewable*/); factory.addParentTable(Account.TABLE_NAME()); factory.addParentTable(Device.TABLE_NAME()); factory.setFieldDefaultValue(FLD_deviceID, ALL_DEVICES); } return factory; }
public static DBFactory<GroupList> getFactory() { if (factory == null) { factory = DBFactory.createDBFactory( GroupList.TABLE_NAME(), GroupList.FieldInfo, DBFactory.KeyType.PRIMARY, GroupList.class, GroupList.Key.class, true /*editable*/, true /*viewable*/); factory.addParentTable(Account.TABLE_NAME()); factory.addParentTable(User.TABLE_NAME()); factory.addParentTable(DeviceGroup.TABLE_NAME()); } return factory; }
private static String getAccountFromAggregate(final Account account) { switch (account.getAccountType()) { case ASSET: case BANK: case CASH: case CHECKING: case SIMPLEINVEST: return BANKACCTFROM; case CREDIT: case LIABILITY: return CCACCTFROM; case INVEST: case MUTUAL: return INVACCTFROM; default: return ""; } }
private static String getStatementResponse(final Account account) { switch (account.getAccountType()) { case ASSET: case BANK: case CASH: case CHECKING: case SIMPLEINVEST: return STMTRS; case CREDIT: case LIABILITY: return CCSTMTRS; case INVEST: case MUTUAL: return INVSTMTRS; default: return ""; } }
private static String getBankingMessageSetAggregate(final Account account) { switch (account.getAccountType()) { case ASSET: case BANK: case CASH: case CHECKING: case SIMPLEINVEST: return BANKMSGSRSV1; case CREDIT: case LIABILITY: return CREDITCARDMSGSRSV1; case INVEST: case MUTUAL: return INVSTMTMSGSRSV1; default: return ""; } }
protected Device loadDevice(String acctID, String devID) { if (StringTools.isBlank(acctID)) { return this.loadDevice(devID); // load ad ModemID } else { try { Account account = Account.getAccount(acctID); if (account == null) { Print.logError("Account-ID not found: " + acctID); return null; } else { Device dev = Transport.loadDeviceByTransportID(account, devID); return dev; } } catch (DBException dbe) { Print.logError("Error getting Device: " + acctID + "/" + devID + " [" + dbe + "]"); return null; } } }
// Note: does NOT return null public static AccountString getAccountString(Account account, String strID, boolean create) throws DBException { /* account-id specified? */ if (account == null) { throw new DBNotFoundException("Account not specified."); } String acctID = account.getAccountID(); /* string-id specified? */ if ((strID == null) || strID.equals("")) { throw new DBNotFoundException("String-ID not specified for account: " + acctID); } /* get/create */ AccountString str = null; AccountString.Key strKey = new AccountString.Key(acctID, strID); if (!strKey.exists()) { if (create) { str = strKey.getDBRecord(); str.setAccount(account); str.setCreationDefaultValues(); return str; // not yet saved! } else { throw new DBNotFoundException("String-ID does not exists: " + strKey); } } else if (create) { // we've been asked to create the AccountString, and it already exists throw new DBAlreadyExistsException("String-ID already exists '" + strKey + "'"); } else { str = AccountString.getAccountString(account, strID); if (str == null) { throw new DBException("Unable to read existing String-ID: " + strKey); } return str; } }
/** * Writes one bank transaction * * @param transaction <code>Transaction</code> to write */ private void writeBankTransaction(final Transaction transaction) { indentedWriter.println(wrapOpen(STMTTRN), indentLevel++); indentedWriter.println( wrapOpen(TRNTYPE) + (transaction.getAmount(account).compareTo(BigDecimal.ZERO) == 1 ? CREDIT : DEBIT), indentLevel); indentedWriter.println(wrapOpen(DTPOSTED) + encodeDate(transaction.getDate()), indentLevel); indentedWriter.println( wrapOpen(TRNAMT) + transaction.getAmount(account).toPlainString(), indentLevel); indentedWriter.println(wrapOpen(REFNUM) + transaction.getUuid(), indentLevel); indentedWriter.println(wrapOpen(NAME) + transaction.getPayee(), indentLevel); indentedWriter.println(wrapOpen(MEMO) + transaction.getMemo(), indentLevel); // write the check number if applicable if (account.getAccountType() == AccountType.CHECKING && !transaction.getNumber().isEmpty()) { indentedWriter.println(wrapOpen(CHECKNUM) + transaction.getNumber(), indentLevel); } // write out the banks transaction id if previously imported writeFitID(transaction); indentedWriter.println(wrapClose(STMTTRN), --indentLevel); }
/* write mapping support JS to stream */ protected void writeJSVariables(PrintWriter out, RequestProperties reqState) throws IOException { // This var initilizations must not use any functions defined in 'jsmap.js' PrivateLabel privLabel = reqState.getPrivateLabel(); I18N i18n = privLabel.getI18N(JSMap.class); Locale locale = reqState.getLocale(); GeoPoint dftCenter = this.getDefaultCenter(null); boolean isFleet = reqState.isFleet(); Account account = reqState.getCurrentAccount(); long maxPushpins = this.getMaxPushpins(reqState); out.write("// --- Map support Javascript [" + this.getName() + "]\n"); JavaScriptTools.writeJSVar(out, "MAP_PROVIDER_NAME", this.getName()); /* properties */ boolean wrotePropHeader = false; RTProperties rtp = this.getProperties(); for (Iterator<?> i = rtp.keyIterator(); i.hasNext(); ) { Object key = i.next(); if (!this._skipPropKey(key)) { if (!wrotePropHeader) { // out.write("\n"); out.write("// Defined properties\n"); wrotePropHeader = true; } String val[] = StringTools.parseStringArray(rtp.getProperty(key, "").toString(), '\n'); String propVar = "PROP_" + key.toString().replace('.', '_').replace('-', '_'); if (val.length == 1) { if (StringTools.isDouble(val[0], true) || StringTools.isLong(val[0], true) || StringTools.isBoolean(val[0], true)) { JavaScriptTools.writeJSVar(out, propVar, val[0], false); } else { JavaScriptTools.writeJSVar(out, propVar, val[0]); } } else if (val.length > 1) { JavaScriptTools.writeJSVar(out, propVar, StringTools.join(val, "\\n")); } } } /* speed units */ Account.SpeedUnits speedUnits = reqState.getSpeedUnits(); boolean speedIsKph = speedUnits.equals(Account.SpeedUnits.KPH); double altUnitsMult = speedIsKph ? 1.0 : GeoPoint.FEET_PER_METER; String altUnitsName = speedIsKph ? i18n.getString("JSMap.altitude.meters", "Meters") : i18n.getString("JSMap.altitude.feet", "Feet"); /* constants (these do not change during the user session) */ out.write("// Element IDs\n"); JavaScriptTools.writeJSVar(out, "MAP_ID", this.getMapID()); JavaScriptTools.writeJSVar(out, "ID_DETAIL_TABLE", ID_DETAIL_TABLE); JavaScriptTools.writeJSVar(out, "ID_DETAIL_CONTROL", ID_DETAIL_CONTROL); JavaScriptTools.writeJSVar(out, "ID_LAT_LON_DISPLAY", ID_LAT_LON_DISPLAY); JavaScriptTools.writeJSVar(out, "ID_DISTANCE_DISPLAY", ID_DISTANCE_DISPLAY); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_DATE", ID_LATEST_EVENT_DATE); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_TIME", ID_LATEST_EVENT_TIME); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_TMZ", ID_LATEST_EVENT_TMZ); JavaScriptTools.writeJSVar(out, "ID_LATEST_BATTERY", ID_LATEST_BATTERY); JavaScriptTools.writeJSVar(out, "ID_MESSAGE_TEXT", ID_MESSAGE_TEXT); out.write("// Geozone IDs\n"); JavaScriptTools.writeJSVar(out, "ID_ZONE_LATITUDE_", ID_ZONE_LATITUDE_); JavaScriptTools.writeJSVar(out, "ID_ZONE_LONGITUDE_", ID_ZONE_LONGITUDE_); JavaScriptTools.writeJSVar(out, "ID_ZONE_RADIUS_M", ID_ZONE_RADIUS_M); out.write("// Session constants\n"); JavaScriptTools.writeJSVar(out, "PUSHPINS_SHOW", rtp.getBoolean(PROP_map_pushpins, true)); JavaScriptTools.writeJSVar(out, "MAX_PUSH_PINS", maxPushpins); JavaScriptTools.writeJSVar(out, "MAX_CREATION_AGE_SEC", rtp.getInt(PROP_map_maxCreationAge, 0)); JavaScriptTools.writeJSVar(out, "MAP_WIDTH", this.getDimension().getWidth()); JavaScriptTools.writeJSVar(out, "MAP_HEIGHT", this.getDimension().getHeight()); JavaScriptTools.writeJSVar(out, "IS_FLEET", isFleet); JavaScriptTools.writeJSVar( out, "SHOW_SAT_COUNT", rtp.getBoolean(PROP_detail_showSatCount, false)); JavaScriptTools.writeJSVar(out, "SHOW_SPEED", rtp.getBoolean(PROP_info_showSpeed, true)); JavaScriptTools.writeJSVar( out, "COMBINE_SPEED_HEAD", rtp.getBoolean(PROP_combineSpeedHeading, true)); JavaScriptTools.writeJSVar(out, "SHOW_ALTITUDE", rtp.getBoolean(PROP_info_showAltitude, false)); JavaScriptTools.writeJSVar(out, "SHOW_ADDR", reqState.getShowAddress()); JavaScriptTools.writeJSVar( out, "INCL_BLANK_ADDR", rtp.getBoolean(PROP_info_inclBlankAddress, true)); JavaScriptTools.writeJSVar( out, "SHOW_OPT_FIELDS", rtp.getBoolean(PROP_info_showOptionalFields, true)); JavaScriptTools.writeJSVar( out, "INCL_BLANK_OPT_FIELDS", rtp.getBoolean(PROP_info_inclBlankOptFields, true)); JavaScriptTools.writeJSVar( out, "LATLON_FORMAT", Account.getLatLonFormat(account).getIntValue()); JavaScriptTools.writeJSVar( out, "DISTANCE_KM_MULT", reqState.getDistanceUnits().getMultiplier()); JavaScriptTools.writeJSVar(out, "SPEED_KPH_MULT", speedUnits.getMultiplier()); JavaScriptTools.writeJSVar(out, "SPEED_UNITS", speedUnits.toString(locale)); JavaScriptTools.writeJSVar(out, "ALTITUDE_METERS_MULT", altUnitsMult); JavaScriptTools.writeJSVar(out, "ALTITUDE_UNITS", altUnitsName); JavaScriptTools.writeJSVar(out, "TIME_ZONE", reqState.getTimeZoneString(null)); // long JavaScriptTools.writeJSVar( out, "DEFAULT_CENTER", "{ lat:" + dftCenter.getLatitude() + ", lon:" + dftCenter.getLongitude() + " }", false); JavaScriptTools.writeJSVar(out, "DEFAULT_ZOOM", this.getDefaultZoom(JSMap.DEFAULT_ZOOM, false)); JavaScriptTools.writeJSVar(out, "PUSHPIN_ZOOM", this.getDefaultZoom(JSMap.PUSHPIN_ZOOM, true)); JavaScriptTools.writeJSVar(out, "MAP_AUTHORIZATION", this.getAuthorization()); JavaScriptTools.writeJSVar( out, "SCROLL_WHEEL_ZOOM", rtp.getBoolean(PROP_scrollWheelZoom, false)); JavaScriptTools.writeJSVar(out, "DEFAULT_VIEW", rtp.getString(PROP_map_view, "").toLowerCase()); JavaScriptTools.writeJSVar(out, "ROUTE_LINE_SHOW", rtp.getBoolean(PROP_map_routeLine, true)); JavaScriptTools.writeJSVar( out, "ROUTE_LINE_COLOR", rtp.getString(PROP_map_routeLine_color, "#FF2222")); JavaScriptTools.writeJSVar( out, "ROUTE_LINE_ARROWS", rtp.getBoolean(PROP_map_routeLine_arrows, false)); JavaScriptTools.writeJSVar( out, "ROUTE_SNAP_TO_ROAD", rtp.getBoolean(PROP_map_routeLine_snapToRoad, false)); // Google V2 only JavaScriptTools.writeJSVar(out, "REPLAY_INTERVAL", this.getReplayInterval()); JavaScriptTools.writeJSVar(out, "REPLAY_SINGLE", this.getReplaySinglePushpin()); /* address title */ String adrTitles[] = reqState.getAddressTitles(); String adrTitle = ListTools.itemAt(adrTitles, 0, null); /* device title */ String devTitles[] = reqState.getDeviceTitles(); String devTitle = ListTools.itemAt(devTitles, 0, null); /* labels */ out.write("// Localized Text/Labels\n"); JavaScriptTools.writeJSVar( out, "HEADING", "new Array(" + "\"" + GeoPoint.CompassHeading.N.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.NE.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.E.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.SE.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.S.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.SW.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.W.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.NW.toString(locale) + "\")", false); JavaScriptTools.writeJSVar(out, "TEXT_INFO_DATE", i18n.getString("JSMap.info.date", "Date")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_GPS", i18n.getString("JSMap.info.gps", "GPS")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_SATS", i18n.getString("JSMap.info.sats", "#Sats")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_SPEED", i18n.getString("JSMap.info.speed", "Speed")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_HEADING", GeoPoint.GetHeadingTitle(locale)); JavaScriptTools.writeJSVar( out, "TEXT_INFO_ALTITUDE", i18n.getString("JSMap.info.altitude", "Altitude")); JavaScriptTools.writeJSVar( out, "TEXT_INFO_STOP_TIME", i18n.getString("JSMap.info.stopTime", "Stop Time")); JavaScriptTools.writeJSVar( out, "TEXT_INFO_ADDR", !StringTools.isBlank(adrTitle) ? adrTitle : i18n.getString("JSMap.info.address", "Address")); JavaScriptTools.writeJSVar( out, "TEXT_DEVICE", !StringTools.isBlank(devTitle) ? devTitle : i18n.getString("JSMap.device", "Device")); JavaScriptTools.writeJSVar(out, "TEXT_DATE", i18n.getString("JSMap.dateTime", "Date/Time")); JavaScriptTools.writeJSVar(out, "TEXT_CODE", i18n.getString("JSMap.code", "Status")); JavaScriptTools.writeJSVar(out, "TEXT_LATLON", i18n.getString("JSMap.latLon", "Lat/Lon")); JavaScriptTools.writeJSVar(out, "TEXT_SATCOUNT", i18n.getString("JSMap.satCount", "#Sats")); JavaScriptTools.writeJSVar( out, "TEXT_ADDR", !StringTools.isBlank(adrTitle) ? adrTitle : i18n.getString("JSMap.address", "Address")); JavaScriptTools.writeJSVar(out, "TEXT_SPEED", reqState.getSpeedUnits().toString(locale)); JavaScriptTools.writeJSVar(out, "TEXT_HEADING", i18n.getString("JSMap.heading", "Heading")); JavaScriptTools.writeJSVar(out, "TEXT_DISTANCE", reqState.getDistanceUnits().toString(locale)); JavaScriptTools.writeJSVar( out, "TEXT_TIMEOUT", i18n.getString("JSMap.sessionTimeout", "Your session has timed-out.\nPlease login ...")); JavaScriptTools.writeJSVar( out, "TEXT_PING_OK", i18n.getString( "JSMap.pingDevice.ok", "A command request has been sent.\nThe {0} should respond shortly ...", devTitles)); JavaScriptTools.writeJSVar( out, "TEXT_PING_ERROR", i18n.getString( "JSMap.pingDevice.err", "The command request failed.\nThe {0} may not support this feature ...", devTitles)); JavaScriptTools.writeJSVar( out, "TEXT_MAXPUSHPINS_ALERT", i18n.getString( "JSMap.maxPushpins.err", "The maximum number of allowed pushpins has been exceeded.\n" + " [max={0}] Not all pushpins may be displayed on this map.\n" + "Adjust the 'From' time to see remaining pushpins", String.valueOf(maxPushpins))); JavaScriptTools.writeJSVar( out, "TEXT_MAXPUSHPINS_MSG", i18n.getString( "JSMap.maxPushpins.msg", "Only partial data displayed. The maximum allowed pushpins has been reached.<BR>" + "Adjust the Date/Time range accordingly to view the remaining pushpins.")); JavaScriptTools.writeJSVar( out, "TEXT_UNAVAILABLE", i18n.getString("JSMap.unavailable", "unavailable")); JavaScriptTools.writeJSVar( out, "TEXT_showLocationDetails", i18n.getString("JSMap.showLocationDetails", "Show Location Details")); JavaScriptTools.writeJSVar( out, "TEXT_hideLocationDetails", i18n.getString("JSMap.hideLocationDetails", "Hide Location Details")); /* map "Loading ..." */ JavaScriptTools.writeJSVar( out, "TEXT_LOADING_MAP_POINTS", (rtp.getBoolean(PROP_MAP_LOADING, false) ? i18n.getString("JSMap.loadingMapPoints", "Loading Map Points ...") : null)); JavaScriptTools.writeJSVar( out, "MAP_LOADING_IMAGE_URI", rtp.getString(PROP_MAP_LOADING_IMAGE, null)); /* icons/shadows */ JSMap.writePushpinArray(out, reqState); /* constants (these do not change during the user session) */ out.write("// Geozone support constants\n"); JavaScriptTools.writeJSVar(out, "jsvGeozoneMode", false); JavaScriptTools.writeJSVar(out, "MAX_ZONE_RADIUS_M", Geozone.MAX_RADIUS_METERS); JavaScriptTools.writeJSVar(out, "MIN_ZONE_RADIUS_M", Geozone.MIN_RADIUS_METERS); JavaScriptTools.writeJSVar( out, "DETAIL_REPORT", this.isFeatureSupported(FEATURE_DETAIL_REPORT)); JavaScriptTools.writeJSVar( out, "DETAIL_INFO_BOX", this.isFeatureSupported(FEATURE_DETAIL_INFO_BOX)); JavaScriptTools.writeJSVar(out, "TEXT_METERS", GeoPoint.DistanceUnits.METERS.toString(locale)); /* variables */ out.write("// TrackMap Vars\n"); JavaScriptTools.writeJSVar(out, "jsvPoiPins", null); JavaScriptTools.writeJSVar(out, "jsvDataSets", null); JavaScriptTools.writeJSVar(out, "jsvDetailPoints", null); JavaScriptTools.writeJSVar(out, "jsvDetailVisible", false); JavaScriptTools.writeJSVar( out, "jsvDetailAscending", privLabel.getBooleanProperty(PrivateLabel.PROP_TrackMap_detailAscending, true)); JavaScriptTools.writeJSVar( out, "jsvDetailCenterPushpin", privLabel.getBooleanProperty(PrivateLabel.PROP_TrackMap_detailCenterPushpin, false)); /* last update time */ TimeZone tmz = reqState.getTimeZone(); String dateFmt = (account != null) ? account.getDateFormat() : BasicPrivateLabel.getDefaultDateFormat(); String timeFmt = (account != null) ? account.getTimeFormat() : BasicPrivateLabel.getDefaultTimeFormat(); DateTime today = new DateTime(tmz); JavaScriptTools.writeJSVar(out, "jsvTodayEpoch", today.getTimeSec()); JavaScriptTools.writeJSVar( out, "jsvTodayYMD", "{ YYYY:" + today.getYear(tmz) + ", MM:" + today.getMonth1(tmz) + ", DD:" + today.getDayOfMonth(tmz) + " }", false); JavaScriptTools.writeJSVar(out, "jsvTodayDateFmt", today.format(dateFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvTodayTimeFmt", today.format(timeFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvTodayTmzFmt", today.format("z", tmz)); /* last event time */ out.write("// Last event time\n"); DateTime lastEventTime = reqState.getLastEventTime(); if (lastEventTime != null) { JavaScriptTools.writeJSVar(out, "jsvLastEventEpoch", lastEventTime.getTimeSec()); JavaScriptTools.writeJSVar( out, "jsvLastEventYMD", "{ YYYY:" + lastEventTime.getYear(tmz) + ", MM:" + lastEventTime.getMonth1(tmz) + ", DD:" + lastEventTime.getDayOfMonth(tmz) + " }", false); JavaScriptTools.writeJSVar(out, "jsvLastEventDateFmt", lastEventTime.format(dateFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvLastEventTimeFmt", lastEventTime.format(timeFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvLastEventTmzFmt", lastEventTime.format("z", tmz)); JavaScriptTools.writeJSVar(out, "jsvLastBatteryLevel", 0L); JavaScriptTools.writeJSVar(out, "jsvLastSignalStrength", 0L); } else { JavaScriptTools.writeJSVar(out, "jsvLastEventEpoch", 0L); JavaScriptTools.writeJSVar(out, "jsvLastEventYMD", null); JavaScriptTools.writeJSVar(out, "jsvLastEventDateFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastEventTimeFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastEventTmzFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastBatteryLevel", 0.0); JavaScriptTools.writeJSVar(out, "jsvLastSignalStrength", 0.0); } /* map pointers */ out.write("// Map vars\n"); JavaScriptTools.writeJSVar(out, "jsmapElem", null); JavaScriptTools.writeJSVar(out, "jsmap", null); }
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); } }
public static void writeMenu( PrintWriter out, RequestProperties reqState, String menuID, boolean expandableMenu, boolean showIcon, int descriptionType, boolean showMenuHelp) throws IOException { PrivateLabel privLabel = reqState.getPrivateLabel(); Locale locale = reqState.getLocale(); String parentPageName = null; Account account = reqState.getCurrentAccount(); /* disable menu help if menu description is not displayed */ boolean showInline = false; if (descriptionType == ExpandMenu.DESC_NONE) { showMenuHelp = false; showInline = true; } /* sub style classes */ String topMenuID = !StringTools.isBlank(menuID) ? menuID : (expandableMenu ? "expandMenu" : "fixedMenu"); String groupClass = "menuGroup"; String leafClass = "itemLeaf"; String leafDescClass = "itemLeafDesc"; String helpClass = "itemLeafHelp"; String helpPadClass = "itemLeafHelpPad"; String leafIconClass = "itemLeafIcon"; /* start menu */ out.println("<ul id='" + topMenuID + "'>"); /* iterate through menu groups */ Map<String, MenuGroup> menuMap = privLabel.getMenuGroupMap(); for (String mgn : menuMap.keySet()) { MenuGroup mg = menuMap.get(mgn); if (!mg.showInTopMenu()) { // skip this group // Print.logInfo("Skipping menu group: %s", mgn); continue; } boolean didDisplayGroup = false; for (WebPage wp : mg.getWebPageList(reqState)) { String menuName = wp.getPageName(); String iconURI = showIcon ? wp.getMenuIconImage() : null; // may be blank/null String menuHelp = wp.getMenuHelp(reqState, parentPageName); String url = wp.encodePageURL(reqState); // , RequestProperties.TRACK_BASE_URI()); /* skip login page */ if (menuName.equalsIgnoreCase(Constants.PAGE_LOGIN)) { // omit login // Print.logInfo("Skipping login page: %s", menuName); continue; } /* skip sysAdmin pages */ if (wp.systemAdminOnly() && !Account.isSystemAdmin(account)) { continue; } /* skip pages that are not ok to display */ if (!wp.isOkToDisplay(reqState)) { continue; } /* menu description */ String menuDesc = null; switch (descriptionType) { case DESC_NONE: menuDesc = null; break; case DESC_SHORT: menuDesc = wp.getNavigationDescription(reqState); break; case DESC_LONG: default: menuDesc = wp.getMenuDescription(reqState, parentPageName); break; } /* skip this menu item? */ if (StringTools.isBlank(menuDesc) && StringTools.isBlank(iconURI)) { // Print.logWarn("Menu name has no description: %s", menuName); continue; } /* start menu group */ if (!didDisplayGroup) { // open Menu Group didDisplayGroup = true; out.write("<li class='" + groupClass + "'>" + mg.getTitle(locale) + "\n"); if (showInline) { out.write("<br><table cellpadding='0' cellspacing='0' border='0'><tr>\n"); } else { out.write("<ul>\n"); // <-- start menu sub group } } /* menu anchor/link */ String anchorStart = "<a"; if (!StringTools.isBlank(menuHelp)) { anchorStart += " title=\"" + menuHelp + "\""; } String target = StringTools.blankDefault(wp.getTarget(), "_self"); // ((WebPageURL)wp).getTarget(); if (target.startsWith("_")) { anchorStart += " href=\"" + url + "\""; anchorStart += " target=\"" + target + "\""; } else { PixelDimension pixDim = wp.getWindowDimension(); if (pixDim != null) { int W = pixDim.getWidth(); int H = pixDim.getHeight(); anchorStart += " onclick=\"javascript:openFixedWindow('" + url + "','" + target + "'," + W + "," + H + ")\""; anchorStart += " style=\"text-decoration: underline; color: blue; cursor: pointer;\""; } else { anchorStart += " href=\"" + url + "\""; anchorStart += " target=\"" + target + "\""; } } anchorStart += ">"; /* inline? */ if (showInline) { /* menu icon (will not be blank here) */ out.write("<td class='" + leafIconClass + "'>"); if (!StringTools.isBlank(iconURI)) { out.write( anchorStart + "<img class='" + leafIconClass + "' src='" + iconURI + "'/></a>"); } else { out.write(" "); } out.write("</td>"); } else { /* start menu list item */ out.write("<li class='" + leafClass + "'>"); /* special case for non-icons */ if (StringTools.isBlank(iconURI)) { /* menu description/help */ if (!StringTools.isBlank(menuDesc)) { out.write( "<span class='" + leafDescClass + "'>" + anchorStart + menuDesc + "</a></span>"); if (showMenuHelp && !StringTools.isBlank(menuHelp)) { out.write("<br>"); out.write("<span class='" + helpPadClass + "'>" + menuHelp + "</span>"); } } } else { // this section may not appear as expected on IE /* start table */ out.write("<table class='" + leafClass + "' cellpadding='0' cellspacing='0'>"); out.write("<tr>"); /* menu icon */ if (!StringTools.isBlank(iconURI)) { out.write("<td class='" + leafIconClass + "'>"); out.write( anchorStart + "<img class='" + leafIconClass + "' src='" + iconURI + "'/></a>"); out.write("</td>"); } /* menu description/help */ if (!StringTools.isBlank(menuDesc)) { out.write("<td class='" + leafDescClass + "'>"); out.write( "<span class='" + leafDescClass + "'>" + anchorStart + menuDesc + "</a></span>"); if (showMenuHelp && !StringTools.isBlank(menuHelp)) { out.write("<br>"); out.write("<span class='" + helpClass + "'>" + menuHelp + "</span>"); } out.write("</td>"); } /* end table */ out.write("</tr>"); out.write("</table>"); } /* end menu list item */ out.write("</li>\n"); } } /* end menu group */ if (didDisplayGroup) { if (showInline) { out.write("</tr></table>\n"); } else { out.write("</ul>\n"); } out.write("</li>\n"); } } /* end of menu */ out.write("</ul>\n"); /* init menu if expandable */ if (expandableMenu) { out.write( "<script type=\"text/javascript\"> new ExpandMenu('" + topMenuID + "'); </script>\n"); } }
/** Writes all bank account transactions within the date range */ private void writeBankTransactions() { for (Transaction transaction : account.getTransactions(startDate, endDate)) { writeBankTransaction(transaction); } }