Search in sources :

Example 6 with Category

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

the class EditCategoriesService method deleteCategory.

/**
 * @param intent
 * @param session
 * @return
 */
private SpeechletResponse deleteCategory(Intent intent, Session session) {
    String category = intent.getSlot("CategoryName").getValue();
    if (category == null || category.equals("")) {
        return getResponse(SERVICE_CARD_TITLE, "Ich konnte den Namen der Kategorie nicht verstehen. Bitte versuche es noch einmal.");
    }
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    int closestDist = Integer.MAX_VALUE;
    Category closestCategory = null;
    for (Category categoryIter : categories) {
        int dist = StringUtils.getLevenshteinDistance(category, categoryIter.getName());
        if (dist < closestDist) {
            closestDist = dist;
            closestCategory = categoryIter;
        }
    }
    if (closestDist > 5) {
        return getResponse(SERVICE_CARD_TITLE, "Ich konnte keine passende Kategorie finden.");
    }
    SessionStorage.getInstance().putObject(session.getSessionId(), SERVICE_CARD_TITLE + ".categoryId", closestCategory);
    session.setAttribute(DIALOG_CONTEXT, DELETE_CATEGORY_INTENT);
    return getAskResponse(SERVICE_CARD_TITLE, "Möchtest du die Kategorie mit dem Namen '" + closestCategory.getName() + "' und dem Limit von " + closestCategory.getLimit() + " Euro wirklich löschen?");
}
Also used : Category(model.db.Category)

Example 7 with Category

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

the class EditCategoriesService method showAllCategories.

/**
 * @param intent
 * @param session
 * @return
 */
private SpeechletResponse showAllCategories(Intent intent, Session session) {
    String intentName = intent.getName();
    LOGGER.info("Intent Name: " + intentName);
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> items = DynamoDbMapper.getInstance().loadAll(Category.class);
    String namesOfCategories = "";
    if (items.size() == 0) {
        return getResponse(SERVICE_CARD_TITLE, "Aktuell hast du keine Kategorien.");
    }
    for (Category item : items) {
        namesOfCategories += item.getName() + ", ";
    }
    return getResponse(SERVICE_CARD_TITLE, "Aktuell hast du folgende Kategorien: " + namesOfCategories);
}
Also used : Category(model.db.Category)

Example 8 with Category

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

the class EditCategoriesService method performDeletion.

/**
 * @param intent
 * @param session
 * @return
 */
private SpeechletResponse performDeletion(Intent intent, Session session) {
    Object closestCategoryObj = SessionStorage.getInstance().getObject(session.getSessionId(), SERVICE_CARD_TITLE + ".categoryId");
    if (closestCategoryObj == null || !(closestCategoryObj instanceof Category)) {
        return getResponse(SERVICE_CARD_TITLE, "Oh, da ist etwas passiert was nicht hätte passieren dürfen. " + "Vielleicht sind ein paar Elektronen in eine andere Speicherzelle getunnelt. " + "Anders kann ich mir das nicht erklären.");
    }
    Category closestCategory = (Category) closestCategoryObj;
    // DynamoDbClient.instance.deleteItem(Category.TABLE_NAME, closestCategory);
    DynamoDbMapper.getInstance().delete(closestCategory);
    return getResponse(SERVICE_CARD_TITLE, "OK, wie du willst. Ich habe die Kategorie mit dem Namen '" + closestCategory.getName() + "' gelöscht.");
}
Also used : Category(model.db.Category)

Example 9 with Category

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

the class SavingsPlanService method standingOrderCategoryResponse.

private SpeechletResponse standingOrderCategoryResponse(Intent intent, Session session) {
    String categoryName = intent.getSlot(CATEGORY_SLOT) != null ? intent.getSlot(CATEGORY_SLOT).getValue().toLowerCase() : null;
    LOGGER.info("Category: " + categoryName);
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    for (Category category : categories) {
        if (category.getName().equals(categoryName)) {
            String standingOrderId = (String) session.getAttribute(STANDING_ORDER_ID_ATTRIBUTE);
            dynamoDbMapper.save(new StandingOrderDB(SOURCE_ACCOUNT, standingOrderId, "" + category.getId()));
            return getResponse(SAVINGS_PLAN, "Verstanden. Der Dauerauftrag wurde zur Kategorie " + categoryName + " hinzugefügt");
        }
    }
    return getResponse(SAVINGS_PLAN, "Ich konnte die Kategorie nicht finden. Tschüss");
}
Also used : Category(model.db.Category) StandingOrderDB(model.db.StandingOrderDB)

Example 10 with Category

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

the class BudgetReportService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    IntentRequest request = requestEnvelope.getRequest();
    if (request.getIntent().getName().equals(BUDGET_REPORT_EMAIL_INTENT)) {
        // Load the mail template from resources
        JtwigTemplate template = JtwigTemplate.classpathTemplate("html-templates/budget-report.twig");
        List<BudgetReportCategory> categories = new ArrayList<>();
        // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
        List<Category> dbCategories = DynamoDbMapper.getInstance().loadAll(Category.class);
        for (Category cat : dbCategories) {
            categories.add(new BudgetReportCategory(cat.getName(), cat.getSpending(), cat.getLimit()));
        }
        JtwigModel model = JtwigModel.newModel().with("categories", categories);
        // Render mail template
        String body = template.render(model);
        String answer = "Okay, ich habe dir deinen Ausgabenreport per E-Mail gesendet.";
        boolean isDebug = SessionStorage.getInstance().getStorage(requestEnvelope.getSession().getSessionId()).containsKey("DEBUG");
        if (!isDebug && !EMailClient.SendHTMLEMail("Ausgabenreport", body)) {
            answer = "Leider konnte der Ausgabenreport nicht gesendet werden.";
        }
        return getResponse("Ausgabenreport", answer);
    }
    return null;
}
Also used : Category(model.db.Category) JtwigModel(org.jtwig.JtwigModel) IntentRequest(com.amazon.speech.speechlet.IntentRequest) ArrayList(java.util.ArrayList) JtwigTemplate(org.jtwig.JtwigTemplate)

Aggregations

Category (model.db.Category)19 Test (org.junit.Test)5 Slot (com.amazon.speech.slu.Slot)4 IOException (java.io.IOException)2 StandingOrder (model.banking.StandingOrder)2 Contact (model.db.Contact)2 Spending (model.db.Spending)2 TransactionDB (model.db.TransactionDB)2 Launcher (amosalexa.server.Launcher)1 AccountData (amosalexa.services.AccountData)1 ContactTransferService (amosalexa.services.bankaccount.ContactTransferService)1 BudgetManager (amosalexa.services.budgettracker.BudgetManager)1 AccountBalanceForecastService (amosalexa.services.financing.AccountBalanceForecastService)1 AffordabilityService (amosalexa.services.financing.AffordabilityService)1 TransactionForecastService (amosalexa.services.financing.TransactionForecastService)1 HelpService (amosalexa.services.help.HelpService)1 DynamoDbClient (api.aws.DynamoDbClient)1 DynamoDbMapper (api.aws.DynamoDbMapper)1 AccountAPI (api.banking.AccountAPI)1 TransactionAPI (api.banking.TransactionAPI)1