Skip to content

Instantly share code, notes, and snippets.

@VineetReynolds
Last active January 31, 2016 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VineetReynolds/fa14a1d57ef25c423b1c to your computer and use it in GitHub Desktop.
Save VineetReynolds/fa14a1d57ef25c423b1c to your computer and use it in GitHub Desktop.
package org.jboss.examples.bankplus.customer.services.client;
public class Accounts {
@Inject
private AccountsAdapter adapter;
public Account getLiabilitiesAccount() {
return adapter.getLiabilitiesAccount();
}
...
}
package org.jboss.examples.bankplus.customer.services.adapters;
public class AccountsAdapter {
@Inject
private AccountTranslator translator;
public org.jboss.examples.bankplus.customer.model.Account getLiabilitiesAccount() {
Client client = ClientBuilder.newClient();
UriBuilder builder = UriBuilder
.fromUri("http://{host}:{port}/bankplus-accounting/rest/")
.path("accounts")
.queryParam("type", "liabilities")
.resolveTemplate("host", host)
.resolveTemplate("port", port);
WebTarget target = client.target(builder);
org.jboss.examples.bankplus.customer.services.adapters.Account account =
target.request(MediaType.APPLICATION_JSON_TYPE)
.get(org.jboss.examples.bankplus.customer.services.adapters.Account.class);
return translator.translate(account);
}
...
}
package org.jboss.examples.bankplus.accounting.rest;
@Path("/accounts")
@Stateless
public class AccountsResource {
@Inject
private Accounts accounts;
@GET
@Produces("application/json")
public Response getAccount(@QueryParam("type") String type, @QueryParam("accountId") String accountId) {
if(type != null && !type.isEmpty()) {
org.jboss.examples.bankplus.accounting.model.Account account = null;
switch (type) {
...
case "liabilities":
account = accounts.getLiabilitiesAccount();
break;
default:
throw new IllegalArgumentException("Invalid account type");
}
Account accountRepresentation = new Account(account);
return Response.ok(accountRepresentation).build();
}
...
}
}
package org.jboss.examples.bankplus.customer.services.translators;
public class AccountTranslator {
public org.jboss.examples.bankplus.customer.model.Account
translate(org.jboss.examples.bankplus.customer.services.adapters.Account container) {
org.jboss.examples.bankplus.customer.model.Account account = null;
if(container != null) {
account = new org.jboss.examples.bankplus.customer.model.Account();
account.setAccountReference(container.getAccountId());
account.setCurrentBalance(container.getCurrentBalance());
account.setLastUpdatedOn(container.getLastUpdatedOn());
}
return account;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment