/** * Transaction menu. * * @param service authenticated client connection to a Finance GData service * @param sc Scanner to read user input from the command line. * @throws IOException If there is a problem communicating with the server. * @throws ServiceException If the service is unable to handle the request. */ private static void transactionMenu(FinanceService service, Scanner sc) throws IOException, ServiceException { printTransactionMenuHelp(); while (true) { String requestUrl = baseUrl + PORTFOLIO_FEED_URL_SUFFIX + "/"; switch (processTransactionMenuCommand(sc.nextLine().toLowerCase())) { case QUERY_FEED: System.out.println("Enter portfolio ID"); portfolioIdProperty = sc.nextLine(); System.out.println("Enter ticker (<exchange>:<symbol>)"); tickerProperty = sc.nextLine(); requestUrl += portfolioIdProperty + POSITION_FEED_URL_SUFFIX + "/" + tickerProperty + TRANSACTION_FEED_URL_SUFFIX; queryTransactionFeed(service, requestUrl); break; case QUERY_ENTRY: System.out.println("Enter portfolio ID"); portfolioIdProperty = sc.nextLine(); System.out.println("Enter ticker (<exchange>:<ticker>)"); tickerProperty = sc.nextLine(); System.out.println("Enter transaction ID"); transactionIdProperty = sc.nextLine(); requestUrl += portfolioIdProperty + POSITION_FEED_URL_SUFFIX + "/" + tickerProperty + TRANSACTION_FEED_URL_SUFFIX + "/" + transactionIdProperty; queryTransactionEntry(service, requestUrl); break; case CREATE: System.out.println("Enter portfolio ID"); portfolioIdProperty = sc.nextLine(); System.out.println("Enter ticker (<exchange>:<ticker>) "); tickerProperty = sc.nextLine(); requestUrl += portfolioIdProperty + POSITION_FEED_URL_SUFFIX + "/" + tickerProperty + TRANSACTION_FEED_URL_SUFFIX; System.out.print("Enter transaction type (Buy, Sell, Sell Short, Buy to Cover): "); String type = sc.nextLine(); System.out.print("Enter transaction date (yyyy-mm-dd or blank): "); String date = sc.nextLine(); System.out.print("Enter number of shares (optional, e.g. 100.0): "); String shares = sc.nextLine(); System.out.print("Enter price (optional, e.g. 141.14): "); String price = sc.nextLine(); System.out.print("Enter commission (optional, e.g. 20.0): "); String commission = sc.nextLine(); System.out.print("Enter currency (optional, e.g. USD, EUR, JPY): "); String currency = sc.nextLine(); System.out.print("Enter any notes: "); String notes = sc.nextLine(); TransactionEntry entry = FinanceUtilities.makeTransactionEntry( type, date, shares, price, commission, currency, notes); insertTransactionEntry(service, requestUrl, entry); break; case UPDATE: System.out.println("Enter portfolio ID"); portfolioIdProperty = sc.nextLine(); System.out.println("Enter ticker (<exchange>:<ticker>) "); tickerProperty = sc.nextLine(); System.out.println("Enter transaction ID"); transactionIdProperty = sc.nextLine(); requestUrl += portfolioIdProperty + POSITION_FEED_URL_SUFFIX + "/" + tickerProperty + TRANSACTION_FEED_URL_SUFFIX + "/" + transactionIdProperty; System.out.print("Enter transaction type (Buy, Sell, Sell Short, Buy to Cover): "); type = sc.nextLine(); System.out.print("Enter transaction date (yyyy-mm-dd or blank): "); date = sc.nextLine(); System.out.print("Enter number of shares (optional, e.g. 100.0): "); shares = sc.nextLine(); System.out.print("Enter price (optional, e.g. 141.14): "); price = sc.nextLine(); System.out.print("Enter commission (optional, e.g. 20.0): "); commission = sc.nextLine(); System.out.print("Enter currency (optional, e.g. USD, EUR, JPY): "); currency = sc.nextLine(); System.out.print("Enter any notes: "); notes = sc.nextLine(); entry = FinanceUtilities.makeTransactionEntry( type, date, shares, price, commission, currency, notes); updateTransactionEntry(service, requestUrl, entry); break; case DELETE: System.out.println("Enter portfolio ID"); portfolioIdProperty = sc.nextLine(); System.out.println("Enter ticker (<exchange>:<ticker>)"); tickerProperty = sc.nextLine(); System.out.println("Enter transaction ID"); transactionIdProperty = sc.nextLine(); requestUrl += portfolioIdProperty + POSITION_FEED_URL_SUFFIX + "/" + tickerProperty + TRANSACTION_FEED_URL_SUFFIX + "/" + transactionIdProperty; deleteTransactionEntry(service, requestUrl); break; case BACK: return; case QUIT: System.exit(0); case HELP: printTransactionMenuHelp(); break; default: printTransactionMenuHelp(); } } }