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; ...@@ -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.*;
...@@ -869,7 +871,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -869,7 +871,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")
; ;
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:h="http://java.sun.com/jsf/html"
xmlns:map="http://java.sun.com/jsf/composite/cditools/map" xmlns:map="http://java.sun.com/jsf/composite/cditools/map"
xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:tools="http://java.sun.com/jsf/composite/cditools"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:c="http://java.sun.com/jsp/jstl/core"
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>
<p:dataTable id="slottable" tableStyle="width: auto;" var="slot" <p:dataTable id="slottable" tableStyle="width: auto;" var="slot"
value="#{mapPlacechangeView.slots}"> value="#{mapPlacechangeView.slots}">
<!-- 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>
<p:column> <p:column>
<ui:fragment rendered="#{empty slot.dst}"> <ui:fragment rendered="#{empty slot.dst}">
<p:commandButton <p:commandButton
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>
</p:dataTable> </p:dataTable>
</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"> <p:commandButton
<p:commandButton 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;"
width="#{ajaxMapView.map.width}px"
<svg id="seatmap" style="margin: auto; border: 1px solid black;" height="#{ajaxMapView.map.height}px"/>
width="#{ajaxMapView.map.width}px" <h:form>
height="#{ajaxMapView.map.height}px" /> <p:remoteCommand name="toggleDstPlace"
<h:form> action="#{mapPlacechangeView.toggleDstPlace()}"
<p:remoteCommand name="toggleDstPlace" update="placeselector" oncomplete="afterToggle()"/>
action="#{mapPlacechangeView.toggleDstPlace()}" </h:form>
update="placeselector" oncomplete="afterToggle()"></p:remoteCommand> <script type="text/javascript">
</h:form>
<script type="text/javascript"> // <![CDATA[
// <![CDATA[ px = placemap({
px = placemap({
element: document.getElementById("seatmap"), element: document.getElementById("seatmap"),
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>
</h:body> </h:body>
</html> </html>
\ No newline at end of file
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
</ui:define> </ui:define>
<ui:define name="content"> <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: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">
......
...@@ -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;
...@@ -26,189 +27,214 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView; ...@@ -26,189 +27,214 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
@ConversationScoped @ConversationScoped
public class MapPlacechangeView extends GenericCDIView { public class MapPlacechangeView extends GenericCDIView {
private static final Logger logger = LoggerFactory.getLogger(MapPlacechangeView.class); private static final Logger logger = LoggerFactory.getLogger(MapPlacechangeView.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Integer userId; private Integer userId;
private EventUser user; private EventUser user;
@EJB @EJB
private UserBeanLocal userbean; private UserBeanLocal userbean;
@EJB @EJB
private PlaceBeanLocal placebean; private PlaceBeanLocal placebean;
private ListDataModel<MoveContainer> slots; private ListDataModel<MoveContainer> slots;
private List<MoveContainer> moveContainers; private List<MoveContainer> moveContainers;
private boolean toggleSuccess; private boolean toggleSuccess;
public static class MoveContainer { public static class MoveContainer {
private boolean moving = false; private boolean moving = false;
private final PlaceSlot src; private final PlaceSlot src;
private Place dst; private Place dst;
public MoveContainer(PlaceSlot p) { public MoveContainer(PlaceSlot p) {
this.src = p; this.src = p;
} }
public static List<MoveContainer> init(List<PlaceSlot> placeslots) { public static List<MoveContainer> init(List<PlaceSlot> placeslots) {
ArrayList<MoveContainer> ret = new ArrayList<>(); ArrayList<MoveContainer> ret = new ArrayList<>();
for (PlaceSlot p : placeslots) { for (PlaceSlot p : placeslots) {
ret.add(new MoveContainer(p)); ret.add(new MoveContainer(p));
} }
return ret; return ret;
} }
public boolean isMoving() { public boolean isMoving() {
return moving; return moving;
} }
public void setMoving(boolean moving) { public void setMoving(boolean moving) {
this.moving = moving; this.moving = moving;
} }
public Place getDst() { public Place getDst() {
return dst; return dst;
} }
public void setDst(Place dst) { public void setDst(Place dst) {
this.dst = dst; this.dst = dst;
} }
public PlaceSlot getSrc() { public PlaceSlot getSrc() {
return src; return src;
} }
} }
public boolean isReadyForCommit() { public boolean isReadyForCommit() {
for (MoveContainer mc : moveContainers) { // If anything is not selected for commit, we are not ready..
if (mc.isMoving() && mc.getDst() == null) { boolean movingAny = false;
return false;
} for (MoveContainer mc : moveContainers) {
} // If we are moving, but destination is not selected, we are not ready..
return true; if (mc.isMoving()) {
} movingAny = true;
if (mc.getDst() == null) {
public void initView() { return false;
}
// If we are overriding user, check permission. }
if (getSlots() == null) { }
if (userId != null && super.requirePermissions(MapPermission.MANAGE_OTHERS)) { return movingAny;
user = userbean.findByUserId(userId, false); }
} else if (super.requirePermissions(MapPermission.BUY_PLACES)) {
user = permbean.getCurrentUser();
} else { public void initView() {
return;
} // If we are overriding user, check permission.
if (super.requirePermissions(
super.beginConversation(); super.hasPermission(MapPermission.MOVE_PLACES) ||
moveContainers = MoveContainer.init(placebean.getPlaceslots(user)); super.hasPermission(MapPermission.MANAGE_MAPS)
slots = new ListDataModel<MoveContainer>(moveContainers); ) && 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();
public String commitMove() { } else {
return;
HashMap<Place, Place> change = new HashMap<Place, Place>(); }
for (MoveContainer s : slots) {
if (s.isMoving() && s.getDst() != null) { super.beginConversation();
change.put(s.getSrc().getPlace(), s.getDst()); moveContainers = MoveContainer.init(placebean.getPlaceslots(user));
} slots = new ListDataModel<>(moveContainers);
}
placebean.movePlaces(change); }
}
// slots = null;
// initView(); public String commitMove() {
return "/place/myGroups?faces_redirect=true";
} HashMap<Place, Place> change = new HashMap<Place, Place>();
for (MoveContainer s : slots) {
public void toggleDstPlace() { if (s.isMoving() && s.getDst() != null) {
Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); change.put(s.getSrc().getPlace(), s.getDst());
Integer placeId = new Integer(paramMap.get("placeId")); }
}
Place place = placebean.find(placeId); try {
toggleSuccess = false; placebean.movePlaces(change);
for (MoveContainer mc : getMoveContainers()) { } catch (PlaceAlreadyTakenException pt) {
if (place.equals(mc.getSrc().getPlace())) { String placename = "";
setSlotState(mc, !mc.isMoving()); if (pt.getPlace() != null) {
return; placename = pt.getPlace().getName();
} for (MoveContainer mv : slots) {
if (place.equals(mc.getDst())) { if (pt.getPlace().equals(mv.getDst())) {
toggleSuccess = true; mv.setDst(null);
mc.setDst(null); }
return; }
} }
} super.addFaceMessage("placemove.alreadyTaken", placename);
return null;
if (!place.isBuyable() || place.isTaken()) {
return; }
} // slots = null;
for (MoveContainer mc : moveContainers) { // initView();
if (mc.isMoving() && mc.dst == null && mc.getSrc().getProduct().equals(place.getProduct())) { return "/place/myGroups?faces_redirect=true";
toggleSuccess = true; }
mc.setDst(place);
return; 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;
public String selectSlot() { for (MoveContainer mc : getMoveContainers()) {
if (place.equals(mc.getSrc().getPlace())) {
setSlotState(slots.getRowData(), true); setSlotState(mc, !mc.isMoving());
return null; return;
} }
if (place.equals(mc.getDst())) {
private void setSlotState(MoveContainer mc, boolean moving) { toggleSuccess = true;
if (!moving && mc.getDst() != null) { mc.setDst(null);
return; return;
} }
mc.setMoving(moving); }
}
if (!place.isBuyable() || place.isTaken()) {
public String unselectSlot() { return;
setSlotState(getSlots().getRowData(), false); }
return null; for (MoveContainer mc : moveContainers) {
} if (mc.isMoving() && mc.dst == null && mc.getSrc().getProduct().equals(place.getProduct())) {
toggleSuccess = true;
public Integer getUserId() { mc.setDst(place);
return userId; return;
} }
}
public void setUserId(Integer userId) {
this.userId = userId; }
}
public String selectSlot() {
public EventUser getUser() {
return user; setSlotState(slots.getRowData(), true);
} return null;
}
public void setUser(EventUser user) {
this.user = user; private void setSlotState(MoveContainer mc, boolean moving) {
} if (!moving && mc.getDst() != null) {
return;
public List<MoveContainer> getMoveContainers() { }
return moveContainers; mc.setMoving(moving);
} }
public void setMoveContainers(List<MoveContainer> moveContainers) { public String unselectSlot() {
this.moveContainers = moveContainers; setSlotState(getSlots().getRowData(), false);
} return null;
}
public ListDataModel<MoveContainer> getSlots() {
return slots; public Integer getUserId() {
} return userId;
}
public void setSlots(ListDataModel<MoveContainer> slots) {
this.slots = slots; public void setUserId(Integer userId) {
} this.userId = userId;
}
public boolean isToggleSuccess() {
return toggleSuccess; public EventUser getUser() {
} return user;
}
public void setToggleSuccess(boolean toggleSuccess) {
this.toggleSuccess = toggleSuccess; 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 ...@@ -1598,3 +1598,5 @@ 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)
placemove.alreadyTaken=
placegroupview.moveUsersPlaces=
...@@ -1876,3 +1876,5 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time ...@@ -1876,3 +1876,5 @@ 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)
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 ...@@ -1863,3 +1863,5 @@ 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)
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!