Search in sources :

Example 11 with Transaction

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

the class ContactTransferService method performTransfer.

/**
 * Performs the transfer.
 */
private SpeechletResponse performTransfer(Intent intent, Session session) {
    Object contactsFoundObj = SESSION_STORAGE.getObject(session.getSessionId(), SESSION_PREFIX + ".contactsFound");
    if (contactsFoundObj == null || !(contactsFoundObj instanceof List)) {
        return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
    }
    Object choiceObj = session.getAttribute(SESSION_PREFIX + ".choice");
    if (choiceObj == null || !(choiceObj instanceof Integer)) {
        return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
    }
    Object amountObj = session.getAttribute(SESSION_PREFIX + ".amount");
    if (amountObj == null || !(amountObj instanceof Double || amountObj instanceof Integer)) {
        return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
    }
    Contact contact = ((List<Contact>) contactsFoundObj).get((int) choiceObj - 1);
    double amount;
    if (amountObj instanceof Double) {
        amount = (double) amountObj;
    } else {
        amount = (int) amountObj;
    }
    DateTimeFormatter apiTransactionFmt = DateTimeFormat.forPattern("yyyy-MM-dd");
    String valueDate = DateTime.now().toString(apiTransactionFmt);
    Transaction transaction = TransactionAPI.createTransaction((int) amount, /*"DE50100000000000000001"*/
    AmosAlexaSpeechlet.ACCOUNT_IBAN, contact.getIban(), valueDate, "Beschreibung", "Hans", null);
    Account account = AccountAPI.getAccount(ACCOUNT_NUMBER);
    String balanceAfterTransaction = String.valueOf(account.getBalance());
    // save transaction id to save in db
    session.setAttribute(TRANSACTION_ID_ATTRIBUTE, transaction.getTransactionId().toString());
    // add category ask to success response
    String categoryAsk = "Zu welcher Kategorie soll die Transaktion hinzugefügt werden. Sag zum Beispiel Kategorie " + Category.categoryListText();
    return getAskResponse(CONTACT_TRANSFER_CARD, "Erfolgreich. " + amount + " Euro wurden an " + contact.getName() + " überwiesen. Dein neuer Kontostand beträgt " + balanceAfterTransaction + " Euro. " + categoryAsk);
}
Also used : Account(model.banking.Account) Transaction(model.banking.Transaction) LinkedList(java.util.LinkedList) List(java.util.List) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Contact(model.db.Contact)

Example 12 with Transaction

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

Example 13 with Transaction

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

the class TransactionAPI method getTransactionForAccount.

public static Transaction getTransactionForAccount(String accountNumber, String transactionId) {
    // Search for transaction
    // TODO this is only a temporary solution
    // TODO wait for API extension to get transaction detail request call /transactions/{transactionId}
    List<Transaction> allTransactions = getTransactionsForAccount(accountNumber);
    Number transactionNumber = Integer.valueOf(transactionId);
    Transaction transaction = null;
    for (Transaction t : allTransactions) {
        if (transactionNumber.equals(t.getTransactionId())) {
            transaction = t;
        }
    }
    return transaction;
}
Also used : Transaction(model.banking.Transaction)

Example 14 with Transaction

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

the class AmosAlexaSimpleTestImpl method contactTest.

@Test
public void contactTest() throws IllegalAccessException, NoSuchFieldException, IOException {
    newSession();
    // Get today´s date in the right format
    Date now = new Date();
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String todayDate = formatter.format(now);
    // Create a transaction that we can use for ContactAddIntent (ingoing transaction)
    Transaction transaction = TransactionAPI.createTransaction(1, AmosAlexaSpeechlet.ACCOUNT_IBAN, /*"DE60100000000000000001"*/
    "DE50100000000000000001", todayDate, "Ueberweisung fuer Unit Test", null, "Sandra");
    /*
        int transactionId1 = 18877; //transaction.getTransactionId().intValue();
        int transactionId2 = 6328; //transaction without remitter or payee
        int transactionId3 = 23432423; //transaction not existent
*/
    int transactionId1 = transaction.getTransactionId().intValue();
    // int transactionId2 = 6328; //transaction without remitter or payee
    // transaction not existent
    int transactionId3 = 23432423;
    // for transactionId1 //transaction.getRemitter();
    String transactionRemitter = "Sandra";
    // Test add contact no transaction number given
    testIntent("ContactAddIntent", "TransactionNumber: ", "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe.");
    // Test add contact successful
    testIntent("ContactAddIntent", "TransactionNumber:" + transactionId1, "Moechtest du " + transactionRemitter + " als " + "Kontakt speichern?");
    testIntent("AMAZON.YesIntent", "Okay! Der Kontakt Sandra wurde angelegt.");
    // Test add contact unknown payee/remitter
    /*
        testIntent(
                "ContactAddIntent",
                "TransactionNumber:" + transactionId2, "Ich kann fuer diese Transaktion keine Kontaktdaten speichern, weil der Name des Auftraggebers" +
                        " nicht bekannt ist. Bitte wiederhole deine Eingabe oder breche ab, indem du \"Alexa, Stop!\" sagst.");
*/
    // Test add contact transaction not existent
    testIntent("ContactAddIntent", "TransactionNumber:" + transactionId3, "Ich habe keine Transaktion mit dieser Nummer gefunden." + " Bitte wiederhole deine Eingabe.");
    // Get the contact that we just created by searching for the contact with highest id
    List<Contact> allContacts = DynamoDbMapper.getInstance().loadAll(Contact.class);
    final Comparator<Contact> comp2 = Comparator.comparingInt(c -> c.getId());
    Contact latestContact = allContacts.stream().max(comp2).get();
    LOGGER.info("Contact: " + latestContact.getName());
    String latestContactId = String.valueOf(latestContact.getId());
    // Test contact list
    testIntentMatches("ContactListInfoIntent", "Kontakt \\d+: Name: (.*), IBAN: (.*).(.*)");
    // Test delete contact. Therefore delete the contact that we just created.
    testIntent("ContactDeleteIntent", "ContactID:" + latestContactId, "Moechtest du Kontakt Nummer " + latestContactId + " wirklich " + "loeschen?");
    testIntent("AMAZON.YesIntent", "Kontakt wurde geloescht.");
}
Also used : Transaction(model.banking.Transaction) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Contact(model.db.Contact) Test(org.junit.Test)

Example 15 with Transaction

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

the class BankAccountService method handleTransactionSpeech.

/**
 * responses each transaction from a account
 *
 * @return SpeechletResponse to alexa
 */
private SpeechletResponse handleTransactionSpeech() {
    List<Transaction> transactions = TransactionAPI.getTransactionsForAccount(account.getNumber());
    if (transactions == null || transactions.isEmpty()) {
        LOGGER.warn("Account: " + account.getNumber() + " has no transactions");
        return getResponse(CARD_NAME, EMPTY_TRANSACTIONS_TEXT);
    }
    StringBuilder stringBuilder = new StringBuilder(Transaction.getTransactionSizeText(transactions.size()));
    int i;
    for (i = 0; i < TRANSACTION_LIMIT; i++) {
        stringBuilder.append(Transaction.getTransactionText(transactions.get(i)));
    }
    if (i - 1 < transactions.size()) {
        stringBuilder.append(Transaction.getAskMoreTransactionText());
        SessionStorage sessionStorage = SessionStorage.getInstance();
        sessionStorage.putObject(sessionID, CONTEXT_FURTHER_TRANSACTION_INDEX, i);
    } else {
        return getResponse(CARD_NAME, LIST_END_TRANSACTIONS_TEXT);
    }
    return getSSMLAskResponse(CARD_NAME, stringBuilder.toString(), 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