Commit ac295b49 by Tuukka Kivilahti

Merge branch 'mapgenfix' into 'master'

Map fixes

- do not generate place pdf on map generation page init
- Do some additional checks on EventMap.enabled
- Add possibility to delete places from a map with wildcard

See merge request !370
2 parents a07c3b85 f57a20f9
...@@ -34,7 +34,7 @@ public interface EventMapBeanLocal { ...@@ -34,7 +34,7 @@ public interface EventMapBeanLocal {
EventMap find(Integer mapId); EventMap find(Integer mapId);
EventMap clearPlaces(EventMap map); EventMap clearPlaces(EventMap map, String placesToDelete);
void deletePlace(Place place); void deletePlace(Place place);
......
...@@ -39,7 +39,7 @@ import fi.codecrew.moya.model.Place; ...@@ -39,7 +39,7 @@ import fi.codecrew.moya.model.Place;
* Session Bean implementation class EventMapBean * Session Bean implementation class EventMapBean
*/ */
@Stateless @Stateless
@DeclareRoles({ MapPermission.S_MANAGE_MAPS }) @DeclareRoles({MapPermission.S_MANAGE_MAPS})
public class EventMapBean implements EventMapBeanLocal { public class EventMapBean implements EventMapBeanLocal {
@EJB @EJB
...@@ -97,10 +97,12 @@ public class EventMapBean implements EventMapBeanLocal { ...@@ -97,10 +97,12 @@ public class EventMapBean implements EventMapBeanLocal {
@Override @Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS) @RolesAllowed(MapPermission.S_MANAGE_MAPS)
public EventMap clearPlaces(EventMap map) { public EventMap clearPlaces(EventMap map, String placesToDelete) {
EventMap leMap = eventmapfacade.reload(map); map = eventmapfacade.reload(map);
leMap.getPlaces().clear(); if (!eventbean.getCurrentEvent().equals(map.getEvent())) {
return leMap; throw new EJBAccessException("Deleting places for wrong event!");
}
return placefacade.deletePlaces(map, placesToDelete);
} }
@Override @Override
...@@ -109,7 +111,7 @@ public class EventMapBean implements EventMapBeanLocal { ...@@ -109,7 +111,7 @@ public class EventMapBean implements EventMapBeanLocal {
place = placefacade.reload(place); place = placefacade.reload(place);
LanEvent currentEvent = eventbean.getCurrentEvent(); LanEvent currentEvent = eventbean.getCurrentEvent();
if (!currentEvent.equals(place.getMap().getEvent())) { if (!currentEvent.equals(place.getMap().getEvent())) {
throw new EJBAccessException("Deleting placce for wrong event!"); throw new EJBAccessException("Deleting place for wrong event!");
} }
placefacade.remove(place); placefacade.remove(place);
} }
......
...@@ -646,7 +646,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -646,7 +646,7 @@ public class PlaceBean implements PlaceBeanLocal {
@Override @Override
public byte[] generatePlacesPdf(float width, float height, double font1, double font2) { public byte[] generatePlacesPdf(float width, float height, double font1, double font2) {
try { try {
List<Place> places = placeFacade.findAll(); List<Place> places = placeFacade.findAll(eventBean.getCurrentEvent());
Collections.sort(places); Collections.sort(places);
logger.info("sorting places etc."); logger.info("sorting places etc.");
...@@ -821,7 +821,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -821,7 +821,7 @@ public class PlaceBean implements PlaceBeanLocal {
@Override @Override
public List<Place> findAllForEvent() { public List<Place> findAllForEvent() {
LanEvent event = eventBean.getCurrentEvent(); LanEvent event = eventBean.getCurrentEvent();
List<Place> ret = placeFacade.findAllForEvent(event); List<Place> ret = placeFacade.findAll(event);
return ret; return ret;
} }
......
...@@ -25,6 +25,7 @@ import javax.ejb.EJB; ...@@ -25,6 +25,7 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
...@@ -49,8 +50,7 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> { ...@@ -49,8 +50,7 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
@EJB @EJB
private PermissionBeanLocal permbean; private PermissionBeanLocal permbean;
public List<EventMap> getMaps() public List<EventMap> getMaps() {
{
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventMap> cq = cb.createQuery(EventMap.class); CriteriaQuery<EventMap> cq = cb.createQuery(EventMap.class);
Root<EventMap> root = cq.from(EventMap.class); Root<EventMap> root = cq.from(EventMap.class);
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package fi.codecrew.moya.facade; package fi.codecrew.moya.facade;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -35,7 +34,6 @@ import org.slf4j.Logger; ...@@ -35,7 +34,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.LoggingBeanLocal; import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -57,11 +55,25 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -57,11 +55,25 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
super(Place.class); super(Place.class);
} }
public EventMap deletePlaces(EventMap map, String nameLike) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaDelete<Place> del = cb.createCriteriaDelete(Place.class);
Root<Place> root = del.getRoot();
del.where(
cb.equal(root.get(Place_.map), map),
cb.like(root.get(Place_.name), nameLike)
);
int i = getEm().createQuery(del).executeUpdate();
logger.info("Deleted {} places from {} with string '{}'", i, map, nameLike);
getEm().getEntityManagerFactory().getCache().evict(EventMap.class, map.getId());
getEm().refresh(map);
return map;
}
public List<Place> findUsersReservations(LanEvent event, EventUser user) { public List<Place> findUsersReservations(LanEvent event, EventUser user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Place> cq = cb.createQuery(Place.class); CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(Place.class); Root<Place> root = cq.from(Place.class);
cq.select(root); cq.select(root);
...@@ -142,11 +154,16 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -142,11 +154,16 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return getSingleNullableResult(getEm().createQuery(cq)); return getSingleNullableResult(getEm().createQuery(cq));
} }
public List<Place> findAll() { public List<Place> findAll(LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Place> cq = cb.createQuery(Place.class); CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(Place.class); Root<Place> root = cq.from(Place.class);
cq.where(cb.equal(root.get(Place_.map).get(EventMap_.event), eventBean.getCurrentEvent()));
Path<EventMap> map = root.get(Place_.map);
cq.where(
cb.isTrue(map.get(EventMap_.active)),
cb.equal(map.get(EventMap_.event), event)
);
cq.orderBy(cb.asc(root.get(Place_.name))); cq.orderBy(cb.asc(root.get(Place_.name)));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
...@@ -162,7 +179,8 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -162,7 +179,8 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
cb.isNull(root.get(Place_.reserveTime)), cb.isNull(root.get(Place_.reserveTime)),
cb.isNull(root.get(Place_.group)), cb.isNull(root.get(Place_.group)),
cb.isFalse(root.get(Place_.disabled)), cb.isFalse(root.get(Place_.disabled)),
cb.isTrue(root.get(Place_.buyable)) cb.isTrue(root.get(Place_.buyable)),
cb.isTrue(root.get(Place_.map).get(EventMap_.active))
); );
return super.getSingleNullableResult(getEm().createQuery(cq)); return super.getSingleNullableResult(getEm().createQuery(cq));
} }
...@@ -175,7 +193,8 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -175,7 +193,8 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
cq.where( cq.where(
cb.equal(root.get(Place_.product), product), cb.equal(root.get(Place_.product), product),
cb.isFalse(root.get(Place_.disabled)) cb.isFalse(root.get(Place_.disabled)),
cb.isTrue(root.get(Place_.map).get(EventMap_.active))
); );
return super.getSingleNullableResult(getEm().createQuery(cq)); return super.getSingleNullableResult(getEm().createQuery(cq));
} }
...@@ -262,7 +281,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -262,7 +281,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
cb.equal(placeJoin.get(Place_.map).get(EventMap_.event), eventBean.getCurrentEvent()) cb.equal(placeJoin.get(Place_.map).get(EventMap_.event), eventBean.getCurrentEvent())
); );
ProductFlag[] flags = { ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT }; ProductFlag[] flags = {ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT};
cq.where( cq.where(
cb.or( cb.or(
...@@ -282,17 +301,12 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -282,17 +301,12 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
CriteriaQuery<Place> cq = cb.createQuery(Place.class); CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(Place.class); Root<Place> root = cq.from(Place.class);
cq.where(cb.equal(root.get(Place_.product).get(Product_.event), event), cb.equal(root.get(Place_.code), code)); cq.where(
cb.equal(root.get(Place_.product).get(Product_.event), event),
cb.equal(root.get(Place_.code), code)
);
return super.getSingleNullableResult(getEm().createQuery(cq)); return super.getSingleNullableResult(getEm().createQuery(cq));
} }
public List<Place> findAllForEvent(LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(Place.class);
cq.where(cb.equal(root.get(Place_.product).get(Product_.event), event));
return getEm().createQuery(cq).getResultList();
}
} }
...@@ -30,18 +30,22 @@ ...@@ -30,18 +30,22 @@
</h:form> </h:form>
<map:genplaces /> <map:genplaces />
<hr />
<h:form> <h:form>
<h:commandButton action="#{mapManageView.removeAllPlaces}" value="#{i18n['mapEdit.removePlaces']}" onclick="return confirm('Are you sure you want to REMOVE ALL PLACES!\nThis action is final')" /> <p:inputText value="#{mapManageView.placesToDelete}" />
<p:commandButton action="#{mapManageView.removeSelectedPlaces}" value="#{i18n['mapEdit.removeSelectedPlaces']}" onclick="return confirm('Are you sure you want to remove these\nThis action is final')" ajax="false"/>
</h:form> </h:form>
<hr/>
<h:form enctype="multipart/form-data"> <h:form enctype="multipart/form-data">
<p:fileUpload mode="simple" value="#{mapManageView.bgFile}" /> <p:fileUpload mode="simple" value="#{mapManageView.bgFile}" />
<h:commandButton action="#{mapManageView.submitBg}" value="#{i18n['map.submitMap']}" /> <p:commandButton action="#{mapManageView.submitBg}" value="#{i18n['map.submitMap']}" ajax="false"/>
</h:form> </h:form>
<h:form> <h:form>
<p:commandButton id="downloadLink" actionListener="mapManageView.generatePlacePdf" value="koodipdf" ajax="false"> <p:commandButton id="downloadLink" actionListener="#{mapManageView.generatePlacePdf()}" value="koodipdf" ajax="false">
<p:fileDownload value="#{mapManageView.streamedFile}" /> <p:fileDownload value="#{mapManageView.placePdf}" />
</p:commandButton> </p:commandButton>
</h:form> </h:form>
</ui:define> </ui:define>
......
...@@ -77,6 +77,7 @@ public class MapManageView extends GenericCDIView { ...@@ -77,6 +77,7 @@ public class MapManageView extends GenericCDIView {
private String mapname; private String mapname;
private String buyableLike; private String buyableLike;
private String placesToDelete;
private boolean tablesHorizontal = false; private boolean tablesHorizontal = false;
private boolean oneRowTable = false; private boolean oneRowTable = false;
...@@ -94,10 +95,8 @@ public class MapManageView extends GenericCDIView { ...@@ -94,10 +95,8 @@ public class MapManageView extends GenericCDIView {
private String namebase; private String namebase;
private Integer mapId; private Integer mapId;
private List<Product> productlist; private List<Product> productlist;
private StreamedContent streamedFile;
private EventMap sourceMap; private EventMap sourceMap;
private DefaultStreamedContent placepdf;
public void initCreate() { public void initCreate() {
if (super.requirePermissions(MapPermission.MANAGE_MAPS)) { if (super.requirePermissions(MapPermission.MANAGE_MAPS)) {
...@@ -111,13 +110,11 @@ public class MapManageView extends GenericCDIView { ...@@ -111,13 +110,11 @@ public class MapManageView extends GenericCDIView {
map = eventmapBean.find(getMapId()); map = eventmapBean.find(getMapId());
setProductlist(productbean.getProducts()); setProductlist(productbean.getProducts());
super.beginConversation(); super.beginConversation();
if (map != null && !map.getPlaces().isEmpty())
streamedFile = new DefaultStreamedContent(new ByteArrayInputStream(placebean.generatePlacesPdf(54, 17, 18, 15)), "application/pdf", "paikkakoodit");
} }
} }
public List<EventMap> getOldMaps() { public List<EventMap> getOldMaps() {
List<EventMap> ret = placebean.getOrganisationsMaps(); List<EventMap> ret = placebean.getOrganisationsMaps();
if (map != null) { if (map != null) {
...@@ -131,12 +128,10 @@ public class MapManageView extends GenericCDIView { ...@@ -131,12 +128,10 @@ public class MapManageView extends GenericCDIView {
return null; return null;
} }
public String submitBg() public String submitBg() {
{
byte[] bytes = bgFile.getContents(); byte[] bytes = bgFile.getContents();
if (bytes == null && bgFile.getSize() > 0) if (bytes == null && bgFile.getSize() > 0) {
{
bytes = new byte[(int) bgFile.getSize()]; bytes = new byte[(int) bgFile.getSize()];
try { try {
bgFile.getInputstream().read(bytes); bgFile.getInputstream().read(bytes);
...@@ -206,9 +201,10 @@ public class MapManageView extends GenericCDIView { ...@@ -206,9 +201,10 @@ public class MapManageView extends GenericCDIView {
startY = Integer.valueOf(requestParams.get(clientId + ".y")).intValue(); startY = Integer.valueOf(requestParams.get(clientId + ".y")).intValue();
} }
public String removeAllPlaces()
{
map = eventmapBean.clearPlaces(map); public String removeSelectedPlaces() {
map = eventmapBean.clearPlaces(map, placesToDelete);
return null; return null;
} }
...@@ -235,8 +231,8 @@ public class MapManageView extends GenericCDIView { ...@@ -235,8 +231,8 @@ public class MapManageView extends GenericCDIView {
Place place = new Place(map); Place place = new Place(map);
place.setHeight(Math.abs(height)); place.setHeight(Math.abs(height));
place.setWidth(Math.abs(width)); place.setWidth(Math.abs(width));
int xpos = startX + rowXStart + (tablesHorizontal ? (placeI -1) * width : 0); int xpos = startX + rowXStart + (tablesHorizontal ? (placeI - 1) * width : 0);
int ypos = startY + rowYStart + (tablesHorizontal ? 0 : (placeI -1) * height); int ypos = startY + rowYStart + (tablesHorizontal ? 0 : (placeI - 1) * height);
logger.debug("Creating map in {} {}", xpos, ypos); logger.debug("Creating map in {} {}", xpos, ypos);
place.setMapX(xpos); place.setMapX(xpos);
place.setMapY(ypos); place.setMapY(ypos);
...@@ -398,12 +394,14 @@ public class MapManageView extends GenericCDIView { ...@@ -398,12 +394,14 @@ public class MapManageView extends GenericCDIView {
this.bgFile = bgFile; this.bgFile = bgFile;
} }
//StreamedContent new DefaultStreamedContent(pdfstream) public void generatePlacesPdf() {
public StreamedContent getStreamedFile() { placepdf = new DefaultStreamedContent(new ByteArrayInputStream(placebean.generatePlacesPdf(54, 17, 18, 15)), "application/pdf", "paikkakoodit");
//DefaultStreamedContent(new ByteArrayInputStream(placebean.generatePlacesPdf(54, 17, 10, 6))); }
return streamedFile; //StreamedContent new DefaultStreamedContent(pdfstream)
public StreamedContent getPlacePdf() {
return placepdf;
} }
public EventMap getSourceMap() { public EventMap getSourceMap() {
...@@ -413,4 +411,12 @@ public class MapManageView extends GenericCDIView { ...@@ -413,4 +411,12 @@ public class MapManageView extends GenericCDIView {
public void setSourceMap(EventMap sourceMap) { public void setSourceMap(EventMap sourceMap) {
this.sourceMap = sourceMap; this.sourceMap = sourceMap;
} }
public String getPlacesToDelete() {
return placesToDelete;
}
public void setPlacesToDelete(String placesToDelete) {
this.placesToDelete = placesToDelete;
}
} }
...@@ -1609,3 +1609,4 @@ product.dependency.multiplier=Multiplier ...@@ -1609,3 +1609,4 @@ 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
submenu.neomap.moveplaces=Change places submenu.neomap.moveplaces=Change places
mapEdit.removeSelectedPlaces=Delete places
...@@ -1890,3 +1890,4 @@ placemove.alreadyTaken=Moving the places was cancelled because place {0} was alr ...@@ -1890,3 +1890,4 @@ placemove.alreadyTaken=Moving the places was cancelled because place {0} was alr
placegroupview.moveUsersPlaces=Move users places placegroupview.moveUsersPlaces=Move users places
submenu.neomap.moveplaces=Change places submenu.neomap.moveplaces=Change places
mapEdit.removeSelectedPlaces=Delete places
...@@ -1876,3 +1876,4 @@ product.dependency.MAX_SUPPORTED_COUNT=Tuotteita voi ostaa enint\u00E4\u00E4n sa ...@@ -1876,3 +1876,4 @@ product.dependency.MAX_SUPPORTED_COUNT=Tuotteita voi ostaa enint\u00E4\u00E4n sa
placemove.alreadyTaken=Paikkojen siirto peruuntui koska paikka {0} oli jo varattu. placemove.alreadyTaken=Paikkojen siirto peruuntui koska paikka {0} oli jo varattu.
placegroupview.moveUsersPlaces=Siirr\u00E4 k\u00E4ytt\u00E4j\u00E4n paikkoja placegroupview.moveUsersPlaces=Siirr\u00E4 k\u00E4ytt\u00E4j\u00E4n paikkoja
submenu.neomap.moveplaces=Vaihda paikkoja submenu.neomap.moveplaces=Vaihda paikkoja
mapEdit.removeSelectedPlaces=Poista paikat
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!