Last active
January 31, 2016 04:17
-
-
Save VineetReynolds/fa14a1d57ef25c423b1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.jboss.examples.bankplus.customer.services.client; | |
public class Accounts { | |
@Inject | |
private AccountsAdapter adapter; | |
public Account getLiabilitiesAccount() { | |
return adapter.getLiabilitiesAccount(); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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