Commit 5aff2beb by Tuomas Riihimäki

Error handling, etc

1 parent 7b83cf06
package fi.codecrew.moya.exceptions;
import fi.codecrew.moya.model.Place;
import javax.ejb.EJBException;
public class PlaceAlreadyTakenException extends EJBException {
public PlaceAlreadyTakenException(Place p) {
super("Place " + (p != null ? p.toString():"") + "already taken");
this.place = p;
}
private final Place place;
public Place getPlace() {
return place;
}
}
...@@ -62,7 +62,7 @@ import fi.codecrew.moya.model.User; ...@@ -62,7 +62,7 @@ import fi.codecrew.moya.model.User;
MapPermission.S_MANAGE_MAPS, MapPermission.S_MANAGE_MAPS,
MapPermission.S_MANAGE_OTHERS, MapPermission.S_MANAGE_OTHERS,
MapPermission.S_BUY_PLACES, MapPermission.S_BUY_PLACES,
// MapPermission.S_RELEASE_PLACE, MapPermission.S_MOVE_PLACES,
ShopPermission.S_LIST_ALL_PRODUCTS, ShopPermission.S_LIST_ALL_PRODUCTS,
ShopPermission.S_LIST_USERPRODUCTS, ShopPermission.S_LIST_USERPRODUCTS,
......
...@@ -49,6 +49,8 @@ import javax.ejb.Stateless; ...@@ -49,6 +49,8 @@ import javax.ejb.Stateless;
import javax.ejb.Timeout; import javax.ejb.Timeout;
import javax.ejb.Timer; import javax.ejb.Timer;
import javax.ejb.TimerService; import javax.ejb.TimerService;
import fi.codecrew.moya.exceptions.PlaceAlreadyTakenException;
import fi.codecrew.moya.facade.*; import fi.codecrew.moya.facade.*;
import fi.codecrew.moya.model.*; import fi.codecrew.moya.model.*;
...@@ -66,7 +68,6 @@ import fi.codecrew.moya.exceptions.BortalCatchableException; ...@@ -66,7 +68,6 @@ import fi.codecrew.moya.exceptions.BortalCatchableException;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType; import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
*
* @author tuukka * @author tuukka
*/ */
@Stateless @Stateless
...@@ -132,11 +133,10 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -132,11 +133,10 @@ public class PlaceBean implements PlaceBeanLocal {
/** /**
* Calculate the price of reserved places for the user Optional parameter * Calculate the price of reserved places for the user Optional parameter
* newPlace can be given when the place is added to the price calculations; * newPlace can be given when the place is added to the price calculations;
* * <p>
* User parameter can be used to select another user than the currently * User parameter can be used to select another user than the currently
* logged in user, but if user does not have enough rights an exception will * logged in user, but if user does not have enough rights an exception will
* be thrown * be thrown
*
*/ */
@RolesAllowed(SpecialPermission.S_USER) @RolesAllowed(SpecialPermission.S_USER)
...@@ -156,7 +156,9 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -156,7 +156,9 @@ public class PlaceBean implements PlaceBeanLocal {
} }
/** Use place slots */ /**
* Use place slots
*/
@Deprecated() @Deprecated()
private BigDecimal addAndCalcPrice(EventUser user, Place newPlace) { private BigDecimal addAndCalcPrice(EventUser user, Place newPlace) {
...@@ -209,10 +211,8 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -209,10 +211,8 @@ public class PlaceBean implements PlaceBeanLocal {
* Reserve the place for user. This reservation will timeout after a while * Reserve the place for user. This reservation will timeout after a while
* buy() method should be called after this when buying place; * buy() method should be called after this when buying place;
* *
* @param place * @param place place to be reserved
* place to be reserved * @param user User for whom the place should be reserved.
* @param user
* User for whom the place should be reserved.
* @return true when successfull. On any error false. * @return true when successfull. On any error false.
*/ */
@Override @Override
...@@ -234,8 +234,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -234,8 +234,7 @@ public class PlaceBean implements PlaceBeanLocal {
boolean canReserve = (price.compareTo(balance) <= 0); boolean canReserve = (price.compareTo(balance) <= 0);
logger.debug("Balance {}, price {}", balance, price); logger.debug("Balance {}, price {}", balance, price);
if (!canReserve && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) if (!canReserve && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) {
{
logger.debug("Did not have enought credits to reserve place! required {} , got {}", price, balance); logger.debug("Did not have enought credits to reserve place! required {} , got {}", price, balance);
return false; return false;
} }
...@@ -268,21 +267,20 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -268,21 +267,20 @@ public class PlaceBean implements PlaceBeanLocal {
} }
@Override @Override
@RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS})
public PlaceGroup buySelectedPlaces(EventUser user) throws BortalCatchableException { public PlaceGroup buySelectedPlaces(EventUser user) throws BortalCatchableException {
return buyOrReserveSelectedPlaces(user, true); return buyOrReserveSelectedPlaces(user, true);
} }
@Override @Override
@RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS})
public PlaceGroup buySelectedPlaces(List<Place> selectedPlaces, EventUser user) throws BortalCatchableException { public PlaceGroup buySelectedPlaces(List<Place> selectedPlaces, EventUser user) throws BortalCatchableException {
return buyOrReserveSelectedPlaces(user, selectedPlaces, true); return buyOrReserveSelectedPlaces(user, selectedPlaces, true);
} }
@Override @Override
@RolesAllowed({ MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({MapPermission.S_MANAGE_OTHERS})
public PlaceGroup reserveSelectedPlaces(EventUser eventuser) throws BortalCatchableException { public PlaceGroup reserveSelectedPlaces(EventUser eventuser) throws BortalCatchableException {
return buyOrReserveSelectedPlaces(eventuser, false); return buyOrReserveSelectedPlaces(eventuser, false);
} }
...@@ -311,10 +309,10 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -311,10 +309,10 @@ public class PlaceBean implements PlaceBeanLocal {
List<Place> places = placeFacade.findUsersReservations(event, user); List<Place> places = placeFacade.findUsersReservations(event, user);
if(selectedPlaces != null) { if (selectedPlaces != null) {
List<Place> newPlaces = new ArrayList<>(); List<Place> newPlaces = new ArrayList<>();
for(Place p : selectedPlaces) { for (Place p : selectedPlaces) {
if(!p.isReservedFor(permbean.getCurrentUser()) && p.isTaken()) if (!p.isReservedFor(permbean.getCurrentUser()) && p.isTaken())
continue; continue;
p = placeFacade.reload(p); // persist teh shit p = placeFacade.reload(p); // persist teh shit
...@@ -331,12 +329,11 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -331,12 +329,11 @@ public class PlaceBean implements PlaceBeanLocal {
// Check wether we should reserve places via credit or plcaeslot // Check wether we should reserve places via credit or plcaeslot
boolean placePrepaidcredit = places.get(0).getProduct().getProductFlags().contains(ProductFlag.PREPAID_CREDIT); boolean placePrepaidcredit = places.get(0).getProduct().getProductFlags().contains(ProductFlag.PREPAID_CREDIT);
// PlaceGroup pg = pgbean.createPlaceGroup(user); // PlaceGroup pg = pgbean.createPlaceGroup(user);
if (placePrepaidcredit && createAccountevents) if (placePrepaidcredit && createAccountevents) {
{
BigDecimal totalprice = addAndCalcPrice(user, null); BigDecimal totalprice = addAndCalcPrice(user, null);
BigDecimal balance = user.getAccountBalance(); BigDecimal balance = user.getAccountBalance();
if (balance.compareTo(totalprice) < 0 && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) { if (balance.compareTo(totalprice) < 0 && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) {
logger.info("User {} Could not buy things because account balance {} is too low for purchase {}", new Object[] { user, balance, totalprice }); logger.info("User {} Could not buy things because account balance {} is too low for purchase {}", new Object[]{user, balance, totalprice});
return null; return null;
} }
...@@ -366,8 +363,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -366,8 +363,7 @@ public class PlaceBean implements PlaceBeanLocal {
logSb.append(p.getName()).append(", "); logSb.append(p.getName()).append(", ");
GroupMembership gm = buy(p, pg); GroupMembership gm = buy(p, pg);
if (!associatedToPlace) if (!associatedToPlace) {
{
logger.info("Associating buyer {} to place {}", user, gm); logger.info("Associating buyer {} to place {}", user, gm);
associatedToPlace = true; associatedToPlace = true;
gm.setUser(user); gm.setUser(user);
...@@ -398,12 +394,10 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -398,12 +394,10 @@ public class PlaceBean implements PlaceBeanLocal {
// If user is not yet associated to this type of product, find it out... // If user is not yet associated to this type of product, find it out...
for (int i = 0; i < quantity.intValue(); ++i) for (int i = 0; i < quantity.intValue(); ++i) {
{
Place freePlace = null; Place freePlace = null;
if (prod.getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT)) if (prod.getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT)) {
{
freePlace = new Place(); freePlace = new Place();
freePlace.setProduct(prod); freePlace.setProduct(prod);
freePlace.setProvidesRole(prod.getProvides()); freePlace.setProvidesRole(prod.getProvides());
...@@ -423,8 +417,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -423,8 +417,7 @@ public class PlaceBean implements PlaceBeanLocal {
} }
GroupMembership gm = buy(freePlace, pg); GroupMembership gm = buy(freePlace, pg);
if (!associatedToPlace) if (!associatedToPlace) {
{
logger.info("Associating buyer {} to place {}", user, gm); logger.info("Associating buyer {} to place {}", user, gm);
associatedToPlace = true; associatedToPlace = true;
gm.setUser(user); gm.setUser(user);
...@@ -440,8 +433,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -440,8 +433,7 @@ public class PlaceBean implements PlaceBeanLocal {
private static boolean isUserMember(EventUser user, Product prod) { private static boolean isUserMember(EventUser user, Product prod) {
boolean ret = false; boolean ret = false;
if (user.getGroupMemberships() != null) if (user.getGroupMemberships() != null) {
{
for (GroupMembership gm : user.getGroupMemberships()) { for (GroupMembership gm : user.getGroupMemberships()) {
if (gm.getPlaceReservation() != null && prod.equals(gm.getPlaceReservation().getProduct())) { if (gm.getPlaceReservation() != null && prod.equals(gm.getPlaceReservation().getProduct())) {
...@@ -466,8 +458,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -466,8 +458,7 @@ public class PlaceBean implements PlaceBeanLocal {
if (pg.getPlaces() == null) { if (pg.getPlaces() == null) {
pg.setPlaces(new ArrayList<Place>()); pg.setPlaces(new ArrayList<Place>());
} }
if (!pg.getPlaces().contains(p)) if (!pg.getPlaces().contains(p)) {
{
pg.getPlaces().add(p); pg.getPlaces().add(p);
} }
return membership; return membership;
...@@ -483,12 +474,11 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -483,12 +474,11 @@ public class PlaceBean implements PlaceBeanLocal {
/** /**
* Release reservation from user * Release reservation from user
* *
* @param place * @param place The place to be released
* The place to be released
* @return true when successfull, on any erroro false. * @return true when successfull, on any erroro false.
*/ */
@Override @Override
@RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS})
public boolean releasePlace(Place place) { public boolean releasePlace(Place place) {
place = placeFacade.reload(place); place = placeFacade.reload(place);
return releasePlacePriv(place) != null; return releasePlacePriv(place) != null;
...@@ -501,7 +491,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -501,7 +491,7 @@ public class PlaceBean implements PlaceBeanLocal {
* @return true when successfull, on any erroro false. * @return true when successfull, on any erroro false.
*/ */
@Override @Override
@RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS})
public boolean userReleasePlace(Place place) { public boolean userReleasePlace(Place place) {
place = placeFacade.reload(place); place = placeFacade.reload(place);
PlaceSlot s = releasePlacePriv(place); PlaceSlot s = releasePlacePriv(place);
...@@ -609,7 +599,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -609,7 +599,7 @@ public class PlaceBean implements PlaceBeanLocal {
float pagey = height / pointInMillim; float pagey = height / pointInMillim;
for (Place place : places) { for (Place place : places) {
Page page = new Page(pdf, new float[] { pagex, pagey }); Page page = new Page(pdf, new float[]{pagex, pagey});
// place code // place code
com.pdfjet.Font font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA); com.pdfjet.Font font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA);
...@@ -618,7 +608,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -618,7 +608,7 @@ public class PlaceBean implements PlaceBeanLocal {
TextLine textLine = new TextLine(font); TextLine textLine = new TextLine(font);
textLine.setText(place.getName()); textLine.setText(place.getName());
textLine.setPosition(5, 15); textLine.setPosition(5, 15);
textLine.setColor(new int[] { 0, 0, 0 }); textLine.setColor(new int[]{0, 0, 0});
textLine.drawOn(page); textLine.drawOn(page);
double currentX = 42; double currentX = 42;
...@@ -631,7 +621,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -631,7 +621,7 @@ public class PlaceBean implements PlaceBeanLocal {
textLine = new TextLine(font); textLine = new TextLine(font);
textLine.setText(place.getPlaceReserver().getUser().getNick()); textLine.setText(place.getPlaceReserver().getUser().getNick());
textLine.setPosition(currentX, 15); textLine.setPosition(currentX, 15);
textLine.setColor(new int[] { 0, 0, 0 }); textLine.setColor(new int[]{0, 0, 0});
textLine.drawOn(page); textLine.drawOn(page);
} }
...@@ -642,7 +632,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -642,7 +632,7 @@ public class PlaceBean implements PlaceBeanLocal {
textLine = new TextLine(font); textLine = new TextLine(font);
textLine.setText(barcodeBean.getPlaceTextCode(place)); textLine.setText(barcodeBean.getPlaceTextCode(place));
textLine.setPosition(currentX, (pagey / 2) + font1); textLine.setPosition(currentX, (pagey / 2) + font1);
textLine.setColor(new int[] { 0, 0, 0 }); textLine.setColor(new int[]{0, 0, 0});
textLine.drawOn(page); textLine.drawOn(page);
} }
...@@ -869,7 +859,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -869,7 +859,7 @@ public class PlaceBean implements PlaceBeanLocal {
throw new EJBAccessException("Trying to move places for another user without permissions!"); throw new EJBAccessException("Trying to move places for another user without permissions!");
} }
if (!dst.isBuyable() || dst.isTaken()) { if (!dst.isBuyable() || dst.isTaken()) {
throw new EJBException("Place already taken!!"); throw new PlaceAlreadyTakenException(dst);
} }
// Store values we want to store to the destination place // Store values we want to store to the destination place
......
...@@ -25,6 +25,7 @@ public enum MapPermission implements IAppPermission { ...@@ -25,6 +25,7 @@ public enum MapPermission implements IAppPermission {
BUY_PLACES, // ("Reserve and buy places from map"), BUY_PLACES, // ("Reserve and buy places from map"),
VIEW, // ("View maps"), VIEW, // ("View maps"),
MANAGE_MAPS, MANAGE_MAPS,
MOVE_PLACES,
//RELEASE_PLACE, // ("Create and modify maps") //RELEASE_PLACE, // ("Create and modify maps")
; ;
...@@ -33,14 +34,15 @@ public enum MapPermission implements IAppPermission { ...@@ -33,14 +34,15 @@ public enum MapPermission implements IAppPermission {
public static final String S_BUY_PLACES = "MAP/BUY_PLACES"; public static final String S_BUY_PLACES = "MAP/BUY_PLACES";
public static final String S_VIEW = "MAP/VIEW"; public static final String S_VIEW = "MAP/VIEW";
public static final String S_MANAGE_MAPS = "MAP/MANAGE_MAPS"; public static final String S_MANAGE_MAPS = "MAP/MANAGE_MAPS";
public static final String S_RELEASE_PLACE = "MAP/RELEASE_PLACE"; public static final String S_MOVE_PLACES = "MAP/MOVE_PLACES";
private final String fullName; private final String fullName;
private final String key; private final String key;
private static final String I18N_HEADER = "bortalApplication.map."; private static final String I18N_HEADER = "bortalApplication.map.";
private MapPermission() { private MapPermission() {
key = I18N_HEADER + name(); key = I18N_HEADER + name();
fullName = new StringBuilder().append(getParent().toString()).append(DELIMITER).append(toString()).toString(); fullName = getParent().toString() + DELIMITER + this.toString();
} }
......
...@@ -10,25 +10,23 @@ ...@@ -10,25 +10,23 @@
xmlns:p="http://primefaces.org/ui"> xmlns:p="http://primefaces.org/ui">
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
<f:event type="preRenderView" <f:viewParam name="userId" value="#{mapPlacechangeView.userId}"/>
listener="#{mapPlacechangeView.initView()}" /> <f:event type="preRenderView" listener="#{mapPlacechangeView.initView()}"/>
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<h:outputScript target="head" library="seatjs" name="d3.min.js" /> <h:outputScript target="head" library="seatjs" name="d3.min.js"/>
<h:outputScript target="head" library="seatjs" name="d3-tip.js" /> <h:outputScript target="head" library="seatjs" name="d3-tip.js"/>
<h:outputScript target="head" library="seatjs" name="seatmap.js" /> <h:outputScript target="head" library="seatjs" name="seatmap.js"/>
<h:outputStylesheet library="seatjs" name="placemap.css" /> <h:outputStylesheet library="seatjs" name="placemap.css"/>
<!-- Place slot count --> <!-- Place slot count -->
<h3> <h3>
<h:outputText value="#{i18n['placemove.header']}" /> <h:outputText value="#{i18n['placemove.header']}"/>
</h3> </h3>
<p:fragment id="placeselector"> <p:fragment id="placeselector">
<h:form> <h:form>
...@@ -38,25 +36,25 @@ ...@@ -38,25 +36,25 @@
<!-- rowStyleClass="#{mapPlacechangeView.srcPlace.contains(slot.place) ? 'selected' : 'unselected'}" --> <!-- rowStyleClass="#{mapPlacechangeView.srcPlace.contains(slot.place) ? 'selected' : 'unselected'}" -->
<p:column headerText="#{i18n['placemove.productname']}"> <p:column headerText="#{i18n['placemove.productname']}">
<h:outputText value="#{slot.src.product.name}" /> <h:outputText value="#{slot.src.product.name}"/>
</p:column> </p:column>
<p:column headerText="#{i18n['placemove.placename']}"> <p:column headerText="#{i18n['placemove.placename']}">
<h:outputText renderer="#{!empty slot.src.place}" <h:outputText renderer="#{!empty slot.src.place}"
value="#{slot.src.place.name}" /> value="#{slot.src.place.name}"/>
</p:column> </p:column>
<p:column headerText="#{i18n['placemove.placeuser']}"> <p:column headerText="#{i18n['placemove.placeuser']}">
<h:outputText rendered="#{!empty slot.src.place.currentUser}" <h:outputText rendered="#{!empty slot.src.place.currentUser}"
value="#{slot.src.place.currentUser.wholeNmae}" /> value="#{slot.src.place.currentUser.wholeNmae}"/>
<h:outputText rendered="#{empty slot.src.place.currentUser}" <h:outputText rendered="#{empty slot.src.place.currentUser}"
value="-" /> value="-"/>
</p:column> </p:column>
<p:column headerText="#{i18n['placemove.dstplace']}"> <p:column headerText="#{i18n['placemove.dstplace']}">
<div style="padding: 0.3em 0;"> <div style="padding: 0.3em 0;">
<h:outputText renderer="#{!empty slot.dst}" <h:outputText renderer="#{!empty slot.dst}"
value="#{slot.dst.name}" /> value="#{slot.dst.name}"/>
</div> </div>
</p:column> </p:column>
...@@ -66,11 +64,11 @@ ...@@ -66,11 +64,11 @@
actionListener="#{mapPlacechangeView.selectSlot}" actionListener="#{mapPlacechangeView.selectSlot}"
rendered="#{!slot.isMoving()}" rendered="#{!slot.isMoving()}"
value="#{i18n['placemove.selectSlotForMove']}" value="#{i18n['placemove.selectSlotForMove']}"
update="placeselector" /> update="placeselector"/>
<p:commandButton <p:commandButton
actionListener="#{mapPlacechangeView.unselectSlot}" actionListener="#{mapPlacechangeView.unselectSlot}"
rendered="#{slot.moving}" value="#{i18n['placemove.deselect']}" rendered="#{slot.moving}" value="#{i18n['placemove.deselect']}"
update="placeselector" /> update="placeselector"/>
</ui:fragment> </ui:fragment>
</p:column> </p:column>
...@@ -78,9 +76,8 @@ ...@@ -78,9 +76,8 @@
</h:form> </h:form>
<script type="text/javascript"> <script type="text/javascript">
toggleSuccess = #{mapPlacechangeView.toggleSuccess}; var toggleSuccess = #{mapPlacechangeView.toggleSuccess};
</script> </script>
</p:fragment>
<div style="padding: 1em 0;"> <div style="padding: 1em 0;">
<h:form id="placemove"> <h:form id="placemove">
...@@ -88,20 +85,19 @@ ...@@ -88,20 +85,19 @@
disabled="#{!mapPlacechangeView.isReadyForCommit()}" disabled="#{!mapPlacechangeView.isReadyForCommit()}"
rendered="#{ajaxMapView.canUserBuy()}" rendered="#{ajaxMapView.canUserBuy()}"
value="#{i18n['placemove.commitMove']}" value="#{i18n['placemove.commitMove']}"
action="#{mapPlacechangeView.commitMove()}" ajax="false" /> action="#{mapPlacechangeView.commitMove()}" ajax="false"/>
</h:form> </h:form>
</div> </div>
</p:fragment>
<svg id="seatmap" style="margin: auto; border: 1px solid black;" <svg id="seatmap" style="margin: auto; border: 1px solid black;"
width="#{ajaxMapView.map.width}px" width="#{ajaxMapView.map.width}px"
height="#{ajaxMapView.map.height}px" /> height="#{ajaxMapView.map.height}px"/>
<h:form> <h:form>
<p:remoteCommand name="toggleDstPlace" <p:remoteCommand name="toggleDstPlace"
action="#{mapPlacechangeView.toggleDstPlace()}" action="#{mapPlacechangeView.toggleDstPlace()}"
update="placeselector" oncomplete="afterToggle()"></p:remoteCommand> update="placeselector" oncomplete="afterToggle()"/>
</h:form> </h:form>
<script type="text/javascript"> <script type="text/javascript">
...@@ -112,26 +108,26 @@ ...@@ -112,26 +108,26 @@
moyaurl: "#{request.contextPath}", moyaurl: "#{request.contextPath}",
map_id: #{ajaxMapView.map.id}, map_id: #{ajaxMapView.map.id},
}); });
px.toggleaction = function(d){ px.toggleaction = function (d) {
latestPlace = d; latestPlace = d;
toggleDstPlace([{name:"placeId", value:d.id} ]) toggleDstPlace([{name: "placeId", value: d.id}])
}; };
function afterToggle(){ function afterToggle() {
if(toggleSuccess){ if (toggleSuccess) {
if(latestPlace.state === "F"){ if (latestPlace.state === "F") {
latestPlace.state = "T"; latestPlace.state = "T";
}else { } else {
latestPlace.state = "F"; latestPlace.state = "F";
} }
px.update_placeobj([latestPlace]); px.update_placeobj([latestPlace]);
} }
} }
// ]]> // ]]>
</script> </script>
<map:legend /> <map:legend/>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "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" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"> 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:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<ui:param name="thispage" value="page.place.mygroups" /> <ui:param name="thispage" value="page.place.mygroups"/>
<f:metadata> <f:metadata>
<f:viewParam name="userid" value="#{userView.userid}" /> <f:viewParam name="userid" value="#{userView.userid}"/>
<f:event type="preRenderView" listener="#{userView.initView}" /> <f:event type="preRenderView" listener="#{userView.initView}"/>
</f:metadata> </f:metadata>
<ui:define name="title"> <ui:define name="title">
...@@ -16,57 +18,70 @@ ...@@ -16,57 +18,70 @@
<!-- <users:usertabs tabId="groups" /> --> <!-- <users:usertabs tabId="groups" /> -->
</ui:define> </ui:define>
<ui:define name="edittab"> <ui:define name="edittab">
<users:usertabs tabId="groups" /> <users:usertabs tabId="groups"/>
</ui:define> </ui:define>
<ui:define name="content"> <ui:define name="content">
<h:outputText rendered="#{empty placeGroupView.groupMemberships}" value="#{i18n['placegroupview.noMemberships']}" /> <h:link outcome="/neomap/moveplaces" value="#{i18n['placegroupview.moveUsersPlaces']}">
<f:param name="userId" value="#{userView.user.user.id}"/>
</h:link>
<h:outputText rendered="#{empty placeGroupView.groupMemberships}"
value="#{i18n['placegroupview.noMemberships']}"/>
<h:form rendered="#{!empty placeGroupView.groupMemberships}" id="placelistform"> <h:form rendered="#{!empty placeGroupView.groupMemberships}" id="placelistform">
<h:dataTable value="#{placeGroupView.groupMemberships}" var="member"> <h:dataTable value="#{placeGroupView.groupMemberships}" var="member">
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['placegroupview.reservationName']}" /> <h:outputText value="#{i18n['placegroupview.reservationName']}"/>
</f:facet> </f:facet>
<h:link value="#{member.placeReservation.name}" outcome="/place/edit"> <h:link value="#{member.placeReservation.name}" outcome="/place/edit">
<f:param name="placeid" value="#{member.placeReservation.id}" /> <f:param name="placeid" value="#{member.placeReservation.id}"/>
</h:link> </h:link>
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['placegroupview.token']}" /> <h:outputText value="#{i18n['placegroupview.token']}"/>
</f:facet> </f:facet>
<h:outputText rendered="#{empty member.user}" value="#{member.inviteToken}" /> <h:outputText rendered="#{empty member.user}" value="#{member.inviteToken}"/>
<h:link rendered="#{!empty member.user}" value="#{member.user.firstnames} #{member.user.lastname} (#{member.user.nick})" outcome="/place/adminGroups"> <h:link rendered="#{!empty member.user}"
<f:param name="userid" value="#{member.user.user.id}" /> value="#{member.user.firstnames} #{member.user.lastname} (#{member.user.nick})"
outcome="/place/adminGroups">
<f:param name="userid" value="#{member.user.user.id}"/>
</h:link> </h:link>
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['placegroupview.groupCreator']}" /> <h:outputText value="#{i18n['placegroupview.groupCreator']}"/>
</f:facet> </f:facet>
<h:link value="#{member.placeGroup.creator.firstnames} #{member.placeGroup.creator.lastname} (#{member.placeGroup.creator.nick})" outcome="/place/adminGroups"> <h:link
<f:param name="userid" value="#{member.placeGroup.creator.user.id}" /> value="#{member.placeGroup.creator.firstnames} #{member.placeGroup.creator.lastname} (#{member.placeGroup.creator.nick})"
outcome="/place/adminGroups">
<f:param name="userid" value="#{member.placeGroup.creator.user.id}"/>
</h:link> </h:link>
</h:column> </h:column>
<h:column> <h:column>
<h:commandButton rendered="#{placeGroupView.canModifyCurrent and placeGroupView.currentMemberUserNotNull}" action="#{placeGroupView.releasePlace()}" <h:commandButton
value="#{i18n['placegroupview.releasePlace']}" /> rendered="#{placeGroupView.canModifyCurrent and placeGroupView.currentMemberUserNotNull}"
action="#{placeGroupView.releasePlace()}"
value="#{i18n['placegroupview.releasePlace']}"/>
</h:column> </h:column>
</h:dataTable> </h:dataTable>
</h:form> </h:form>
<p> <p>
<input type="button" onclick="location.replace('#{request.contextPath}/PlaceGroupPdf?eventuserId=#{placeGroupView.user.id}');" value="#{i18n['placegroup.printPdf']}" /> <input type="button"
onclick="location.replace('#{request.contextPath}/PlaceGroupPdf?eventuserId=#{placeGroupView.user.id}');"
value="#{i18n['placegroup.printPdf']}"/>
</p> </p>
<h2>#{i18n['placetoken.pageHeader']}</h2> <h2>#{i18n['placetoken.pageHeader']}</h2>
<p>#{i18n['placetoken.topText']}</p> <p>#{i18n['placetoken.topText']}</p>
<h:form id="placeTokenForm"> <h:form id="placeTokenForm">
<h:outputLabel value="#{i18n['placetoken.token']}:" /> <h:outputLabel value="#{i18n['placetoken.token']}:"/>
<h:inputText value="#{tokenView.token}" /> <h:inputText value="#{tokenView.token}"/>
<h:commandButton id="commitbtn" action="#{tokenView.saveToken()}" value="#{i18n['placetoken.commit']}" /> <h:commandButton id="commitbtn" action="#{tokenView.saveToken()}" value="#{i18n['placetoken.commit']}"/>
</h:form> </h:form>
<h2>Place slots</h2> <h2>Place slots</h2>
...@@ -74,38 +89,43 @@ ...@@ -74,38 +89,43 @@
<p:dataTable var="slot" value="#{placeGroupView.placeslots}" id="placeslots"> <p:dataTable var="slot" value="#{placeGroupView.placeslots}" id="placeslots">
<p:column headerText="#{i18n['placeslot.id']}"> <p:column headerText="#{i18n['placeslot.id']}">
<h:outputText value="#{slot.id}" /> <h:outputText value="#{slot.id}"/>
</p:column> </p:column>
<p:column headerText="#{i18n['placeslot.state']}"> <p:column headerText="#{i18n['placeslot.state']}">
<h:outputText value="#{slot.bill.expired ? i18n['placeslot.state.expired'] : ( slot.bill.paid ? i18n['placeslot.state.paid'] : i18n['placeslot.state.notPaid'])}" /> <h:outputText
value="#{slot.bill.expired ? i18n['placeslot.state.expired'] : ( slot.bill.paid ? i18n['placeslot.state.paid'] : i18n['placeslot.state.notPaid'])}"/>
</p:column> </p:column>
<p:column headerText="#{i18n['placeslot.product']}"> <p:column headerText="#{i18n['placeslot.product']}">
<h:outputText value="#{slot.product.name}" /> <h:outputText value="#{slot.product.name}"/>
</p:column> </p:column>
<p:column headerText="#{i18n['placeslot.place']}"> <p:column headerText="#{i18n['placeslot.place']}">
<h:link value="#{slot.place.name}" rendered="#{!empty slot.place}" outcome="/place/edit"> <h:link value="#{slot.place.name}" rendered="#{!empty slot.place}" outcome="/place/edit">
<f:param name="placeid" value="#{slot.place.id}" /> <f:param name="placeid" value="#{slot.place.id}"/>
</h:link> </h:link>
</p:column> </p:column>
<p:column headerText="#{i18n['placeslot.used']}"> <p:column headerText="#{i18n['placeslot.used']}">
<h:outputText value="#{slot.used}"> <h:outputText value="#{slot.used}">
<f:convertDateTime timeZone="#{sessionHandler.timezone}" pattern="#{sessionHandler.shortDatetimeFormat}" /> <f:convertDateTime timeZone="#{sessionHandler.timezone}"
pattern="#{sessionHandler.shortDatetimeFormat}"/>
</h:outputText> </h:outputText>
</p:column> </p:column>
<p:column headerText="#{i18n['placeslot.bill']}"> <p:column headerText="#{i18n['placeslot.bill']}">
<h:link outcome="/bill/showBill" value="#{i18n['bill.billNumber']}: #{slot.bill.id}"> <h:link outcome="/bill/showBill" value="#{i18n['bill.billNumber']}: #{slot.bill.id}">
<f:param name="billid" value="#{slot.bill.id}" /> <f:param name="billid" value="#{slot.bill.id}"/>
</h:link> </h:link>
</p:column> </p:column>
<p:column> <p:column>
<p:commandButton rendered="#{empty slot.place and empty slot.used}" value="#{i18n['placeslot.lockSlot']}" actionListener="#{placeGroupView.lockSlot}" update="placeslots" /> <p:commandButton rendered="#{empty slot.place and empty slot.used}"
<p:commandButton rendered="#{empty slot.place and not empty slot.used}" value="#{i18n['placeslot.releaseSlot']}" actionListener="#{placeGroupView.releaseSlot}" update="placeslots" /> value="#{i18n['placeslot.lockSlot']}"
actionListener="#{placeGroupView.lockSlot}" update="placeslots"/>
<p:commandButton rendered="#{empty slot.place and not empty slot.used}"
value="#{i18n['placeslot.releaseSlot']}"
actionListener="#{placeGroupView.releaseSlot}" update="placeslots"/>
</p:column> </p:column>
</p:dataTable> </p:dataTable>
</h:form> </h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<h:outputText value="#{dependency.priority}"/> <h:outputText value="#{dependency.priority}"/>
</h:column> </h:column>
<h:column> <h:column>
<p:commandButton action="#{productView.deleteProductDependency}" value="#{i18n['productDependency.delete']}" update=":dependencies"/> <p:commandButton action="#{productView.deleteProductDependency}" value="#{i18n['product.dependency.delete']}" update=":dependencies"/>
</h:column> </h:column>
<!-- Not yet in use. <!-- Not yet in use.
......
...@@ -11,6 +11,7 @@ import javax.faces.context.FacesContext; ...@@ -11,6 +11,7 @@ import javax.faces.context.FacesContext;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import javax.inject.Named; import javax.inject.Named;
import fi.codecrew.moya.exceptions.PlaceAlreadyTakenException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -80,18 +81,29 @@ public class MapPlacechangeView extends GenericCDIView { ...@@ -80,18 +81,29 @@ public class MapPlacechangeView extends GenericCDIView {
} }
public boolean isReadyForCommit() { public boolean isReadyForCommit() {
// If anything is not selected for commit, we are not ready..
boolean movingAny = false;
for (MoveContainer mc : moveContainers) { for (MoveContainer mc : moveContainers) {
if (mc.isMoving() && mc.getDst() == null) { // If we are moving, but destination is not selected, we are not ready..
if (mc.isMoving()) {
movingAny = true;
if (mc.getDst() == null) {
return false; return false;
} }
} }
return true; }
return movingAny;
} }
public void initView() { public void initView() {
// If we are overriding user, check permission. // If we are overriding user, check permission.
if (getSlots() == null) { if (super.requirePermissions(
super.hasPermission(MapPermission.MOVE_PLACES) ||
super.hasPermission(MapPermission.MANAGE_MAPS)
) && getSlots() == null) {
if (userId != null && super.requirePermissions(MapPermission.MANAGE_OTHERS)) { if (userId != null && super.requirePermissions(MapPermission.MANAGE_OTHERS)) {
user = userbean.findByUserId(userId, false); user = userbean.findByUserId(userId, false);
} else if (super.requirePermissions(MapPermission.BUY_PLACES)) { } else if (super.requirePermissions(MapPermission.BUY_PLACES)) {
...@@ -102,7 +114,7 @@ public class MapPlacechangeView extends GenericCDIView { ...@@ -102,7 +114,7 @@ public class MapPlacechangeView extends GenericCDIView {
super.beginConversation(); super.beginConversation();
moveContainers = MoveContainer.init(placebean.getPlaceslots(user)); moveContainers = MoveContainer.init(placebean.getPlaceslots(user));
slots = new ListDataModel<MoveContainer>(moveContainers); slots = new ListDataModel<>(moveContainers);
} }
} }
...@@ -115,8 +127,22 @@ public class MapPlacechangeView extends GenericCDIView { ...@@ -115,8 +127,22 @@ public class MapPlacechangeView extends GenericCDIView {
change.put(s.getSrc().getPlace(), s.getDst()); change.put(s.getSrc().getPlace(), s.getDst());
} }
} }
try {
placebean.movePlaces(change); placebean.movePlaces(change);
} catch (PlaceAlreadyTakenException pt) {
String placename = "";
if (pt.getPlace() != null) {
placename = pt.getPlace().getName();
for (MoveContainer mv : slots) {
if (pt.getPlace().equals(mv.getDst())) {
mv.setDst(null);
}
}
}
super.addFaceMessage("placemove.alreadyTaken", placename);
return null;
}
// slots = null; // slots = null;
// initView(); // initView();
return "/place/myGroups?faces_redirect=true"; return "/place/myGroups?faces_redirect=true";
......
...@@ -1876,11 +1876,16 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time ...@@ -1876,11 +1876,16 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time
mapView.reserveTimeLeft=Time to reserve places mapView.reserveTimeLeft=Time to reserve places
queuemgmt.queueEnabled=Queue is ENABLED queuemgmt.queueEnabled=Queue is ENABLED
queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page) queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page)
product.dependency.add=Add product dependency product.dependency.add=Add product dependency
product.dependency.create=Create product.dependency.create=Create
product.dependency.supporter=Depended product product.dependency.supporter=Depended product
product.dependency.type=Dependency type product.dependency.type=Dependency type
product.dependency.priority=Priority product.dependency.priority=Priority
productDependency.delete=Delete product.dependency.delete=Delete
product.dependency.multiplier=Multiplier product.dependency.multiplier=Multiplier
product.dependency.MAX_SUPPORTED_COUNT=Only up to same number of products can be bought product.dependency.MAX_SUPPORTED_COUNT=Only up to same number of products can be bought
placemove.alreadyTaken=Moving the places was cancelled because place {0} was already taken.
placegroupview.moveUsersPlaces=Move users places
...@@ -1863,11 +1863,15 @@ reservequeue.reservingTimeIsUpAlert=Sinulle varattu varausauka on kulunut loppuu ...@@ -1863,11 +1863,15 @@ reservequeue.reservingTimeIsUpAlert=Sinulle varattu varausauka on kulunut loppuu
mapView.reserveTimeLeft=Aikaa varata paikkasi mapView.reserveTimeLeft=Aikaa varata paikkasi
queuemgmt.queueEnabled=Varausjono ON k\u00E4yt\u00F6ss\u00E4 queuemgmt.queueEnabled=Varausjono ON k\u00E4yt\u00F6ss\u00E4
queuemgmt.queueDisabled=K\u00E4ytt\u00E4j\u00E4jono EI OLE k\u00E4yt\u00F6ss\u00E4 (ota k\u00E4yttoon tapahtuman tiedot -sivulta) queuemgmt.queueDisabled=K\u00E4ytt\u00E4j\u00E4jono EI OLE k\u00E4yt\u00F6ss\u00E4 (ota k\u00E4yttoon tapahtuman tiedot -sivulta)
product.dependency.add=Lis\u00E4\u00E4 tuoteriippuvuus product.dependency.add=Lis\u00E4\u00E4 tuoteriippuvuus
product.dependency.create=Luo uusi product.dependency.create=Luo uusi
product.dependency.supporter=Tuote josta on riippuvuus product.dependency.supporter=Tuote josta on riippuvuus
product.dependency.type=Riippuvuuden tyyppi product.dependency.type=Riippuvuuden tyyppi
product.dependency.priority=Prioriteetti product.dependency.priority=Prioriteetti
productDependency.delete=Poista product.dependency.delete=Poista
product.dependency.multiplier=Kerroin product.dependency.multiplier=Kerroin
product.dependency.MAX_SUPPORTED_COUNT=Tuotteita voi ostaa enint\u00E4\u00E4n saman m\u00E4\u00E4r\u00E4n product.dependency.MAX_SUPPORTED_COUNT=Tuotteita voi ostaa enint\u00E4\u00E4n saman m\u00E4\u00E4r\u00E4n
placemove.alreadyTaken=Paikkojen siirto peruuntui koska paikka {0} oli jo varattu.
placegroupview.moveUsersPlaces=Siirrä käyttäjän paikkoja
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!