Commit f591cc15 by Tuomas Riihimäki

Error handlin, etc

1 parent 3631ff43
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;
}
}
......@@ -49,6 +49,8 @@ import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import fi.codecrew.moya.exceptions.PlaceAlreadyTakenException;
import fi.codecrew.moya.facade.*;
import fi.codecrew.moya.model.*;
......@@ -869,7 +871,7 @@ public class PlaceBean implements PlaceBeanLocal {
throw new EJBAccessException("Trying to move places for another user without permissions!");
}
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
......
......@@ -25,6 +25,7 @@ public enum MapPermission implements IAppPermission {
BUY_PLACES, // ("Reserve and buy places from map"),
VIEW, // ("View maps"),
MANAGE_MAPS,
MOVE_PLACES,
//RELEASE_PLACE, // ("Create and modify maps")
;
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:map="http://java.sun.com/jsf/composite/cditools/map"
xmlns:tools="http://java.sun.com/jsf/composite/cditools"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:map="http://java.sun.com/jsf/composite/cditools/map"
xmlns:tools="http://java.sun.com/jsf/composite/cditools"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView"
listener="#{mapPlacechangeView.initView()}" />
</f:metadata>
<ui:define name="content">
<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="seatmap.js" />
<h:outputStylesheet library="seatjs" name="placemap.css" />
<!-- Place slot count -->
<h3>
<h:outputText value="#{i18n['placemove.header']}" />
</h3>
<p:fragment id="placeselector">
<h:form>
<p:dataTable id="slottable" tableStyle="width: auto;" var="slot"
value="#{mapPlacechangeView.slots}">
<!-- rowStyleClass="#{mapPlacechangeView.srcPlace.contains(slot.place) ? 'selected' : 'unselected'}" -->
<p:column headerText="#{i18n['placemove.productname']}">
<h:outputText value="#{slot.src.product.name}" />
</p:column>
<p:column headerText="#{i18n['placemove.placename']}">
<h:outputText renderer="#{!empty slot.src.place}"
value="#{slot.src.place.name}" />
</p:column>
<p:column headerText="#{i18n['placemove.placeuser']}">
<h:outputText rendered="#{!empty slot.src.place.currentUser}"
value="#{slot.src.place.currentUser.wholeNmae}" />
<h:outputText rendered="#{empty slot.src.place.currentUser}"
value="-" />
</p:column>
<p:column headerText="#{i18n['placemove.dstplace']}">
<div style="padding: 0.3em 0;">
<h:outputText renderer="#{!empty slot.dst}"
value="#{slot.dst.name}" />
</div>
</p:column>
<p:column>
<ui:fragment rendered="#{empty slot.dst}">
<p:commandButton
actionListener="#{mapPlacechangeView.selectSlot}"
rendered="#{!slot.isMoving()}"
value="#{i18n['placemove.selectSlotForMove']}"
update="placeselector" />
<p:commandButton
actionListener="#{mapPlacechangeView.unselectSlot}"
rendered="#{slot.moving}" value="#{i18n['placemove.deselect']}"
update="placeselector" />
</ui:fragment>
</p:column>
</p:dataTable>
</h:form>
<script type="text/javascript">
toggleSuccess = #{mapPlacechangeView.toggleSuccess};
</script>
</p:fragment>
<div style="padding: 1em 0;">
<h:form id="placemove">
<p:commandButton
disabled="#{!mapPlacechangeView.isReadyForCommit()}"
rendered="#{ajaxMapView.canUserBuy()}"
value="#{i18n['placemove.commitMove']}"
action="#{mapPlacechangeView.commitMove()}" ajax="false" />
</h:form>
</div>
<svg id="seatmap" style="margin: auto; border: 1px solid black;"
width="#{ajaxMapView.map.width}px"
height="#{ajaxMapView.map.height}px" />
<h:form>
<p:remoteCommand name="toggleDstPlace"
action="#{mapPlacechangeView.toggleDstPlace()}"
update="placeselector" oncomplete="afterToggle()"></p:remoteCommand>
</h:form>
<script type="text/javascript">
// <![CDATA[
px = placemap({
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="userId" value="#{mapPlacechangeView.userId}"/>
<f:event type="preRenderView" listener="#{mapPlacechangeView.initView()}"/>
</f:metadata>
<ui:define name="content">
<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="seatmap.js"/>
<h:outputStylesheet library="seatjs" name="placemap.css"/>
<!-- Place slot count -->
<h3>
<h:outputText value="#{i18n['placemove.header']}"/>
</h3>
<p:fragment id="placeselector">
<h:form>
<p:dataTable id="slottable" tableStyle="width: auto;" var="slot"
value="#{mapPlacechangeView.slots}">
<!-- rowStyleClass="#{mapPlacechangeView.srcPlace.contains(slot.place) ? 'selected' : 'unselected'}" -->
<p:column headerText="#{i18n['placemove.productname']}">
<h:outputText value="#{slot.src.product.name}"/>
</p:column>
<p:column headerText="#{i18n['placemove.placename']}">
<h:outputText renderer="#{!empty slot.src.place}"
value="#{slot.src.place.name}"/>
</p:column>
<p:column headerText="#{i18n['placemove.placeuser']}">
<h:outputText rendered="#{!empty slot.src.place.currentUser}"
value="#{slot.src.place.currentUser.wholeNmae}"/>
<h:outputText rendered="#{empty slot.src.place.currentUser}"
value="-"/>
</p:column>
<p:column headerText="#{i18n['placemove.dstplace']}">
<div style="padding: 0.3em 0;">
<h:outputText renderer="#{!empty slot.dst}"
value="#{slot.dst.name}"/>
</div>
</p:column>
<p:column>
<ui:fragment rendered="#{empty slot.dst}">
<p:commandButton
actionListener="#{mapPlacechangeView.selectSlot}"
rendered="#{!slot.isMoving()}"
value="#{i18n['placemove.selectSlotForMove']}"
update="placeselector"/>
<p:commandButton
actionListener="#{mapPlacechangeView.unselectSlot}"
rendered="#{slot.moving}" value="#{i18n['placemove.deselect']}"
update="placeselector"/>
</ui:fragment>
</p:column>
</p:dataTable>
</h:form>
<script type="text/javascript">
var toggleSuccess = #{mapPlacechangeView.toggleSuccess};
</script>
<div style="padding: 1em 0;">
<h:form id="placemove">
<p:commandButton
disabled="#{!mapPlacechangeView.isReadyForCommit()}"
rendered="#{ajaxMapView.canUserBuy()}"
value="#{i18n['placemove.commitMove']}"
action="#{mapPlacechangeView.commitMove()}" ajax="false"/>
</h:form>
</div>
</p:fragment>
<svg id="seatmap" style="margin: auto; border: 1px solid black;"
width="#{ajaxMapView.map.width}px"
height="#{ajaxMapView.map.height}px"/>
<h:form>
<p:remoteCommand name="toggleDstPlace"
action="#{mapPlacechangeView.toggleDstPlace()}"
update="placeselector" oncomplete="afterToggle()"/>
</h:form>
<script type="text/javascript">
// <![CDATA[
px = placemap({
element: document.getElementById("seatmap"),
moyaurl: "#{request.contextPath}",
map_id: #{ajaxMapView.map.id},
});
px.toggleaction = function(d){
latestPlace = d;
toggleDstPlace([{name:"placeId", value:d.id} ])
px.toggleaction = function (d) {
latestPlace = d;
toggleDstPlace([{name: "placeId", value: d.id}])
};
function afterToggle(){
if(toggleSuccess){
if(latestPlace.state === "F"){
latestPlace.state = "T";
}else {
latestPlace.state = "F";
}
px.update_placeobj([latestPlace]);
}
}
// ]]>
function afterToggle() {
if (toggleSuccess) {
if (latestPlace.state === "F") {
latestPlace.state = "T";
} else {
latestPlace.state = "F";
}
px.update_placeobj([latestPlace]);
}
}
// ]]>
</script>
<map:legend />
<map:legend/>
</ui:define>
</ui:composition>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -20,6 +20,10 @@
</ui:define>
<ui:define name="content">
<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:dataTable value="#{placeGroupView.groupMemberships}" var="member">
......
......@@ -11,6 +11,7 @@ import javax.faces.context.FacesContext;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import fi.codecrew.moya.exceptions.PlaceAlreadyTakenException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -26,189 +27,214 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
@ConversationScoped
public class MapPlacechangeView extends GenericCDIView {
private static final Logger logger = LoggerFactory.getLogger(MapPlacechangeView.class);
private static final long serialVersionUID = 1L;
private Integer userId;
private EventUser user;
@EJB
private UserBeanLocal userbean;
@EJB
private PlaceBeanLocal placebean;
private ListDataModel<MoveContainer> slots;
private List<MoveContainer> moveContainers;
private boolean toggleSuccess;
public static class MoveContainer {
private boolean moving = false;
private final PlaceSlot src;
private Place dst;
public MoveContainer(PlaceSlot p) {
this.src = p;
}
public static List<MoveContainer> init(List<PlaceSlot> placeslots) {
ArrayList<MoveContainer> ret = new ArrayList<>();
for (PlaceSlot p : placeslots) {
ret.add(new MoveContainer(p));
}
return ret;
}
public boolean isMoving() {
return moving;
}
public void setMoving(boolean moving) {
this.moving = moving;
}
public Place getDst() {
return dst;
}
public void setDst(Place dst) {
this.dst = dst;
}
public PlaceSlot getSrc() {
return src;
}
}
public boolean isReadyForCommit() {
for (MoveContainer mc : moveContainers) {
if (mc.isMoving() && mc.getDst() == null) {
return false;
}
}
return true;
}
public void initView() {
// If we are overriding user, check permission.
if (getSlots() == null) {
if (userId != null && super.requirePermissions(MapPermission.MANAGE_OTHERS)) {
user = userbean.findByUserId(userId, false);
} else if (super.requirePermissions(MapPermission.BUY_PLACES)) {
user = permbean.getCurrentUser();
} else {
return;
}
super.beginConversation();
moveContainers = MoveContainer.init(placebean.getPlaceslots(user));
slots = new ListDataModel<MoveContainer>(moveContainers);
}
}
public String commitMove() {
HashMap<Place, Place> change = new HashMap<Place, Place>();
for (MoveContainer s : slots) {
if (s.isMoving() && s.getDst() != null) {
change.put(s.getSrc().getPlace(), s.getDst());
}
}
placebean.movePlaces(change);
// slots = null;
// initView();
return "/place/myGroups?faces_redirect=true";
}
public void toggleDstPlace() {
Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
Integer placeId = new Integer(paramMap.get("placeId"));
Place place = placebean.find(placeId);
toggleSuccess = false;
for (MoveContainer mc : getMoveContainers()) {
if (place.equals(mc.getSrc().getPlace())) {
setSlotState(mc, !mc.isMoving());
return;
}
if (place.equals(mc.getDst())) {
toggleSuccess = true;
mc.setDst(null);
return;
}
}
if (!place.isBuyable() || place.isTaken()) {
return;
}
for (MoveContainer mc : moveContainers) {
if (mc.isMoving() && mc.dst == null && mc.getSrc().getProduct().equals(place.getProduct())) {
toggleSuccess = true;
mc.setDst(place);
return;
}
}
}
public String selectSlot() {
setSlotState(slots.getRowData(), true);
return null;
}
private void setSlotState(MoveContainer mc, boolean moving) {
if (!moving && mc.getDst() != null) {
return;
}
mc.setMoving(moving);
}
public String unselectSlot() {
setSlotState(getSlots().getRowData(), false);
return null;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser user) {
this.user = user;
}
public List<MoveContainer> getMoveContainers() {
return moveContainers;
}
public void setMoveContainers(List<MoveContainer> moveContainers) {
this.moveContainers = moveContainers;
}
public ListDataModel<MoveContainer> getSlots() {
return slots;
}
public void setSlots(ListDataModel<MoveContainer> slots) {
this.slots = slots;
}
public boolean isToggleSuccess() {
return toggleSuccess;
}
public void setToggleSuccess(boolean toggleSuccess) {
this.toggleSuccess = toggleSuccess;
}
private static final Logger logger = LoggerFactory.getLogger(MapPlacechangeView.class);
private static final long serialVersionUID = 1L;
private Integer userId;
private EventUser user;
@EJB
private UserBeanLocal userbean;
@EJB
private PlaceBeanLocal placebean;
private ListDataModel<MoveContainer> slots;
private List<MoveContainer> moveContainers;
private boolean toggleSuccess;
public static class MoveContainer {
private boolean moving = false;
private final PlaceSlot src;
private Place dst;
public MoveContainer(PlaceSlot p) {
this.src = p;
}
public static List<MoveContainer> init(List<PlaceSlot> placeslots) {
ArrayList<MoveContainer> ret = new ArrayList<>();
for (PlaceSlot p : placeslots) {
ret.add(new MoveContainer(p));
}
return ret;
}
public boolean isMoving() {
return moving;
}
public void setMoving(boolean moving) {
this.moving = moving;
}
public Place getDst() {
return dst;
}
public void setDst(Place dst) {
this.dst = dst;
}
public PlaceSlot getSrc() {
return src;
}
}
public boolean isReadyForCommit() {
// If anything is not selected for commit, we are not ready..
boolean movingAny = false;
for (MoveContainer mc : moveContainers) {
// 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 movingAny;
}
public void initView() {
// If we are overriding user, check permission.
if (super.requirePermissions(
super.hasPermission(MapPermission.MOVE_PLACES) ||
super.hasPermission(MapPermission.MANAGE_MAPS)
) && getSlots() == null) {
if (userId != null && super.requirePermissions(MapPermission.MANAGE_OTHERS)) {
user = userbean.findByUserId(userId, false);
} else if (super.requirePermissions(MapPermission.BUY_PLACES)) {
user = permbean.getCurrentUser();
} else {
return;
}
super.beginConversation();
moveContainers = MoveContainer.init(placebean.getPlaceslots(user));
slots = new ListDataModel<>(moveContainers);
}
}
public String commitMove() {
HashMap<Place, Place> change = new HashMap<Place, Place>();
for (MoveContainer s : slots) {
if (s.isMoving() && s.getDst() != null) {
change.put(s.getSrc().getPlace(), s.getDst());
}
}
try {
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;
// initView();
return "/place/myGroups?faces_redirect=true";
}
public void toggleDstPlace() {
Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
Integer placeId = new Integer(paramMap.get("placeId"));
Place place = placebean.find(placeId);
toggleSuccess = false;
for (MoveContainer mc : getMoveContainers()) {
if (place.equals(mc.getSrc().getPlace())) {
setSlotState(mc, !mc.isMoving());
return;
}
if (place.equals(mc.getDst())) {
toggleSuccess = true;
mc.setDst(null);
return;
}
}
if (!place.isBuyable() || place.isTaken()) {
return;
}
for (MoveContainer mc : moveContainers) {
if (mc.isMoving() && mc.dst == null && mc.getSrc().getProduct().equals(place.getProduct())) {
toggleSuccess = true;
mc.setDst(place);
return;
}
}
}
public String selectSlot() {
setSlotState(slots.getRowData(), true);
return null;
}
private void setSlotState(MoveContainer mc, boolean moving) {
if (!moving && mc.getDst() != null) {
return;
}
mc.setMoving(moving);
}
public String unselectSlot() {
setSlotState(getSlots().getRowData(), false);
return null;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser user) {
this.user = user;
}
public List<MoveContainer> getMoveContainers() {
return moveContainers;
}
public void setMoveContainers(List<MoveContainer> moveContainers) {
this.moveContainers = moveContainers;
}
public ListDataModel<MoveContainer> getSlots() {
return slots;
}
public void setSlots(ListDataModel<MoveContainer> slots) {
this.slots = slots;
}
public boolean isToggleSuccess() {
return toggleSuccess;
}
public void setToggleSuccess(boolean toggleSuccess) {
this.toggleSuccess = toggleSuccess;
}
}
......@@ -1598,3 +1598,5 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time
mapView.reserveTimeLeft=Time to reserve places
queuemgmt.queueEnabled=Queue is ENABLED
queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page)
placemove.alreadyTaken=
placegroupview.moveUsersPlaces=
......@@ -1876,3 +1876,5 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time
mapView.reserveTimeLeft=Time to reserve places
queuemgmt.queueEnabled=Queue is ENABLED
queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page)
placemove.alreadyTaken=Moving the places was cancelled because place {0} was already taken.
placegroupview.moveUsersPlaces=Move users places
......@@ -1863,3 +1863,5 @@ reservequeue.reservingTimeIsUpAlert=Sinulle varattu varausauka on kulunut loppuu
mapView.reserveTimeLeft=Aikaa varata paikkasi
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)
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!