Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Fixed injection problem with stored procedure

- Divided service endpoints from servlets
- Minor changes
  • Loading branch information...
commit 22acc8aade7d3825d288623e0faee64d47493401 1 parent b436cdc
@alexbiehl alexbiehl authored
View
4 src/main/java/org/fhw/asta/kasse/server/common/UserLdapNameProvider.java
@@ -12,6 +12,8 @@
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.servlet.RequestScoped;
/**
* Returns the email of the current logged in user if present.
@@ -19,12 +21,14 @@
* @author alexbiehl
*
*/
+@RequestScoped
public class UserLdapNameProvider implements Supplier<Optional<String>> {
private static final String COOKIE_NAME = "ldap_name";
private final HttpServletRequest req;
+ @Inject
public UserLdapNameProvider(HttpServletRequest req) {
this.req = req;
}
View
8 src/main/java/org/fhw/asta/kasse/server/dao/ArticleDao.java
@@ -14,10 +14,11 @@
import org.springframework.jdbc.object.StoredProcedure;
import com.google.common.base.Optional;
+import com.google.inject.Inject;
public class ArticleDao extends GenericDao {
- private CreateNewArticleProcedure createNewArticleProcedure = new CreateNewArticleProcedure(this.template);
+ private CreateNewArticleProcedure createNewArticleProcedure;
private static class ArticleRowMapper implements RowMapper<Article> {
@Override
@@ -52,6 +53,11 @@ public void createNewArticle(final String name, final String description, final
}
}
+ @Inject
+ public void init(JdbcTemplate template) {
+ createNewArticleProcedure = new CreateNewArticleProcedure(template);
+ }
+
public List<Article> getAllArticles() {
return this.template.query("SELECT article_id," + "article_revision, name, description, price, tax_category_name,"
View
3  src/main/java/org/fhw/asta/kasse/server/inject/RootInjector.java
@@ -5,6 +5,7 @@
import org.fhw.asta.kasse.server.inject.modules.ComponentModule;
import org.fhw.asta.kasse.server.inject.modules.ConfigModule;
import org.fhw.asta.kasse.server.inject.modules.DaoModule;
+import org.fhw.asta.kasse.server.inject.modules.ServiceModule;
import org.fhw.asta.kasse.server.inject.modules.ServletConfigModule;
import com.google.inject.Guice;
@@ -15,7 +16,7 @@
@Override
protected Injector getInjector() {
- return Guice.createInjector(new ServletConfigModule(), new ConfigModule(), new ComponentModule(), new DaoModule());
+ return Guice.createInjector(new ServletConfigModule(), new ServiceModule(), new ConfigModule(), new ComponentModule(), new DaoModule());
}
}
View
12 src/main/java/org/fhw/asta/kasse/server/inject/modules/DaoModule.java
@@ -1,5 +1,6 @@
package org.fhw.asta.kasse.server.inject.modules;
+import org.fhw.asta.kasse.server.dao.ArticleDao;
import org.fhw.asta.kasse.server.dao.BillOrderDao;
import org.fhw.asta.kasse.server.dao.UserDao;
@@ -8,10 +9,11 @@
public class DaoModule extends AbstractModule {
- @Override
- protected void configure() {
- this.bind(UserDao.class).in(Singleton.class);
- this.bind(BillOrderDao.class).in(Singleton.class);
- }
+ @Override
+ protected void configure() {
+ this.bind(ArticleDao.class).in(Singleton.class);
+ this.bind(UserDao.class).in(Singleton.class);
+ this.bind(BillOrderDao.class).in(Singleton.class);
+ }
}
View
21 src/main/java/org/fhw/asta/kasse/server/inject/modules/ServletConfigModule.java
@@ -1,10 +1,10 @@
package org.fhw.asta.kasse.server.inject.modules;
-import org.fhw.asta.kasse.server.service.ArticleServiceEndpoint;
-import org.fhw.asta.kasse.server.service.BillOrderServiceEndpoint;
-import org.fhw.asta.kasse.server.service.CheckoutServiceEndpoint;
-import org.fhw.asta.kasse.server.service.LetterHeadServiceEndpoint;
-import org.fhw.asta.kasse.server.service.UserServiceEndpoint;
+import org.fhw.asta.kasse.server.servlet.ArticleServiceServlet;
+import org.fhw.asta.kasse.server.servlet.BillOrderServiceServlet;
+import org.fhw.asta.kasse.server.servlet.CheckoutServiceServlet;
+import org.fhw.asta.kasse.server.servlet.LetterheadServiceServlet;
+import org.fhw.asta.kasse.server.servlet.UserServiceServlet;
import com.google.inject.servlet.ServletModule;
@@ -12,11 +12,12 @@
@Override
protected void configureServlets() {
- serve("/kasse/user").with(UserServiceEndpoint.class);
- serve("/kasse/article").with(ArticleServiceEndpoint.class);
- serve("/kasse/checkout").with(CheckoutServiceEndpoint.class);
- serve("/kasse/billorder").with(BillOrderServiceEndpoint.class);
- serve("/kasse/letterhead").with(LetterHeadServiceEndpoint.class);
+ serve("/kasse/user").with(UserServiceServlet.class);
+ serve("/kasse/article").with(ArticleServiceServlet.class);
+ serve("/kasse/checkout").with(CheckoutServiceServlet.class);
+ serve("/kasse/billorder").with(BillOrderServiceServlet.class);
+ serve("/kasse/letterhead").with(LetterheadServiceServlet.class);
+
}
}
View
50 src/main/java/org/fhw/asta/kasse/server/service/ArticleServiceEndpoint.java
@@ -1,50 +0,0 @@
-package org.fhw.asta.kasse.server.service;
-
-import java.util.List;
-
-import org.fhw.asta.kasse.server.dao.ArticleDao;
-import org.fhw.asta.kasse.shared.model.Article;
-import org.fhw.asta.kasse.shared.model.Category;
-import org.fhw.asta.kasse.shared.service.article.ArticleService;
-
-import com.google.common.base.Optional;
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-
-@Singleton
-public class ArticleServiceEndpoint extends RemoteServiceServlet implements
- ArticleService {
- private static final long serialVersionUID = 1L;
-
- @Inject
- private ArticleDao dao;
-
- @Override
- public List<Article> getArticles() {
- return this.dao.getAllArticles();
- }
-
- @Override
- public List<Article> getArticleComponents(Article article) {
- return this.dao.getArticleComponents(article);
- }
-
- @Override
- public Optional<Article> getArticleById(String id) {
- return this.dao.getArticleById(id);
- }
-
- @Override
- public List<Category> getCategories() {
- return this.dao.getAllCategories();
- }
-
- @Override
- public List<Article> getArticlesByCategory(String id) {
- return this.dao.getArticlesByCategory(id);
- }
-
-
-
-}
View
36 src/main/java/org/fhw/asta/kasse/server/service/BillOrderServiceEndpoint.java
@@ -1,36 +0,0 @@
-package org.fhw.asta.kasse.server.service;
-
-import java.util.List;
-
-import org.fhw.asta.kasse.server.dao.ArticleDao;
-import org.fhw.asta.kasse.server.dao.BillOrderDao;
-import org.fhw.asta.kasse.shared.basket.BasketItem;
-import org.fhw.asta.kasse.shared.model.BillOrder;
-import org.fhw.asta.kasse.shared.service.billorder.BillOrderService;
-
-import com.google.common.base.Optional;
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-
-@Singleton
-public class BillOrderServiceEndpoint extends RemoteServiceServlet implements BillOrderService {
- private static final long serialVersionUID = 1L;
-
- @Inject
- private ArticleDao articleDao;
-
- @Inject
- private BillOrderDao billOrderDao;
-
- @Override
- public Optional<BillOrder> getBillOrder(int id) {
- return this.billOrderDao.getBillOrder(id);
- }
-
- @Override
- public List<BasketItem> getBillOrderArticles(int id) {
- return this.billOrderDao.getBillOrderArticles(id);
- }
-
-}
View
67 src/main/java/org/fhw/asta/kasse/server/service/BillOrderServiceImpl.java
@@ -0,0 +1,67 @@
+package org.fhw.asta.kasse.server.service;
+
+import java.util.List;
+
+import javax.annotation.Nullable;
+
+import org.fhw.asta.kasse.server.dao.ArticleDao;
+import org.fhw.asta.kasse.server.dao.BillOrderDao;
+import org.fhw.asta.kasse.shared.basket.BasketItem;
+import org.fhw.asta.kasse.shared.model.BillOrder;
+import org.fhw.asta.kasse.shared.model.BillOrderData;
+import org.fhw.asta.kasse.shared.model.Person;
+import org.fhw.asta.kasse.shared.service.billorder.BillOrderService;
+import org.fhw.asta.kasse.shared.service.letterhead.LetterHeadService;
+import org.fhw.asta.kasse.shared.service.user.UserService;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+public class BillOrderServiceImpl implements BillOrderService {
+
+ @Inject
+ private UserService userService;
+
+ @Inject
+ private LetterHeadService letterHeadService;
+
+ @Inject
+ private ArticleDao articleDao;
+
+ @Inject
+ private BillOrderDao billOrderDao;
+
+ @Override
+ public Optional<BillOrder> getBillOrder(int id) {
+ return this.billOrderDao.getBillOrder(id);
+ }
+
+ @Override
+ public List<BasketItem> getBillOrderArticles(int id) {
+ return this.billOrderDao.getBillOrderArticles(id);
+ }
+
+ @Override
+ public BillOrderData getBillOrderData(int id) {
+
+ BillOrder billOrder = getBillOrder(id).or(new BillOrder());
+ List<BasketItem> basket = getBillOrderArticles(id);
+
+ Person issuer = userService.getUserByIdAndRevision(billOrder.getIssuerLdapName(), billOrder.getIssuerRevision()).or(new Person());
+ Person receipient = userService.getUserByIdAndRevision(billOrder.getRecipientLdapName(), billOrder.getReceipientRevision()).or(new Person());
+
+ BillOrderData bod = new BillOrderData();
+
+ bod.setBillOrder(billOrder);
+ bod.setBasket(basket);
+ bod.setIssuer(issuer);
+ bod.setReceipient(receipient);
+
+ return bod;
+ }
+
+
+}
View
13 ...kasse/server/service/CheckoutServiceEndpoint.java → ...sta/kasse/server/service/CheckoutServiceImpl.java
@@ -11,18 +11,21 @@
import org.fhw.asta.kasse.shared.service.checkout.CheckoutService;
import com.google.common.base.Optional;
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Inject;
+import com.google.inject.Injector;
import com.google.inject.Singleton;
@Singleton
-public class CheckoutServiceEndpoint extends RemoteServiceServlet implements CheckoutService {
- private static final long serialVersionUID = 1L;
- private static final Logger LOGGER = Logger.getLogger(CheckoutServiceEndpoint.class);
+public class CheckoutServiceImpl implements CheckoutService {
+
+ private static final Logger LOGGER = Logger.getLogger(CheckoutServiceImpl.class);
private static final String DEFAULT_RECIPIENT = "default";
@Inject
+ private Injector injector;
+
+ @Inject
private UserDao userDao;
@Inject
@@ -32,7 +35,7 @@
public Integer doCheckout(List<BasketItem> items, int discount, String receipientLdapName, char orderState)
throws CheckoutException {
- final Optional<String> issuerLdapName = new UserLdapNameProvider(this.getThreadLocalRequest()).get();
+ final Optional<String> issuerLdapName = injector.getInstance(UserLdapNameProvider.class).get();
if (issuerLdapName.isPresent() && this.userDao.exists(issuerLdapName.get())) {
View
8 ...sse/server/service/LetterHeadServiceEndpoint.java → ...a/kasse/server/service/LetterHeadServiceImpl.java
@@ -3,16 +3,10 @@
import org.fhw.asta.kasse.shared.model.LetterHead;
import org.fhw.asta.kasse.shared.service.letterhead.LetterHeadService;
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Singleton;
@Singleton
-public class LetterHeadServiceEndpoint extends RemoteServiceServlet implements LetterHeadService {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
+public class LetterHeadServiceImpl implements LetterHeadService {
@Override
public LetterHead getLetterHead() {
View
27 ...sta/kasse/server/service/UserServiceEndpoint.java → ...hw/asta/kasse/server/service/UserServiceImpl.java
@@ -2,6 +2,8 @@
import java.util.List;
+import javax.annotation.Nullable;
+
import org.fhw.asta.kasse.server.common.User;
import org.fhw.asta.kasse.server.common.UserLdapNameProvider;
import org.fhw.asta.kasse.server.component.user.UserComponent;
@@ -12,21 +14,23 @@
import org.fhw.asta.kasse.shared.model.PersonGroup;
import org.fhw.asta.kasse.shared.service.user.UserService;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Inject;
+import com.google.inject.Injector;
import com.google.inject.Singleton;
@Singleton
-public class UserServiceEndpoint extends RemoteServiceServlet implements
- UserService {
-
- private static final long serialVersionUID = 1L;
+public class UserServiceImpl implements UserService {
// private static final Logger LOGGER =
// LoggerFactory.getLogger(UserServiceEndpoint.class);
@Inject
+ private Injector injector;
+
+ @Inject
private UserComponent userComponent;
@Inject
@@ -68,12 +72,13 @@ public AuthenticationResult authenticate(String email, String password) {
@Override
public Boolean loggedOnUserIsAdmin() {
- final Optional<String> ldapName = new UserLdapNameProvider(this.getThreadLocalRequest()).get();
- if (ldapName.isPresent()) {
- return this.userDao.userIsAdmin(ldapName.get());
- } else {
- return false;
- }
+ final Optional<String> ldapName = injector.getInstance(UserLdapNameProvider.class).get();
+
+ if (ldapName.isPresent()) {
+ return this.userDao.userIsAdmin(ldapName.get());
+ } else {
+ return false;
+ }
}
@Override
@@ -84,6 +89,6 @@ public Boolean loggedOnUserIsAdmin() {
@Override
public void updateOrCreateUserAndAccount(Person person, Account account) {
this.userDao.updateOrCreateUser(person);
- this.userDao.updateOrCreateAccount(account);
+ this.userDao.updateOrCreateAccount(account);
}
}
View
4 src/main/java/org/fhw/asta/kasse/shared/service/billorder/BillOrderService.java
@@ -4,6 +4,7 @@
import org.fhw.asta.kasse.shared.basket.BasketItem;
import org.fhw.asta.kasse.shared.model.BillOrder;
+import org.fhw.asta.kasse.shared.model.BillOrderData;
import com.google.common.base.Optional;
import com.google.gwt.user.client.rpc.RemoteService;
@@ -14,4 +15,7 @@
public interface BillOrderService extends RemoteService {
Optional<BillOrder> getBillOrder(int id);
List<BasketItem> getBillOrderArticles(int id);
+
+ BillOrderData getBillOrderData(int id);
+
}
View
3  src/main/java/org/fhw/asta/kasse/shared/service/billorder/BillOrderServiceAsync.java
@@ -4,6 +4,7 @@
import org.fhw.asta.kasse.shared.basket.BasketItem;
import org.fhw.asta.kasse.shared.model.BillOrder;
+import org.fhw.asta.kasse.shared.model.BillOrderData;
import com.google.common.base.Optional;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -14,4 +15,6 @@
void getBillOrderArticles(int id, AsyncCallback<List<BasketItem>> callback);
+ void getBillOrderData(int id, AsyncCallback<BillOrderData> callback);
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.