Search in sources :

Example 1 with SecuritiesAccount

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

the class SecuritiesAccountInformationService method getSecuritiesAccountInformation.

private SpeechletResponse getSecuritiesAccountInformation(Session session) {
    LOGGER.info("SecuritiesAccountInformation called.");
    SecuritiesAccount securitiesAccount = SecuritiesAccountAPI.getSecuritiesAccount(SEC_ACCOUNT_ID);
    Collection<Security> securitiesCollection = SecuritiesAccountAPI.getSecuritiesForAccount(SEC_ACCOUNT_ID);
    if (securitiesAccount == null || securitiesCollection == null || securitiesCollection.size() == 0) {
        return getResponse(SECURITIES_ACCOUNT_INFORMATION, "Keine Depotinformationen vorhanden.");
    }
    securities = new LinkedList<>(securitiesCollection);
    StringBuilder textBuilder = new StringBuilder();
    textBuilder.append("Du hast momentan ").append(securities.size() == 1 ? "ein Wertpapier in deinem Depot. " : securities.size() + " Wertpapiere in deinem Depot. ");
    for (int i = 0; i <= 1; i++) {
        String stockPrice = FinanceApi.getStockPrice(securities.get(i));
        LOGGER.info("Stock Price: " + stockPrice);
        textBuilder.append("Wertpapier Nummer ").append(securities.get(i).getSecurityId()).append(": ").append(securities.get(i).getDescription()).append(", " + securities.get(i).getQuantity() + " Stueck, ").append("mit einem momentanen Wert von ").append(stockPrice).append(" Euro. ");
    }
    if (securities.size() > 2) {
        textBuilder.append("Moechtest du einen weiteren Eintrag hoeren?");
        String text = textBuilder.toString();
        // Save current list offset in this session
        session.setAttribute("NextSecurity", 2);
        return getAskResponse(SECURITIES_ACCOUNT_INFORMATION, text);
    }
    String text = textBuilder.toString();
    return getResponse(SECURITIES_ACCOUNT_INFORMATION, text);
}
Also used : SecuritiesAccount(model.banking.SecuritiesAccount) Security(model.banking.Security)

Example 2 with SecuritiesAccount

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

the class AmosAlexaExtendedTestImpl method securitiesAccountTest.

@Test
public void securitiesAccountTest() throws IllegalAccessException, NoSuchFieldException, IOException {
    newSession();
    // Securities Account with ID 2 is the one we use for test purpose!
    SecuritiesAccount testSecuritiesAccount = SecuritiesAccountAPI.getSecuritiesAccount(2);
    Set<Security> securitiesBefore = new HashSet<>(SecuritiesAccountAPI.getSecuritiesForAccount(2));
    LOGGER.debug("List Before: " + securitiesBefore);
    for (Security s : securitiesBefore) {
        SecuritiesAccountAPI.deleteSecurity(2, s.getSecurityId());
    }
    // Test speech answer with empty depot
    testIntent("SecuritiesAccountInformationIntent", "Keine Depotinformationen vorhanden.");
    // Add some securities
    Security testSecurity1 = new Security("DE000A1EWWW0", "A1EWWW", "Adidas Aktie", 10, 174.19, new Date(), Security.SecurityType.STOCK);
    Security testSecurity2 = new Security("US1912161007", "850663", "The Coca-Cola Company Aktie", 3, 2200, new Date(), Security.SecurityType.STOCK);
    Security testSecurity3 = new Security("US0378331005", "865985", "Apple Inc. Aktie", 2, 9999, new Date(), Security.SecurityType.STOCK);
    Security testSecurity4 = new Security("DE0007164600", "716460 ", "SAP Aktie", 4, 3636, new Date(), Security.SecurityType.STOCK);
    testSecurity1 = SecuritiesAccountAPI.addSecurityToAccount(testSecuritiesAccount.getSecuritiesAccountId(), testSecurity1);
    testSecurity2 = SecuritiesAccountAPI.addSecurityToAccount(testSecuritiesAccount.getSecuritiesAccountId(), testSecurity2);
    testSecurity3 = SecuritiesAccountAPI.addSecurityToAccount(testSecuritiesAccount.getSecuritiesAccountId(), testSecurity3);
    testSecurity4 = SecuritiesAccountAPI.addSecurityToAccount(testSecuritiesAccount.getSecuritiesAccountId(), testSecurity4);
    // Test speech answer with some securities in the depot
    String response = performIntent("SecuritiesAccountInformationIntent");
    Pattern p = Pattern.compile("Du hast momentan 4 Wertpapiere in deinem Depot. " + "Wertpapier Nummer ([0-9]+): Adidas Aktie, ([0-9]+) Stueck, mit einem momentanen Wert von ([0-9\\\\.]+) Euro. " + "Wertpapier Nummer ([0-9]+): The Coca-Cola Company Aktie, ([0-9]+) Stueck, mit einem momentanen Wert von ([0-9\\.]+) Euro. " + "Moechtest du einen weiteren Eintrag hoeren?");
    Matcher m = p.matcher(response);
    if (!m.find()) {
        fail("Unexpected speech output.\nExcpected: " + p.pattern() + "\nAcutual: " + response);
    }
    response = performIntent("AMAZON.YesIntent");
    p = Pattern.compile("Wertpapier Nummer ([0-9]+): " + "Apple Inc. Aktie, ([0-9]+) Stueck, mit einem momentanen Wert von ([0-9\\\\.]+) Euro. " + "Moechtest du einen weiteren Eintrag hoeren?");
    m = p.matcher(response);
    if (!m.find()) {
        fail("Unexpected speech output.\nExcpected: " + p.pattern() + "\nAcutual: " + response);
    }
    testIntent("AMAZON.NoIntent", "Okay, tschuess!");
    SecuritiesAccountAPI.deleteSecurity(2, testSecurity1.getSecurityId());
    SecuritiesAccountAPI.deleteSecurity(2, testSecurity2.getSecurityId());
    SecuritiesAccountAPI.deleteSecurity(2, testSecurity3.getSecurityId());
    // Restore securities as before test
    for (Security s : securitiesBefore) {
        SecuritiesAccountAPI.addSecurityToAccount(2, s);
    }
}
Also used : SecuritiesAccount(model.banking.SecuritiesAccount) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Security(model.banking.Security) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SecuritiesAccount (model.banking.SecuritiesAccount)2 Security (model.banking.Security)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Test (org.junit.Test)1