private void transfer(final Date date, final Account account1, final Account account2) { persistence.runInTransaction( em -> { BigDecimal amount1 = randomExpenseAmount(account1, date, 0.5); if (BigDecimal.ZERO.compareTo(amount1) >= 0) return; BigDecimal amount2 = transferAmount(account1, account2, amount1); Operation operation = metadata.create(Operation.class); operation.setOpType(OperationType.TRANSFER); operation.setOpDate(date); operation.setAcc1(account1); operation.setAmount1(amount1); operation.setAcc2(account2); operation.setAmount2(amount2); em.persist(operation); log.info( "Transfer: " + date + ", " + account1.getName() + ", " + amount1 + ", " + account2.getName() + ", " + amount2); }); }
/** * Deliveres notification to the user that an email has been dropped. Typically due to size * restriction * * @param account * @param messageNumber * @param message * @throws Exception */ public void saveMessageDroppedNotification( Account account, int messageNumber, Message message, int reportedSize) throws Exception { MessageParser parser = new MessageParser(); Email email = new Email(); email.setSubject( "Your email"); // ReceiverUtilsTools.subSubject(parser.parseMsgSubject(message), // subjectSize)); email.setFrom(parser.parseMsgAddress(message, "FROM", false)); email.setTo(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "TO", true))); email.setCc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "CC", true))); email.setBcc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "BCC", true))); email.setMaildate(ReceiverUtilsTools.dateToStr(message.getSentDate())); email.setStatus("0"); email.setUserId(account.getUser_id()); email.setMessage_type("EMAIL"); Body body = new Body(); String droppedMessage = getEmailDroppedMessage(account, getMessageDate(message), reportedSize, email.getFrom()); body.setData(droppedMessage.getBytes()); email.setBodySize(droppedMessage.length()); int saveStatus = DALDominator.newSaveMail(account, email, body); if (log.isDebugEnabled()) log.debug( String.format( "[%s] msgNum=%d, saving completed for dropped message with status %s", account.getName(), messageNumber, saveStatus)); }
public void updateProfile(String key, Account pAccount) throws SQLException, ConnectionException, MissingDataException, NullAccountException, ProfileException, PasswordException, EmailException { try (Connection connect = DBConnection.getConnection()) { pAccount = testAccount(pAccount); String sql = "UPDATE account" + "set name = '" + Utility.Replace(testProfileData(pAccount.getName())) + "', surname = '" + Utility.Replace(testProfileData(pAccount.getSurname())) + "', password = '******', secondaryEmail = '" + testEmail(pAccount.getSecondaryEmail()) + "WHERE email = '" + key + "'"; String sql2 = "UPDATE " + pAccount.getTypeAccount(); if (pAccount instanceof PhdStudent) { sql2 += " set telephone = '" + testProfileData(((PhdStudent) pAccount).getTelephone()) + "', link = '" + testProfileData(((PhdStudent) pAccount).getLink()) + "', deparment = '" + testProfileData(((PhdStudent) pAccount).getDepartment()) + "', researchInterest = '" + testProfileData(((PhdStudent) pAccount).getResearchInterest()) + "' WHERE fkAccount = '" + testProfileData(((PhdStudent) pAccount).getSecondaryEmail()); } if (pAccount instanceof Professor) { sql2 += " set link = '" + ((Professor) pAccount).getLink() + "', set department = '" + ((Professor) pAccount).getDepartment() + "' WHERE fkAccount = '" + ((Professor) pAccount).getSecondaryEmail() + "'"; } if (pAccount.getTypeAccount().equals("basic")) // aggiorna solo info base Utility.executeOperation(connect, sql); else { Utility.executeOperation(connect, sql); Utility.executeOperation(connect, sql2); } connect.commit(); } }
/** * It so happens Gmail sends us sent messages as well as received once * * @param account * @param message * @return * @throws Exception */ protected boolean isSentMessage(Account account, Message message) throws Exception { MessageParser parser = new MessageParser(); if (EmailUtil.isFromSameAsAccount(account, message)) { String to = parser.parseMsgAddress(message, "TO", true); String cc = parser.parseMsgAddress(message, "CC", true); if (!to.contains(account.getName()) && !cc.contains(account.getName())) { log.warn( String.format( "msgNum=%d, message is 'sent' not 'received' discarding, for %s", message.getMessageNumber(), account.getName())); return true; } } return false; }
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); } }
private void income( final Date date, final Account account, final Category category, final BigDecimal amount) { persistence.runInTransaction( em -> { Operation operation = metadata.create(Operation.class); operation.setOpType(OperationType.INCOME); operation.setOpDate(date); operation.setAcc2(account); operation.setCategory(category); operation.setAmount2(amount); em.persist(operation); log.info("Income: " + date + ", " + account.getName() + ", " + amount); }); }
boolean isMessageTooBig(Folder folder, Account account, Message message, int messageNumber) throws Exception { int messageSize = (folder instanceof POP3Folder) ? ((POP3Folder) folder).getMessageSize(messageNumber) : getMessageSize(message, account); boolean messageTooBig = messageSize > maximumMessageSize; if (messageTooBig) { log.warn( String.format( "msgNum=%d, message is too big %d bytes, discarding for %s", messageNumber, messageSize, account.getName())); saveMessageDroppedNotification(account, messageNumber, message, messageSize); } return messageTooBig; }
private void expense(final Date date, final Account account, final Context context) { persistence.runInTransaction( em -> { int categoryIdx = (int) Math.round(Math.random() * (context.expenseCategories.size() - 1)); Category category = context.expenseCategories.get(categoryIdx); if (category == null) return; int categoryWeight = context.expenseCategories.size() - categoryIdx; BigDecimal amount = randomExpenseAmount(account, date, 0.1 + (categoryWeight * 0.05)); if (BigDecimal.ZERO.compareTo(amount) >= 0) return; Operation operation = metadata.create(Operation.class); operation.setOpType(OperationType.EXPENSE); operation.setOpDate(date); operation.setAcc1(account); operation.setCategory(category); operation.setAmount1(amount); em.persist(operation); log.info("Expense: " + date + ", " + account.getName() + ", " + amount); }); }