Commit a3bca642 by Tuomas Riihimäki

Jepjep.. paikkojen varaaminen valmis. Pieniä kantamuutoksia, ym...

1 parent 3af76726
Showing with 2223 additions and 707 deletions
...@@ -37,5 +37,14 @@ ...@@ -37,5 +37,14 @@
<dependent-module archiveName="granite-beanvalidation.jar" deploy-path="/lib" handle="module:/classpath/lib/LanBortal/ExtraLibs/granite-beanvalidation.jar"> <dependent-module archiveName="granite-beanvalidation.jar" deploy-path="/lib" handle="module:/classpath/lib/LanBortal/ExtraLibs/granite-beanvalidation.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="compass-2.3.0-beta1.jar" deploy-path="/lib" handle="module:/classpath/lib/LanBortal/ExtraLibs/compass-2.3.0-beta1.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="commons-logging.jar" deploy-path="/lib" handle="module:/classpath/lib/LanBortal/ExtraLibs/commons-logging.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="PDFjet.jar" deploy-path="/lib" handle="module:/classpath/lib/LanBortal/ExtraLibs/PDFjet.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
</wb-module> </wb-module>
</project-modules> </project-modules>
...@@ -2,11 +2,6 @@ ...@@ -2,11 +2,6 @@
<classpath> <classpath>
<classpathentry kind="src" path="ejbModule"/> <classpathentry kind="src" path="ejbModule"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="libs/PDFjet.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="../"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/LanBortalBeansClient"/> <classpathentry combineaccessrules="false" kind="src" path="/LanBortalBeansClient"/>
<classpathentry combineaccessrules="false" kind="src" path="/LanBortalAuthModuleClient"/> <classpathentry combineaccessrules="false" kind="src" path="/LanBortalAuthModuleClient"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish Server Open Source Edition 3 (Java EE 6)"> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish Server Open Source Edition 3 (Java EE 6)">
......
Manifest-Version: 1.0 Manifest-Version: 1.0
Class-Path: lib/LanBortalDatabase.jar Class-Path: lib/LanBortalDatabase.jar
lib/LanBortalDatabase.jar
lib/PDFjet.jar
...@@ -2,7 +2,8 @@ package fi.insomnia.bortal.beans; ...@@ -2,7 +2,8 @@ package fi.insomnia.bortal.beans;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.RoundingMode;
import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -13,16 +14,14 @@ import javax.persistence.PersistenceContext; ...@@ -13,16 +14,14 @@ import javax.persistence.PersistenceContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beanutil.AuthorisationBeanLocal;
import fi.insomnia.bortal.beanutil.AuthorisationBeanLocal.Right;
import fi.insomnia.bortal.beanutil.AuthorisationBeanLocal.RightType;
import fi.insomnia.bortal.beanutil.PdfPrinter; import fi.insomnia.bortal.beanutil.PdfPrinter;
import fi.insomnia.bortal.bortal.views.BillSummary;
import fi.insomnia.bortal.enums.Permission; import fi.insomnia.bortal.enums.Permission;
import fi.insomnia.bortal.enums.RolePermission; import fi.insomnia.bortal.enums.RolePermission;
import fi.insomnia.bortal.exceptions.PermissionDeniedException; import fi.insomnia.bortal.exceptions.PermissionDeniedException;
import fi.insomnia.bortal.facade.BillFacade; import fi.insomnia.bortal.facade.BillFacade;
import fi.insomnia.bortal.facade.BillLineFacade; import fi.insomnia.bortal.facade.BillLineFacade;
import fi.insomnia.bortal.facade.EventFacade; import fi.insomnia.bortal.model.AccountEvent;
import fi.insomnia.bortal.model.Bill; import fi.insomnia.bortal.model.Bill;
import fi.insomnia.bortal.model.BillLine; import fi.insomnia.bortal.model.BillLine;
import fi.insomnia.bortal.model.Discount; import fi.insomnia.bortal.model.Discount;
...@@ -38,8 +37,6 @@ public class BillBean implements BillBeanLocal { ...@@ -38,8 +37,6 @@ public class BillBean implements BillBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(BillBean.class); private static final Logger logger = LoggerFactory.getLogger(BillBean.class);
private static final MathContext MATHCONTEXT_TWOSCALE = new MathContext(2);;
@EJB @EJB
private BillFacade billFacade; private BillFacade billFacade;
...@@ -50,16 +47,15 @@ public class BillBean implements BillBeanLocal { ...@@ -50,16 +47,15 @@ public class BillBean implements BillBeanLocal {
private SecurityBeanLocal secubean; private SecurityBeanLocal secubean;
@EJB @EJB
private AuthorisationBeanLocal authbean;
@EJB
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
@EJB @EJB
private EventFacade eventfacade;
@EJB
private BillLineFacade billLineFacade; private BillLineFacade billLineFacade;
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@EJB
private ProductBeanLocal productBean;
/** /**
* Default constructor. * Default constructor.
*/ */
...@@ -139,21 +135,54 @@ public class BillBean implements BillBeanLocal { ...@@ -139,21 +135,54 @@ public class BillBean implements BillBeanLocal {
BillLine line = new BillLine(bill, product.getName(), product.getUnitName(), count, product.getPrice(), product.getVat()); BillLine line = new BillLine(bill, product.getName(), product.getUnitName(), count, product.getPrice(), product.getVat());
billLineFacade.create(line); billLineFacade.create(line);
for (Discount disc : product.getDiscounts()) { List<Discount> discounts = productBean.getActiveDiscounts(product, count);
if (disc.isActive() && count.compareTo(disc.getAmountMax()) <= 0 && count.compareTo(disc.getAmountMin()) >= 0) {
BigDecimal disccounts = count; for (Discount disc : discounts) {
if (disc.getMaxNum().compareTo(disccounts) >= 0) { BigDecimal unitPrice = product.getPrice().subtract(product.getPrice().multiply(disc.getPercentage())).negate().setScale(2, RoundingMode.HALF_UP);
disccounts = disc.getMaxNum(); BigDecimal vatPrice = product.getVat().subtract(product.getVat().multiply(disc.getPercentage())).negate().setScale(2, RoundingMode.HALF_UP);
}
BillLine discountLine = new BillLine(bill, disc.getShortdesc(), product.getUnitName(), disccounts, BillLine discountLine = new BillLine(bill, disc.getShortdesc(), product.getUnitName(), count, unitPrice, vatPrice);
product.getPrice().subtract(product.getPrice().multiply(disc.getPercentage(), MATHCONTEXT_TWOSCALE)).negate(), billLineFacade.create(discountLine);
product.getVat().subtract(product.getVat().multiply(disc.getPercentage(), MATHCONTEXT_TWOSCALE)).negate());
billLineFacade.create(discountLine);
}
} }
em.flush(); em.flush();
return line; return line;
} }
@Override
public List<Bill> findAll() {
if (!userBean.hasPermission(Permission.TICKET_SALES, RolePermission.WRITE)) {
throw new PermissionDeniedException(secubean, userBean.getCurrentUser(), "User tried to list all bills without sufficient permissions");
}
return billFacade.findAll();
}
@Override
public List<BillSummary> getBillLineSummary() {
userBean.fatalPermission(Permission.TICKET_SALES, RolePermission.WRITE, "User tried to view the bill summary");
List<BillSummary> ret = billLineFacade.getLineSummary();
for (BillSummary foo : ret) {
logger.debug("linesum {}", foo);
}
return ret;
}
@Override
public void markPaid(Bill bill, Calendar when) {
Product creditproduct = productBean.findCreditProduct();
AccountEvent ac = productBean.createAccountEvent(creditproduct, bill.totalPrice(), bill.getUser());
ac.setDelivered(when);
ac.setEventTime(when);
ac.setBill(bill);
ac.setSeller(userBean.getCurrentUser());
bill.setAccountEvent(ac);
bill.setPaidDate(when);
billFacade.merge(bill);
}
} }
...@@ -7,7 +7,6 @@ import fi.insomnia.bortal.facade.DiscountFacade; ...@@ -7,7 +7,6 @@ import fi.insomnia.bortal.facade.DiscountFacade;
import fi.insomnia.bortal.facade.EventFacade; import fi.insomnia.bortal.facade.EventFacade;
import fi.insomnia.bortal.facade.ProductFacade; import fi.insomnia.bortal.facade.ProductFacade;
import fi.insomnia.bortal.model.Discount; import fi.insomnia.bortal.model.Discount;
import fi.insomnia.bortal.model.Product;
/** /**
* Session Bean implementation class DiscountBean * Session Bean implementation class DiscountBean
...@@ -15,7 +14,6 @@ import fi.insomnia.bortal.model.Product; ...@@ -15,7 +14,6 @@ import fi.insomnia.bortal.model.Product;
@Stateless @Stateless
public class DiscountBean implements DiscountBeanLocal { public class DiscountBean implements DiscountBeanLocal {
@EJB @EJB
private DiscountFacade discountfacade; private DiscountFacade discountfacade;
@EJB @EJB
...@@ -24,28 +22,27 @@ public class DiscountBean implements DiscountBeanLocal { ...@@ -24,28 +22,27 @@ public class DiscountBean implements DiscountBeanLocal {
private ProductFacade productfacade; private ProductFacade productfacade;
@EJB @EJB
private EventFacade eventfacade; private EventFacade eventfacade;
public DiscountBean() { public DiscountBean() {
} }
@Override @Override
public Discount save(Discount discount) { public Discount save(Discount discount) {
Discount ret = discountfacade.merge(discount); Discount ret = discountfacade.merge(discount);
productfacade.evict(discount.getProduct()); productfacade.evictClass();
discountfacade.evictClass();
return ret; return ret;
} }
@Override @Override
public Discount create(Product product,String discountdesc) { public Discount create(String discountdesc) {
Discount ret = new Discount(eventbean.getCurrentEvent()); Discount ret = new Discount(eventbean.getCurrentEvent());
ret.setShortdesc(discountdesc); ret.setShortdesc(discountdesc);
ret.setProduct(product); discountfacade.create(ret);
discountfacade.create(ret); eventfacade.evict(eventbean.getCurrentEvent());
eventfacade.evict(eventbean.getCurrentEvent());
productfacade.evict(product); return ret;
return ret;
} }
} }
...@@ -3,6 +3,8 @@ package fi.insomnia.bortal.beans; ...@@ -3,6 +3,8 @@ package fi.insomnia.bortal.beans;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.insomnia.bortal.enums.Permission;
import fi.insomnia.bortal.enums.RolePermission;
import fi.insomnia.bortal.facade.EventMapFacade; import fi.insomnia.bortal.facade.EventMapFacade;
import fi.insomnia.bortal.model.EventMap; import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.LanEvent; import fi.insomnia.bortal.model.LanEvent;
...@@ -16,23 +18,40 @@ public class EventMapBean implements EventMapBeanLocal { ...@@ -16,23 +18,40 @@ public class EventMapBean implements EventMapBeanLocal {
@EJB @EJB
private EventMapFacade eventmapfacade; private EventMapFacade eventmapfacade;
public EventMapBean() { @EJB
// TODO Auto-generated constructor stub private EventBeanLocal eventbean;
} @EJB
private UserBeanLocal userbean;
@Override @Override
public EventMap saveMap(EventMap eventmap) { public EventMap saveMap(EventMap eventmap) {
userbean.fatalPermission(Permission.TICKET_SALES, RolePermission.WRITE);
return eventmapfacade.merge(eventmap); return eventmapfacade.merge(eventmap);
} }
@Override @Override
public EventMap create(LanEvent event, String mapname) { public EventMap create(String mapname) {
EventMap ret = new EventMap(event); userbean.fatalPermission(Permission.TICKET_SALES, RolePermission.WRITE);
EventMap ret = new EventMap(eventbean.getCurrentEvent());
ret.setName(mapname); ret.setName(mapname);
eventmapfacade.create(ret); LanEvent event = eventbean.getCurrentEvent();
event.getEventMaps().add(ret);
eventbean.mergeChanges(event);
return ret; return ret;
} }
@Override
public void sendImage(int destId, byte[] imagedata) {
userbean.fatalPermission(Permission.TICKET_SALES, RolePermission.WRITE);
LanEvent event = eventbean.getCurrentEvent();
EventMap map = eventmapfacade.find(event.getId(), destId);
if (map != null) {
map.setMapData(imagedata);
}
}
} }
...@@ -41,7 +41,6 @@ public class JaasBean implements JaasBeanLocal, JaasBeanRemote { ...@@ -41,7 +41,6 @@ public class JaasBean implements JaasBeanLocal, JaasBeanRemote {
User user = userfacade.findByLogin(username.trim()); User user = userfacade.findByLogin(username.trim());
logger.debug("Trying to login as {}", username); logger.debug("Trying to login as {}", username);
logger.info("Logging test");
User ret = null; User ret = null;
if (user != null) { if (user != null) {
if (user.checkPassword(password)) { if (user.checkPassword(password)) {
......
...@@ -4,28 +4,204 @@ ...@@ -4,28 +4,204 @@
*/ */
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import fi.insomnia.bortal.enums.Permission; import fi.insomnia.bortal.enums.Permission;
import fi.insomnia.bortal.enums.RolePermission; import fi.insomnia.bortal.enums.RolePermission;
import fi.insomnia.bortal.exceptions.BortalCatchableException;
import fi.insomnia.bortal.exceptions.PermissionDeniedException;
import fi.insomnia.bortal.facade.PlaceFacade; import fi.insomnia.bortal.facade.PlaceFacade;
import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.Place; import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.PlaceGroup;
import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.model.User;
import javax.annotation.Resource;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.persistence.RollbackException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
* @author tuukka * @author tuukka
*/ */
@Stateless @Stateless
public class PlaceBean implements PlaceBeanLocal { public class PlaceBean implements PlaceBeanLocal {
private static final String PLACE_RESERVE_TIMEOUTER = "Map reserve timeouter";
private static final Logger logger = LoggerFactory.getLogger(PlaceBean.class);
@Resource
private TimerService ts;
@EJB @EJB
private PlaceFacade placeFacade; private PlaceFacade placeFacade;
@EJB @EJB
private UserBeanLocal userbean; private UserBeanLocal userbean;
@EJB
private ProductBeanLocal productBean;
@EJB
private EventBeanLocal eventBean;
@EJB
private PlaceGroupBeanLocal pgbean;
@EJB
private SecurityBeanLocal secubean;
@EJB
private EventMapBeanLocal mapfacade;
@Override
public Place mergeChanges(Place place) { public Place mergeChanges(Place place) {
userbean.fatalPermission(Permission.TICKET_SALES, RolePermission.EXECUTE, "User tried to modify place ", place); userbean.fatalPermission(Permission.TICKET_SALES, RolePermission.EXECUTE, "User tried to modify place ", place);
return placeFacade.merge(place); return placeFacade.merge(place);
} }
@Override
public BigDecimal totalReservationPrice(EventMap e, Place newPlace) {
Set<Place> places = new HashSet<Place>();
places.addAll(placeFacade.findUsersReservations(e, userbean.getCurrentUser()));
if (newPlace != null) {
places.add(newPlace);
}
Map<Product, Integer> mockmap = getPlaceProductcount(places);
BigDecimal total = BigDecimal.ZERO;
for (Entry<Product, Integer> entry : mockmap.entrySet()) {
logger.debug("Adding to price {} of {}", entry.getValue(), entry.getKey().getName());
if (entry.getKey() != null) {
total = total.add(productBean.calculateTotal(entry.getKey(), new BigDecimal(entry.getValue())));
}
}
return total;
}
private static Map<Product, Integer> getPlaceProductcount(Collection<Place> places) {
HashMap<Product, Integer> mockmap = new HashMap<Product, Integer>();
for (Place p : places) {
if (p != null) {
Product prod = p.getProduct();
Integer val = mockmap.get(prod);
if (val == null) {
val = 0;
}
mockmap.put(prod, ++val);
}
}
return mockmap;
}
//
// @Override
// public List<Place> findPlaces(List<Integer> placeIds) {
//
// return placeFacade.find(eventBean.getCurrentEvent(), placeIds);
// }
// TODO: Kantakysely tähän!
@Override
public Place findPlace(EventMap e, int x, int y) {
for (Place place : e.getPlaces()) {
if (place.isCoordinateInPlace(x, y)) {
return place;
}
}
return null;
}
@Override
public boolean reservePlace(Place p, User user) {
boolean ret = placeFacade.reservePlace(p, user);
boolean foundTimeout = false;
for (Timer t : ts.getTimers()) {
if (t.getInfo().equals(PLACE_RESERVE_TIMEOUTER)) {
foundTimeout = true;
}
}
if (!foundTimeout) {
logger.info("Place timeout calculator not started. Starting new.");
ts.createTimer(new Date(), 1000 * 60, PLACE_RESERVE_TIMEOUTER);
}
return ret;
}
@Timeout
public void checkTimedOutPlaces(Timer timer) {
// logger.debug("Checking Timed out places at {}", new Date());
placeFacade.timeoutPlaces();
}
@Override
public void releaseUsersPlaces() {
logger.debug("timeouting places");
placeFacade.releasePlaces(userbean.getCurrentUser());
}
@Override
public boolean releasePlace(Place place, User user) {
return placeFacade.releasePlace(user, place);
}
@Override
public boolean buySelectedPlaces(EventMap e) throws BortalCatchableException {
User user = userbean.getCurrentUser();
List<Place> places = placeFacade.findUsersReservations(e, user);
if (places.size() <= 0) {
return false;
}
PlaceGroup pg = pgbean.createPlaceGroup(user);
BigDecimal totalprice = totalReservationPrice(e, null);
BigDecimal balance = userbean.getCurrentUser().getAccountBalance();
if (balance.compareTo(totalprice) < 0) {
logger.debug("User {} Could not buy things because account balance is too low!", user);
return false;
}
for (Place p : places) {
if (!p.buy(pg)) {
throw new BortalCatchableException("Error while buying places");
}
placeFacade.merge(p);
pgbean.createGroupMembership(pg, p);
}
for (Entry<Product, Integer> line : getPlaceProductcount(places).entrySet()) {
productBean.createAccountEvent(line.getKey(), new BigDecimal(line.getValue()), user);
}
return true;
}
} }
package fi.insomnia.bortal.beans;
import java.util.Calendar;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import fi.insomnia.bortal.facade.GroupMembershipFacade;
import fi.insomnia.bortal.facade.PlaceGroupFacade;
import fi.insomnia.bortal.model.GroupMembership;
import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.PlaceGroup;
import fi.insomnia.bortal.model.User;
/**
* Session Bean implementation class PlaceGroupBean
*/
@Stateless
public class PlaceGroupBean implements PlaceGroupBeanLocal {
@EJB
private EventBeanLocal eventbean;
@EJB
private PlaceGroupFacade pgfacade;
@EJB
private GroupMembershipFacade gmemfacade;
/**
* Default constructor.
*/
public PlaceGroupBean() {
// TODO Auto-generated constructor stub
}
@Override
public PlaceGroup createPlaceGroup(User creator) {
PlaceGroup pg = new PlaceGroup(eventbean.getCurrentEvent(), Calendar.getInstance(), Calendar.getInstance(), true);
pg.setCreator(creator);
pgfacade.create(pg);
return pg;
}
@Override
public GroupMembership createGroupMembership(PlaceGroup pg, Place p) {
GroupMembership membership = new GroupMembership(eventbean.getCurrentEvent(), pg, p, gmemfacade.createInviteToken());
gmemfacade.create(membership);
return membership;
}
}
...@@ -51,93 +51,13 @@ public class PlaceMapBean implements PlaceMapBeanLocal { ...@@ -51,93 +51,13 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
@EJB @EJB
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
public void printPlaceMapToStream(OutputStream outputStream, String filetype, Integer mapId, List<Integer> placeIds) throws IOException { public Long selectablePlaceCount(EventMap map) {
User user = userbean.getCurrentUser(); return placeFacade.countSelectable(map);
userbean.fatalPermission(Permission.TICKET_SALES, RolePermission.READ, "User tried to print the placemap to Stream");
long begin = new Date().getTime();
Integer eventId = eventbean.getCurrentEvent().getId();
List<Place> selectedPlaceList = new ArrayList<Place>();
EventMap map = null;
for (Integer id : placeIds) {
selectedPlaceList.add(placeFacade.find(eventId, id));
}
if (logger.isDebugEnabled()) {
logger.debug("Fetching map for event {}", eventbean.getCurrentEvent());
logger.debug("Got mapid {}, time {}", mapId, new Date().getTime() - begin);
}
logger.debug("SelectedPlaceList: {}, size {}", selectedPlaceList, selectedPlaceList.size());
if (selectedPlaceList.size() > 0) {
Place selPlace = selectedPlaceList.get(0);
logger.debug("Selected place: {}", selPlace);
map = selPlace.getMap();
} else {
logger.debug("Fetching from EventMapFacade with eventid {}, mapid {}", eventId, mapId);
map = eventMapFacade.find(eventId, mapId);
}
if (map == null) {
throw new PermissionDeniedException(secubean, user, "Map not found with id: " + mapId + " and event id: " + eventbean.getCurrentEvent());
}
logger.debug("Got map object {}", map);
List<Place> places = map.getPlaces();
logger.info("Places: from map {}, time {}", places.size(), new Date().getTime() - begin);
BufferedImage image = map.getMapWithPlaces();
for (PlaceGroup uplacegroup : user.getPlaceGroups()) {
for (Place uplace : uplacegroup.getPlaces()) {
if (uplace.getMap().equals(map)) {
uplace.drawOwnedPlace(image);
}
}
}
logger.debug("sometime {}", new Date().getTime() - begin);
for (Place place : selectedPlaceList) {
place.drawSelectedPlace(image);
}
logger.debug("Prewrite {}", new Date().getTime() - begin);
ImageIO.write(image, filetype, outputStream);
logger.debug("postwrite {}", new Date().getTime() - begin);
}
public String getSelectPlaceMapUrl(EventMap activeMap, List<Place> selectedPlaces, User user) {
String parameters = "?";
if (selectedPlaces != null && selectedPlaces.size() > 0) {
parameters += "placeid=";
for (Place place : selectedPlaces) {
parameters += place.getId().getId() + ",";
}
if (parameters.endsWith(",")) {
parameters.substring(parameters.length() - 1);
}
} else {
parameters += "mapid=" + activeMap.getId().getId();
}
if (user != null) {
parameters += "&userid=" + user.getId();
}
return "/PlaceMap" + parameters;
} }
public long selectablePlaceCount(User user) { @Override
return placeFacade.count(eventbean.getCurrentEvent()); public EventMap findMap(Integer mapId) {
return eventMapFacade.find(eventbean.getCurrentEvent().getId(), mapId);
} }
} }
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -8,8 +11,17 @@ import javax.ejb.Stateless; ...@@ -8,8 +11,17 @@ import javax.ejb.Stateless;
import fi.insomnia.bortal.enums.Permission; import fi.insomnia.bortal.enums.Permission;
import fi.insomnia.bortal.enums.RolePermission; import fi.insomnia.bortal.enums.RolePermission;
import fi.insomnia.bortal.facade.AccountEventFacade;
import fi.insomnia.bortal.facade.DiscountInstanceFacade;
import fi.insomnia.bortal.facade.ProductFacade; import fi.insomnia.bortal.facade.ProductFacade;
import fi.insomnia.bortal.facade.UserFacade;
import fi.insomnia.bortal.model.AccountEvent;
import fi.insomnia.bortal.model.Discount;
import fi.insomnia.bortal.model.DiscountInstance;
import fi.insomnia.bortal.model.LanEvent;
import fi.insomnia.bortal.model.Product; import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.model.User;
/** /**
* Session Bean implementation class ProductBean * Session Bean implementation class ProductBean
...@@ -17,6 +29,8 @@ import fi.insomnia.bortal.model.Product; ...@@ -17,6 +29,8 @@ import fi.insomnia.bortal.model.Product;
@Stateless @Stateless
public class ProductBean implements ProductBeanLocal { public class ProductBean implements ProductBeanLocal {
private static final String DEFAULT_CREDIT_PRODCT = "Automagic Credit product";
@EJB @EJB
private ProductFacade productFacade; private ProductFacade productFacade;
...@@ -25,6 +39,13 @@ public class ProductBean implements ProductBeanLocal { ...@@ -25,6 +39,13 @@ public class ProductBean implements ProductBeanLocal {
@EJB @EJB
private UserBeanLocal userbean; private UserBeanLocal userbean;
@EJB
private AccountEventFacade accounteventfacade;
@EJB
private DiscountInstanceFacade discountinstancefacade;
@EJB
private UserFacade userFacade;
/** /**
* Default constructor. * Default constructor.
*/ */
...@@ -34,13 +55,12 @@ public class ProductBean implements ProductBeanLocal { ...@@ -34,13 +55,12 @@ public class ProductBean implements ProductBeanLocal {
@Override @Override
public List<Product> listUserShoppableProducts() { public List<Product> listUserShoppableProducts() {
// XXX: Only user shoppable products return productFacade.findPrepaidProducts(eventBean.getCurrentEvent());
return productFacade.findAll();
} }
@Override @Override
public Product createProduct(String name, BigDecimal price) { public Product createProduct(String name, BigDecimal price) {
userbean.fatalPermission(Permission.PRODUCT, RolePermission.WRITE, "User tried to create product: ",name); userbean.fatalPermission(Permission.PRODUCT, RolePermission.WRITE, "User tried to create product: ", name);
Product entity = new Product(eventBean.getCurrentEvent(), name, price); Product entity = new Product(eventBean.getCurrentEvent(), name, price);
productFacade.create(entity); productFacade.create(entity);
...@@ -49,15 +69,82 @@ public class ProductBean implements ProductBeanLocal { ...@@ -49,15 +69,82 @@ public class ProductBean implements ProductBeanLocal {
@Override @Override
public List<Product> getProducts() { public List<Product> getProducts() {
userbean.fatalPermission(Permission.PRODUCT, RolePermission.READ, "User tried to fetch all products"); userbean.fatalPermission(Permission.PRODUCT, RolePermission.READ, "User tried to fetch all products");
return productFacade.findAll(); return productFacade.findAll();
} }
@Override @Override
public void mergeChanges(Product product) { public Product mergeChanges(Product product) {
userbean.fatalPermission(Permission.PRODUCT, RolePermission.WRITE, "User tried to save changes for product: ",product); userbean.fatalPermission(Permission.PRODUCT, RolePermission.WRITE, "User tried to save changes for product: ", product);
productFacade.merge(product); return productFacade.merge(product);
}
@Override
public Product findCreditProduct() {
Product ret = productFacade.findProductByPrice(eventBean.getCurrentEvent(), BigDecimal.ONE.negate());
if (ret == null) {
ret = new Product(eventBean.getCurrentEvent(), DEFAULT_CREDIT_PRODCT, BigDecimal.ONE.negate());
productFacade.create(ret);
}
return ret;
}
@Override
public BigDecimal calculateTotal(Product product, BigDecimal quantity) {
if (product == null || quantity == null) {
throw new RuntimeException("Some parameter is null!");
}
BigDecimal total = product.getPrice();
for (Discount d : getActiveDiscounts(product, quantity)) {
total = total.multiply(d.getPercentage());
}
return total.setScale(2, RoundingMode.HALF_UP).multiply(quantity);
}
// TODO: alennukset lasketaan täällä. HUOMHUOM!!
@Override
public List<Discount> getActiveDiscounts(Product product, BigDecimal quantity) {
ArrayList<Discount> ret = new ArrayList<Discount>();
for (Discount d : product.getDiscounts()) {
if (d.isActive() && quantity.compareTo(d.getAmountMax()) <= 0 && quantity.compareTo(d.getAmountMin()) >= 0) {
ret.add(d);
}
}
return ret;
} }
@Override
public AccountEvent createAccountEvent(Product product, BigDecimal quantity, User user) {
BigDecimal unitPrice = product.getPrice().negate();
List<Discount> discounts = getActiveDiscounts(product, quantity);
for (Discount d : discounts) {
unitPrice = unitPrice.multiply(d.getPercentage());
}
AccountEvent ret = new AccountEvent(eventBean.getCurrentEvent(), user, product, unitPrice, quantity, Calendar.getInstance());
ret.setUser(user);
ret.setDelivered(Calendar.getInstance());
ret.setSeller(userbean.getCurrentUser());
accounteventfacade.create(ret);
LanEvent event = eventBean.getCurrentEvent();
for (Discount d : discounts) {
DiscountInstance discInst = new DiscountInstance(event, ret, d);
discountinstancefacade.create(discInst);
}
accounteventfacade.evict(ret);
userFacade.evict(user);
product.getUnitName();
return ret;
}
@Override
public Product findById(int id) {
return productFacade.find(eventBean.getCurrentEvent().getId(), id);
}
} }
...@@ -73,15 +73,15 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -73,15 +73,15 @@ public class TestDataBean implements TestDataBeanLocal {
} }
public void writeMap( long bytes) { public void writeMap( byte[] bytes) {
EventMap map = new EventMap(eventBean.getCurrentEvent()); EventMap map = new EventMap(eventBean.getCurrentEvent());
map.setName("test" + bytes); map.setName("test" + bytes);
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes; ++i) { // for (int i = 0; i < bytes; ++i) {
//
sb.append((char) (33 + i % 92)); // sb.append((char) (33 + i % 92));
} // }
map.setMapData(sb.toString()); map.setMapData(bytes);
eventMapFacade.create(map); eventMapFacade.create(map);
} }
...@@ -223,9 +223,8 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -223,9 +223,8 @@ public class TestDataBean implements TestDataBeanLocal {
} }
stream.close(); stream.close();
String str = Base64.encodeBase64String(bytes);
logger.debug("Saving image with {} base64 encoded chars", str.length()); map.setMapData(bytes);
map.setMapData(str);
map.setName("test0"); map.setName("test0");
eventMapFacade.create(map); eventMapFacade.create(map);
......
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.math.BigDecimal;
import java.security.Principal; import java.security.Principal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -19,12 +22,17 @@ import javax.persistence.PersistenceContext; ...@@ -19,12 +22,17 @@ import javax.persistence.PersistenceContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.sun.xml.internal.xsom.impl.scd.Iterators.Map;
import fi.insomnia.bortal.enums.Permission; import fi.insomnia.bortal.enums.Permission;
import fi.insomnia.bortal.enums.RolePermission; import fi.insomnia.bortal.enums.RolePermission;
import fi.insomnia.bortal.exceptions.PermissionDeniedException; import fi.insomnia.bortal.exceptions.PermissionDeniedException;
import fi.insomnia.bortal.facade.RoleFacade; import fi.insomnia.bortal.facade.RoleFacade;
import fi.insomnia.bortal.facade.UserFacade; import fi.insomnia.bortal.facade.UserFacade;
import fi.insomnia.bortal.facade.UserImageFacade; import fi.insomnia.bortal.facade.UserImageFacade;
import fi.insomnia.bortal.model.AccountEvent;
import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.model.Role; import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.model.RoleRight; import fi.insomnia.bortal.model.RoleRight;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
...@@ -61,6 +69,8 @@ public class UserBean implements UserBeanLocal { ...@@ -61,6 +69,8 @@ public class UserBean implements UserBeanLocal {
private RoleFacade rolefacade; private RoleFacade rolefacade;
@EJB @EJB
private UserImageFacade userimagefacade; private UserImageFacade userimagefacade;
@EJB
private ProductBeanLocal productBean;
/** /**
* Default constructor. * Default constructor.
...@@ -69,17 +79,6 @@ public class UserBean implements UserBeanLocal { ...@@ -69,17 +79,6 @@ public class UserBean implements UserBeanLocal {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@Override
public User createNewUser(String login, String password) {
User returnUser = new User();
returnUser.setLogin(login);
returnUser.resetPassword(password);
// Tallennetaan olio kantaan...
userFacade.create(returnUser);
em.flush();
return returnUser;
}
public List<User> getUsers() { public List<User> getUsers() {
fatalPermission(Permission.USER_MANAGEMENT, RolePermission.READ); fatalPermission(Permission.USER_MANAGEMENT, RolePermission.READ);
...@@ -274,4 +273,20 @@ public class UserBean implements UserBeanLocal { ...@@ -274,4 +273,20 @@ public class UserBean implements UserBeanLocal {
return ret; return ret;
} }
public List<User> searchName(String name) {
return userFacade.search(name, new String[] { "nick", "login", "firstnames", "lastname" });
}
@Override
public User createNewUser(User user, String password) {
user.resetPassword(password);
// Tallennetaan olio kantaan...
userFacade.create(user);
em.flush();
return user;
}
} }
package fi.insomnia.bortal.beans;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
/**
* Session Bean implementation class UtilBean
*/
@Stateless
public class UtilBean implements UtilBeanLocal {
@PersistenceContext
private EntityManager em;
@PersistenceUnit
private EntityManagerFactory emf;
/**
* Default constructor.
*/
public UtilBean() {
// TODO Auto-generated constructor stub
}
//
// public void reindexCompass()
// {
// JpaCompassGps gps = EclipseLinkHelper.getCompassGps(emf);
//// JpaCompassGps gps = EclipseLinkHelper.getCompassGps(em);
// gps.index();
// }
}
package fi.insomnia.bortal.beanutil;
import javax.ejb.Stateless;
import fi.insomnia.bortal.model.User;
/**
* Session Bean implementation class AuthorisationBean
*/
@Stateless
public class AuthorisationBean implements AuthorisationBeanLocal {
/**
* Default constructor.
*/
public AuthorisationBean() {
// TODO Auto-generated constructor stub
}
public boolean isAuthorised(User user, Right r, RightType t) {
if (user.isSuperadmin()) {
return true;
} else {
}
return false;
}
}
package fi.insomnia.bortal.beanutil;
import javax.ejb.Local;
import fi.insomnia.bortal.model.User;
@Local
public interface AuthorisationBeanLocal {
public enum Right {
ADMIN
}
public enum RightType {
READ, WRITE, EXECUTE
}
boolean isAuthorised(User currentuser, Right admin, RightType read);
}
package fi.insomnia.bortal.beanutil;
import java.math.BigDecimal;
import java.util.ArrayList;
import fi.insomnia.bortal.model.Discount;
import fi.insomnia.bortal.model.Product;
public class DiscountCollection {
private Product product;
private BigDecimal quantity;
private ArrayList<Discount> discounts;
public DiscountCollection(Product prod, BigDecimal quant, Discount d) {
product = prod;
quantity = quant;
discounts = new ArrayList<Discount>();
discounts.add(d);
}
public void noticeDiscount(Discount d) {
for (Discount oldD : discounts) {
}
}
public BigDecimal getTotal() {
BigDecimal ret = BigDecimal.ZERO;
for (Discount d : discounts) {
if(d.isActive())
{
ret = ret.multiply(d.getPercentage());
}
}
return ret;
}
}
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
...@@ -13,6 +14,8 @@ public class AccountEventFacade extends EventChildGenericFacade<AccountEvent> { ...@@ -13,6 +14,8 @@ public class AccountEventFacade extends EventChildGenericFacade<AccountEvent> {
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@EJB
private UserFacade userfacade;
public AccountEventFacade() { public AccountEventFacade() {
super(AccountEvent.class); super(AccountEvent.class);
} }
...@@ -21,4 +24,12 @@ public class AccountEventFacade extends EventChildGenericFacade<AccountEvent> { ...@@ -21,4 +24,12 @@ public class AccountEventFacade extends EventChildGenericFacade<AccountEvent> {
return em; return em;
} }
@Override
public void create(AccountEvent event)
{
super.create(event);
userfacade.evict(event.getUser());
}
} }
...@@ -7,6 +7,7 @@ import javax.persistence.EntityManager; ...@@ -7,6 +7,7 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit; import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -23,10 +24,10 @@ public class BillFacade extends EventChildGenericFacade<Bill> { ...@@ -23,10 +24,10 @@ public class BillFacade extends EventChildGenericFacade<Bill> {
private static final Logger logger = LoggerFactory.getLogger(BillFacade.class); private static final Logger logger = LoggerFactory.getLogger(BillFacade.class);
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@EJB @EJB
private UserFacade userfacade; private UserFacade userfacade;
public BillFacade() { public BillFacade() {
super(Bill.class); super(Bill.class);
} }
...@@ -36,20 +37,18 @@ public class BillFacade extends EventChildGenericFacade<Bill> { ...@@ -36,20 +37,18 @@ public class BillFacade extends EventChildGenericFacade<Bill> {
} }
@Override @Override
public void create(Bill entity) public void create(Bill entity) {
{
super.create(entity); super.create(entity);
userfacade.evict(entity.getUser()); userfacade.evict(entity.getUser());
} }
public Integer getBiggestBillNumber(LanEvent e) { public Integer getBiggestBillNumber(LanEvent e) {
TypedQuery<Integer> q = getEm().createNamedQuery("Bill.findbiggestBillNumber", Integer.class); TypedQuery<Integer> q = getEm().createNamedQuery("Bill.findbiggestBillNumber", Integer.class);
q.setParameter("event", e); q.setParameter("event", e);
return getSingleNullableResult(q); return getSingleNullableResult(q);
} }
} }
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import fi.insomnia.bortal.bortal.views.BillSummary;
import fi.insomnia.bortal.model.BillLine; import fi.insomnia.bortal.model.BillLine;
@Stateless @Stateless
...@@ -14,19 +21,30 @@ public class BillLineFacade extends EventChildGenericFacade<BillLine> { ...@@ -14,19 +21,30 @@ public class BillLineFacade extends EventChildGenericFacade<BillLine> {
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@EJB @EJB
private BillFacade billfacade; private BillFacade billfacade;
public BillLineFacade() { public BillLineFacade() {
super(BillLine.class); super(BillLine.class);
} }
public void create(BillLine entity) public void create(BillLine entity) {
{
super.create(entity); super.create(entity);
billfacade.evict(entity.getBill()); billfacade.evict(entity.getBill());
} }
public List<BillSummary> getLineSummary() {
TypedQuery<Object[]> q = em.createQuery("SELECT l.name as name, sum(l.quantity) as total from BillLine l GROUP BY l.name", Object[].class);
List<Object[]> objlist = q.getResultList();
List<BillSummary> ret = new ArrayList<BillSummary>();
for(Object[] obj:objlist)
{
ret.add(new BillSummary(obj));
}
return ret;
}
protected EntityManager getEm() { protected EntityManager getEm() {
return em; return em;
} }
......
...@@ -15,13 +15,12 @@ import org.slf4j.LoggerFactory; ...@@ -15,13 +15,12 @@ import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.model.LanEvent; import fi.insomnia.bortal.model.LanEvent;
import fi.insomnia.bortal.model.EventChildInterface; import fi.insomnia.bortal.model.EventChildInterface;
import fi.insomnia.bortal.model.EventPk; import fi.insomnia.bortal.model.EventPk;
import fi.insomnia.bortal.model.Product;
/** /**
* Session Bean implementation class GenericFacade * Session Bean implementation class GenericFacade
*/ */
public abstract class EventChildGenericFacade<T extends EventChildInterface> { public abstract class EventChildGenericFacade<T extends EventChildInterface> {
private static final Logger logger = LoggerFactory.getLogger(EventChildGenericFacade.class); private static final Logger logger = LoggerFactory.getLogger(EventChildGenericFacade.class);
...@@ -30,7 +29,6 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> { ...@@ -30,7 +29,6 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> {
EventPk pk = new EventPk(eventId); EventPk pk = new EventPk(eventId);
pk.setId(id); pk.setId(id);
logger.debug("Fetching object {} with key {}", this.getEntityClass(), pk);
return find(pk); return find(pk);
} }
...@@ -45,40 +43,42 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> { ...@@ -45,40 +43,42 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> {
TypedQuery<Long> q = getEm().createQuery(query); TypedQuery<Long> q = getEm().createQuery(query);
return q.getSingleResult(); return q.getSingleResult();
} }
private Class<T> entClass; private Class<T> entClass;
public EventChildGenericFacade(Class<T>entityClass)
{ public EventChildGenericFacade(Class<T> entityClass) {
this.entClass = entityClass; this.entClass = entityClass;
} }
protected Class<T> getEntityClass()
{ protected Class<T> getEntityClass() {
return entClass; return entClass;
} }
protected abstract EntityManager getEm(); protected abstract EntityManager getEm();
public void create(T entity) { public void create(T entity) {
getEm().persist(entity); getEm().persist(entity);
} }
public void remove(T entity) { public void remove(T entity) {
getEm().remove(entity); getEm().remove(entity);
} }
public T merge(T entity) { public T merge(T entity) {
return getEm().merge(entity); return getEm().merge(entity);
} }
public T find(EventPk id) { public T find(EventPk id) {
logger.debug("GenericFacade Find class {} By pk {}", new Object[]{getEntityClass(), id});
T ret = getEm().find(getEntityClass(), id); T ret = getEm().find(getEntityClass(), id);
return ret; return ret;
} }
public List<T> findAll() { public List<T> findAll() {
CriteriaQuery<T> cq = getEm().getCriteriaBuilder().createQuery(getEntityClass()); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(getEntityClass());
Root<T> root = cq.from(getEntityClass());
cq.orderBy(cb.asc(root.get("id").get("id")));
cq.select(cq.from(getEntityClass())); cq.select(cq.from(getEntityClass()));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
...@@ -99,9 +99,8 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> { ...@@ -99,9 +99,8 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> {
TypedQuery<Long> q = getEm().createQuery(cq); TypedQuery<Long> q = getEm().createQuery(cq);
return q.getSingleResult(); return q.getSingleResult();
} }
protected static <K> K getSingleNullableResult(TypedQuery<K> q) {
protected static <K> K getSingleNullableResult(TypedQuery<K> q) {
K ret = null; K ret = null;
try { try {
ret = q.getSingleResult(); ret = q.getSingleResult();
...@@ -110,9 +109,15 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> { ...@@ -110,9 +109,15 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> {
} }
return ret; return ret;
} }
public void evict(T entity) { public void evict(T entity) {
if (entity != null && entity.getId() != null) { if (entity != null && entity.getId() != null) {
getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId()); getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId());
} }
} }
public void evictClass() {
getEm().getEntityManagerFactory().getCache().evict(getClass());
}
} }
...@@ -5,6 +5,7 @@ import java.util.List; ...@@ -5,6 +5,7 @@ import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
...@@ -12,7 +13,6 @@ import org.slf4j.Logger; ...@@ -12,7 +13,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.model.ModelInterface; import fi.insomnia.bortal.model.ModelInterface;
import fi.insomnia.bortal.model.User;
/** /**
* Session Bean implementation class GenericFacade * Session Bean implementation class GenericFacade
...@@ -43,17 +43,20 @@ public abstract class GenericFacade<PK, T extends ModelInterface> { ...@@ -43,17 +43,20 @@ public abstract class GenericFacade<PK, T extends ModelInterface> {
public T merge(T entity) { public T merge(T entity) {
return getEm().merge(entity); return getEm().merge(entity);
} }
public T find(PK id) { public T find(PK id) {
logger.debug("GenericFacade Find class {} By pk {}", new Object[] { getEntityClass(), id });
T ret = getEm().find(getEntityClass(), id); T ret = getEm().find(getEntityClass(), id);
return ret; return ret;
} }
public List<T> findAll() { public List<T> findAll() {
CriteriaQuery<T> cq = getEm().getCriteriaBuilder().createQuery(getEntityClass()); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(getEntityClass());
Root<T> root = cq.from(getEntityClass());
cq.orderBy(cb.asc(root.get("id")));
cq.select(cq.from(getEntityClass())); cq.select(cq.from(getEntityClass()));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
...@@ -90,4 +93,34 @@ public abstract class GenericFacade<PK, T extends ModelInterface> { ...@@ -90,4 +93,34 @@ public abstract class GenericFacade<PK, T extends ModelInterface> {
getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId()); getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId());
} }
} }
//
// @SuppressWarnings("unchecked")
// public List<T> search(String query, String[] fields) {
// CompassSession sess =
// EclipseLinkHelper.getCurrentCompassSession(getEm());
// CompassQueryBuilder qb = sess.queryBuilder();
// CompassMultiPropertyQueryStringBuilder properties =
// qb.multiPropertyQueryString(query);
//
// for (String field : fields) {
// properties.add(field);
// }
// String alias = getClass().getSimpleName().toLowerCase();
//
// logger.debug("searching class {}", alias);
// CompassHits hits =
// qb.bool().addMust(qb.alias(alias)).addMust(properties.toQuery()).toQuery().hits();
//
// Iterator<CompassHit> iter = hits.iterator();
// ArrayList<T> ret = new ArrayList<T>();
// while (iter.hasNext()) {
//
// Object data = iter.next().getData();
// logger.debug("Found user {}", data);
// ret.add((T) data);
//
// }
// return ret;
//
// }
} }
...@@ -4,12 +4,19 @@ import javax.ejb.LocalBean; ...@@ -4,12 +4,19 @@ import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.model.GroupMembership; import fi.insomnia.bortal.model.GroupMembership;
import fi.insomnia.bortal.utilities.PasswordFunctions;
@Stateless @Stateless
@LocalBean @LocalBean
public class GroupMembershipFacade extends EventChildGenericFacade<GroupMembership> { public class GroupMembershipFacade extends EventChildGenericFacade<GroupMembership> {
private static final Logger logger = LoggerFactory.getLogger(GroupMembershipFacade.class);
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
...@@ -21,4 +28,22 @@ public class GroupMembershipFacade extends EventChildGenericFacade<GroupMembersh ...@@ -21,4 +28,22 @@ public class GroupMembershipFacade extends EventChildGenericFacade<GroupMembersh
return em; return em;
} }
public String createInviteToken() {
String token = null;
GroupMembership gm = null;
do {
if (token != null) {
logger.info("Generated token {} found from GoupMembership: {} Generating new!", token, gm);
}
token = PasswordFunctions.generateRandomString(15);
gm = findByToken(token);
} while (gm != null);
return token;
}
public GroupMembership findByToken(String token) {
TypedQuery<GroupMembership> q = em.createQuery("Select gm from GroupMembership gm where gm.inviteToken = :token ", GroupMembership.class);
q.setParameter("token", token);
return getSingleNullableResult(q);
}
} }
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import java.util.List;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.Place; import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.User;
@Stateless @Stateless
@LocalBean @LocalBean
public class PlaceFacade extends EventChildGenericFacade<Place> { public class PlaceFacade extends EventChildGenericFacade<Place> {
private static final Logger logger = LoggerFactory.getLogger(PlaceFacade.class);
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
...@@ -21,4 +31,83 @@ public class PlaceFacade extends EventChildGenericFacade<Place> { ...@@ -21,4 +31,83 @@ public class PlaceFacade extends EventChildGenericFacade<Place> {
return em; return em;
} }
public boolean reservePlace(Place p, User reserver) {
boolean ret = p.reserve(reserver);
merge(p);
return ret;
}
//
// public List<Place> find(LanEvent event, List<Integer> placeIds) {
// if (placeIds == null || placeIds.size() <= 0) {
// return new ArrayList<Place>();
// }
//
// TypedQuery<Place> q =
// em.createQuery("Select p from Place p where p.id.eventId = :eventid and p.id.id IN :places",
// Place.class);
// q.setParameter("eventid", event.getId());
// q.setParameter("places", placeIds);
// return q.getResultList();
// }
public void timeoutPlaces() {
TypedQuery<Place> q = em.createQuery("SELECT p from Place p where p.releaseTime < CURRENT_TIMESTAMP", Place.class);
int updated = timeoutPlaces(q.getResultList(), true);
if (updated > 0) {
logger.info("{} places released for sale after release time exceeded.", updated);
}
}
private int timeoutPlaces(List<Place> places, boolean checkFromEntity) {
int updated = 0;
for (Place p : places) {
logger.debug("Releasing place {} at automagic timed place check.", p);
if (!checkFromEntity || p.checkReleased()) {
++updated;
merge(p);
}
}
// logger.debug("Checking timeouted places took: {} ms",
// Calendar.getInstance().getTimeInMillis()-begin.getTimeInMillis());
return updated;
}
public Long countSelectable(EventMap map) {
if (map == null) {
return null;
}
TypedQuery<Place> q = em.createQuery("SELECT p from Place p where p.map = :map and p.releaseTime is null", Place.class);
q.setParameter("map", map);
long count = 0;
for (Place p : q.getResultList()) {
if (p.getGroup() == null) {
++count;
}
}
return count;
}
public boolean releasePlace(User user, Place place) {
boolean ret = place.release(user);
merge(place);
return ret;
}
public List<Place> findUsersReservations(EventMap map, User user) {
TypedQuery<Place> q = em.createQuery("select p from Place p where p.map = :map and p.currentUser = :user and p.releaseTime is not null", Place.class);
q.setParameter("map", map);
q.setParameter("user", user);
return q.getResultList();
}
public void releasePlaces(User user) {
TypedQuery<Place> q = em.createQuery("SELECT p from Place p where p.releaseTime < CURRENT_TIMESTAMP and currentUser = :user", Place.class);
q.setParameter("user", user);
int updated = timeoutPlaces(q.getResultList(), false);
logger.debug("Released {} places from user {}", updated, user);
}
} }
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import java.math.BigDecimal;
import java.util.List;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import fi.insomnia.bortal.model.LanEvent;
import fi.insomnia.bortal.model.Product; import fi.insomnia.bortal.model.Product;
@Stateless @Stateless
...@@ -26,4 +31,24 @@ public class ProductFacade extends EventChildGenericFacade<Product> { ...@@ -26,4 +31,24 @@ public class ProductFacade extends EventChildGenericFacade<Product> {
throw new RuntimeException(); throw new RuntimeException();
} }
public Product findProductByPrice(LanEvent event, BigDecimal price) {
// EventPk id = new EventPk(event);
TypedQuery<Product> q = em.createQuery("select p from Product p where p.id.eventId = :eventid and p.price = :price", Product.class);
q.setParameter("price", price);
q.setParameter("eventid", event.getId());
List<Product> results = q.getResultList();
if (results.size() > 0) {
return results.get(0);
}
return null;
}
public List<Product> findPrepaidProducts(LanEvent e) {
TypedQuery<Product> q = em.createQuery("select p from Product p where p.id.eventId = :eventid and p.prepaid = true", Product.class);
q.setParameter("eventid", e.getId());
return q.getResultList();
}
} }
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import java.util.List;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
@Stateless @Stateless
@LocalBean @LocalBean
public class UserFacade extends GenericFacade<Integer, User> { public class UserFacade extends GenericFacade<Integer, User> {
private static final Logger logger = LoggerFactory.getLogger(UserFacade.class);
public enum UserField {
id, nick, login, firstname, lastname
}
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
...@@ -29,6 +39,9 @@ public class UserFacade extends GenericFacade<Integer, User> { ...@@ -29,6 +39,9 @@ public class UserFacade extends GenericFacade<Integer, User> {
return getSingleNullableResult(q); return getSingleNullableResult(q);
} }
public List<User> search(String name, String[] strings) {
// TODO Auto-generated method stub
return null;
}
} }
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
import fi.insomnia.bortal.bortal.views.BillSummary;
import fi.insomnia.bortal.model.Bill; import fi.insomnia.bortal.model.Bill;
import fi.insomnia.bortal.model.BillLine; import fi.insomnia.bortal.model.BillLine;
import fi.insomnia.bortal.model.Product; import fi.insomnia.bortal.model.Product;
...@@ -21,6 +23,13 @@ public interface BillBeanLocal { ...@@ -21,6 +23,13 @@ public interface BillBeanLocal {
BillLine addProductToBill(Bill bill, Product product, BigDecimal count); BillLine addProductToBill(Bill bill, Product product, BigDecimal count);
List<Bill> findAll();
List<BillSummary> getBillLineSummary();
void markPaid(Bill bill, Calendar when);
} }
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.math.BigDecimal;
import javax.ejb.Local; import javax.ejb.Local;
import fi.insomnia.bortal.model.Discount; import fi.insomnia.bortal.model.Discount;
...@@ -10,6 +12,7 @@ public interface DiscountBeanLocal { ...@@ -10,6 +12,7 @@ public interface DiscountBeanLocal {
Discount save(Discount discount); Discount save(Discount discount);
Discount create(Product product, String discountdesc); Discount create(String discountdesc);
} }
...@@ -9,6 +9,8 @@ public interface EventMapBeanLocal { ...@@ -9,6 +9,8 @@ public interface EventMapBeanLocal {
EventMap saveMap(EventMap eventmap); EventMap saveMap(EventMap eventmap);
EventMap create(LanEvent currentEvent, String mapname); EventMap create(String mapname);
void sendImage(int destId, byte[] imagedata);
} }
...@@ -5,19 +5,41 @@ ...@@ -5,19 +5,41 @@
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.math.BigDecimal;
import java.util.List;
import fi.insomnia.bortal.exceptions.BortalCatchableException;
import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.Place; import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.model.User;
import javax.ejb.Local; import javax.ejb.Local;
import org.granite.messaging.service.annotations.RemoteDestination; import org.granite.messaging.service.annotations.RemoteDestination;
/** /**
* *
* @author tuukka * @author tuukka
*/ */
@Local @Local
@RemoteDestination @RemoteDestination
public interface PlaceBeanLocal { public interface PlaceBeanLocal {
public Place mergeChanges(Place place); Place mergeChanges(Place place);
Place findPlace(EventMap e, int x, int y);
void releaseUsersPlaces();
boolean reservePlace(Place place, User user);
boolean releasePlace(Place place, User user);
BigDecimal totalReservationPrice(EventMap e, Place newPlace);
boolean buySelectedPlaces(EventMap e) throws BortalCatchableException;
} }
package fi.insomnia.bortal.beans;
import javax.ejb.Local;
import fi.insomnia.bortal.model.GroupMembership;
import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.PlaceGroup;
import fi.insomnia.bortal.model.User;
@Local
public interface PlaceGroupBeanLocal {
PlaceGroup createPlaceGroup(User currentUser);
GroupMembership createGroupMembership(PlaceGroup pg, Place p);
}
...@@ -16,10 +16,13 @@ import fi.insomnia.bortal.model.User; ...@@ -16,10 +16,13 @@ import fi.insomnia.bortal.model.User;
@RemoteDestination @RemoteDestination
public interface PlaceMapBeanLocal { public interface PlaceMapBeanLocal {
void printPlaceMapToStream(OutputStream outputStream, String filetype, Integer mapId, List<Integer> placeIds) throws IOException; // public String getSelectPlaceMapUrl(EventMap activeMap, List<Place> selectedPlaces, User user);
public String getSelectPlaceMapUrl(EventMap activeMap, List<Place> selectedPlaces, User user);
public long selectablePlaceCount(User user); public Long selectablePlaceCount(EventMap activeMap);
public EventMap findMap(Integer mapId);
// public List<Place> findSelectedPlaces(EventMap map);
// public EventMap findMap(int i); // public EventMap findMap(int i);
......
...@@ -5,7 +5,11 @@ import java.util.List; ...@@ -5,7 +5,11 @@ import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
import fi.insomnia.bortal.model.AccountEvent;
import fi.insomnia.bortal.model.Discount;
import fi.insomnia.bortal.model.Product; import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.model.User;
@Local @Local
public interface ProductBeanLocal { public interface ProductBeanLocal {
...@@ -16,6 +20,16 @@ public interface ProductBeanLocal { ...@@ -16,6 +20,16 @@ public interface ProductBeanLocal {
List<Product> getProducts(); List<Product> getProducts();
void mergeChanges(Product product); Product mergeChanges(Product product);
Product findCreditProduct();
BigDecimal calculateTotal(Product key, BigDecimal value);
AccountEvent createAccountEvent(Product product, BigDecimal quantity, User user);
List<Discount> getActiveDiscounts(Product product, BigDecimal quantity);
Product findById(int parseInt);
} }
...@@ -29,7 +29,7 @@ public interface TestDataBeanLocal { ...@@ -29,7 +29,7 @@ public interface TestDataBeanLocal {
EventMap readMap(long bytes); EventMap readMap(long bytes);
void writeMap(long bytes); void writeMap(byte[] bytes);
void flushMaps(); void flushMaps();
void contextTest(); void contextTest();
......
...@@ -6,15 +6,14 @@ import javax.ejb.Local; ...@@ -6,15 +6,14 @@ import javax.ejb.Local;
import fi.insomnia.bortal.enums.Permission; import fi.insomnia.bortal.enums.Permission;
import fi.insomnia.bortal.enums.RolePermission; import fi.insomnia.bortal.enums.RolePermission;
import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.model.UserImage; import fi.insomnia.bortal.model.UserImage;
@Local @Local
public interface UserBeanLocal { public interface UserBeanLocal {
User createNewUser(String nick, String password);
List<User> getUsers(); List<User> getUsers();
User getUser(String nick); User getUser(String nick);
...@@ -33,8 +32,7 @@ public interface UserBeanLocal { ...@@ -33,8 +32,7 @@ public interface UserBeanLocal {
boolean isLoggedIn(); boolean isLoggedIn();
void fatalPermission(Permission target, RolePermission permission, Object... failmessage);
void fatalPermission(Permission target, RolePermission permission, Object ... failmessage);
void fatalNotLoggedIn(); void fatalNotLoggedIn();
...@@ -42,7 +40,8 @@ public interface UserBeanLocal { ...@@ -42,7 +40,8 @@ public interface UserBeanLocal {
UserImage findUserImage(int id); UserImage findUserImage(int id);
List<User> searchName(String name);
User createNewUser(User user, String password);
} }
package fi.insomnia.bortal.beans;
import javax.ejb.Local;
@Local
public interface UtilBeanLocal {
}
package fi.insomnia.bortal.bortal.views;
import java.math.BigDecimal;
public class BillSummary {
public BillSummary(Object[] o) {
name = o[0].toString();
total = (BigDecimal) o[1];
}
private String name;
private BigDecimal total;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getTotal() {
return total;
}
public void setTotal(BigDecimal total) {
this.total = total;
}
}
package fi.insomnia.bortal.exceptions;
public class BortalCatchableException extends Exception {
public BortalCatchableException(String string) {
super(string);
}
/**
*
*/
private static final long serialVersionUID = 4744284457862674051L;
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="BortalDb" transaction-type="JTA"> <persistence-unit name="BortalDb" transaction-type="JTA">
<jta-data-source>jdbc/bortal</jta-data-source> <jta-data-source>jdbc/bortal</jta-data-source>
<properties> <properties>
<property name="eclipselink.ddl-generation" value="create-tables"/> <property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/>
</properties>
</properties> </persistence-unit>
</persistence-unit>
</persistence> </persistence>
...@@ -16,11 +16,11 @@ public enum Permission { ...@@ -16,11 +16,11 @@ public enum Permission {
// NOTE. add conversion Value to RoleRight // NOTE. add conversion Value to RoleRight
// PERMISSION("Description"), // PERMISSION("Description"),
LOGIN("User can see loginbutton(r), create new user(w)"), LOGIN("User can see loginbutton(r), create new user(w)"),
USER_MANAGEMENT("User has right to view all users(r), modify users(w), execute actions for user(x), Eg shop! "), USER_MANAGEMENT("User has right to view all users(r), modify users(w), execute actions for user(x) "),
TICKET_SALES("User has right to view(r), administer(w) and buy(x)"), TICKET_SALES("User has right to view(r), administer(w) and buy(x)"),
ROLE_MANAGEMENT("User has right to view(r), modify(w) and assign(x) roles"), ROLE_MANAGEMENT("User has right to view(r), modify(w) and assign(x) roles"),
PRODUCT("View(r), modify(w), and shop(x) products"), PRODUCT("View(r), modify(w), and shop(x) products"),
SHOP("View shopped events(r), Modify AccountEvents() and Shop(x)")
; ;
private String description; private String description;
......
...@@ -9,6 +9,7 @@ import java.math.BigDecimal; ...@@ -9,6 +9,7 @@ import java.math.BigDecimal;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.EmbeddedId; import javax.persistence.EmbeddedId;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -24,6 +25,7 @@ import javax.persistence.Temporal; ...@@ -24,6 +25,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Version; import javax.persistence.Version;
/** /**
* Account event contains the money / credit traffic for the user. Each row * Account event contains the money / credit traffic for the user. Each row
* references a Product entity. * references a Product entity.
...@@ -33,13 +35,12 @@ import javax.persistence.Version; ...@@ -33,13 +35,12 @@ import javax.persistence.Version;
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "AccountEvent.findAll", query = "SELECT a FROM AccountEvent a"), @NamedQuery(name = "AccountEvent.findAll", query = "SELECT a FROM AccountEvent a"),
@NamedQuery(name = "AccountEvent.findByUnitPrice", query = "SELECT a FROM AccountEvent a WHERE a.unitPrice = :unitPrice"), @NamedQuery(name = "AccountEvent.findByUnitPrice", query = "SELECT a FROM AccountEvent a WHERE a.unitPrice = :unitPrice"),
@NamedQuery(name = "AccountEvent.findByUnits", query = "SELECT a FROM AccountEvent a WHERE a.units = :units"), @NamedQuery(name = "AccountEvent.findByQuantity", query = "SELECT a FROM AccountEvent a WHERE a.quantity = :units"),
@NamedQuery(name = "AccountEvent.findByEventTime", query = "SELECT a FROM AccountEvent a WHERE a.eventTime = :eventTime"), @NamedQuery(name = "AccountEvent.findByEventTime", query = "SELECT a FROM AccountEvent a WHERE a.eventTime = :eventTime"),
@NamedQuery(name = "AccountEvent.findByDelivered", query = "SELECT a FROM AccountEvent a WHERE a.delivered = :delivered") }) @NamedQuery(name = "AccountEvent.findByDelivered", query = "SELECT a FROM AccountEvent a WHERE a.delivered = :delivered") })
public class AccountEvent implements EventChildInterface { public class AccountEvent implements EventChildInterface {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@EmbeddedId @EmbeddedId
private EventPk id; private EventPk id;
...@@ -53,7 +54,7 @@ public class AccountEvent implements EventChildInterface { ...@@ -53,7 +54,7 @@ public class AccountEvent implements EventChildInterface {
* The units of the product, eg 1.345 (l), 5 (units) 888.32 (g).. * The units of the product, eg 1.345 (l), 5 (units) 888.32 (g)..
*/ */
@Column(name = "quantity", nullable = false, precision = 24, scale = 4) @Column(name = "quantity", nullable = false, precision = 24, scale = 4)
private BigDecimal units; private BigDecimal quantity;
/** /**
* The time this AccountEvent is created. * The time this AccountEvent is created.
...@@ -114,12 +115,13 @@ public class AccountEvent implements EventChildInterface { ...@@ -114,12 +115,13 @@ public class AccountEvent implements EventChildInterface {
* When user has paid a bill a Account event for product "Credit" is created * When user has paid a bill a Account event for product "Credit" is created
* and reference to that bill is here.. * and reference to that bill is here..
*/ */
@JoinColumns({ @OneToOne(mappedBy = "accountEvent")
@JoinColumn(name = "bill_id", referencedColumnName = "id", nullable = false, updatable = false, insertable = false),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@OneToOne
private Bill bill; private Bill bill;
public BigDecimal getTotal() {
return getQuantity().multiply(getUnitPrice());
}
@Version @Version
@Column(nullable = false) @Column(nullable = false)
private int jpaVersionField = 0; private int jpaVersionField = 0;
...@@ -151,12 +153,16 @@ public class AccountEvent implements EventChildInterface { ...@@ -151,12 +153,16 @@ public class AccountEvent implements EventChildInterface {
this.id = new EventPk(event); this.id = new EventPk(event);
} }
public AccountEvent(LanEvent event, BigDecimal unitPrice,
BigDecimal quantity, Calendar eventTime) {
public AccountEvent(LanEvent event, User u, Product prod, BigDecimal unitPrice, BigDecimal quantity, Calendar eventTime) {
this.id = new EventPk(event); this.id = new EventPk(event);
this.setUnitPrice(unitPrice); this.setUnitPrice(unitPrice);
this.setQuantity(quantity); this.setQuantity(quantity);
this.product = prod;
this.eventTime = eventTime; this.eventTime = eventTime;
this.user = u;
} }
public Calendar getEventTime() { public Calendar getEventTime() {
...@@ -259,12 +265,12 @@ public class AccountEvent implements EventChildInterface { ...@@ -259,12 +265,12 @@ public class AccountEvent implements EventChildInterface {
return unitPrice; return unitPrice;
} }
public void setQuantity(BigDecimal units) { public void setQuantity(BigDecimal quantity) {
this.units = units; this.quantity = quantity;
} }
public BigDecimal getQuantity() { public BigDecimal getQuantity() {
return units; return quantity;
} }
} }
...@@ -19,6 +19,7 @@ import javax.persistence.NamedQueries; ...@@ -19,6 +19,7 @@ import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
...@@ -43,7 +44,10 @@ import static javax.persistence.TemporalType.DATE; ...@@ -43,7 +44,10 @@ import static javax.persistence.TemporalType.DATE;
@NamedQuery(name = "Bill.findbiggestBillNumber", query = "SELECT max(b.billNumber) from Bill b where b.event = :event") }) @NamedQuery(name = "Bill.findbiggestBillNumber", query = "SELECT max(b.billNumber) from Bill b where b.event = :event") })
public class Bill implements EventChildInterface { public class Bill implements EventChildInterface {
private static final long serialVersionUID = 1L; /**
*
*/
private static final long serialVersionUID = -6713643278149221869L;
@EmbeddedId @EmbeddedId
private EventPk id; private EventPk id;
...@@ -84,7 +88,7 @@ public class Bill implements EventChildInterface { ...@@ -84,7 +88,7 @@ public class Bill implements EventChildInterface {
@Column(nullable = false, name = "sent_time") @Column(nullable = false, name = "sent_time")
@Temporal(DATE) @Temporal(DATE)
private Calendar sentDate = Calendar.getInstance(); private Calendar sentDate = Calendar.getInstance();
@Column(name = "payment_time", nullable = false) @Column(name = "payment_time", nullable = false)
private Integer paymentTime = 0; private Integer paymentTime = 0;
@Column(name = "notice_days", nullable = false) @Column(name = "notice_days", nullable = false)
...@@ -108,8 +112,9 @@ public class Bill implements EventChildInterface { ...@@ -108,8 +112,9 @@ public class Bill implements EventChildInterface {
/** /**
* Bill may have multiple items on multiple rows. * Bill may have multiple items on multiple rows.
*/ */
@OneToMany(mappedBy = "bill") @OneToMany(mappedBy = "bill")
@OrderBy("id.id")
private List<BillLine> billLines; private List<BillLine> billLines;
/** /**
...@@ -133,7 +138,10 @@ public class Bill implements EventChildInterface { ...@@ -133,7 +138,10 @@ public class Bill implements EventChildInterface {
private LanEvent event; private LanEvent event;
public Integer getReferenceNumberBase() { public Integer getReferenceNumberBase() {
return event.getReferenceNumberBase() + billNumber; if (event != null && event.getReferenceNumberBase() != null && billNumber != null) {
return event.getReferenceNumberBase() + billNumber;
}
return null;
} }
/** /**
...@@ -200,9 +208,9 @@ public class Bill implements EventChildInterface { ...@@ -200,9 +208,9 @@ public class Bill implements EventChildInterface {
public Bill(LanEvent event, User user) { public Bill(LanEvent event, User user) {
this.id = new EventPk(event); this.id = new EventPk(event);
this.setUser(user); this.setUser(user);
this.setAddr1(user.getFirstnames() +" " + user.getLastname()); this.setAddr1(user.getFirstnames() + " " + user.getLastname());
this.setAddr2(user.getAddress()); this.setAddr2(user.getAddress());
this.setAddr3(user.getZip() +" "+ user.getTown()); this.setAddr3(user.getZip() + " " + user.getTown());
} }
public Calendar getDueDate() { public Calendar getDueDate() {
......
...@@ -15,6 +15,7 @@ import javax.persistence.Entity; ...@@ -15,6 +15,7 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns; import javax.persistence.JoinColumns;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
...@@ -44,7 +45,7 @@ public class Discount implements EventChildInterface { ...@@ -44,7 +45,7 @@ public class Discount implements EventChildInterface {
@Column(name = "shortdesc") @Column(name = "shortdesc")
private String shortdesc; private String shortdesc;
@Column(name = "amount_min", nullable = false, precision = 24, scale = 4) @Column(name = "amount_min", nullable = false, precision = 24, scale = 4)
private BigDecimal amountMin = BigDecimal.ZERO; private BigDecimal amountMin = BigDecimal.ZERO;
...@@ -60,14 +61,15 @@ public class Discount implements EventChildInterface { ...@@ -60,14 +61,15 @@ public class Discount implements EventChildInterface {
@Column(name = "per_user", nullable = false, precision = 24, scale = 4) @Column(name = "per_user", nullable = false, precision = 24, scale = 4)
private BigDecimal perUser = BigDecimal.ZERO; private BigDecimal perUser = BigDecimal.ZERO;
@Column(name = "total_count", nullable = false, precision = 24, scale = 4)
private BigDecimal totalCount = BigDecimal.ZERO;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "discount") @OneToMany(cascade = CascadeType.ALL, mappedBy = "discount")
private List<DiscountInstance> discountInstances; private List<DiscountInstance> discountInstances;
@JoinColumns({ @JoinColumns({
@JoinColumn(name = "role_id", referencedColumnName = "id"), @JoinColumn(name = "role_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
})
@ManyToOne() @ManyToOne()
private Role role; private Role role;
...@@ -76,8 +78,8 @@ public class Discount implements EventChildInterface { ...@@ -76,8 +78,8 @@ public class Discount implements EventChildInterface {
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false)
}) })
@ManyToOne(optional = false) @ManyToMany(mappedBy = "discounts")
private Product product; private List<Product> products;
@Version @Version
@Column(nullable = false) @Column(nullable = false)
...@@ -209,14 +211,7 @@ public class Discount implements EventChildInterface { ...@@ -209,14 +211,7 @@ public class Discount implements EventChildInterface {
return role; return role;
} }
public void setProduct(Product product) {
this.product = product;
}
public Product getProduct() {
return product;
}
public void setPercentage(BigDecimal percentage) { public void setPercentage(BigDecimal percentage) {
this.percentage = percentage; this.percentage = percentage;
} }
...@@ -233,4 +228,20 @@ public class Discount implements EventChildInterface { ...@@ -233,4 +228,20 @@ public class Discount implements EventChildInterface {
return shortdesc; return shortdesc;
} }
public void setTotalCount(BigDecimal totalCount) {
this.totalCount = totalCount;
}
public BigDecimal getTotalCount() {
return totalCount;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public List<Product> getProducts() {
return products;
}
} }
...@@ -24,7 +24,7 @@ import javax.persistence.Version; ...@@ -24,7 +24,7 @@ import javax.persistence.Version;
*/ */
@Entity @Entity
@Table(name = "discount_instances") @Table(name = "discount_instances")
@NamedQueries( { @NamedQuery(name = "DiscountInstance.findAll", query = "SELECT d FROM DiscountInstance d") }) @NamedQueries({ @NamedQuery(name = "DiscountInstance.findAll", query = "SELECT d FROM DiscountInstance d") })
public class DiscountInstance implements EventChildInterface { public class DiscountInstance implements EventChildInterface {
/** /**
...@@ -35,26 +35,18 @@ public class DiscountInstance implements EventChildInterface { ...@@ -35,26 +35,18 @@ public class DiscountInstance implements EventChildInterface {
@EmbeddedId @EmbeddedId
private EventPk id; private EventPk id;
@Column(name = "create_time", nullable = false) @JoinColumns({
@Temporal(TemporalType.TIMESTAMP)
private Calendar createTime = Calendar.getInstance();
@JoinColumns( {
@JoinColumn(name = "account_event_id", referencedColumnName = "id", nullable = false, updatable = false), @JoinColumn(name = "account_event_id", referencedColumnName = "id", nullable = false, updatable = false),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne @ManyToOne
private AccountEvent accountEvent; private AccountEvent accountEvent;
@JoinColumns( { @JoinColumns({
@JoinColumn(name = "discount_id", referencedColumnName = "id", nullable = false, updatable = false), @JoinColumn(name = "discount_id", referencedColumnName = "id", nullable = false, updatable = false),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne(optional = false) @ManyToOne(optional = false)
private Discount discount; private Discount discount;
@JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
@ManyToOne(optional = false)
private User user;
@Version @Version
@Column(nullable = false) @Column(nullable = false)
private int jpaVersionField = 0; private int jpaVersionField = 0;
...@@ -62,7 +54,9 @@ public class DiscountInstance implements EventChildInterface { ...@@ -62,7 +54,9 @@ public class DiscountInstance implements EventChildInterface {
public DiscountInstance() { public DiscountInstance() {
} }
public DiscountInstance(LanEvent event) { public DiscountInstance(LanEvent event, AccountEvent ac, Discount d) {
accountEvent = ac;
discount = d;
this.id = new EventPk(event); this.id = new EventPk(event);
} }
...@@ -82,14 +76,6 @@ public class DiscountInstance implements EventChildInterface { ...@@ -82,14 +76,6 @@ public class DiscountInstance implements EventChildInterface {
this.discount = discountsId; this.discount = discountsId;
} }
public User getUser() {
return user;
}
public void setUser(User usersId) {
this.user = usersId;
}
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 0; int hash = 0;
...@@ -152,11 +138,4 @@ public class DiscountInstance implements EventChildInterface { ...@@ -152,11 +138,4 @@ public class DiscountInstance implements EventChildInterface {
this.jpaVersionField = jpaVersionField; this.jpaVersionField = jpaVersionField;
} }
public void setCreateTime(Calendar createTime) {
this.createTime = createTime;
}
public Calendar getCreateTime() {
return createTime;
}
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
*/ */
package fi.insomnia.bortal.model; package fi.insomnia.bortal.model;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
...@@ -21,6 +22,7 @@ import javax.persistence.ManyToOne; ...@@ -21,6 +22,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Version; import javax.persistence.Version;
...@@ -45,10 +47,12 @@ public class EventMap implements EventChildInterface { ...@@ -45,10 +47,12 @@ public class EventMap implements EventChildInterface {
private EventPk id; private EventPk id;
@Lob @Lob
@Column(name = "map_data") @Column(name = "map_data")
private String mapData; private byte[] mapData;
@Column(name = "map_name") @Column(name = "map_name")
private String name; private String name;
@OrderBy("name")
@OneToMany(cascade = CascadeType.ALL, mappedBy = "map") @OneToMany(cascade = CascadeType.ALL, mappedBy = "map")
private List<Place> places = new ArrayList<Place>(); private List<Place> places = new ArrayList<Place>();
@ManyToOne(optional = false) @ManyToOne(optional = false)
...@@ -60,6 +64,9 @@ public class EventMap implements EventChildInterface { ...@@ -60,6 +64,9 @@ public class EventMap implements EventChildInterface {
@OneToMany(mappedBy = "eventMap") @OneToMany(mappedBy = "eventMap")
private List<Reader> readers; private List<Reader> readers;
@Column(nullable = false)
private boolean active = true;
public EventMap() { public EventMap() {
} }
...@@ -67,7 +74,6 @@ public class EventMap implements EventChildInterface { ...@@ -67,7 +74,6 @@ public class EventMap implements EventChildInterface {
this.id = new EventPk(event); this.id = new EventPk(event);
} }
public String getName() { public String getName() {
return name; return name;
} }
...@@ -160,44 +166,27 @@ public class EventMap implements EventChildInterface { ...@@ -160,44 +166,27 @@ public class EventMap implements EventChildInterface {
this.readers = readers; this.readers = readers;
} }
public BufferedImage getMapWithPlaces() throws IOException {
BufferedImage image = ImageIO.read(new ByteArrayInputStream(Base64.decodeBase64( getMapData())));
List<Place> myplaces = getPlaces();
logger.info("Getting places in Event map {}, found {}", this, myplaces.size());
for (Place place : myplaces) {
place.drawPlace(image);
}
return image;
}
public LanEvent getEvent() { public LanEvent getEvent() {
return event; return event;
} }
public Place findPlace(int x, int y) { public void setMapData(byte[] mapData) {
for (Place place : getPlaces()) { this.mapData = mapData;
if (place.getMapX() < x }
&& (place.getMapX() + place.getWidth()) > x
&& place.getMapY() < y
&& (place.getMapY() + place.getHeight()) > y) {
return place;
}
}
return null;
public byte[] getMapData() {
return mapData;
} }
public void setMapData(String mapData) { public void setActive(boolean active) {
this.mapData = mapData; this.active = active;
} }
public String getMapData() { public boolean isActive() {
return mapData; return active;
} }
} }
...@@ -18,6 +18,7 @@ import javax.persistence.ManyToOne; ...@@ -18,6 +18,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Version; import javax.persistence.Version;
...@@ -44,6 +45,7 @@ public class EventOrganiser implements ModelInterface { ...@@ -44,6 +45,7 @@ public class EventOrganiser implements ModelInterface {
@Column(name = "bundle_country") @Column(name = "bundle_country")
private String bundleCountry; private String bundleCountry;
@OrderBy
@OneToMany(cascade = CascadeType.ALL, mappedBy = "organiser") @OneToMany(cascade = CascadeType.ALL, mappedBy = "organiser")
private List<LanEvent> events; private List<LanEvent> events;
......
...@@ -31,13 +31,13 @@ public class EventPk implements Serializable { ...@@ -31,13 +31,13 @@ public class EventPk implements Serializable {
super(); super();
this.setEventId(eventId); this.setEventId(eventId);
} }
public EventPk(Integer eventId, Integer id)
{ public EventPk(Integer eventId, Integer id) {
super(); super();
this.setEventId(eventId); this.setEventId(eventId);
this.setId(id); this.setId(id);
} }
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
...@@ -47,10 +47,12 @@ public class EventPk implements Serializable { ...@@ -47,10 +47,12 @@ public class EventPk implements Serializable {
} }
public int hashCode() { public int hashCode() {
return (id == null)?0:id.hashCode() + ((getEventId() == null)? 0:getEventId().hashCode()); return (id == null) ? 0 : id.hashCode() + ((getEventId() == null) ? 0 : getEventId().hashCode());
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) if (obj == null)
return false; return false;
if (obj == this) if (obj == this)
......
...@@ -21,13 +21,15 @@ import javax.persistence.TemporalType; ...@@ -21,13 +21,15 @@ import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import javax.persistence.Version; import javax.persistence.Version;
import fi.insomnia.bortal.utilities.PasswordFunctions;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "group_memberships", uniqueConstraints = { @UniqueConstraint(columnNames = { @Table(name = "group_memberships", uniqueConstraints = { @UniqueConstraint(columnNames = {
"user_id", "group_id" }) }) "user_id", "group_id" }) })
@NamedQueries( { @NamedQueries({
@NamedQuery(name = "GroupMembership.findAll", query = "SELECT g FROM GroupMembership g"), @NamedQuery(name = "GroupMembership.findAll", query = "SELECT g FROM GroupMembership g"),
@NamedQuery(name = "GroupMembership.findByInviteAccepted", query = "SELECT g FROM GroupMembership g WHERE g.inviteAccepted = :inviteAccepted"), @NamedQuery(name = "GroupMembership.findByInviteAccepted", query = "SELECT g FROM GroupMembership g WHERE g.inviteAccepted = :inviteAccepted"),
...@@ -39,6 +41,9 @@ public class GroupMembership implements EventChildInterface { ...@@ -39,6 +41,9 @@ public class GroupMembership implements EventChildInterface {
@EmbeddedId @EmbeddedId
private EventPk id; private EventPk id;
@Column(name = "invite_token", unique = true, nullable = false)
private String inviteToken;
@Column(name = "invite_accepted") @Column(name = "invite_accepted")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar inviteAccepted; private Calendar inviteAccepted;
...@@ -49,13 +54,13 @@ public class GroupMembership implements EventChildInterface { ...@@ -49,13 +54,13 @@ public class GroupMembership implements EventChildInterface {
@Column(name = "invite_name") @Column(name = "invite_name")
private String inviteName; private String inviteName;
@JoinColumns( { @JoinColumns({
@JoinColumn(name = "group_id", referencedColumnName = "id", nullable = false), @JoinColumn(name = "group_id", referencedColumnName = "id", nullable = false),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne(optional = false) @ManyToOne(optional = false)
private PlaceGroup placeGroup; private PlaceGroup placeGroup;
@JoinColumns( { @JoinColumns({
@JoinColumn(name = "place_reservation_id", referencedColumnName = "id", nullable = false), @JoinColumn(name = "place_reservation_id", referencedColumnName = "id", nullable = false),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@OneToOne(optional = false) @OneToOne(optional = false)
...@@ -76,8 +81,11 @@ public class GroupMembership implements EventChildInterface { ...@@ -76,8 +81,11 @@ public class GroupMembership implements EventChildInterface {
public GroupMembership() { public GroupMembership() {
} }
public GroupMembership(LanEvent event) { public GroupMembership(LanEvent event, PlaceGroup pg, Place p, String token) {
this.id = new EventPk(event); this.id = new EventPk(event);
this.setPlaceGroup(pg);
this.setPlaceReservation(p);
this.inviteToken = token;
} }
public Calendar getInviteAccepted() { public Calendar getInviteAccepted() {
...@@ -203,4 +211,12 @@ public class GroupMembership implements EventChildInterface { ...@@ -203,4 +211,12 @@ public class GroupMembership implements EventChildInterface {
public void setEnteredEvent(Calendar enteredEvent) { public void setEnteredEvent(Calendar enteredEvent) {
this.enteredEvent = enteredEvent; this.enteredEvent = enteredEvent;
} }
public void setInviteToken(String inviteToken) {
this.inviteToken = inviteToken;
}
public String getInviteToken() {
return inviteToken;
}
} }
...@@ -4,13 +4,10 @@ ...@@ -4,13 +4,10 @@
*/ */
package fi.insomnia.bortal.model; package fi.insomnia.bortal.model;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.Serializable; import java.io.Serializable;
import java.util.Calendar; import java.util.Calendar;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.EmbeddedId; import javax.persistence.EmbeddedId;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -26,23 +23,23 @@ import javax.persistence.Temporal; ...@@ -26,23 +23,23 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Version; import javax.persistence.Version;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "places") @Table(name = "places")
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "Place.findAll", query = "SELECT p FROM Place p"), @NamedQuery(name = "Place.findAll", query = "SELECT p FROM Place p"),
@NamedQuery(name = "Place.findByDescription", query = "SELECT p FROM Place p WHERE p.description = :description"), @NamedQuery(name = "Place.findByDescription", query = "SELECT p FROM Place p WHERE p.description = :description"),
@NamedQuery(name = "Place.findByName", query = "SELECT p FROM Place p WHERE p.name = :name"), @NamedQuery(name = "Place.findByName", query = "SELECT p FROM Place p WHERE p.name = :name"),
@NamedQuery(name = "Place.findByMapX", query = "SELECT p FROM Place p WHERE p.mapX = :mapX"), @NamedQuery(name = "Place.findByMapX", query = "SELECT p FROM Place p WHERE p.mapX = :mapX"),
@NamedQuery(name = "Place.findByMapY", query = "SELECT p FROM Place p WHERE p.mapY = :mapY"), @NamedQuery(name = "Place.findByMapY", query = "SELECT p FROM Place p WHERE p.mapY = :mapY"),
@NamedQuery(name = "Place.findByDetails", query = "SELECT p FROM Place p WHERE p.details = :details"), @NamedQuery(name = "Place.findByDetails", query = "SELECT p FROM Place p WHERE p.details = :details"),
@NamedQuery(name = "Place.findByCode", query = "SELECT p FROM Place p WHERE p.code = :code")}) @NamedQuery(name = "Place.findByCode", query = "SELECT p FROM Place p WHERE p.code = :code") })
public class Place implements EventChildInterface, Serializable { public class Place implements EventChildInterface, Serializable {
public static final int RESERVE_MINUTES = 20;
/** /**
* *
*/ */
...@@ -59,12 +56,12 @@ public class Place implements EventChildInterface, Serializable { ...@@ -59,12 +56,12 @@ public class Place implements EventChildInterface, Serializable {
@Column(name = "map_y") @Column(name = "map_y")
private int mapY = 0; private int mapY = 0;
@Column(name = "width") @Column(name = "width")
private int width = 0; private int width = 0;
@Column(name = "height") @Column(name = "height")
private int height = 0; private int height = 0;
@Column(name = "release_time") @Column(name = "release_time")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar releaseTime = Calendar.getInstance(); private Calendar releaseTime;
@Column(name = "place_details") @Column(name = "place_details")
@Lob @Lob
private String details = ""; private String details = "";
...@@ -76,21 +73,22 @@ public class Place implements EventChildInterface, Serializable { ...@@ -76,21 +73,22 @@ public class Place implements EventChildInterface, Serializable {
* Which group has bought the place * Which group has bought the place
*/ */
@JoinColumns({ @JoinColumns({
@JoinColumn(name = "group_id", referencedColumnName = "id", updatable = true, insertable = true), @JoinColumn(name = "group_id", referencedColumnName = "id", updatable = true, insertable = true),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false)}) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne @ManyToOne
private PlaceGroup group; private PlaceGroup group;
@JoinColumns({ @JoinColumns({
@JoinColumn(name = "map_id", referencedColumnName = "id", nullable = false, updatable = true, insertable = true), @JoinColumn(name = "map_id", referencedColumnName = "id", nullable = false, updatable = true, insertable = true),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false)}) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne(optional = false) @ManyToOne(optional = false, cascade = CascadeType.ALL)
private EventMap map; private EventMap map;
/** /**
* Which ticket type is this place sold as * Which ticket type is this place sold as
*/ */
@JoinColumns({ @JoinColumns({
@JoinColumn(name = "products_id", referencedColumnName = "id"), @JoinColumn(name = "products_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false)}) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne() @ManyToOne()
private Product product; private Product product;
/** /**
...@@ -110,7 +108,7 @@ public class Place implements EventChildInterface, Serializable { ...@@ -110,7 +108,7 @@ public class Place implements EventChildInterface, Serializable {
public Place(EventMap eventMap) { public Place(EventMap eventMap) {
this.id = new EventPk(); this.id = new EventPk();
this.id.setEventId(eventMap.getId().getEventId()); this.id.setEventId(eventMap.getId().getEventId());
this.map = eventMap;
} }
public String getDescription() { public String getDescription() {
...@@ -309,64 +307,142 @@ public class Place implements EventChildInterface, Serializable { ...@@ -309,64 +307,142 @@ public class Place implements EventChildInterface, Serializable {
return false; return false;
} }
private static final Color NORMAL_COLOR = Color.BLUE;
private static final Color RESERVED_COLOR = Color.RED;
private static final Color SELECTED_COLOR = Color.GREEN;
private static final Color OWNED_COLOR = Color.GREEN;
public void drawPlace(BufferedImage targetImage) { public boolean isTaken() {
Graphics2D g = targetImage.createGraphics();
if (isReserved()) { return (releaseTime != null || getGroup() != null);
g.setColor(RESERVED_COLOR);
g.fill(new Rectangle(mapX, mapY, width, height));
} else {
g.setColor(NORMAL_COLOR);
g.draw(new Rectangle(mapX, mapY, width, height));
}
} }
public void drawSelectedPlace(BufferedImage targetImage) { /**
Graphics2D g = targetImage.createGraphics(); *
g.setColor(SELECTED_COLOR); * @return Is the place reserved ( not bought for user)
*/
g.fill(new Rectangle(mapX, mapY, width, height)); public boolean isReservedFor(User u) {
} return (u.equals(getCurrentUser()) && getGroup() == null);
public void drawOwnedPlace(BufferedImage targetImage) {
Graphics2D g = targetImage.createGraphics();
g.setColor(OWNED_COLOR);
g.fill(new Rectangle(mapX, mapY, width, height));
} }
public boolean isReserved() { /**
* Reserve the place for user. This reservation will timeout after a while
* buy() method should be called after this when buying place;
*
* Remember to merge afterwards!
*
* @param user
* @return true when successfull. On any error false.
*/
public boolean reserve(User user) {
if (getCurrentUser() != null || getGroup() != null) {
return false;
}
setCurrentUser(user);
releaseTime = Calendar.getInstance();
releaseTime.add(Calendar.MINUTE, RESERVE_MINUTES);
return true;
}
if (releaseTime != null) { /**
if (System.currentTimeMillis() > releaseTime.getTimeInMillis()) { * Release reservation from user
setReserved(false); *
} else { * Remember to merge afterwards!
return true; *
} * @param user
* @return true when successfull, on any erroro false.
*/
public boolean release(User user) {
if (getGroup() != null || getCurrentUser() == null || !getCurrentUser().equals(user)) {
return false;
} }
setCurrentUser(null);
releaseTime = null;
if(group != null) { return true;
return true; }
/**
* Reserve this place for the group permanently. reserve method has to be
* called before this method!!
*
* Remember to merge afterwards!
*
* @param group
* @return true when successfull. On any error false.
*/
public boolean buy(PlaceGroup group) {
if (getCurrentUser() == null || getGroup() != null || !group.getCreator().equals(getCurrentUser())) {
return false;
} }
releaseTime = null;
setGroup(group);
// Current user temporarily used at place reservation. When buying
// release field for its original use.
setCurrentUser(null);
return true;
return false;
} }
public static final long RESERVE_TIME = 1000*60*20; // 20min. /**
public void setReserved(boolean reserved) { * Check if the places releasetime has expired and it should be released for
if(reserved) { * shopping
releaseTime = Calendar.getInstance(); *
releaseTime.setTimeInMillis(System.currentTimeMillis()+RESERVE_TIME); * @return If the status of thie entity changed and it should be merged.
} else { */
public boolean checkReleased() {
boolean ret = false;
if (getGroup() == null && Calendar.getInstance().after(releaseTime)) {
setCurrentUser(null);
releaseTime = null; releaseTime = null;
ret = true;
} }
} return ret;
}
// public void drawSelectedPlace(BufferedImage targetImage) {
// Graphics2D g = targetImage.createGraphics();
// g.setColor(SELECTED_COLOR);
//
// g.fill(new Rectangle(mapX, mapY, width, height));
// }
//
// public void drawOwnedPlace(BufferedImage targetImage) {
// Graphics2D g = targetImage.createGraphics();
// g.setColor(OWNED_COLOR);
//
// g.fill(new Rectangle(mapX, mapY, width, height));
// }
// public boolean isReserved() {
//
// if (releaseTime != null) {
// if (getGroup() == null && System.currentTimeMillis() >
// releaseTime.getTimeInMillis()) {
// setReserved(null);
// } else {
// return true;
// }
// }
//
// if (group != null) {
// return true;
// }
//
// return false;
// }
// public void setReserved(User user) {
//
// if (user != null) {
// setShouldMerge(true);
// setCurrentUser(user);
// releaseTime = Calendar.getInstance();
// releaseTime.setTimeInMillis(System.currentTimeMillis() + RESERVE_TIME);
// } else {
// releaseTime = null;
// if (getGroup() == null) {
// setCurrentUser(null);
// setShouldMerge(true);
// }
// }
// }
} }
...@@ -27,7 +27,7 @@ import javax.persistence.Version; ...@@ -27,7 +27,7 @@ import javax.persistence.Version;
*/ */
@Entity @Entity
@Table(name = "products") @Table(name = "products")
@NamedQueries( { @NamedQueries({
@NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"), @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
@NamedQuery(name = "Product.findByProductName", query = "SELECT p FROM Product p WHERE p.name = :name"), @NamedQuery(name = "Product.findByProductName", query = "SELECT p FROM Product p WHERE p.name = :name"),
@NamedQuery(name = "Product.findByPrice", query = "SELECT p FROM Product p WHERE p.price = :price"), @NamedQuery(name = "Product.findByPrice", query = "SELECT p FROM Product p WHERE p.price = :price"),
...@@ -43,7 +43,7 @@ public class Product implements EventChildInterface { ...@@ -43,7 +43,7 @@ public class Product implements EventChildInterface {
@Column(name = "product_name") @Column(name = "product_name")
private String name; private String name;
@Column(name = "price", nullable = false,precision = 24, scale = 4) @Column(name = "price", nullable = false, precision = 24, scale = 4)
private BigDecimal price; private BigDecimal price;
@Column(name = "sort", nullable = false) @Column(name = "sort", nullable = false)
...@@ -61,18 +61,24 @@ public class Product implements EventChildInterface { ...@@ -61,18 +61,24 @@ public class Product implements EventChildInterface {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product") @OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
private List<AccountEvent> accountEvents; private List<AccountEvent> accountEvents;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product") @ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "product_discounts", inverseJoinColumns = {
@JoinColumn(name = "discount_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") },
joinColumns = { @JoinColumn(name = "product_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id")
})
private List<Discount> discounts; private List<Discount> discounts;
private BigDecimal vat = BigDecimal.ZERO; private BigDecimal vat = BigDecimal.ZERO;
private String unitName = ""; private String unitName = "";
@ManyToMany() @ManyToMany()
@JoinTable(name = "product_foodwavetemplate", joinColumns = { @JoinTable(name = "product_foodwavetemplate", joinColumns = {
@JoinColumn(name = "product_id", referencedColumnName = "id"), @JoinColumn(name = "product_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") }, inverseJoinColumns = { @JoinColumn(name = "event_id", referencedColumnName = "event_id") }, inverseJoinColumns = {
@JoinColumn(name = "food_wave_template_id", referencedColumnName = "id"), @JoinColumn(name = "food_wave_template_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") }, @JoinColumn(name = "event_id", referencedColumnName = "event_id") },
uniqueConstraints = { @UniqueConstraint(columnNames = { "product_id", "food_wave_template_id", "event_id" }) }) uniqueConstraints = { @UniqueConstraint(columnNames = { "product_id", "food_wave_template_id", "event_id" }) })
private List<FoodWaveTemplate> foodWaveTemplates; private List<FoodWaveTemplate> foodWaveTemplates;
...@@ -80,6 +86,7 @@ public class Product implements EventChildInterface { ...@@ -80,6 +86,7 @@ public class Product implements EventChildInterface {
@Column(nullable = false) @Column(nullable = false)
private int jpaVersionField = 0; private int jpaVersionField = 0;
public Product() { public Product() {
} }
...@@ -91,7 +98,7 @@ public class Product implements EventChildInterface { ...@@ -91,7 +98,7 @@ public class Product implements EventChildInterface {
this(event); this(event);
this.price = price; this.price = price;
this.name = name; this.name = name;
} }
public String getName() { public String getName() {
...@@ -227,7 +234,8 @@ public class Product implements EventChildInterface { ...@@ -227,7 +234,8 @@ public class Product implements EventChildInterface {
} }
/** /**
* @param prepaid the prepaid to set * @param prepaid
* the prepaid to set
*/ */
public void setPrepaid(boolean prepaid) { public void setPrepaid(boolean prepaid) {
this.prepaid = prepaid; this.prepaid = prepaid;
...@@ -248,5 +256,6 @@ public class Product implements EventChildInterface { ...@@ -248,5 +256,6 @@ public class Product implements EventChildInterface {
public String getUnitName() { public String getUnitName() {
return unitName; return unitName;
} }
} }
...@@ -22,7 +22,6 @@ import javax.persistence.OneToMany; ...@@ -22,7 +22,6 @@ import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import javax.persistence.Version; import javax.persistence.Version;
/** /**
* *
*/ */
......
...@@ -37,7 +37,9 @@ import fi.insomnia.bortal.enums.Permission; ...@@ -37,7 +37,9 @@ import fi.insomnia.bortal.enums.Permission;
@ConversionValue(dataValue = "USER_MANAGEMENT", objectValue = "USER_MANAGEMENT"), @ConversionValue(dataValue = "USER_MANAGEMENT", objectValue = "USER_MANAGEMENT"),
@ConversionValue(dataValue = "TICKET_SALES", objectValue = "TICKET_SALES"), @ConversionValue(dataValue = "TICKET_SALES", objectValue = "TICKET_SALES"),
@ConversionValue(dataValue = "ROLE_MANAGEMENT", objectValue = "ROLE_MANAGEMENT"), @ConversionValue(dataValue = "ROLE_MANAGEMENT", objectValue = "ROLE_MANAGEMENT"),
@ConversionValue(dataValue = "PRODUCT", objectValue = "PRODUCT") @ConversionValue(dataValue = "PRODUCT", objectValue = "PRODUCT"),
@ConversionValue(dataValue = "SHOP", objectValue = "SHOP")
}) })
public class RoleRight implements EventChildInterface { public class RoleRight implements EventChildInterface {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
*/ */
package fi.insomnia.bortal.model; package fi.insomnia.bortal.model;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
...@@ -22,11 +24,14 @@ import javax.persistence.NamedQueries; ...@@ -22,11 +24,14 @@ import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.Version; import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.persistence.annotations.ConversionValue; import org.eclipse.persistence.annotations.ConversionValue;
import org.eclipse.persistence.annotations.Convert; import org.eclipse.persistence.annotations.Convert;
...@@ -47,22 +52,8 @@ import fi.insomnia.bortal.utilities.PasswordFunctions; ...@@ -47,22 +52,8 @@ import fi.insomnia.bortal.utilities.PasswordFunctions;
@ConversionValue(objectValue = "FEMALE", dataValue = "F"), @ConversionValue(objectValue = "FEMALE", dataValue = "F"),
@ConversionValue(objectValue = "UNDEFINED", dataValue = "U"), @ConversionValue(objectValue = "UNDEFINED", dataValue = "U"),
}) })
@NamedQueries( { @NamedQueries({
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"), @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u order by u.created"),
@NamedQuery(name = "User.findById", query = "SELECT u FROM User u WHERE u.id = :id"),
@NamedQuery(name = "User.findByCreated", query = "SELECT u FROM User u WHERE u.created = :created"),
@NamedQuery(name = "User.findByActive", query = "SELECT u FROM User u WHERE u.active = :active"),
@NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password"),
@NamedQuery(name = "User.findByLastname", query = "SELECT u FROM User u WHERE u.lastname = :lastname"),
@NamedQuery(name = "User.findByFirstnames", query = "SELECT u FROM User u WHERE u.firstnames = :firstnames"),
@NamedQuery(name = "User.findByBirthday", query = "SELECT u FROM User u WHERE u.birthday = :birthday"),
@NamedQuery(name = "User.findByNick", query = "SELECT u FROM User u WHERE u.nick = :nick"),
@NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email"),
@NamedQuery(name = "User.findByAddress", query = "SELECT u FROM User u WHERE u.address = :address"),
@NamedQuery(name = "User.findByZip", query = "SELECT u FROM User u WHERE u.zip = :zip"),
@NamedQuery(name = "User.findByTown", query = "SELECT u FROM User u WHERE u.town = :town"),
@NamedQuery(name = "User.findByPhone", query = "SELECT u FROM User u WHERE u.phone = :phone"),
@NamedQuery(name = "User.findByGender", query = "SELECT u FROM User u WHERE u.gender = :gender"),
@NamedQuery(name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login = :login") }) @NamedQuery(name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login = :login") })
public class User implements ModelInterface { public class User implements ModelInterface {
...@@ -73,7 +64,8 @@ public class User implements ModelInterface { ...@@ -73,7 +64,8 @@ public class User implements ModelInterface {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id; private Integer id;
@Column(name = "created", nullable = false) //, columnDefinition = "timestamptz default now()") @Column(name = "created", nullable = false)
// , columnDefinition = "timestamptz default now()")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar created = Calendar.getInstance(); private Calendar created = Calendar.getInstance();
...@@ -84,39 +76,41 @@ public class User implements ModelInterface { ...@@ -84,39 +76,41 @@ public class User implements ModelInterface {
private String password; private String password;
@Column(name = "lastname") @Column(name = "lastname")
private String lastname =""; private String lastname = "";
@Column(name = "firstnames") @Column(name = "firstnames")
private String firstnames =""; private String firstnames = "";
@Column(name = "birthday") @Column(name = "birthday")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar birthday; private Calendar birthday;
@NotNull
@Size(min = 3)
@Column(name = "nick") @Column(name = "nick")
private String nick =""; private String nick = "";
@Column(name = "email") @Column(name = "email")
private String email = ""; private String email = "";
@Column(name = "address") @Column(name = "address")
private String address =""; private String address = "";
@Column(name = "zip") @Column(name = "zip")
private String zip =""; private String zip = "";
@Column(name = "postal_town") @Column(name = "postal_town")
private String postalTown =""; private String postalTown = "";
@Column(name = "town") @Column(name = "town")
private String town =""; private String town = "";
@Column(name = "phone") @Column(name = "phone")
private String phone =""; private String phone = "";
@OneToOne() @OneToOne()
private UserImage currentImage; private UserImage currentImage;
@Convert("gender") @Convert("gender")
@Column(name = "gender", nullable = false) @Column(name = "gender", nullable = false)
private Gender gender = Gender.UNDEFINED; private Gender gender = Gender.UNDEFINED;
...@@ -130,7 +124,7 @@ public class User implements ModelInterface { ...@@ -130,7 +124,7 @@ public class User implements ModelInterface {
@Column(name = "confirm_time") @Column(name = "confirm_time")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar confirmTime; private Calendar confirmTime;
@Column(name = "superadmin") @Column(name = "superadmin")
private boolean superadmin = false; private boolean superadmin = false;
...@@ -138,27 +132,28 @@ public class User implements ModelInterface { ...@@ -138,27 +132,28 @@ public class User implements ModelInterface {
private List<Vote> votes; private List<Vote> votes;
@ManyToMany(cascade = CascadeType.ALL) @ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "role_memberships", inverseJoinColumns = { @JoinTable(name = "role_memberships", inverseJoinColumns = {
@JoinColumn(name = "role_id", referencedColumnName = "id"), @JoinColumn(name = "role_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id") }, @JoinColumn(name = "event_id", referencedColumnName = "event_id") },
joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "user_id") }) joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "user_id") })
private List<Role> roles = new ArrayList<Role>(); private List<Role> roles = new ArrayList<Role>();
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
private List<LogEntry> logEntryList; private List<LogEntry> logEntryList;
@OneToMany(mappedBy = "user",fetch=FetchType.LAZY) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
@OrderBy
private List<UserImage> userImageList; private List<UserImage> userImageList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user") @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<CompoEntryParticipant> compoEntryParticipants; private List<CompoEntryParticipant> compoEntryParticipants;
@OneToMany(mappedBy = "creator") @OneToMany(mappedBy = "creator")
@OrderBy("id")
private List<CompoEntry> compoEntries; private List<CompoEntry> compoEntries;
@OneToMany(mappedBy = "creator") @OneToMany(mappedBy = "creator")
private List<PlaceGroup> placeGroups; private List<PlaceGroup> placeGroups = new ArrayList<PlaceGroup>();
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
private List<GroupMembership> groupMemberships; private List<GroupMembership> groupMemberships;
...@@ -166,22 +161,23 @@ public class User implements ModelInterface { ...@@ -166,22 +161,23 @@ public class User implements ModelInterface {
/** /**
* The places this user has registered into. * The places this user has registered into.
*/ */
@OneToMany(mappedBy = "currentUser", fetch=FetchType.LAZY) @OneToMany(mappedBy = "currentUser", fetch = FetchType.LAZY)
@OrderBy("id")
private List<Place> currentPlaces; private List<Place> currentPlaces;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user") @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<PrintedCard> printedCards; private List<PrintedCard> printedCards;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user") @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
@OrderBy("id.id")
private List<AccountEvent> accountEvents; private List<AccountEvent> accountEvents;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user") @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<DiscountInstance> discountInstances; @OrderBy("id.id")
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<Bill> bills; private List<Bill> bills;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "seller") @OneToMany(cascade = CascadeType.ALL, mappedBy = "seller")
@OrderBy("id.id")
private List<AccountEvent> soldItems; private List<AccountEvent> soldItems;
@Version @Version
...@@ -194,6 +190,14 @@ public class User implements ModelInterface { ...@@ -194,6 +190,14 @@ public class User implements ModelInterface {
@Transient @Transient
private static final Logger logger = LoggerFactory.getLogger(User.class); private static final Logger logger = LoggerFactory.getLogger(User.class);
public BigDecimal getAccountBalance() {
BigDecimal ret = BigDecimal.ZERO;
for (AccountEvent ac : getAccountEvents()) {
ret = ret.add(ac.getTotal()).setScale(2, RoundingMode.HALF_UP);
}
return ret;
}
public User() { public User() {
} }
...@@ -321,7 +325,12 @@ public class User implements ModelInterface { ...@@ -321,7 +325,12 @@ public class User implements ModelInterface {
} }
public void setLogin(String login) { public void setLogin(String login) {
this.login = login; if (login != null) {
this.login = login.trim();
} else {
login = null;
}
} }
public List<Vote> getVoteList() { public List<Vote> getVoteList() {
...@@ -405,14 +414,6 @@ public class User implements ModelInterface { ...@@ -405,14 +414,6 @@ public class User implements ModelInterface {
this.accountEvents = accountEventList; this.accountEvents = accountEventList;
} }
public List<DiscountInstance> getDiscountInstances() {
return discountInstances;
}
public void setDiscountInstances(List<DiscountInstance> discountInstanceList) {
this.discountInstances = discountInstanceList;
}
public List<Bill> getBills() { public List<Bill> getBills() {
return bills; return bills;
} }
...@@ -528,8 +529,6 @@ public class User implements ModelInterface { ...@@ -528,8 +529,6 @@ public class User implements ModelInterface {
this.confirmTime = confirmTime; this.confirmTime = confirmTime;
} }
public void resetPassword(String password) { public void resetPassword(String password) {
String newEncryptedPassword = PasswordFunctions.getEncryptedPassword(password); String newEncryptedPassword = PasswordFunctions.getEncryptedPassword(password);
this.password = newEncryptedPassword; // Bypass setter this.password = newEncryptedPassword; // Bypass setter
......
package fi.insomnia.bortal.model.exceptions;
public class AlreadyReservedException extends Exception {
/**
*
*/
private static final long serialVersionUID = -1665703508349810298L;
}
...@@ -9,9 +9,6 @@ import org.slf4j.LoggerFactory; ...@@ -9,9 +9,6 @@ import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.utilities.apachecodec.binary.Base64; import fi.insomnia.bortal.utilities.apachecodec.binary.Base64;
public class PasswordFunctions { public class PasswordFunctions {
private static final Logger logger = LoggerFactory private static final Logger logger = LoggerFactory
...@@ -43,15 +40,14 @@ public class PasswordFunctions { ...@@ -43,15 +40,14 @@ public class PasswordFunctions {
public static boolean checkPlainPassword(String plainPassword, public static boolean checkPlainPassword(String plainPassword,
String saltedPassword) { String saltedPassword) {
String oldBase64 = saltedPassword.substring("{SSHA}".length()); String oldBase64 = saltedPassword.substring("{SSHA}".length());
String decodedHashedAndSalt; String decodedHashedAndSalt;
decodedHashedAndSalt = new String(Base64.decodeBase64(oldBase64.getBytes())); decodedHashedAndSalt = new String(Base64.decodeBase64(oldBase64.getBytes()));
logger.debug("Decoded Str {} to {}", oldBase64, decodedHashedAndSalt ); logger.debug("Decoded Str {} to {}", oldBase64, decodedHashedAndSalt);
logger.debug("HashAndSalt: {}", decodedHashedAndSalt); logger.debug("HashAndSalt: {}", decodedHashedAndSalt);
String salt = decodedHashedAndSalt.substring(decodedHashedAndSalt.length() String salt = decodedHashedAndSalt.substring(decodedHashedAndSalt.length()
- getSaltLenght(), decodedHashedAndSalt.length()); - SALT_LENGTH, decodedHashedAndSalt.length());
String newBase64 = shaWithSaltToBase64(plainPassword, salt); String newBase64 = shaWithSaltToBase64(plainPassword, salt);
...@@ -59,22 +55,22 @@ public class PasswordFunctions { ...@@ -59,22 +55,22 @@ public class PasswordFunctions {
return theSame; return theSame;
} }
private static int getSaltLenght() { private static final int SALT_LENGTH = 4;
return 4;
} private static final String ALLOWED_RANDOM_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static String generateSalt() { private static String generateSalt() {
return generateRandomString(SALT_LENGTH);
}
public static String generateRandomString(int length) {
Random random = new Random(); Random random = new Random();
String lettahs = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < getSaltLenght(); i++) { for (int i = 0; i < length; i++) {
int index = random.nextInt(lettahs.length()); int index = random.nextInt(ALLOWED_RANDOM_CHARS.length());
sb.append(lettahs.charAt(index)); sb.append(ALLOWED_RANDOM_CHARS.charAt(index));
} }
return sb.toString(); return sb.toString();
} }
} }
<!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:bills="http://java.sun.com/jsf/composite/tools/bills"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.bill.billSummary" />
<ui:define name="content">
<h:dataTable border="0" id="billSummary" value="#{billView.billLineSummary}" var="sumline">
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['product.name']}" />
</f:facet>
<h:outputText value="#{sumline.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['product.boughtTotal']}" />
</f:facet>
<h:outputText value="#{sumline.total}" >
<f:convertNumber />
</h:outputText>
</h:column>
</h:dataTable>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!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:users="http://java.sun.com/jsf/composite/tools/user"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.bill.edit" />
<ui:define name="content">
<h:form id="billform">
<h:inputHidden value="#{billManageView.bill.id}" />
<h:panelGrid columns="2">
<h:outputLabel for="paidTime" value="#{i18n['bill.paidDate']}:" />
<h:inputText id="paidDate" value="#{billManageView.bill.paidDate.time}">
<f:convertDateTime />
</h:inputText>
<h:outputLabel value="#{i18n['bill.billNumber']}:" />
<h:inputText value="#{billManageView.bill.billNumber}" />
<h:outputLabel value="#{i18n['bill.addr1']}:" />
<h:inputText value="#{billManageView.bill.addr1}" />
<h:outputLabel value="#{i18n['bill.addr2']}:" />
<h:inputText value="#{billManageView.bill.addr2}" />
<h:outputLabel value="#{i18n['bill.addr3']}:" />
<h:inputText value="#{billManageView.bill.addr3}" />
<h:outputLabel value="#{i18n['bill.addr4']}:" />
<h:inputText value="#{billManageView.bill.addr4}" />
<h:outputLabel value="#{i18n['bill.addr5']}:" />
<h:inputText value="#{billManageView.bill.addr5}" />
<h:outputLabel for="sentDate" value="#{i18n['bill.sentDate']}:" />
<h:inputText id="sentDate" value="#{billManageView.bill.sentDate.time}">
<f:convertDateTime />
</h:inputText>
<h:outputLabel for="paymenttime" value="#{i18n['bill.paymentTime']}:" />
<h:inputText id ="paymenttime" value="#{billManageView.bill.paymentTime}" />
<h:outputLabel value="#{i18n['bill.noticetime']}:" />
<h:inputText value="#{billManageView.bill.noticetime}" />
<h:outputLabel value="#{i18n['bill.theirReference']}:" />
<h:inputText value="#{billManageView.bill.theirReference}" />
<h:outputLabel value="#{i18n['bill.ourReference']}:" />
<h:inputText value="#{billManageView.bill.ourReference}" />
<h:outputLabel value="#{i18n['bill.deliveryTerms']}:" />
<h:inputText value="#{billManageView.bill.deliveryTerms}" />
<h:outputLabel value="#{i18n['bill.notes']}:" />
<h:inputText value="#{billManageView.bill.notes}" />
<h:commandButton id="commitbtn" action="#{billManageView.save()}"
value="#{i18n['bill.save']}" />
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!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:bills="http://java.sun.com/jsf/composite/tools/bills"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.bill.listAll" />
<ui:define name="content">
<bills:list billview="#{billManageView}"/>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
<ui:param name="thispage" value="page.eventorg.edit" /> <ui:param name="thispage" value="page.eventorg.edit" />
<ui:define name="content"> <ui:define name="content">
<h:form id="orgform"> <h:form id="orgform">
<h:panelGrid columns="2"> <h:inputHidden value="#{eventView.eventmap.id}" />
<h:outputLabel value="#{i18n['eventmap.name']}:" /><h:inputText value="#{eventView.eventmap.name}" /> <h:panelGrid columns="2">
<h:commandButton id="commitbtn" action="#{eventView.saveMap()}" value="#{i18n['eventmap.save']}" /> <h:outputLabel value="#{i18n['eventmap.name']}:" /><h:inputText value="#{eventView.eventmap.name}" />
</h:panelGrid> <h:commandButton id="commitbtn" action="#{eventView.saveMap()}" value="#{i18n['eventmap.save']}" />
</h:panelGrid>
</h:form> </h:form>
<h2>#{i18n['eventmap.places']}</h2> <h2>#{i18n['eventmap.places']}</h2>
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<ui:param name="thispage" value="page.eventorg.edit" /> <ui:param name="thispage" value="page.eventorg.edit" />
<ui:define name="content"> <ui:define name="content">
<h:form id="orgform"> <h:form id="orgform">
<h:inputHidden id="#{eventView.eventmap.id}" />
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['eventmap.name']}:" /><h:inputText value="#{eventView.eventmap.name}" /> <h:outputLabel value="#{i18n['eventmap.name']}:" /><h:inputText value="#{eventView.eventmap.name}" />
<h:commandButton id="commitbtn" action="#{eventView.saveMap()}" value="#{i18n['eventmap.save']}" /> <h:commandButton id="commitbtn" action="#{eventView.saveMap()}" value="#{i18n['eventmap.save']}" />
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<ui:param name="thispage" value="page.eventorg.edit" /> <ui:param name="thispage" value="page.eventorg.edit" />
<ui:define name="content"> <ui:define name="content">
<h:form id="orgform"> <h:form id="orgform">
<h:inputHidden value="#{eventorgView.eventorg.id}" />
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['eventorg.organisation']}:" /><h:inputText value="#{eventorgView.eventorg.organisation}" /> <h:outputLabel value="#{i18n['eventorg.organisation']}:" /><h:inputText value="#{eventorgView.eventorg.organisation}" />
<h:outputLabel value="#{i18n['eventorg.bundleCountry']}:" /><h:inputText value="#{eventorgView.eventorg.bundleCountry}" /> <h:outputLabel value="#{i18n['eventorg.bundleCountry']}:" /><h:inputText value="#{eventorgView.eventorg.bundleCountry}" />
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<ui:define name="content"> <ui:define name="content">
<h:messages /> <h:messages />
<h:form id="orgform"> <h:form id="orgform">
<h:inputHidden value="#{eventorgView.event.id}" />
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['event.name']}:" /><h:inputText value="#{eventorgView.event.name}" /> <h:outputLabel value="#{i18n['event.name']}:" /><h:inputText value="#{eventorgView.event.name}" />
<h:outputLabel value="#{i18n['event.referer']}:" /><h:inputText value="#{eventorgView.event.referer}" /> <h:outputLabel value="#{i18n['event.referer']}:" /><h:inputText value="#{eventorgView.event.referer}" />
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<br /> <br />
<h:commandButton value="Generate map tests" action="#{TestDataView.generateMapTests}" /> <h:commandButton value="Generate map tests" action="#{TestDataView.generateMapTests}" />
<br /> <br />
<h:commandButton value="execute map tests" action="#{TestDataView.executeMapTests}" /> <h:commandButton value="Gen Test map" action="#{TestDataView.generateTestMap}" />
<br /> <br />
<h:commandButton value="Context Test" action="#{TestDataView.contextTest}" /> <h:commandButton value="Context Test" action="#{TestDataView.contextTest}" />
<br /> <br />
......
...@@ -6,20 +6,48 @@ ...@@ -6,20 +6,48 @@
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"> xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
>
<h:body> <h:body>
<ui:composition template="/layout/insomnia1/sidebartemplate.xhtml"> <ui:composition rendered="#{sessionHandler.loggedIn}" template="/layout/insomnia1/sidebartemplate.xhtml">
<ui:param name="rendered" value="true" /> <ui:param name="rendered" value="true" />
<ui:define name="sidebarcontent"> <ui:define name="sidebarcontent">
<tools:canRead target="ROLE_MANAGEMENT" >
#{i18n['sidebar.roles']}
<ul> <ul>
<li><h:link outcome="/role/create" value="#{i18n['sidebar.role.create']}"/></li> <li><h:link outcome="/role/create" value="#{i18n['sidebar.role.create']}"/></li>
<li><h:link outcome="/role/list" value="#{i18n['sidebar.role.list']}"/></li> <li><h:link outcome="/role/list" value="#{i18n['sidebar.role.list']}"/></li>
<li><h:link outcome="/role/create" value="#{i18n['sidebar.role.create']}"/></li>
<li><h:link outcome="/eventorg/list" value="#{i18n['sidebar.eventorg.list']}"/></li> </ul>
</tools:canRead>
<tools:canWrite target="TICKET_SALES" >
#{i18n['sidebar.bills']}
<ul>
<li><h:link outcome="/bill/listAll" value="#{i18n['sidebar.bill.listAll']}"/></li>
<li><h:link outcome="/bill/billSummary" value="#{i18n['sidebar.bill.summary']}"/></li>
</ul>
</tools:canWrite>
<tools:canRead target="USER_MANAGEMENT">
#{i18n['sidebar.users']}
<ul>
<li><h:link outcome="/user/create" value="#{i18n['sidebar.user.create']}"/></li>
<li><h:link outcome="/user/list" value="#{i18n['sidebar.user.list']}"/></li>
</ul>
</tools:canRead>
<tools:canRead target="PRODUCT" >
#{i18n['sidebar.products']}
<ul>
<li><h:link outcome="/product/create" value="#{i18n['sidebar.product.create']}"/></li>
<li><h:link outcome="/product/list" value="#{i18n['sidebar.product.list']}"/></li>
</ul>
</tools:canRead>
#{i18n['sidebar.other']}
<ul>
<li><h:link outcome="/eventorg/list" value="#{i18n['sidebar.eventorg.list']}"/></li> <li><h:link outcome="/eventorg/list" value="#{i18n['sidebar.eventorg.list']}"/></li>
</ul> </ul>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<ui:param name="rendered" value="#{!sessionHandler.isLoggedIn()}" /> <ui:param name="rendered" value="#{!sessionHandler.isLoggedIn()}" />
<ui:define name="sidebarcontent"> <ui:define name="sidebarcontent">
<ul> <ul>
<li><h:link outcome="/user/create.xhtml" value="#{i18n['sidebar.user.create']}"/></li> <li><h:link outcome="/user/create.xhtml" value="#{i18n['sidebar.createuser']}"/></li>
</ul> </ul>
</ui:define> </ui:define>
......
...@@ -14,13 +14,9 @@ ...@@ -14,13 +14,9 @@
<ui:define name="sidebarcontent"> <ui:define name="sidebarcontent">
<ul> <ul>
<tools:canWrite target="PRODUCT" >
<li><h:link outcome="/product/create" value="#{i18n['sidebar.product.create']}"/></li> <li><h:link outcome="/bill/list" value="#{i18n['sidebar.bill.list']}"/></li>
<li><h:link outcome="/product/list" value="#{i18n['sidebar.product.list']}"/></li>
</tools:canWrite>
<li><h:link outcome="/user/createBill" value="#{i18n['sidebar.product.createBill']}"/></li>
<!-- <li><h:link outcome="/map/placemap" value="#{i18n['sidebar.map.placemap']}"/></li>
-->
</ul> </ul>
</ui:define> </ui:define>
......
...@@ -12,14 +12,10 @@ ...@@ -12,14 +12,10 @@
<ui:composition template="/layout/insomnia1/sidebartemplate.xhtml"> <ui:composition template="/layout/insomnia1/sidebartemplate.xhtml">
<ui:param name="rendered" value="#{sessionHandler.isLoggedIn()}" /> <ui:param name="rendered" value="#{sessionHandler.isLoggedIn()}" />
<ui:define name="sidebarcontent"> <ui:define name="sidebarcontent">
<ul> <ul>
<tools:canRead target="USER_MANAGEMENT">
<li><h:link outcome="/user/list" value="#{i18n['sidebar.user.list']}"/></li>
<li><h:link outcome="/user/create" value="#{i18n['sidebar.user.create']}"/></li>
</tools:canRead>
<li><h:link outcome="/bill/list" value="#{i18n['sidebar.bill.list']}"/></li>
<li><h:link outcome="/user/sendPicture" value="#{i18n['user.sendPicture']}"/></li> <li><h:link outcome="/user/sendPicture" value="#{i18n['user.sendPicture']}"/></li>
<li><h:link outcome="/user/changePassword" value="#{i18n['user.changePassword']}"/></li> <li><h:link outcome="/user/changePassword" value="#{i18n['user.changePassword']}"/></li>
<li><h:link outcome="/user/accountEvents" value="#{i18n['user.accountEvents']}"/></li>
</ul> </ul>
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/style/insomnia1/style.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/style/insomnia1/style.css" />
</h:head> </h:head>
<h:body> <h:body>
<tools:canRead target="USER_MANAGEMENT">
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'admin'?'a':''}"> <h:link outcome="/product/list" value="#{i18n['topmenu.adminfront']}" /></div>
</tools:canRead>
<div id="wrapper"> <div id="wrapper">
<div id="navigation"> <div id="navigation">
<img id="head" src="#{request.contextPath}/resources/style/insomnia1/img/header.gif" alt="headerimage" /> <img id="head" src="#{request.contextPath}/resources/style/insomnia1/img/header.gif" alt="headerimage" />
...@@ -28,22 +31,15 @@ ...@@ -28,22 +31,15 @@
</tools:isLoggedIn> </tools:isLoggedIn>
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'placemap'?'a':''}"> <h:link outcome="/bill/placemap" value="#{i18n['topmenu.placemap']}" /></div> <div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'placemap'?'a':''}"> <h:link outcome="/place/placemap" value="#{i18n['topmenu.placemap']}" /></div>
<!--
<tools:canRead target="USER_MANAGEMENT">
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'admin'?'a':''}"> <h:link outcome="/product/list" value="#{i18n['topmenu.adminfront']}" /></div>
</tools:canRead>
-->
</div> </div>
</div> </div>
</div> </div>
<div id="content"> <div id="content">
<div id="cwrap"> <div id="cwrap">
<ui:include src="/layout/insomnia1/sidebar-#{i18n[util.concat(thispage,'.pagegroup')]}.xhtml" /> <ui:include src="/layout/insomnia1/sidebar-#{i18n[util.concat(thispage,'.pagegroup')]}.xhtml" />
<c:if test="#{sessionHandler.hasPermission('USER_MANAGEMENT', 'READ')}">
<ui:include src="/layout/insomnia1/sidebar-admin.xhtml" />
</c:if>
<h:messages globalOnly="true" /> <h:messages globalOnly="true" />
<ui:insert name="content" /> <ui:insert name="content" />
</div> </div>
......
<!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/tools/map"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.role.edit" />
<ui:define name="content">
<map:create />
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!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/tools/map"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.role.edit" />
<ui:define name="content">
<map:edit />
<img width="600" src="#{request.contextPath}#{mapView.selectPlaceMapUrl}"
alt="placeimage" />
<map:genplaces />
<map:submitBg />
<map:listPlaces />
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!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/tools/map"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.role.list" />
<ui:define name="content">
<map:list />
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <html xmlns="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets" 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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:map="http://java.sun.com/jsf/composite/tools/map"
xmlns:map="http://java.sun.com/jsf/composite/tools/map" xmlns:tools="http://java.sun.com/jsf/composite/tools">
>
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.map.placemap" /> <ui:param name="thispage" value="page.place.placemap" />
<ui:define name="content"> <ui:define name="content">
<map:placeSelect />
<tools:isLoggedIn>
<f:facet name="errormessage">
<img src="#{request.contextPath}#{mapView.selectPlaceMapUrl}" alt="placeimage" />
</f:facet>
<map:placeSelect />
</tools:isLoggedIn>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<ui:define name="content"> <ui:define name="content">
<tools:fatalPermission target="PRODUCT" permission="WRITE" /> <tools:fatalPermission target="PRODUCT" permission="WRITE" />
<h:form id="discountform"> <h:form id="discountform">
<h:inputHidden name="#{productView.discount.id}" />
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['discount.shortdesc']}:" /> <h:outputLabel value="#{i18n['discount.shortdesc']}:" />
<h:inputText value="#{productView.discount.shortdesc}" /> <h:inputText value="#{productView.discount.shortdesc}" />
......
.linka A:link {color:#133E51; text-decoration:none} .linka A:link {
.linka A:active {color:#133E51; text-decoration:none} color: #133E51;
.linka A:visited {color:#133E51; text-decoration:none} text-decoration: none
.linka A:hover {color:#133E51; text-decoration:underline;} }
.link A:link {color:#FFF; text-decoration:none} .linka A:active {
.link A:active {color:#FFF; text-decoration:none} color: #133E51;
.link A:visited {color:#FFF; text-decoration:none} text-decoration: none
.link A:hover {color:#FFF; text-decoration:underline;} }
body { .linka A:visited {
background-color: #133e51; color: #133E51;
margin: 0 auto 0 auto; text-decoration: none
font-family: helvetica, arial; }
font-size: 10pt;
} .linka A:hover {
color: #133E51;
#wrapper { text-decoration: underline;
margin: 0 auto 0 auto; }
width: 900px;
height: auto; .link A:link {
} color: #FFF;
#navigation { text-decoration: none
width: 900px; }
height: 80px;
} .link A:active {
#content { color: #FFF;
width: 100%; text-decoration: none
background-image:url('img/top.gif'); }
background-repeat: no-repeat;
background-color: #FFF; .link A:visited {
padding-top: 10px 20px; color: #FFF;
} text-decoration: none
}
.link A:hover {
color: #FFF;
text-decoration: underline;
}
h3 {
font-size: 18px;
color: #01202e;
font-family: trebuchet ms, lucida grande, helvetica, arial;
}
body {
background-color: #133e51;
margin: 0 auto 0 auto;
font-family: helvetica, arial;
font-size: 10pt;
}
#wrapper {
margin: 0 auto 0 auto;
width: 900px;
height: auto;
}
#navigation {
width: 900px;
height: 80px;
}
#content {
width: 100%;
background-image: url('img/top.gif');
background-repeat: no-repeat;
background-color: #FFF;
padding-top: 10px 20px;
}
#headerbox { #headerbox {
height: 33px; height: 33px;
text-align: right; text-align: right;
margin: 15px 30px 5px 30px; margin: 15px 30px 5px 30px;
color: #FFFFFF; color: #FFFFFF;
} }
#headerbox a { #headerbox a {
color: #FFFFFF; color: #FFFFFF;
} }
#headerbox input
{ #headerbox input {
margin: 0; margin: 0; padding 0;
padding 0;
border-style: solid; border-style: solid;
border-width: 1px; border-width: 1px;
} }
#sidebar { #sidebar {
float:right; float: right;
border-width: 1px; border: 1px solid #023952;
border-style: solid; background: #62a5c3;
border-color: #000000;
background-color: #FFFFDD;
margin: 10px 15px; margin: 10px 15px;
padding: 0 1em 0 0; padding: 0 1em 0 0;
} }
.linka { #sidebar a:link {
background-image:url('img/linka2.gif'); color: #023952;
width: 117px; text-decoration: none;
height: 27px; }
color: #133E51;
float: left; #sidebar a:active {
vertical-align: bottom; color: #023952;
line-height: 30px; text-decoration: none;
text-align: center; }
font-weight: bold;
margin-right: 3px; #sidebar a:visited {
} color: #023952;
.link { text-decoration: none;
background-image:url('img/link2.gif'); }
width: 117px;
height: 27px; #sidebar a:hover {
color: #FFF; color: #023952;
float: left; text-decoration: underline;
vertical-align: bottom; }
line-height: 30px;
text-align: center; .linka {
font-weight: bold; background-image: url('img/linka2.gif');
margin-right: 3px; width: 117px;
} height: 27px;
#head { color: #133E51;
padding-top: 5px; float: left;
margin-right: 10px; vertical-align: bottom;
float: left; line-height: 30px;
} text-align: center;
#cwrap { font-weight: bold;
padding: 10px; margin-right: 3px;
min-height: 100px; }
}
#footer { .link {
background-image:url('img/bottom.gif'); background-image: url('img/link2.gif');
height: 21px; width: 117px;
text-align:center; height: 27px;
} color: #FFF;
float: left;
.imgcenter vertical-align: bottom;
{ line-height: 30px;
text-align: center;
font-weight: bold;
margin-right: 3px;
}
#head {
padding-top: 5px;
margin-right: 10px;
float: left;
}
#cwrap {
padding: 10px;
min-height: 100px;
}
#footer {
background-image: url('img/bottom.gif');
height: 21px;
text-align: center;
}
.imgcenter {
display: block; display: block;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
......
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface>
<composite:attribute name="accountview" required="true" />
</composite:interface>
<composite:implementation>
<h:form id="accountEventForm">
<h:dataTable border="1" id="ac" value="#{cc.attrs.accountview.accountEvents}"
var="ac">
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.productname']}" />
</f:facet>
<h:outputText value="#{ac.product.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.quantity']}" />
</f:facet>
<h:outputText value="#{ac.quantity}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.unitPrice']}" />
</f:facet>
<h:outputText value="#{ac.unitPrice}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.total']}" />
</f:facet>
<h:outputText value="#{ac.total}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.eventTime']}" />
</f:facet>
<h:outputText value="#{ac.eventTime.time}">
<f:convertDateTime type="both" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.delivered']}" />
</f:facet>
<h:outputText value="#{ac.delivered.time}">
<f:convertDateTime type="both" />
</h:outputText>
</h:column>
<h:column>
<h:commandButton action="#{cc.attrs.accountview.editAccount()}"
value="#{i18n['accountEvent.edit']}" />
</h:column>
</h:dataTable>
</h:form>
</composite:implementation>
</html>
...@@ -17,8 +17,15 @@ ...@@ -17,8 +17,15 @@
<composite:implementation> <composite:implementation>
<h:form> <h:outputText rendered="#{cc.attrs.billview.bills.rowCount le 0}" value="#{i18n['bills.noBills']}" />
<h:form rendered="#{cc.attrs.billview.bills.rowCount gt 0}">
<h:dataTable border="0" id="billList" value="#{cc.attrs.billview.bills}" var="bill"> <h:dataTable border="0" id="billList" value="#{cc.attrs.billview.bills}" var="bill">
<h:column rendered="#{sessionHandler.hasPermission('TICKET_SALES', 'WRITE')}">
<f:facet name="header">
<h:outputText value="${i18n['bill.payer']}" />
</f:facet>
<h:outputText value="#{bill.addr1}" />
</h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['bill.sentDate']}" /> <h:outputText value="${i18n['bill.sentDate']}" />
...@@ -35,6 +42,14 @@ ...@@ -35,6 +42,14 @@
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['bill.referencenumber']}" />
</f:facet>
<h:outputText value="#{bill.referenceNumberBase}" >
<f:converter binding="#{referenceNumberConverter}" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['bill.totalPrice']}" /> <h:outputText value="${i18n['bill.totalPrice']}" />
</f:facet> </f:facet>
<h:outputText value="#{bill.totalPrice()}" > <h:outputText value="#{bill.totalPrice()}" >
...@@ -45,6 +60,14 @@ ...@@ -45,6 +60,14 @@
<a href="#{request.contextPath}/PrintBill?billid=#{bill.id.id}" target="_blank" >#{i18n['bill.printBill']}</a> <a href="#{request.contextPath}/PrintBill?billid=#{bill.id.id}" target="_blank" >#{i18n['bill.printBill']}</a>
</h:column> </h:column>
<h:column rendered="#{cc.attrs.billView.manage}">
<h:commandButton action="#{cc.attrs.billview.edit()}" value="#{i18n['bill.edit']}" />
</h:column>
<h:column rendered="#{cc.attrs.billview.manage}">
<h:commandButton rendered="#{bill.paidDate == null}" action="#{cc.attrs.billview.markPaid()}" value="#{i18n['bill.markPaid']}" />
<h:outputText rendered="#{bill.paidDate != null}" value="#{i18n['bill.isPaid']}" />
</h:column>
</h:dataTable> </h:dataTable>
......
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<tools:fatalPermission target="TICKET_SALES" permission="WRITE" />
<h:form>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['map.name']}" />
<h:inputText value="#{mapManageView.mapname}" />
<h:commandButton id="createrole" value="#{i18n['map.create']}"
action="#{mapManageView.createMap}" />
</h:panelGrid>
</h:form>
</composite:implementation>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form id="productform">
<h:inputHidden value="#{mapManageView.map.id.id}" />
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['product.name']}:" />
<h:inputText value="#{mapManageView.map.name}" />
<h:commandButton id="commitbtn" action="#{cc.attrs.commitaction}"
value="#{cc.attrs.commitvalue}" />
</h:panelGrid>
</h:form>
</composite:implementation>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form id="productform">
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['map.tablesHorizontal']}:" />
<h:selectBooleanCheckbox value="#{mapManageView.tablesHorizontal}" />
<h:outputLabel value="#{i18n['map.oneRowTable']}:" />
<h:selectBooleanCheckbox value="#{mapManageView.oneRowTable}" />
<h:outputLabel value="#{i18n['map.width']}:" />
<h:inputText value="#{mapManageView.width}" />
<h:outputLabel value="#{i18n['map.height']}:" />
<h:inputText value="#{mapManageView.height}" />
<h:outputLabel value="#{i18n['map.startX']}:" />
<h:inputText value="#{mapManageView.startX}" />
<h:outputLabel value="#{i18n['map.startY']}:" />
<h:inputText value="#{mapManageView.startY}" />
<h:outputLabel value="#{i18n['map.placesInRow']}:" />
<h:inputText value="#{mapManageView.placesInRow}" />
<h:outputLabel value="#{i18n['map.tableCount']}:" />
<h:inputText value="#{mapManageView.tableCount}" />
<h:outputLabel value="#{i18n['map.tableXdiff']}:" />
<h:inputText value="#{mapManageView.tableXdiff}" />
<h:outputLabel value="#{i18n['map.tableYdiff']}:" />
<h:inputText value="#{mapManageView.tableYdiff}" />
<h:outputLabel value="#{i18n['map.namebase']}:" />
<h:inputText value="#{mapManageView.namebase}" />
<h:outputLabel value="#{i18n['map.product']}:" />
<h:selectOneMenu converter="#{productConverter}"
value="#{mapManageView.mapproduct}">
<f:selectItems var="prod" itemLabel="#{prod.name}"
value="#{productView.productlist}" />
</h:selectOneMenu>
<h:commandButton id="commitbtn" action="#{mapManageView.generatePlaces()}"
value="#{i18n['map.generate']}" />
</h:panelGrid>
</h:form>
</composite:implementation>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<h:dataTable border="1" id="productListTable" value="#{mapManageView.maps}"
var="map">
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['map.id']}" />
</f:facet>
<h:outputText value="#{map.id.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['map.name']}" />
</f:facet>
<h:outputText value="#{map.name}" />
</h:column>
<h:column>
<h:commandButton id="saverole" action="#{mapManageView.editMap()}"
value="#{i18n['map.edit']}" />
</h:column>
</h:dataTable>
</h:form>
</composite:implementation>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<h:dataTable border="1" id="Placelist" value="#{mapManageView.map.places}"
var="place">
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['place.id']}" />
</f:facet>
<h:outputText value="#{place.id.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['place.name']}" />
</f:facet>
<h:outputText value="#{place.name}" />
</h:column>
<h:column>
<h:commandButton id="saverole" action="#{mapManageView.editplace()}"
value="#{i18n['place.edit']}" />
</h:column>
</h:dataTable>
</h:form>
</composite:implementation>
</html>
<?xml version='1.0' encoding='UTF-8' ?> <?xml version='1.0' encoding='UTF-8' ?>
<!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 <html xmlns="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:role="http://java.sun.com/jsf/composite/tools/role">
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface> <composite:interface>
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<h:form id="placeselectform"> <h:form id="placeselectform">
<h:commandButton id="commandbutton" image="#{mapView.selectPlaceMapUrl}" actionListener="#{mapView.placeSelectActionListener}" /> <h:commandButton value="#{i18n['mapView.buyPlaces']}" action="#{mapView.buySelectedPlaces()}" />
<h:outputText value="#{i18n['placeSelect.placesleft']}: #{mapView.placeLeftToSelect()}" /> <h:outputText value="#{i18n['placeSelect.placesleft']}: #{mapView.placeLeftToSelect()}" />
</h:form>
<h:commandButton id="commandbutton" image="#{mapView.selectPlaceMapUrl}"
actionListener="#{mapView.placeSelectActionListener}" />
</h:form>
</composite:implementation>
</composite:implementation>
</html> </html>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<form id="bgsubmit"
onsubmit="window.open('', 'imagesubmitpopup', 'height=200,width=400'); this.target='imagesubmitpopup'; return true; "
action="#{request.contextPath}/UploadServlet?type=mapimage" enctype="multipart/form-data"
method="post">
<p> <input type="hidden" name="id" value="#{mapManageView.map.id.id}" />
Lähetä kartan taustakuva</p>
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['imagefile.file']}" />
<input type="file" name="file" />
<!-- <h:outputLabel value="#{i18n['imagefile.description']}"/><input type="text" name="description" /> -->
<h:panelGroup>
<input type="submit" name="submit" value="#{i18n['user.imagesubmit']}" />
</h:panelGroup>
</h:panelGrid>
</form>
</composite:implementation>
</html>
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<composite:implementation> <composite:implementation>
<h:form id="productform"> <h:form id="productform">
<h:inputHidden value="#{productView.product.id.id}" />
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['product.name']}:" /> <h:outputLabel value="#{i18n['product.name']}:" />
<h:inputText value="#{productView.product.name}" /> <h:inputText value="#{productView.product.name}" />
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
<composite:implementation> <composite:implementation>
<p> <p>
<h:form> <h:form id="roleform">
<h:inputHidden id="id" value="roleView.role.id.id" />
<f:facet name="errorMessage"> <f:facet name="errorMessage">
<h:outputText value="#{i18n['nasty.user']}" /> <h:outputText value="#{i18n['nasty.user']}" />
</f:facet> </f:facet>
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
<composite:interface> <composite:interface>
<composite:attribute name="creating" required="false" default="false" />
<composite:attribute name="commitvalue" required="true" /> <composite:attribute name="commitvalue" required="true" />
<composite:attribute name="commitaction" required="true" method-signature="java.lang.String action()" /> <composite:attribute name="commitaction" required="true" method-signature="java.lang.String action()" />
</composite:interface> </composite:interface>
...@@ -20,8 +22,16 @@ ...@@ -20,8 +22,16 @@
<h:form id="userform"> <h:form id="userform">
<h:inputHidden rendered="#{!cc.attrs.creating}" value="#{userView.user.id}" />
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['user.login']}:" for="login"/><h:outputText id="login" value="#{userView.user.login}" /> <h:outputLabel rendered="#{!cc.attrs.creating}" value="#{i18n['user.login']}:" for="viewlogin"/>
<h:outputText rendered="#{!cc.attrs.creating}" id="viewlogin" value="#{userView.user.login}" />
<h:outputLabel rendered="#{cc.attrs.creating}" value="#{i18n['user.login']}:" for="login"/>
<h:inputText rendered="#{cc.attrs.creating}" id="login" value="#{userView.user.login}" />
<h:outputLabel value="#{i18n['user.nick']}:" for="nick" /><h:inputText id="nick" value="#{userView.user.nick}" /> <h:outputLabel value="#{i18n['user.nick']}:" for="nick" /><h:inputText id="nick" value="#{userView.user.nick}" />
<h:outputLabel value="#{i18n['user.email']}:" for="email"/><h:inputText id="email" value="#{userView.user.email}" /> <h:outputLabel value="#{i18n['user.email']}:" for="email"/><h:inputText id="email" value="#{userView.user.email}" />
<h:outputLabel value="#{i18n['user.firstNames']}:" for="firstnames" /><h:inputText id="firstnames" value="#{userView.user.firstnames}" /> <h:outputLabel value="#{i18n['user.firstNames']}:" for="firstnames" /><h:inputText id="firstnames" value="#{userView.user.firstnames}" />
...@@ -44,6 +54,12 @@ ...@@ -44,6 +54,12 @@
<f:selectItem id="male" itemLabel="#{i18n['user.sex.MALE']}" itemValue="MALE" /> <f:selectItem id="male" itemLabel="#{i18n['user.sex.MALE']}" itemValue="MALE" />
<f:selectItem id="female" itemLabel="#{i18n['user.sex.FEMALE']}" itemValue="FEMALE" /> <f:selectItem id="female" itemLabel="#{i18n['user.sex.FEMALE']}" itemValue="FEMALE" />
</h:selectOneRadio> </h:selectOneRadio>
<h:outputLabel rendered="#{cc.attrs.creating}" value="#{i18n['user.password']}:" for="password"/>
<h:inputSecret rendered="#{cc.attrs.creating}" id="password" value="#{userView.password}"/>
<h:outputLabel rendered="#{cc.attrs.creating}" value="#{i18n['user.passwordcheck']}:" for="passwordcheck"/>
<h:inputSecret rendered="#{cc.attrs.creating}" id="passwordcheck" value="#{userView.passwordcheck}"/>
<h:outputLabel rendered="#{sessionHandler.hasPermission('ROLE_MANAGEMENT', 'READ')}" value="#{i18n['user.roles']}:" for="roles"/> <h:outputLabel rendered="#{sessionHandler.hasPermission('ROLE_MANAGEMENT', 'READ')}" value="#{i18n['user.roles']}:" for="roles"/>
<h:selectManyCheckbox converter="#{sessionHandler.roleConverter}" rendered="#{sessionHandler.hasPermission('ROLE_MANAGEMENT', 'READ')}" disabled="#{!sessionHandler.hasPermission('ROLE_MANAGEMENT', 'WRITE')}" layout="pageDirection" id="roles" value="#{userView.user.roles}"> <h:selectManyCheckbox converter="#{sessionHandler.roleConverter}" rendered="#{sessionHandler.hasPermission('ROLE_MANAGEMENT', 'READ')}" disabled="#{!sessionHandler.hasPermission('ROLE_MANAGEMENT', 'WRITE')}" layout="pageDirection" id="roles" value="#{userView.user.roles}">
......
<?xml version='1.0' encoding='UTF-8' ?> <?xml version='1.0' encoding='UTF-8' ?>
<!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 <html xmlns="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite" xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:c="http://java.sun.com/jsp/jstl/core"
...@@ -18,25 +16,31 @@ ...@@ -18,25 +16,31 @@
<h:dataTable border="1" id="user" value="#{userView.users}" var="user"> <h:dataTable border="1" id="user" value="#{userView.users}" var="user">
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="Id" /> <h:outputText value="Id" />
</f:facet> </f:facet>
<h:outputText value="#{user.id}" /> <h:outputText value="#{user.id}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['user.nick']}" /> <h:outputText value="#{i18n['user.login']}" />
</f:facet>
<h:outputText value="#{user.login}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['user.nick']}" />
</f:facet> </f:facet>
<h:outputText value="#{user.nick}" /> <h:outputText value="#{user.nick}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['user.firstnames']}" /> <h:outputText value="#{i18n['user.firstNames']}" />
</f:facet> </f:facet>
<h:outputText value="#{user.firstnames}" /> <h:outputText value="#{user.firstnames}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['user.lastname']}" /> <h:outputText value="#{i18n['user.lastName']}" />
</f:facet> </f:facet>
<h:outputText value="#{user.lastname}" /> <h:outputText value="#{user.lastname}" />
</h:column> </h:column>
...@@ -47,6 +51,14 @@ ...@@ -47,6 +51,14 @@
<h:outputText value="#{user.email}" /> <h:outputText value="#{user.email}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header">
<h:outputText value="#{i18n['user.accountBalance']}" />
</f:facet>
<h:outputText value="#{user.accountBalance}">
<f:convertNumber />
</h:outputText>
</h:column>
<h:column>
<h:commandButton action="#{userView.edit()}" value="#{i18n['user.edit']}" /> <h:commandButton action="#{userView.edit()}" value="#{i18n['user.edit']}" />
</h:column> </h:column>
</h:dataTable> </h:dataTable>
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
<tools:fatalPermission target="LOGIN" permission="WRITE" /> <tools:fatalPermission target="LOGIN" permission="WRITE" />
<ui:param name="thispage" value="page.role.create" /> <ui:param name="thispage" value="page.role.create" />
<ui:define name="content"> <ui:define name="content">
<tools:fatalPermission target="ROLE_MANAGEMENT" permission="WRITE" /> <tools:fatalPermission target="ROLE_MANAGEMENT" permission="WRITE" />
<role:create /> <role:create />
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
<!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:account="http://java.sun.com/jsf/composite/tools/account"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.account.list" />
<ui:define name="content">
#{userView.editSelf()}
<h:outputLabel value="#{i18n['user.accountBalance']}: " for="accountbalance"/> <h:outputText id="accountbalance" value="#{userView.user.accountBalance}" />
<account:list accountview="#{userView}"/>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -2,23 +2,22 @@ ...@@ -2,23 +2,22 @@
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" <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:h="http://java.sun.com/jsf/html" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:users="http://java.sun.com/jsf/composite/tools/user"
xmlns:c="http://java.sun.com/jsp/jstl/core"> xmlns:f="http://java.sun.com/jsf/core"
<h:body> xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.user.create" /> <ui:param name="thispage" value="page.user.create" />
<ui:define name="content"> <ui:define name="content">
<h:form id="userform"> #{userView.initCreateuser()}
<h:panelGrid columns="2"> <users:edit creating="true" commitaction="#{userView.createUser()}"
<h:outputLabel value="#{i18n['user.username']}:" /><h:inputText id="username" value="#{userView.login}" /> commitvalue="#{i18n['user.create']}" />
<h:outputLabel value="#{i18n['user.password']}:" /><h:inputSecret id="password" value="#{userView.password}" />
<h:outputLabel value="#{i18n['user.passwordcheck']}:" /><h:inputSecret id="passwordcheck" value="#{userView.passwordcheck}" />
<h:commandButton id="createuserbtn" action="#{userView.createUser()}" value="#{i18n['user.create']}" />
</h:panelGrid> </ui:define>
</h:form> </ui:composition>
</ui:define>
</ui:composition>
</h:body> </h:body>
</html> </html>
\ No newline at end of file \ No newline at end of file
...@@ -2,17 +2,56 @@ ...@@ -2,17 +2,56 @@
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" <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:h="http://java.sun.com/jsf/html" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:f="http://java.sun.com/jsf/core" xmlns:users="http://java.sun.com/jsf/composite/tools/user"
xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core"> xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.user.create" /> <ui:param name="thispage" value="page.user.create" />
<ui:define name="content"> <ui:define name="content">
<users:edit commitaction="#{userView.saveUser()}" commitvalue="#{i18n['user.save']}"/> <users:edit commitaction="#{userView.saveUser()}"
commitvalue="#{i18n['user.save']}" />
<tools:canRead target="SHOP">
<h:form id="accountform">
<h:dataTable border="0" id="accountevent"
value="#{userView.user.accountEvents}" var="event">
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountevent.productname']}" />
</f:facet>
<h:outputText value="#{event.product.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountevent.quantity']}" />
</f:facet>
<h:outputText value="#{event.quantity}">
<f:convertNumber />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountevent.unitPrice']}" />
</f:facet>
<h:outputText value="#{event.unitPrice}">
<f:convertNumber />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountevent.total']}" />
</f:facet>
<h:outputText value="#{event.total}">
<f:convertNumber />
</h:outputText>
</h:column>
</h:dataTable>
</h:form>
</tools:canRead>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
</html> </html>
\ No newline at end of file
<!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:users="http://java.sun.com/jsf/composite/tools/user"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.user.create" />
<ui:define name="content">
<users:edit creating="true" commitaction="#{userView.createUser()}"
commitvalue="#{i18n['user.create']}" />
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!