use of model.banking.StandingOrder 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);
}
use of model.banking.StandingOrder in project amos-ss17-alexa by c-i-ber.
the class StandingOrderService method getStandingOrdersInfoResponse.
/**
* Creates a {@code SpeechletResponse} for the standing orders intent.
*
* @return SpeechletResponse spoken and visual response for the given intent
*/
private SpeechletResponse getStandingOrdersInfoResponse(Intent intent, Session session) {
LOGGER.info("StandingOrdersResponse called.");
Map<String, Slot> slots = intent.getSlots();
Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
// Create the Simple card content.
SimpleCard card = new SimpleCard();
card.setTitle("Daueraufträge");
// Create the plain text output.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
if (standingOrdersCollection == null || standingOrdersCollection.isEmpty()) {
card.setContent("Keine Daueraufträge vorhanden.");
speech.setText("Keine Dauerauftraege vorhanden.");
return SpeechletResponse.newTellResponse(speech, card);
}
standingOrders = new ArrayList<>(standingOrdersCollection);
// Check if user requested to have their stranding orders sent to their email address
Slot channelSlot = slots.get("Channel");
boolean sendPerEmail = channelSlot != null && channelSlot.getValue() != null && channelSlot.getValue().toLowerCase().replace(" ", "").equals("email");
StringBuilder builder = new StringBuilder();
if (sendPerEmail) {
StringBuilder standingOrderMailBody = new StringBuilder();
for (StandingOrder so : standingOrders) {
standingOrderMailBody.append(so.getSpeechOutput() + "\n");
}
EMailClient.SendEMail("Daueraufträge", standingOrderMailBody.toString());
builder.append("Ich habe eine Übersicht deiner ").append(standingOrders.size()).append(" Daueraufträge an deine E-Mail-Adresse gesendet.");
} else {
// We want to directly return standing orders here
Slot payeeSlot = slots.get("Payee");
String payee = (payeeSlot == null ? null : payeeSlot.getValue());
if (payee != null) {
// User specified a recipient
standingOrders.clear();
// Find closest standing orders that could match the request.
for (int i = 0; i < standingOrders.size(); i++) {
if (StringUtils.getLevenshteinDistance(payee, standingOrders.get(i).getPayee()) <= standingOrders.get(i).getPayee().length() / 3) {
standingOrders.add(standingOrders.get(i));
}
}
builder.append(standingOrders.size() == 1 ? "Es wurde ein Dauerauftrag gefunden. " : "Es wurden " + standingOrders.size() + " Dauerauftraege gefunden. ");
for (int i = 0; i <= 1; i++) {
builder.append(standingOrders.get(i).getSpeechOutput());
}
if (standingOrders.size() > 2) {
return askForFurtherStandingOrderEntry(session, builder, 2);
}
} else {
// Just return all standing orders
builder.append("Du hast momentan ").append(standingOrders.size() == 1 ? "einen Dauerauftrag. " : standingOrders.size() + " Dauerauftraege. ");
for (int i = 0; i <= 1; i++) {
builder.append(standingOrders.get(i).getSpeechOutput());
}
if (standingOrders.size() > 2) {
return askForFurtherStandingOrderEntry(session, builder, 2);
}
}
}
String text = builder.toString();
card.setContent(text);
speech.setText(text);
return SpeechletResponse.newTellResponse(speech, card);
}
use of model.banking.StandingOrder in project amos-ss17-alexa by c-i-ber.
the class AccountFactory method createStandingOrders.
private void createStandingOrders(Account demoAccount, List<Account> contactAccounts) {
for (Account contactAccount : contactAccounts) {
StandingOrder standingOrder = AccountAPI.createStandingOrderForAccount(demoAccount.getNumber(), getContactName(contactAccount.getNumber()), 50, contactAccount.getIban(), TODAY_DATE, StandingOrder.ExecutionRate.MONTHLY, "Demo Dauerauftrag");
dynamoDbMapper.save(new StandingOrderDB(demoAccount.getNumber(), standingOrder.getStandingOrderId().toString(), getRandomCategoryId()));
}
}
use of model.banking.StandingOrder in project amos-ss17-alexa by c-i-ber.
the class SavingsPlanService method createSavingsPlan.
private SpeechletResponse createSavingsPlan(Intent intent, Session session) {
String grundbetrag = (String) session.getAttribute(BASIC_AMOUNT_KEY);
String monatlicheZahlung = (String) session.getAttribute(MONTHLY_PAYMENT_KEY);
createSavingsPlanOneOffPayment(grundbetrag);
StandingOrder standingOrder = createSavingsPlanStandingOrder(monatlicheZahlung);
String speechtext = "Okay! Ich habe den Sparplan angelegt. Der Grundbetrag von " + grundbetrag + " Euro wird deinem Sparkonto " + "gutgeschrieben. Die erste regelmaeßige Einzahlung von " + monatlicheZahlung + " Euro erfolgt am " + standingOrder.getFirstExecutionSpeechString() + ".";
// save transaction id to save in db
session.setAttribute(STANDING_ORDER_ID_ATTRIBUTE, standingOrder.getStandingOrderId().toString());
// add category ask to success response
String categoryAsk = " Zu welcher Kategorie soll der Dauerauftrag hinzugefügt werden. Sag zum Beispiel Kategorie " + Category.categoryListText();
return getAskResponse(SAVINGS_PLAN, speechtext + categoryAsk);
}
use of model.banking.StandingOrder in project amos-ss17-alexa by c-i-ber.
the class AccountAPI method getStandingOrdersForAccount.
/**
* Get all standing orders for the given account.
*
* @param accountNumber Account number
* @return Collection of StandingOrders
* @throws HttpClientErrorException
*/
public static Collection<StandingOrder> getStandingOrdersForAccount(String accountNumber) throws HttpClientErrorException {
// TODO: Create a generic method for getting embedded JSON-HAL collections (in BankingRESTClient)
Traverson traverson = null;
try {
traverson = new Traverson(new URI(BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V2 + "/accounts/" + accountNumber + "/standingorders"), MediaTypes.HAL_JSON);
} catch (URISyntaxException e) {
log.error("getStandingOrdersForAccount failed", e);
return null;
}
ParameterizedTypeReference<Resources<StandingOrder>> typeRefDevices = new ParameterizedTypeReference<Resources<StandingOrder>>() {
};
Resources<StandingOrder> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
return resResponses.getContent();
}
Aggregations