Search in sources :

Example 6 with Contact

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

the class StandingOrderService method smartUpdateStandingOrderConfirmation.

/**
 * Creates a {@code SpeechletResponse} for the standing orders intent.
 *
 * @return SpeechletResponse spoken and visual response for the given intent
 */
private SpeechletResponse smartUpdateStandingOrderConfirmation(Intent intent, Session session) {
    LOGGER.info("SmartStandingOrders called.");
    Map<String, Slot> slots = intent.getSlots();
    Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
    standingOrders = new ArrayList<>(standingOrdersCollection);
    SimpleCard card = new SimpleCard();
    card.setTitle("Daueraufträge");
    Slot payeeSlot = slots.get("Payee");
    String payee = (payeeSlot == null ? null : payeeSlot.getValue());
    Slot payeeSecondNameSlot = slots.get("PayeeSecondName");
    String payeeSecondName = (payeeSecondNameSlot == null ? null : payeeSecondNameSlot.getValue());
    Slot amountSlot = slots.get("orderAmount");
    String amount = (amountSlot == null ? null : amountSlot.getValue());
    String payeeFullName;
    if (payee == null) {
        payeeFullName = payeeSecondName.toLowerCase();
    } else if (payeeSecondName == null) {
        payeeFullName = payee.toLowerCase();
    } else {
        payeeFullName = (payee + " " + payeeSecondName).toLowerCase();
    }
    LOGGER.info("full name: " + payeeFullName);
    session.setAttribute("NewAmount", amount);
    session.setAttribute("Payee", payee);
    session.setAttribute("PayeeSecondName", payeeSecondName);
    for (StandingOrder standingOrder : standingOrders) {
        String amountString = Integer.toString(standingOrder.getAmount().intValue());
        LOGGER.info(standingOrder.getPayee().toLowerCase() + ": " + payeeFullName);
        if (standingOrder.getPayee().toLowerCase().equals(payeeFullName)) {
            // getting data object
            DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
            Date executionDate;
            try {
                executionDate = dateFormat.parse(standingOrder.getFirstExecution());
            } catch (java.text.ParseException e) {
                e.printStackTrace();
            }
            // Create the plain text output
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
            speech.setText("Der Dauerauftrag für " + payeeFullName + " über " + standingOrder.getAmount() + " Euro existiert schon. Möchtest du diesen aktualisieren");
            session.setAttribute("StandingOrderToModify", standingOrder.getStandingOrderId());
            // Create reprompt
            Reprompt reprompt = new Reprompt();
            reprompt.setOutputSpeech(speech);
            return SpeechletResponse.newAskResponse(speech, reprompt);
        }
    }
    // creating a new stating order if its in contact list
    List<Contact> contactList = DynamoDbMapper.getInstance().loadAll(Contact.class);
    List<Contact> contacts = new ArrayList<>(contactList);
    for (int i = 0; i < contacts.size(); i++) {
        LOGGER.info(contacts.get(i).getName().toString().toLowerCase());
        if (contacts.get(i).getName().toString().toLowerCase().equals(payeeFullName)) {
            StandingOrder standingOrder = new StandingOrder();
            standingOrder.setPayee(payeeFullName);
            standingOrder.setAmount(Integer.parseInt(amount));
            standingOrder.setDestinationAccount(contacts.get(i).getIban());
            standingOrder.setFirstExecution("09-09-2017");
            standingOrder.setDestinationAccount("DE39100000007777777777");
            AccountAPI.createStandingOrderForAccount(ACCOUNT_NUMBER, standingOrder);
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
            speech.setText("Ich habe den neuen Dauerauftrag für" + payeeFullName + " über " + amount + " Euro erfolgreich eingerichtet");
            // deleting attributes
            session.removeAttribute("NewAmount");
            session.removeAttribute("Payee");
            session.removeAttribute("PayeeSecondName");
            return SpeechletResponse.newTellResponse(speech, card);
        }
    }
    // Contact not found
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("Ich habe " + payeeFullName + " in deiner Kontaktliste nicht gefunden. " + "Du musst ihm erst in der Kontaktliste hinzufügen");
    // deleting attributes
    session.removeAttribute("NewAmount");
    session.removeAttribute("Payee");
    session.removeAttribute("PayeeSecondName");
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : StandingOrder(model.banking.StandingOrder) Contact(model.db.Contact) SimpleCard(com.amazon.speech.ui.SimpleCard) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Reprompt(com.amazon.speech.ui.Reprompt) Slot(com.amazon.speech.slu.Slot) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with Contact

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

the class ContactService method createNewContact.

private SpeechletResponse createNewContact(Session session) {
    // Acutally create and save contact
    String contactName = (String) session.getAttribute("ContactName");
    Contact contact = new Contact(contactName, "DE50100000000000000001");
    DynamoDbMapper.getInstance().save(contact);
    return getResponse(CONTACTS, "Okay! Der Kontakt " + contactName + " wurde angelegt.");
}
Also used : Contact(model.db.Contact)

Example 8 with Contact

use of model.db.Contact 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 9 with Contact

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

the class ContactTest method createAndDeleteContact.

@Test
public void createAndDeleteContact() {
    Contact contact = new Contact("Lucas", "DE12345678901234");
    DynamoDbMapper.getInstance().save(contact);
    List<Contact> contacts = DynamoDbMapper.getInstance().loadAll(Contact.class);
    assertTrue(contacts.contains(contact));
    DynamoDbMapper.getInstance().delete(contact);
    contacts = DynamoDbMapper.getInstance().loadAll(Contact.class);
    assertFalse(contacts.contains(contact));
}
Also used : Contact(model.db.Contact) Test(org.junit.Test)

Example 10 with Contact

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

the class ContactTransferService method confirm.

private SpeechletResponse confirm(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;
    }
    session.setAttribute(DIALOG_CONTEXT, CONTACT_CHOICE_INTENT);
    Account account = AccountAPI.getAccount(ACCOUNT_NUMBER);
    String balanceBeforeTransation = String.valueOf(account.getBalance());
    return getAskResponse(CONTACT_TRANSFER_CARD, "Dein aktueller Kontostand beträgt " + balanceBeforeTransation + " Euro. Möchtest du " + amount + " Euro an " + contact.getName() + " überweisen?");
}
Also used : Account(model.banking.Account) LinkedList(java.util.LinkedList) List(java.util.List) Contact(model.db.Contact)

Aggregations

Contact (model.db.Contact)10 LinkedList (java.util.LinkedList)3 Test (org.junit.Test)3 Reprompt (com.amazon.speech.ui.Reprompt)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 List (java.util.List)2 Account (model.banking.Account)2 Transaction (model.banking.Transaction)2 Slot (com.amazon.speech.slu.Slot)1 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)1 SimpleCard (com.amazon.speech.ui.SimpleCard)1 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)1 StandingOrder (model.banking.StandingOrder)1 Category (model.db.Category)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1