Commit d4b4ed4d by Tuukka Kivilahti

Merge branch 'mapcopy' into 'master'

Map copying functions from existing events

Some events have same map and layout repeating in events.
This MR adds possibility to copy existing map places, products and backround from any existing events map to this event.

See merge request !275
2 parents 9ef0569c c1add52a
......@@ -129,4 +129,8 @@ public interface PlaceBeanLocal {
boolean releaseSlot(PlaceSlot row);
List<EventMap> getOrganisationsMaps();
EventMap copyMap(EventMap sourceMap, EventMap map);
}
......@@ -764,4 +764,42 @@ public class PlaceBean implements PlaceBeanLocal {
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 = new Product(p.getProduct(), dst.getEvent());
productBean.create(product);
prodmapping.put(p.getProduct(), product);
}
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 @@
package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.EJBAccessException;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
......@@ -28,8 +29,13 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
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.EventOrganiser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEvent_;
@Stateless
@LocalBean
......@@ -41,6 +47,8 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
@EJB
private EventBeanLocal eventbean;
@EJB
private PermissionBeanLocal permbean;
public List<EventMap> getMaps()
{
......@@ -56,11 +64,23 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
@Override
public EventMap find(Integer 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!");
}
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> {
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() {
return description;
}
......
......@@ -144,6 +144,21 @@ public class Product extends GenericEntity {
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() {
BigDecimal tot = BigDecimal.ZERO;
for (AccountEvent ac : this.getAccountEvents()) {
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"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"
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">
<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: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>
......@@ -13,8 +13,19 @@
<ui:define name="content">
<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 />
<h:form>
<h:commandButton styleClass="imgcenter" id="commandbutton" image="/PlaceMap?mapid=#{mapView.activeMap.id}" actionListener="#{mapManageView.mapClick}" />
</h:form>
......@@ -30,7 +41,7 @@
</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:commandButton>
</h:form>
......
......@@ -98,7 +98,7 @@ public class MapManageView extends GenericCDIView {
private StreamedContent streamedFile;
private LanEvent copyEvent;
private EventMap sourceMap;
public void initCreate() {
if (super.requirePermissions(MapPermission.MANAGE_MAPS)) {
......@@ -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()
{
......@@ -147,7 +160,6 @@ public class MapManageView extends GenericCDIView {
addFaceMessage("map.upload.failed");
}
return null;
}
......@@ -379,14 +391,6 @@ public class MapManageView extends GenericCDIView {
return productlist;
}
public LanEvent getCopyEvent() {
return copyEvent;
}
public void setCopyEvent(LanEvent copyEvent) {
this.copyEvent = copyEvent;
}
public UploadedFile getBgFile() {
return bgFile;
}
......@@ -402,4 +406,12 @@ public class MapManageView extends GenericCDIView {
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!