Search in sources :

Example 1 with StandingOrder

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

the class AmosAlexaSimpleTestImpl method savingsPlanTest.

@Test
public void savingsPlanTest() throws Exception {
    newSession();
    // DynamoDbMapper.getInstance().loadAll(Category.class);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = categories.get(0);
    testIntent("SavingsPlanIntroIntent", "Was moechtest du als Grundbetrag anlegen?");
    testIntent("PlainNumberIntent", "Number:1500", "Wie viele Jahre moechtest du das Geld anlegen?");
    testIntent("PlainNumberIntent", "Number:2", "Welchen Geldbetrag moechtest du monatlich investieren?");
    testIntentMatches("PlainNumberIntent", "Number:150", "Bei einem Zinssatz von zwei Prozent waere der Gesamtsparbetrag am Ende des Zeitraums insgesamt (.*) Euro\\. Soll ich diesen Sparplan fuer dich anlegen\\?");
    // Calculate what first payment date of the savings plan should be (depending on today´s date)
    Calendar calendar = Calendar.getInstance();
    String nextPayin = String.format("01.%02d.%d", calendar.get(Calendar.MONTH) + 2, calendar.get(Calendar.YEAR));
    // Test NoIntent handling
    testIntent("AMAZON.NoIntent", "Nenne einen der Parameter, die du aendern willst " + "oder beginne neu, indem du \"Neu\" sagst.");
    testIntent("SavingsPlanChangeParameterIntent", "SavingsPlanParameter:laufzeit", "Wie viele Jahre moechtest du das Geld anlegen?");
    testIntentMatches("PlainNumberIntent", "Number:6", "Bei einem Zinssatz von zwei Prozent waere der Gesamtsparbetrag am Ende des Zeitraums insgesamt (.*) Euro\\. " + "Soll ich diesen Sparplan fuer dich anlegen\\?");
    // Test with YesIntent, savings plan should be actually created
    testIntent("AMAZON.YesIntent", "Okay! Ich habe den Sparplan angelegt. Der Grundbetrag von 1500 Euro wird deinem Sparkonto gutgeschrieben. Die erste regelmaeßige Einzahlung von 150 Euro erfolgt am " + nextPayin + "." + " Zu welcher Kategorie soll der Dauerauftrag hinzugefügt werden. Sag zum Beispiel Kategorie " + Category.categoryListText());
    testIntentMatches("PlainCategoryIntent", "Category:" + category.getName(), "Verstanden. Der Dauerauftrag wurde zur Kategorie " + category.getName() + " hinzugefügt");
    Collection<StandingOrder> allStandingOrders = AccountAPI.getStandingOrdersForAccount(TEST_ACCOUNT_NUMBER);
    final Comparator<StandingOrder> comp = Comparator.comparingInt(s -> s.getStandingOrderId().intValue());
    int latestStandingOrderId = allStandingOrders.stream().max(comp).get().getStandingOrderId().intValue();
    LOGGER.info("Latest standing order ID: " + latestStandingOrderId);
    // We need to start a new session here because the dialog ends after the YesIntent
    newSession();
    testIntent("StandingOrdersDeleteIntent", "Number:" + latestStandingOrderId, "Moechtest du den Dauerauftrag mit der Nummer " + latestStandingOrderId + " wirklich loeschen?");
    testIntent("AMAZON.YesIntent", "Dauerauftrag Nummer " + latestStandingOrderId + " wurde geloescht.");
}
Also used : Category(model.db.Category) StandingOrder(model.banking.StandingOrder) Test(org.junit.Test)

Example 2 with StandingOrder

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

the class StandingOrderTest method getStandingOrdersTest.

@Test
public void getStandingOrdersTest() {
    Collection<StandingOrder> standingOrders = AccountAPI.getStandingOrdersForAccount(AccountData.ACCOUNT_DEFAULT);
    for (StandingOrder standingOrder : standingOrders) {
        System.out.println("Id: " + standingOrder.getStandingOrderId());
        System.out.println("First: " + standingOrder.getFirstExecution());
        System.out.println("Rate: " + standingOrder.getExecutionRateString());
        System.out.println("Status: " + standingOrder.getStatus());
        System.out.println("Amount: " + standingOrder.getAmount());
        System.out.println("Destination: " + standingOrder.getDestinationAccount());
    }
}
Also used : StandingOrder(model.banking.StandingOrder) Test(org.junit.Test)

Example 3 with StandingOrder

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

the class StandingOrderService method getStandingOrdersModifyResponse.

private SpeechletResponse getStandingOrdersModifyResponse(Intent intent, Session session) {
    String standingOrderToModify = (String) session.getAttribute("StandingOrderToModify");
    String newAmount = (String) session.getAttribute("NewAmount");
    // TODO never used
    String newExecutionRate = (String) session.getAttribute("NewExecutionRate");
    String newFirstExecution = (String) session.getAttribute("NewFirstExecution");
    ObjectMapper mapper = new ObjectMapper();
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Ändere Dauerauftrag");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    Number standingOrderNum = Integer.parseInt(standingOrderToModify);
    StandingOrder standingOrder = AccountAPI.getStandingOrder(ACCOUNT_NUMBER, standingOrderNum);
    // TODO: Actually update the StandingOrder
    standingOrder.setAmount(Integer.parseInt(newAmount));
    AccountAPI.updateStandingOrder(ACCOUNT_NUMBER, standingOrder);
    card.setContent("Dauerauftrag Nummer " + standingOrderToModify + " wurde geändert.");
    speech.setText("Dauerauftrag Nummer " + standingOrderToModify + " wurde geaendert.");
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : StandingOrder(model.banking.StandingOrder) SimpleCard(com.amazon.speech.ui.SimpleCard) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with StandingOrder

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

the class StandingOrderService method getStandingOrdersInfoForKeyword.

private SpeechletResponse getStandingOrdersInfoForKeyword(Intent intent, Session session) {
    Map<String, Slot> slots = intent.getSlots();
    Slot standingOrderKeywordSlot = slots.get("StandingOrderKeyword");
    Slot transactionKeywordSlot = slots.get("TransactionKeyword");
    if ((standingOrderKeywordSlot == null || standingOrderKeywordSlot.getValue() == null) && (transactionKeywordSlot == null || transactionKeywordSlot.getValue() == null)) {
        // TODO
        return null;
    }
    String keyword = standingOrderKeywordSlot.getValue() != null ? standingOrderKeywordSlot.getValue() : transactionKeywordSlot.getValue();
    LOGGER.info("Keyword: " + keyword);
    if (keyword.equals("ersparnisse")) {
        keyword = "sparplan regelm. einzahlung";
    }
    Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
    standingOrders = new ArrayList<>();
    for (StandingOrder so : standingOrdersCollection) {
        String description = so.getDescription().toLowerCase();
        // LOGGER.info("Description: " + description);
        if (!description.equals(keyword)) {
            String[] singleWords = description.split("\\s+");
            for (String s : singleWords) {
                if (keyword.equals(s)) {
                    standingOrders.add(so);
                    continue;
                }
                double similarity = getStringSimilarity(s, keyword);
                // 0.9 seems to be a good value for similarity
                if (similarity >= 0.9) {
                    standingOrders.add(so);
                }
            }
        } else {
            standingOrders.add(so);
            continue;
        }
    }
    if (standingOrders.size() == 0) {
        String answer = "Ich konnte keine Dauerauftraege finden, die zu diesem Stichwort passen.";
        return getResponse(STANDING_ORDERS, answer);
    }
    double total = 0;
    for (StandingOrder so : standingOrders) {
        if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.MONTHLY)) {
            total += so.getAmount().doubleValue();
        } else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.QUARTERLY)) {
            total += so.getAmount().doubleValue() / 3;
        } else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.HALF_YEARLY)) {
            total += so.getAmount().doubleValue() / 6;
        } else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.YEARLY)) {
            total += so.getAmount().doubleValue() / 12;
        }
    }
    StringBuilder builder = new StringBuilder();
    builder.append("<speak>");
    builder.append("Aus ").append(standingOrders.size() == 1 ? "<phoneme alphabet=\"ipa\" ph=\"ˈaɪ̯nəm\">einem</phoneme>" + " gefundenen Dauerauftrag " : standingOrders.size() + " gefundenen Dauerauftraegen ").append("konnte ich berechnen, dass du monatlich " + total + " Euro ").append(keyword.equals("sparplan regelm. einzahlung") ? "zum Sparen zuruecklegst. " : "fuer " + keyword + " bezahlst. ");
    builder.append("Soll ich die gefundenen Dauerauftraege aufzaehlen? ");
    builder.append("</speak>");
    SsmlOutputSpeech speech = new SsmlOutputSpeech();
    speech.setSsml(builder.toString());
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : StandingOrder(model.banking.StandingOrder) Reprompt(com.amazon.speech.ui.Reprompt) Slot(com.amazon.speech.slu.Slot) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech)

Example 5 with StandingOrder

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

the class StandingOrderService method smartUpdateStandingOrderResponse.

/**
 * Creates a {@code SpeechletResponse} for the standing orders intent.
 *
 * @return SpeechletResponse spoken and visual response for the given intent
 */
private SpeechletResponse smartUpdateStandingOrderResponse(Session session) {
    LOGGER.info("SmartStandingOrders Confirmation called.");
    int standingOrderToModify = (int) session.getAttribute("StandingOrderToModify");
    String newAmount = (String) session.getAttribute("NewAmount");
    int orderAmount = Integer.parseInt(newAmount);
    // deleting old orders
    Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
    standingOrders = new ArrayList<>(standingOrdersCollection);
    String payeeFullName = AccountAPI.getStandingOrder(ACCOUNT_NUMBER, standingOrderToModify).getPayee().toLowerCase();
    String firstExecution = AccountAPI.getStandingOrder(ACCOUNT_NUMBER, standingOrderToModify).getFirstExecution().toString();
    for (int i = 0; i < standingOrders.size(); i++) {
        if (standingOrders.get(i).getStandingOrderId().intValue() != standingOrderToModify && standingOrders.get(i).getPayee().toLowerCase().equals(payeeFullName) && standingOrders.get(i).getFirstExecution().toString().equals(firstExecution)) {
            orderAmount += standingOrders.get(i).getAmount().intValue();
            AccountAPI.deleteStandingOrder(ACCOUNT_NUMBER, standingOrders.get(i).getStandingOrderId().intValue());
        }
    }
    StandingOrder standingOrder = AccountAPI.getStandingOrder(ACCOUNT_NUMBER, standingOrderToModify);
    standingOrder.setAmount(orderAmount);
    AccountAPI.updateStandingOrder(ACCOUNT_NUMBER, standingOrder);
    String speechText = "Der Dauerauftrag Nummer " + standingOrderToModify + " für " + standingOrder.getPayee() + " über " + orderAmount + " euro wurde erfolgreich aktualisiert";
    // delete session attributes
    session.removeAttribute("SmartCreateStandingOrderIntent");
    session.removeAttribute("StandingOrderToModify");
    session.removeAttribute("NewAmount");
    return getAskResponse(STANDING_ORDERS, speechText);
}
Also used : StandingOrder(model.banking.StandingOrder)

Aggregations

StandingOrder (model.banking.StandingOrder)15 Test (org.junit.Test)5 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)4 SimpleCard (com.amazon.speech.ui.SimpleCard)4 Slot (com.amazon.speech.slu.Slot)3 Reprompt (com.amazon.speech.ui.Reprompt)3 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Account (model.banking.Account)1 Category (model.db.Category)1 Contact (model.db.Contact)1 DateTime (org.joda.time.DateTime)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 Resources (org.springframework.hateoas.Resources)1 Traverson (org.springframework.hateoas.client.Traverson)1