Commit f2cc64c0 by Tuomas Riihimäki

Copy map places to a map from existing map possibly from other event

1 parent cfc74206
...@@ -129,4 +129,8 @@ public interface PlaceBeanLocal { ...@@ -129,4 +129,8 @@ public interface PlaceBeanLocal {
boolean releaseSlot(PlaceSlot row); boolean releaseSlot(PlaceSlot row);
List<EventMap> getOrganisationsMaps();
EventMap copyMap(EventMap sourceMap, EventMap map);
} }
...@@ -764,4 +764,42 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -764,4 +764,42 @@ public class PlaceBean implements PlaceBeanLocal {
return true; return true;
} }
@Override
public List<EventMap> getOrganisationsMaps() {
return eventMapFacade.findOrganisationMaps();
}
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
public EventMap copyMap(EventMap src, EventMap dst) {
src = eventMapFacade.reload(src);
dst = eventMapFacade.reload(dst);
if (dst.getPlaces() != null && !dst.getPlaces().isEmpty()) {
throw new EJBException("Destination can not have existing places!");
}
Map<Product, Product> prodmapping = new HashMap<>();
dst.setPlaces(new ArrayList<>());
for (Place p : src.getPlaces()) {
Place np = new Place(p, dst);
Product product = prodmapping.get(p.getProduct());
if (product == null) {
Product nprod = new Product(p.getProduct(), dst.getEvent());
productBean.create(nprod);
prodmapping.put(p.getProduct(), nprod);
}
np.setProduct(product);
dst.getPlaces().add(np);
placeFacade.create(np);
}
dst.setActive(true);
dst.setHeight(src.getHeight());
dst.setWidth(src.getWidth());
dst.setMapData(src.getMapData());
dst.setMimeType(src.getMimeType());
// dst.setName("Copy of " + src.getName());
dst.setNotes(src.getNotes());
return dst;
}
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package fi.codecrew.moya.facade; package fi.codecrew.moya.facade;
import java.util.List; import java.util.List;
import javax.ejb.EJBAccessException; import javax.ejb.EJBAccessException;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
...@@ -28,8 +29,13 @@ import javax.persistence.criteria.CriteriaQuery; ...@@ -28,8 +29,13 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventMap_; import fi.codecrew.moya.model.EventMap_;
import fi.codecrew.moya.model.EventOrganiser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEvent_;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -41,6 +47,8 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> { ...@@ -41,6 +47,8 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
@EJB @EJB
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
@EJB
private PermissionBeanLocal permbean;
public List<EventMap> getMaps() public List<EventMap> getMaps()
{ {
...@@ -56,11 +64,23 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> { ...@@ -56,11 +64,23 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
@Override @Override
public EventMap find(Integer id) { public EventMap find(Integer id) {
EventMap ret = super.find(id); EventMap ret = super.find(id);
if (ret != null && !ret.getEvent().equals(eventbean.getCurrentEvent())) { if (ret != null && !ret.getEvent().equals(eventbean.getCurrentEvent()) && !permbean.hasPermission(MapPermission.MANAGE_MAPS)) {
throw new EJBAccessException("Trying to find map from wrong event!"); throw new EJBAccessException("Trying to find map from wrong event!");
} }
return ret; return ret;
} }
public List<EventMap> findOrganisationMaps() {
EventOrganiser org = eventbean.getCurrentEvent().getOrganiser();
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventMap> cq = cb.createQuery(EventMap.class);
Root<EventMap> root = cq.from(EventMap.class);
cq.where(cb.equal(root.get(EventMap_.event).get(LanEvent_.organiser), org),
cb.isTrue(root.get(EventMap_.active)));
return getEm().createQuery(cq).getResultList();
}
} }
...@@ -156,6 +156,20 @@ public class Place extends GenericEntity implements Comparable<Place> { ...@@ -156,6 +156,20 @@ public class Place extends GenericEntity implements Comparable<Place> {
this.map = eventMap; this.map = eventMap;
} }
// Copy constructor
public Place(Place p, EventMap dst) {
this.map = dst;
this.buyable = p.buyable;
this.description = p.description;
this.details = p.details;
this.disabled = p.disabled;
this.height = p.height;
this.width = p.width;
this.mapX = p.mapX;
this.mapY = p.mapY;
this.name = p.name;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
......
...@@ -144,6 +144,21 @@ public class Product extends GenericEntity { ...@@ -144,6 +144,21 @@ public class Product extends GenericEntity {
this.name = name; this.name = name;
} }
public Product(Product src, LanEvent event) {
super();
this.event = event;
this.barcode = src.barcode;
this.buyInPrice = src.buyInPrice;
this.color = src.color;
this.description = src.description;
this.name = src.name;
this.price = src.price;
this.productFlags = new HashSet<>(src.getProductFlags());
this.sort = src.sort;
this.unitName = src.unitName;
this.vat = src.vat;
}
public BigDecimal getSoldCash() { public BigDecimal getSoldCash() {
BigDecimal tot = BigDecimal.ZERO; BigDecimal tot = BigDecimal.ZERO;
for (AccountEvent ac : this.getAccountEvents()) { for (AccountEvent ac : this.getAccountEvents()) {
......
<!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:f="http://java.sun.com/jsf/core" <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:f="http://java.sun.com/jsf/core" 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:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui"> 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> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
...@@ -13,8 +13,19 @@ ...@@ -13,8 +13,19 @@
<ui:define name="content"> <ui:define name="content">
<map:edit commitaction="#{mapManageView.saveMap()}" commitvalue="#{i18n['mapedit.save']}" /> <map:edit commitaction="#{mapManageView.saveMap()}" commitvalue="#{i18n['mapedit.save']}" />
<ui:fragment rendered="#{empty mapManageView.map.places}">
<h:form>
<p:selectOneMenu value="#{mapManageView.sourceMap}" converter="#{eventMapConverter}">
<f:selectItems value="#{mapManageView.oldMaps}" var="m" itemLabel="#{m.event.name} - #{m.name}" />
</p:selectOneMenu>
<h:commandButton action="#{mapManageView.copyMap}" value="#{i18n['mapEdit.copyMap']}" />
</h:form>
</ui:fragment>
<map:setBuyable /> <map:setBuyable />
<h:form> <h:form>
<h:commandButton styleClass="imgcenter" id="commandbutton" image="/PlaceMap?mapid=#{mapView.activeMap.id}" actionListener="#{mapManageView.mapClick}" /> <h:commandButton styleClass="imgcenter" id="commandbutton" image="/PlaceMap?mapid=#{mapView.activeMap.id}" actionListener="#{mapManageView.mapClick}" />
</h:form> </h:form>
...@@ -28,11 +39,11 @@ ...@@ -28,11 +39,11 @@
<p:fileUpload mode="simple" value="#{mapManageView.bgFile}" /> <p:fileUpload mode="simple" value="#{mapManageView.bgFile}" />
<h:commandButton action="#{mapManageView.submitBg}" value="#{i18n['map.submitMap']}" /> <h:commandButton action="#{mapManageView.submitBg}" value="#{i18n['map.submitMap']}" />
</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.streamedFile}" />
</p:commandButton> </p:commandButton>
</h:form> </h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
...@@ -98,7 +98,7 @@ public class MapManageView extends GenericCDIView { ...@@ -98,7 +98,7 @@ public class MapManageView extends GenericCDIView {
private StreamedContent streamedFile; private StreamedContent streamedFile;
private LanEvent copyEvent; private EventMap sourceMap;
public void initCreate() { public void initCreate() {
if (super.requirePermissions(MapPermission.MANAGE_MAPS)) { if (super.requirePermissions(MapPermission.MANAGE_MAPS)) {
...@@ -119,6 +119,19 @@ public class MapManageView extends GenericCDIView { ...@@ -119,6 +119,19 @@ public class MapManageView extends GenericCDIView {
} }
public List<EventMap> getOldMaps() {
List<EventMap> ret = placebean.getOrganisationsMaps();
if (map != null) {
ret.remove(map);
}
return ret;
}
public String copyMap() {
map = placebean.copyMap(sourceMap, map);
return null;
}
public String submitBg() public String submitBg()
{ {
...@@ -147,7 +160,6 @@ public class MapManageView extends GenericCDIView { ...@@ -147,7 +160,6 @@ public class MapManageView extends GenericCDIView {
addFaceMessage("map.upload.failed"); addFaceMessage("map.upload.failed");
} }
return null; return null;
} }
...@@ -379,14 +391,6 @@ public class MapManageView extends GenericCDIView { ...@@ -379,14 +391,6 @@ public class MapManageView extends GenericCDIView {
return productlist; return productlist;
} }
public LanEvent getCopyEvent() {
return copyEvent;
}
public void setCopyEvent(LanEvent copyEvent) {
this.copyEvent = copyEvent;
}
public UploadedFile getBgFile() { public UploadedFile getBgFile() {
return bgFile; return bgFile;
} }
...@@ -402,4 +406,12 @@ public class MapManageView extends GenericCDIView { ...@@ -402,4 +406,12 @@ public class MapManageView extends GenericCDIView {
return streamedFile; return streamedFile;
} }
public EventMap getSourceMap() {
return sourceMap;
}
public void setSourceMap(EventMap sourceMap) {
this.sourceMap = sourceMap;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!