Commit 3bdb6c29 by Petri Järvisalo

implemented user barcode reader for shop

1 parent 5f7fa08d
......@@ -489,4 +489,11 @@ public class UserBean implements UserBeanLocal {
}
}
@Override
@RolesAllowed(UserPermission.S_VIEW_ALL)
public EventUser getUserByBarcode(String barcode) {
EventUser user = eventUserFacade.findByBarcode(barcode);
return user;
}
}
\ No newline at end of file
......@@ -12,6 +12,8 @@ import javax.persistence.criteria.Root;
import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.EventUser_;
import fi.insomnia.bortal.model.PrintedCard;
import fi.insomnia.bortal.model.PrintedCard_;
import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.model.User_;
......@@ -40,7 +42,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
return getSingleNullableResult(getEm().createQuery(cq));
}
public EventUser find(User user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class);
......@@ -62,5 +64,18 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
eventBean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList();
}
public EventUser findByBarcode(String barcode) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class);
Root<PrintedCard> root = cq.from(PrintedCard.class);
cq.select(root.get(PrintedCard_.user));
cq.where(
cb.equal(root.get(PrintedCard_.barcode), barcode),
cb.equal(root.get(PrintedCard_.event), eventBean.getCurrentEvent())
);
return getSingleNullableResult(getEm().createQuery(cq));
}
}
......@@ -65,5 +65,7 @@ public interface UserBeanLocal {
EventUser getEventUser(User user);
EventUser validateUser(String username, String password);
EventUser getUserByBarcode(String barcode);
}
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:shop="http://java.sun.com/jsf/composite/cditools/shop" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<f:metadata>
<f:event type="preRenderView" listener="#{barcodeView.initView}" />
</f:metadata>
<ui:define name="content">
<h:form>
<h:inputText name="barcode" value="#{barcodeView.barcode}" />
<h:commandButton action="#{barcodeView.readBarcode}" value="#{i18n['barcodeReader.readBarcode']}"/>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -17,9 +17,6 @@
</ui:define>
<ui:define name="content">
<h:form id="shoppingcartform">
<h:panelGrid columns="2">
......
......@@ -63,7 +63,7 @@ httpsession.creationTime = Luotu
#Bill number
# Validationmessages
map.id = #
map.id = #
navi.auth.login = frontpage
navi.auth.loginerror = frontpage
......
......@@ -231,6 +231,8 @@ mapView.errorWhenReservingPlace = Error when reserving place!
mapView.errorWhileBuyingPlaces = Error when buying places. Please try again. If error reoccurs please contact organizers.
mapView.notEnoughCreditsToReserve = You don't have enough credits to reserve this place.
mapedit.save = Save
nasty.user = Go away!
org.hibernate.validator.constraints.Email.message = not a well-formed email address
......
......@@ -238,6 +238,8 @@ mapView.errorWhenReservingPlace = Paikkaa varatessa tapahtui virhe.
mapView.errorWhileBuyingPlaces = Virhe paikkojen ostossa. Ole hyv\u00E4 ja yrit\u00E4 uudelleen. Jos virhe toistuu ota yhteytt\u00E4 j\u00E4rjest\u00E4jiin.
mapView.notEnoughCreditsToReserve = Sinulla ei ole riitt\u00E4v\u00E4sti suoritettuja konepaikkamaksuja t\u00E4m\u00E4n paikan varaamiseen.
mapedit.save = Tallenna
menu.index = Etusivu
menu.place.placemap = Paikkakartta
menu.poll.index = Kyselyt
......
......@@ -2,7 +2,7 @@
#Bill number
# Validationmessages
bill.billMarkedPaidMail.message = Laskusi numero {0} on merkitty maksetuksi. Voit nyt siirty\u00E4 lippukauppaan varamaamaan haluamasi paikat. \nTervetuloa tapahtumaan\!\n\nTerveisin,\nInsomnia lippupalvelu\nwww.insomnia.fi
bill.billMarkedPaidMail.message = Laskusi numero {0} on merkitty maksetuksi. Voit nyt siirty\u00E4 lippukauppaan varamaamaan haluamasi paikat. \nTervetuloa tapahtumaan!\n\nTerveisin,\nInsomnia lippupalvelu\nwww.insomnia.fi
bill.billMarkedPaidMail.subject = [INSOMNIA] Lasku merkitty maksetuksi
eventorg.edit = Muokkaa
......
package fi.insomnia.bortal.web.cdiview.shop;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.enums.apps.UserPermission;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.web.cdiview.GenericCDIView;
import fi.insomnia.bortal.web.cdiview.user.UserView;
@Named
@ConversationScoped
public class BarcodeView extends GenericCDIView {
private String barcode;
private static final Logger logger = LoggerFactory
.getLogger(BarcodeView.class);
@Inject
private UserView userView;
@Inject
private ProductShopView productShopView;
@EJB
private UserBeanLocal userBean;
public String getBarcode() {
return barcode;
}
public void initView() {
super.requirePermissions(UserPermission.VIEW_ALL);
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public String readBarcode() {
EventUser user = userBean.getUserByBarcode(barcode);
userView.setUser(user);
if (user == null) {
super.addFaceMessage("barcodeView.userNotFound", barcode);
logger.info("User not found by barcode: {}", barcode);
return null;
}
productShopView.initShopView();
super.beginConversation();
logger.info("Recieved Barcode: {}", barcode);
return "/shop/shopToUser";
}
public UserView getUserView() {
return userView;
}
public void setUserView(UserView userView) {
this.userView = userView;
}
public ProductShopView getProductShopView() {
return productShopView;
}
public void setProductShopView(ProductShopView productShopView) {
this.productShopView = productShopView;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!