Search in sources :

Example 6 with Transaction

use of model.banking.Transaction 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 7 with Transaction

use of model.banking.Transaction 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 8 with Transaction

use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.

the class TransactionAPI method createTransaction.

/**
 * Create transaction.
 *
 * @param amount          the amount
 * @param sourceIban      the source IBAN (NOT ACCOUNT NUMBER)
 * @param destinationIban the destination IBAN (NOT ACCOUNT NUMBER)
 * @param valueDate       the value date
 * @param description     the description
 * @param payee           the payee
 * @param remitter        the remitter
 * @return the transaction
 */
public static Transaction createTransaction(Number amount, String sourceIban, String destinationIban, String valueDate, String description, String payee, String remitter) {
    Transaction newTransaction = new Transaction();
    newTransaction.setAmount(amount);
    newTransaction.setSourceAccount(sourceIban);
    newTransaction.setDestinationAccount(destinationIban);
    newTransaction.setValueDate(valueDate);
    newTransaction.setDescription(description);
    newTransaction.setPayee(payee);
    newTransaction.setRemitter(remitter);
    return createTransaction(newTransaction);
}
Also used : Transaction(model.banking.Transaction)

Example 9 with Transaction

use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.

the class TransactionAPI method getTransactions.

/**
 * Get all transactions for the given account.
 *
 * @param accountNumber Account number
 * @return Collection of Cards
 * @throws HttpClientErrorException
 */
private static Collection<Transaction> getTransactions(String accountNumber) throws HttpClientErrorException {
    // TODO: Create a generic method for getting embedded JSON-HAL collections (in BankingRESTClient)
    Traverson traverson = null;
    String uri = BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V2 + "/accounts/" + accountNumber + "/transactions";
    log.info("URI: " + uri);
    try {
        traverson = new Traverson(new URI(uri), MediaTypes.HAL_JSON);
    } catch (URISyntaxException e) {
        log.error("getTransactionsForAccount failed", e);
        return null;
    }
    ParameterizedTypeReference<Resources<Transaction>> typeRefDevices = new ParameterizedTypeReference<Resources<Transaction>>() {
    };
    Resources<Transaction> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
    return resResponses.getContent();
}
Also used : Transaction(model.banking.Transaction) Traverson(org.springframework.hateoas.client.Traverson) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) URISyntaxException(java.net.URISyntaxException) Resources(org.springframework.hateoas.Resources) URI(java.net.URI)

Example 10 with Transaction

use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.

the class BankAccountService method getNextTransaction.

/**
 * returns a response with the next transaction in the list
 *
 * @param i index at the current postion in the transaction list
 * @return speechletResponse
 */
private SpeechletResponse getNextTransaction(int i) {
    List<Transaction> transactions = TransactionAPI.getTransactionsForAccount(account.getNumber());
    String transactionText = Transaction.getTransactionText(transactions.get(i));
    if (i - 1 < transactions.size()) {
        transactionText = transactionText + Transaction.getAskMoreTransactionText();
        SessionStorage sessionStorage = SessionStorage.getInstance();
        sessionStorage.putObject(sessionID, CONTEXT_FURTHER_TRANSACTION_INDEX, i + 1);
    }
    return getSSMLAskResponse(CARD_NAME, transactionText, REPROMPT_TEXT);
}
Also used : Transaction(model.banking.Transaction) SessionStorage(amosalexa.SessionStorage)

Aggregations

Transaction (model.banking.Transaction)15 TransactionDB (model.db.TransactionDB)4 Test (org.junit.Test)3 SessionStorage (amosalexa.SessionStorage)2 Contact (model.db.Contact)2 DynamoDbMapper (api.aws.DynamoDbMapper)1 Slot (com.amazon.speech.slu.Slot)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Account (model.banking.Account)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 Ignore (org.junit.Ignore)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 Resources (org.springframework.hateoas.Resources)1 Traverson (org.springframework.hateoas.client.Traverson)1