Search in sources :

Example 1 with Traverson

use of org.springframework.hateoas.client.Traverson in project amos-ss17-alexa by c-i-ber.

the class AccountAPI method getCardsForAccount.

/**
 * Get all cards (credit / debit) for the given account.
 *
 * @param accountNumber Account number
 * @return Collection of Cards
 * @throws HttpClientErrorException
 */
public static Collection<Card> getCardsForAccount(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 + "/cards"), MediaTypes.HAL_JSON);
    } catch (URISyntaxException e) {
        log.error("getCardsForAccount failed", e);
        return null;
    }
    ParameterizedTypeReference<Resources<Card>> typeRefDevices = new ParameterizedTypeReference<Resources<Card>>() {
    };
    Resources<Card> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
    return resResponses.getContent();
}
Also used : Traverson(org.springframework.hateoas.client.Traverson) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) URISyntaxException(java.net.URISyntaxException) Resources(org.springframework.hateoas.Resources) URI(java.net.URI) Card(model.banking.Card)

Example 2 with Traverson

use of org.springframework.hateoas.client.Traverson in project amos-ss17-alexa by c-i-ber.

the class TransactionAPI method getTransactions.

/**
 * Get all transactions for the given account.
 *
 * @param accountNumber Account number
 * @return Collection of Cards
 * @throws HttpClientErrorException
 */
private static Collection<Transaction> getTransactions(String accountNumber) throws HttpClientErrorException {
    // TODO: Create a generic method for getting embedded JSON-HAL collections (in BankingRESTClient)
    Traverson traverson = null;
    String uri = BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V2 + "/accounts/" + accountNumber + "/transactions";
    log.info("URI: " + uri);
    try {
        traverson = new Traverson(new URI(uri), MediaTypes.HAL_JSON);
    } catch (URISyntaxException e) {
        log.error("getTransactionsForAccount failed", e);
        return null;
    }
    ParameterizedTypeReference<Resources<Transaction>> typeRefDevices = new ParameterizedTypeReference<Resources<Transaction>>() {
    };
    Resources<Transaction> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
    return resResponses.getContent();
}
Also used : Transaction(model.banking.Transaction) Traverson(org.springframework.hateoas.client.Traverson) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) URISyntaxException(java.net.URISyntaxException) Resources(org.springframework.hateoas.Resources) URI(java.net.URI)

Example 3 with Traverson

use of org.springframework.hateoas.client.Traverson 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 4 with Traverson

use of org.springframework.hateoas.client.Traverson 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();
}
Also used : StandingOrder(model.banking.StandingOrder) Traverson(org.springframework.hateoas.client.Traverson) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) URISyntaxException(java.net.URISyntaxException) Resources(org.springframework.hateoas.Resources) URI(java.net.URI)

Example 5 with Traverson

use of org.springframework.hateoas.client.Traverson in project amos-ss17-alexa by c-i-ber.

the class SecuritiesAccountAPI method getSecuritiesForAccount.

/**
 * Get all securities for the given securities account.
 *
 * @param securitiesAccountNumber Account number
 * @return Collection of securities
 * @throws HttpClientErrorException
 */
public static Collection<Security> getSecuritiesForAccount(Number securitiesAccountNumber) 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 + "/securitiesAccounts/" + securitiesAccountNumber), MediaTypes.HAL_JSON);
    } catch (URISyntaxException e) {
        LOGGER.error("getSecuritiesForAccount failed", e);
        return null;
    }
    ParameterizedTypeReference<Resources<Security>> typeRefDevices = new ParameterizedTypeReference<Resources<Security>>() {
    };
    Resources<Security> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
    return resResponses.getContent();
}
Also used : Traverson(org.springframework.hateoas.client.Traverson) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) URISyntaxException(java.net.URISyntaxException) Resources(org.springframework.hateoas.Resources) URI(java.net.URI)

Aggregations

URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)5 Resources (org.springframework.hateoas.Resources)5 Traverson (org.springframework.hateoas.client.Traverson)5 Card (model.banking.Card)1 StandingOrder (model.banking.StandingOrder)1 Transaction (model.banking.Transaction)1 CardResponse (model.banking.account.CardResponse)1