Search in sources :

Example 1 with Transaction

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

the class TransactionTest method getTransactions.

@Test
public void getTransactions() {
    Collection<Transaction> transactions = TransactionAPI.getTransactionsForAccount(ACCOUNT_NUMBER1);
    System.out.println(AccountAPI.getAccount(ACCOUNT_NUMBER1).getIban());
    List<Transaction> txs = new ArrayList<>(transactions);
    Collections.reverse(txs);
    for (Transaction transaction : txs) {
        System.out.println("ID: " + transaction.getTransactionId());
        System.out.println("Source: " + transaction.getSourceAccount());
        System.out.println("Destination: " + transaction.getDestinationAccount());
        System.out.println("Date: " + transaction.getValueDate());
    }
}
Also used : Transaction(model.banking.Transaction) Test(org.junit.Test)

Example 2 with Transaction

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

the class TransactionTest method testAndGetTransaction.

@Test
public void testAndGetTransaction() {
    Transaction newTransaction = TransactionAPI.createTransaction(1, ACCOUNT_IBAN1, ACCOUNT_IBAN2, VALUE_DATE, "TestDescription", "Hans", "Helga");
    assertEquals(1, newTransaction.getValue());
    assertEquals(ACCOUNT_IBAN1, newTransaction.getSourceAccount());
    assertEquals(ACCOUNT_IBAN2, newTransaction.getDestinationAccount());
    assertEquals(VALUE_DATE, newTransaction.getValueDate());
    assertEquals("TestDescription", newTransaction.getDescription());
    Collection<Transaction> transactions = TransactionAPI.getTransactionsForAccount(ACCOUNT_NUMBER1);
    boolean foundTransaction = false;
    log.info("Found transactions: " + transactions.size());
    for (Transaction transaction : transactions) {
        if (transaction.getTransactionId().equals(newTransaction.getTransactionId())) {
            foundTransaction = true;
            break;
        }
    }
    assertTrue(foundTransaction);
}
Also used : Transaction(model.banking.Transaction) Test(org.junit.Test)

Example 3 with Transaction

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

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

the class ContactService method askForNewContactConfirmation.

private SpeechletResponse askForNewContactConfirmation(Intent intent, Session session) {
    Map<String, Slot> slots = intent.getSlots();
    Slot transactionNumberSlot = slots.get("TransactionNumber");
    if (transactionNumberSlot.getValue() == null || StringUtils.isBlank(transactionNumberSlot.getValue())) {
        String speechText = "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe.";
        session.getAttributes().clear();
        return getAskResponse(CONTACTS, speechText);
    }
    LOGGER.info("TransactionNumber: " + transactionNumberSlot.getValue());
    String speechText = "";
    List<Transaction> allTransactions = TransactionAPI.getTransactionsForAccount(AmosAlexaSpeechlet.ACCOUNT_ID);
    Number transactionNumber = Integer.valueOf(transactionNumberSlot.getValue());
    Transaction transaction = null;
    for (Transaction t : allTransactions) {
        if (transactionNumber.equals(t.getTransactionId())) {
            transaction = t;
        }
    }
    LOGGER.info("Found transaction: " + transaction);
    if (transaction == null) {
        speechText = "Ich habe keine Transaktion mit dieser Nummer gefunden. Bitte wiederhole deine Eingabe.";
        session.getAttributes().clear();
        return getAskResponse(CONTACTS, speechText);
    }
    LOGGER.info("Payee: " + transaction.getPayee());
    LOGGER.info("Remitter: " + transaction.getRemitter());
    String payee = transaction.getPayee();
    String remitter = transaction.getRemitter();
    String ibanRegex = ".*\\d+.*";
    if ((payee == null && remitter == null) || (transaction.isOutgoing() && payee.matches(ibanRegex)) || (!transaction.isOutgoing() && remitter.matches(ibanRegex))) {
        speechText = "Ich kann fuer diese Transaktion keine Kontaktdaten speichern, weil der Name des";
        speechText = speechText.concat(transaction.isOutgoing() ? " Zahlungsempfaengers" : " Auftraggebers");
        speechText = speechText.concat(" nicht bekannt ist. Bitte wiederhole deine Eingabe oder breche ab, indem du \"Alexa, Stop!\" sagst.");
        session.getAttributes().clear();
        return getAskResponse(CONTACTS, speechText);
    } else {
        // TODO improve
        // Actually asking for confirmation
        session.setAttribute("ContactName", transaction.isOutgoing() ? payee : remitter);
        speechText = "Moechtest du ";
        speechText = speechText.concat(transaction.isOutgoing() ? payee : remitter);
        speechText = speechText.concat(" als Kontakt speichern?");
    }
    return getAskResponse(CONTACTS, speechText);
}
Also used : Transaction(model.banking.Transaction) Slot(com.amazon.speech.slu.Slot)

Example 5 with Transaction

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

the class PeriodicTransactionService method markPeriodicTransactions.

private int markPeriodicTransactions() {
    List<Transaction> transactions = new ArrayList(TransactionAPI.getTransactionsForAccount(ACCOUNT_NUMBER));
    LOGGER.info("Size: " + transactions.size());
    Map<Number, Set<Transaction>> candidates = new HashMap<>();
    for (Transaction t : transactions) {
        LOGGER.info("Transaction: " + t);
        if (!candidates.containsKey(t.getAmount())) {
            LOGGER.info("Not contains");
            Set<Transaction> tList = new HashSet<>();
            tList.add(t);
            candidates.put(t.getAmount(), tList);
        } else {
            candidates.get(t.getAmount()).add(t);
        }
    }
    Iterator<Number> iter = candidates.keySet().iterator();
    while (iter.hasNext()) {
        Number key = iter.next();
        if (candidates.get(key).size() <= 1) {
            iter.remove();
        }
    }
    LOGGER.info("Candidates: " + candidates);
    return candidates.size();
}
Also used : Transaction(model.banking.Transaction)

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