Commit c89b2886 by Tuomas Riihimäki

Create possibility to lock places for users

1 parent 428307cd
......@@ -345,8 +345,10 @@ public class PlaceBean implements PlaceBeanLocal {
return null;
}
// Check wether we should reserve places via credit or plcaeslot
boolean placePrepaidcredit = places.get(0).getProduct().getProductFlags().contains(ProductFlag.PREPAID_CREDIT);
// PlaceGroup pg = pgbean.createPlaceGroup(user);
if (createAccountevents)
if (placePrepaidcredit && createAccountevents)
{
BigDecimal totalprice = addAndCalcPrice(user, null);
BigDecimal balance = user.getAccountBalance();
......
<!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:c="http://java.sun.com/jsp/jstl/core"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<ui:param name="thispage" value="page.place.mygroups" />
<f:metadata>
<f:viewParam name="mapid" value="#{unlockedPlaceView.mapId}" />
<f:event type="preRenderView" listener="#{unlockedPlaceView.init}" />
</f:metadata>
<ui:define name="title">
<h1>#{i18n['placegroupview.header']}</h1>
<!-- <users:usertabs tabId="groups" /> -->
</ui:define>
<ui:define name="content">
<ui:fragment rendered="#{!empty unlockedPlaceView.newPg}">
created placegroup <h:outputText value="#{unlockedPlaceView.newPg}" />
</ui:fragment>
<h:form>
<p:dataTable var="pc" value="#{unlockedPlaceView.places}">
<p:column>
<h:outputText
value="#{pc.user.user.login} #{pc.user.user.wholeName}" />
</p:column>
<p:column>
<p:dataTable var="p" value="#{pc.places}">
<p:column>
<h:outputText value="#{p.name}" />
</p:column>
<p:column>
<h:outputText value="#{p.releaseTime.time}">
<f:convertDateTime />
</h:outputText>
</p:column>
</p:dataTable>
</p:column>
<p:column>
<p:commandButton ajax="false" value="#{i18n['placegroup.lock']}"
action="#{unlockedPlaceView.lockUser()}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -102,7 +102,7 @@ public class AjaxMapView extends GenericCDIView {
public String buySelectedPlaces() {
try {
EventUser user = userview.getSelectedUser();
placebean.reserveSelectedPlaces(user);
placebean.buySelectedPlaces(user);
return "/place/myGroups";
} catch (BortalCatchableException e) {
addFaceMessage("mapView.errorWhileBuyingPlaces");
......
package fi.codecrew.moya.web.cdiview.map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class UnlockedPlaceView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 7430277821503568386L;
private ListDataModel<UnlockedPlaceContainer> places;
private Integer mapId;
public static class UnlockedPlaceContainer
{
public UnlockedPlaceContainer(EventUser currentUser) {
user = currentUser;
places = new ArrayList<>();
}
private final EventUser user;
private final List<Place> places;
public void addPlace(Place p) {
places.add(p);
}
public EventUser getUser() {
return user;
}
public List<Place> getPlaces() {
return places;
}
}
@EJB
private PlaceBeanLocal placebean;
private PlaceGroup newPg;
private static final Logger logger = LoggerFactory.getLogger(UnlockedPlaceContainer.class);
public String lockUser()
{
UnlockedPlaceContainer uc = places.getRowData();
logger.info("Locking places for user {}", uc.getUser());
newPg = placebean.buySelectedPlaces(uc.getUser());
places = null;
init();
return null;
}
public void init()
{
if (places == null) {
HashMap<EventUser, UnlockedPlaceContainer> usermap = new HashMap<EventUser, UnlockedPlaceContainer>();
EventMap map = null;
if (getMapId() != null) {
map = placebean.findMap(getMapId());
} else {
List<EventMap> maps = placebean.getMaps();
for (EventMap m : maps)
{
if (!m.isActive())
continue;
map = m;
}
}
mapId = map.getId();
for (Place p : map.getPlaces()) {
if (p.getReleaseTime() != null) {
UnlockedPlaceContainer uc = usermap.get(p.getCurrentUser());
if (uc == null) {
uc = new UnlockedPlaceContainer(p.getCurrentUser());
usermap.put(p.getCurrentUser(), uc);
}
uc.addPlace(p);
}
}
places = new ListDataModel<>(new ArrayList<>(usermap.values()));
super.beginConversation();
}
}
public ListDataModel<UnlockedPlaceContainer> getPlaces() {
return places;
}
public void setPlaces(ListDataModel<UnlockedPlaceContainer> places) {
this.places = places;
}
public PlaceGroup getNewPg() {
return newPg;
}
public void setNewPg(PlaceGroup newPg) {
this.newPg = newPg;
}
public Integer getMapId() {
return mapId;
}
public void setMapId(Integer mapId) {
this.mapId = mapId;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!