Skip to content

Commit

Permalink
- Removed code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbiehl committed Mar 25, 2013
1 parent 7fbc918 commit 2b5ca04
Showing 1 changed file with 7 additions and 5 deletions.
Expand Up @@ -20,6 +20,8 @@ public class CheckoutServiceEndpoint extends RemoteServiceServlet implements Che
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Logger LOGGER = Logger.getLogger(CheckoutServiceEndpoint.class); private static final Logger LOGGER = Logger.getLogger(CheckoutServiceEndpoint.class);


private static final String DEFAULT_RECIPIENT = "default";

@Inject @Inject
private UserDao userDao; private UserDao userDao;


Expand All @@ -33,11 +35,11 @@ public Integer doCheckout(List<BasketItem> items, int discount, String receipien
final Optional<String> issuerLdapName = new UserLdapNameProvider(this.getThreadLocalRequest()).get(); final Optional<String> issuerLdapName = new UserLdapNameProvider(this.getThreadLocalRequest()).get();


if (issuerLdapName.isPresent() && this.userDao.exists(issuerLdapName.get())) { if (issuerLdapName.isPresent() && this.userDao.exists(issuerLdapName.get())) {
if(this.userDao.exists(receipientLdapName)) {
return this.billOrderDao.saveBillOrder(items, discount, receipientLdapName, issuerLdapName.get(), orderState); String receipient = this.userDao.exists(receipientLdapName) ? receipientLdapName : DEFAULT_RECIPIENT;
} else {
return this.billOrderDao.saveBillOrder(items, discount, "default", issuerLdapName.get(), orderState); return this.billOrderDao.saveBillOrder(items, discount, receipient, issuerLdapName.get(), orderState);
}
} else { } else {
LOGGER.info("A non registered user tried to checkout"); LOGGER.info("A non registered user tried to checkout");
throw new CheckoutException("No issuer for checkout given. Are you logged in?"); throw new CheckoutException("No issuer for checkout given. Are you logged in?");
Expand Down

0 comments on commit 2b5ca04

Please sign in to comment.