use of model.banking.account.StandingOrderResponse in project amos-ss17-alexa by c-i-ber.
the class StandingOrderDialog 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, SessionStorage.Storage storage) {
LOGGER.info("StandingOrdersResponse called.");
Map<String, Slot> slots = intent.getSlots();
ObjectMapper mapper = new ObjectMapper();
ApiHelper helper = new ApiHelper();
String test = null;
try {
test = helper.sendGet("http://amos-bank-lb-723794096.eu-central-1.elb.amazonaws.com/api/v1_0/accounts/9999999999/standingorders");
} catch (Exception e) {
//TODO
}
StandingOrderResponse standingOrderResponse = null;
try {
standingOrderResponse = mapper.readValue(test, StandingOrderResponse.class);
} catch (IOException e) {
LOGGER.error(e.getMessage());
}
// Create the Simple card content.
SimpleCard card = new SimpleCard();
card.setTitle("Daueraufträge");
// Create the plain text output.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
if (standingOrderResponse == null || standingOrderResponse.get_embedded() == null) {
card.setContent("Keine Daueraufträge vorhanden.");
speech.setText("Keine Dauerauftraege vorhanden.");
return SpeechletResponse.newTellResponse(speech, card);
}
standingOrders = standingOrderResponse.get_embedded().getStandingOrders();
// 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().equals("email");
StringBuilder textBuilder = new StringBuilder();
if (sendPerEmail) {
// TODO: Send standing orders to user's email address
textBuilder.append("Ich habe").append(standingOrders.length).append(" an deine E-Mail-Adresse gesendet.");
} else {
// We want to directly return standing orders here
Slot payeeSlot = slots.get("Payee");
String payee = payeeSlot.getValue();
if (payee != null) {
// User specified a recipient
List<StandingOrder> orders = new LinkedList<>();
// Find closest standing orders that could match the request.
for (int i = 0; i < standingOrders.length; i++) {
if (StringUtils.getLevenshteinDistance(payee, standingOrders[i].getPayee()) <= standingOrders[i].getPayee().length() / 3) {
orders.add(standingOrders[i]);
}
}
textBuilder.append(orders.size() == 1 ? "Es wurde ein Dauerauftrag gefunden." : "Es wurden " + orders.size() + " Dauerauftraege gefunden.");
int i = 1;
for (StandingOrder order : orders) {
textBuilder.append(' ');
textBuilder.append("Dauerauftrag ").append(order.getStandingOrderId()).append(": ");
textBuilder.append("Ueberweise ").append(order.getExecutionRateString()).append(order.getAmount()).append(" Euro an ").append(order.getPayee()).append(".");
i++;
}
} else {
// Just return all standing orders
textBuilder.append("Du hast momentan ").append(standingOrders.length == 1 ? "einen Dauerauftrag. " : standingOrders.length + " Dauerauftraege. ");
for (int i = 0; i <= 1; i++) {
textBuilder.append(' ');
textBuilder.append("Dauerauftrag ").append(standingOrders[i].getStandingOrderId()).append(": ");
textBuilder.append("Ueberweise ").append(standingOrders[i].getExecutionRateString()).append(standingOrders[i].getAmount()).append(" Euro an ").append(standingOrders[i].getPayee()).append(".");
}
if (standingOrders.length > 2) {
textBuilder.append(" Moechtest du einen weiteren Eintrag hoeren?");
String text = textBuilder.toString();
card.setContent(text);
speech.setText(text);
// Create reprompt
Reprompt reprompt = new Reprompt();
reprompt.setOutputSpeech(speech);
// Save current list offset in this session
storage.put("NextStandingOrder", 2);
return SpeechletResponse.newAskResponse(speech, reprompt);
}
}
}
String text = textBuilder.toString();
card.setContent(text);
speech.setText(text);
return SpeechletResponse.newTellResponse(speech, card);
}
Aggregations