Search in sources :

Example 1 with TransactionDB

use of model.db.TransactionDB in project amos-ss17-alexa by c-i-ber.

the class Transaction method getPeriodicTransactions.

/**
 * gets all periodic transaction from DB/API
 * @param accountNumber account number
 * @return List of all periodic transactions
 */
public static List<Transaction> getPeriodicTransactions(String accountNumber) {
    ArrayList<Transaction> periodicTransactions = new ArrayList<>();
    DynamoDbMapper dynamoDbMapper = DynamoDbMapper.getInstance();
    List<TransactionDB> transactionsDB = dynamoDbMapper.loadAll(TransactionDB.class);
    for (TransactionDB transactionDB : transactionsDB) {
        if (transactionDB.isPeriodic() && transactionDB.getAccountNumber().equals(accountNumber)) {
            Transaction transaction = getCachedTransactionForAccount(accountNumber, transactionDB.getTransactionId());
            periodicTransactions.add(transaction);
        }
    }
    return periodicTransactions;
}
Also used : DynamoDbMapper(api.aws.DynamoDbMapper) ArrayList(java.util.ArrayList) TransactionDB(model.db.TransactionDB)

Example 2 with TransactionDB

use of model.db.TransactionDB in project amos-ss17-alexa by c-i-ber.

the class TransactionTest method createPeriodicTransactionTest.

@Ignore
public void createPeriodicTransactionTest() {
    DynamoDbMapper dynamoDbMapper = DynamoDbMapper.getInstance();
    String source = AccountAPI.getAccount(AccountData.ACCOUNT_DEFAULT).getIban();
    String destination = AccountAPI.getAccount(AccountData.ACCOUNT_DEFAULT_2).getIban();
    // create sample transactions
    String date = new DateTime(2017, 8, 14, 12, 0).toLocalDate().toString();
    Transaction transaction = TransactionAPI.createTransaction(10, source, destination, date, "Netflix", "Netflix", "Peter Müller");
    TransactionDB tDB1 = new TransactionDB(transaction.getTransactionId().toString(), "", AccountData.ACCOUNT_DEFAULT);
    tDB1.setPeriodic(true);
    dynamoDbMapper.save(tDB1);
}
Also used : DynamoDbMapper(api.aws.DynamoDbMapper) Transaction(model.banking.Transaction) TransactionDB(model.db.TransactionDB) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore)

Example 3 with TransactionDB

use of model.db.TransactionDB in project amos-ss17-alexa by c-i-ber.

the class PeriodicTransactionService method listPeriodicTransactions.

private SpeechletResponse listPeriodicTransactions(Session session) {
    List<TransactionDB> allTransactionsDb = dynamoDbMapper.loadAll(TransactionDB.class);
    List<TransactionDB> transactionsDb = new ArrayList<>();
    for (TransactionDB transactionDb : allTransactionsDb) {
        if (transactionDb.getAccountNumber().equals(ACCOUNT_NUMBER))
            transactionsDb.add(transactionDb);
    }
    transactionsDb = transactionsDb.stream().filter(t -> t.isPeriodic()).collect(Collectors.toList());
    LOGGER.info("TransactionsDB: " + transactionsDb);
    if (transactionsDb == null || transactionsDb.isEmpty()) {
        LOGGER.warn("No periodic transactions have been found.");
        return getResponse(PERIODIC_TRANSACTION, "Du hast momentan keine Transaktionen als periodisch markiert.");
    }
    StringBuilder stringBuilder = new StringBuilder(Transaction.getTransactionSizeText(transactionsDb.size()));
    int i;
    for (i = 0; i < TRANSACTION_LIMIT; i++) {
        if (i < transactionsDb.size()) {
            Transaction transaction = TransactionAPI.getTransactionForAccount(ACCOUNT_NUMBER, transactionsDb.get(i).getTransactionId());
            LOGGER.info("TRANSACTION: " + transaction);
            stringBuilder.append(Transaction.getTransactionText(transaction));
        } else {
            break;
        }
    }
    if (i - 1 < transactionsDb.size()) {
        stringBuilder.append(Transaction.getAskMoreTransactionText());
        session.setAttribute(NEXT_TRANSACTION_KEY, i);
    } else {
        return getResponse(PERIODIC_TRANSACTION, "Das waren alle periodischen Transaktionen.");
    }
    return getSSMLAskResponse(PERIODIC_TRANSACTION, stringBuilder.toString());
}
Also used : Transaction(model.banking.Transaction) TransactionDB(model.db.TransactionDB)

Example 4 with TransactionDB

use of model.db.TransactionDB in project amos-ss17-alexa by c-i-ber.

the class PeriodicTransactionService method savePeriodicTransaction.

private SpeechletResponse savePeriodicTransaction(Intent intent, Session session, boolean confirmed) {
    if (!confirmed) {
        if (intent.getSlot(TRANSACTION_NUMBER_KEY) == null || StringUtils.isBlank(intent.getSlot(TRANSACTION_NUMBER_KEY).getValue())) {
            session.getAttributes().clear();
            return getAskResponse(PERIODIC_TRANSACTION, "Das habe ich nicht verstanden. Bitte wiederhole deine Eingabe.");
        } else {
            String transactionId = intent.getSlot(TRANSACTION_NUMBER_KEY).getValue();
            // Search for transaction
            // TODO wait for API extension to get transaction detail request call
            Transaction transaction = TransactionAPI.getTransactionForAccount("8888888888", transactionId);
            LOGGER.info("Found transaction: " + transaction);
            if (transaction == null) {
                session.getAttributes().clear();
                return getAskResponse(PERIODIC_TRANSACTION, "Ich kann Transaktion Nummer " + transactionId + " nicht finden." + " Bitte aendere deine Eingabe.");
            }
            session.setAttribute(TRANSACTION_NUMBER_KEY, transactionId);
            return getAskResponse(PERIODIC_TRANSACTION, "Moechtest du die Transaktion mit der Nummer " + transactionId + " wirklich als periodisch markieren?");
        }
    } else {
        String transactionId = (String) session.getAttribute(TRANSACTION_NUMBER_KEY);
        if (transactionId != null) {
            TransactionDB transactionDb = (TransactionDB) dynamoDbMapper.load(TransactionDB.class, transactionId);
            LOGGER.info("TransactionDb: " + transactionDb);
            if (transactionDb == null) {
                transactionDb = new TransactionDB(transactionId);
                transactionDb.setPeriodic(true);
                transactionDb.setAccountNumber(ACCOUNT_NUMBER);
            }
            dynamoDbMapper.save(transactionDb);
            List<TransactionDB> allDbts = dynamoDbMapper.loadAll(TransactionDB.class);
            LOGGER.info("AllDBTransactions: " + allDbts);
            return getResponse(PERIODIC_TRANSACTION, "Transaktion Nummer " + transactionId + " wurde als periodisch markiert.");
        }
    }
    return null;
}
Also used : Transaction(model.banking.Transaction) TransactionDB(model.db.TransactionDB)

Example 5 with TransactionDB

use of model.db.TransactionDB in project amos-ss17-alexa by c-i-ber.

the class BudgetManager method getTransactionAmount.

private double getTransactionAmount(String categoryId, DateTime start, DateTime end) {
    double sum = 0;
    Collection<Transaction> apiTransactions = TransactionAPI.getTransactionsForAccount(AmosAlexaSpeechlet.ACCOUNT_ID);
    List<TransactionDB> dbTransactions = dynamoDbMapper.loadAll(TransactionDB.class);
    for (TransactionDB transactionDB : dbTransactions) {
        if (transactionDB.getCategoryId() == null || !transactionDB.getCategoryId().equals(categoryId)) {
            continue;
        }
        for (Transaction transaction : apiTransactions) {
            if (transactionDB.getTransactionId().equals(transaction.getTransactionId().toString())) {
                if (transaction.getValueDateAsDateTime().isAfter(start) && transaction.getValueDateAsDateTime().isBefore(end)) {
                    sum += Math.abs(transaction.getAmount().doubleValue());
                }
            }
        }
    }
    return sum;
}
Also used : Transaction(model.banking.Transaction) TransactionDB(model.db.TransactionDB)

Aggregations

TransactionDB (model.db.TransactionDB)7 Transaction (model.banking.Transaction)4 DynamoDbMapper (api.aws.DynamoDbMapper)2 ArrayList (java.util.ArrayList)1 Category (model.db.Category)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1