Search in sources :

Example 1 with CardResponse

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

the class AccountFactory method getCardsForAccount.

/**
     * Get all cards (credit / debit) for the given account
     * @param number Account number
     * @return Collection of CardResponses
     * @throws URISyntaxException
     * @throws HttpClientErrorException
     */
public Collection<CardResponse> getCardsForAccount(String number) throws HttpClientErrorException {
    Traverson traverson = null;
    try {
        traverson = new Traverson(new URI(BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V1 + "/accounts/" + number + "/cards"), MediaTypes.HAL_JSON);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    ParameterizedTypeReference<Resources<CardResponse>> typeRefDevices = new ParameterizedTypeReference<Resources<CardResponse>>() {
    };
    Resources<CardResponse> resCardResponses = traverson.follow(rel("$._links.self.href")).toObject(typeRefDevices);
    Collection<CardResponse> cards = resCardResponses.getContent();
    return cards;
}
Also used : Traverson(org.springframework.hateoas.client.Traverson) CardResponse(model.banking.account.CardResponse) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) URISyntaxException(java.net.URISyntaxException) Resources(org.springframework.hateoas.Resources) URI(java.net.URI)

Example 2 with CardResponse

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

the class ReplacementCardDialog method askForCardNumber.

private SpeechletResponse askForCardNumber(SessionStorage.Storage storage, boolean errored) {
    // TODO: Load account from session
    Collection<CardResponse> cards = AccountFactory.getInstance().getCardsForAccount("0000000000");
    if (cards.size() == 0) {
        // This user does not have any cards, ordering a replacement card is impossible.
        PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
        speech.setText("Es wurden keine Kredit- oder EC-Karten gefunden.");
        return SpeechletResponse.newTellResponse(speech);
    } else {
        SsmlOutputSpeech speech = new SsmlOutputSpeech();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<speak>");
        if (errored) {
            stringBuilder.append("Entschuldigung, das habe ich nicht verstanden. ");
        }
        stringBuilder.append("Bestellung einer Ersatzkarte. Es wurden folgende Karten gefunden: ");
        List<String> userCards = new ArrayList<>();
        for (CardResponse card : cards) {
            // Check if this card is active
            if (card.status != CardResponse.Status.ACTIVE) {
                continue;
            }
            userCards.add(card.cardNumber);
            String prefix = (card.cardType == CardResponse.CardType.CREDIT ? "Kredit" : "EC-");
            stringBuilder.append(prefix + "karte mit den Endziffern <say-as interpret-as=\"digits\">" + card.cardNumber.substring(card.cardNumber.length() - 4) + "</say-as>. ");
        }
        // Store all card numbers in the session
        storage.put(STORAGE_VALID_CARDS, userCards);
        stringBuilder.append("Bitte gib die Endziffern der Karte an, für die du Ersatz benötigst.");
        stringBuilder.append("</speak>");
        speech.setSsml(stringBuilder.toString());
        // Create reprompt
        Reprompt reprompt = new Reprompt();
        reprompt.setOutputSpeech(speech);
        return SpeechletResponse.newAskResponse(speech, reprompt);
    }
}
Also used : CardResponse(model.banking.account.CardResponse) ArrayList(java.util.ArrayList) Reprompt(com.amazon.speech.ui.Reprompt) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech)

Aggregations

CardResponse (model.banking.account.CardResponse)2 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)1 Reprompt (com.amazon.speech.ui.Reprompt)1 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 Resources (org.springframework.hateoas.Resources)1 Traverson (org.springframework.hateoas.client.Traverson)1