Commit 2fbb269d by Tuukka Kivilahti

Merge remote-tracking branch 'tkfftk/master' into ui_fixes

Conflicts:
	code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n.properties
	code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n_en.properties
	code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n_fi.properties
2 parents 06b92cc2 d5834201
Showing with 1167 additions and 114 deletions
......@@ -39,7 +39,8 @@ public interface BarcodeBeanLocal {
public String getPlaceTextCode(Place place);
public Place getPlaceFromTextCode(String hexcode);
public String checkVrAuthCode(String code);
public String getUserTextCode(EventUser user);
public Product getProduct(String barcode);
public Place getPlaceFromBarcode(String barcode);
......
......@@ -46,6 +46,8 @@ public interface EventBeanLocal {
String getPropertyString(LanEventPropertyKey property);
boolean getPropertyBoolean(LanEventPropertyKey property);
LanEventProperty saveOrCreateProperty(LanEventProperty property);
EventOrganiser mergeChanges(EventOrganiser eventorg);
......
......@@ -120,4 +120,6 @@ public interface PlaceBeanLocal {
List<PlaceSlot> getFreePlaceslots(EventUser user, Product product);
List<Place> findPlacePrintlistForUser(EventUser user);
}
......@@ -54,4 +54,5 @@ public interface PlaceGroupBeanLocal {
void markGrouMembershipNotEntered(GroupMembership row);
List<GroupMembership> findMembershipPrintlistForUser(EventUser user);
}
package fi.codecrew.moya.beans;
import javax.ejb.Local;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.map.MapReservationQueueEntry;
@Local
public interface QueueBeanLocal {
MapReservationQueueEntry enterQueue(EventMap map, EventUser user);
boolean isReserving(EventMap map, EventUser user);
Integer getQueuePosition(EventMap map, EventUser user);
boolean isQueueEnabled();
MapReservationQueueEntry remove(EventMap map, EventUser user);
}
......@@ -49,11 +49,11 @@ public class BarcodeBean implements BarcodeBeanLocal {
private static final String PLACE_BARCODEPREFIX = "289"; //2Y
private static final String PRINTED_CARD_TEXTCODEPREFIX = "10";
private static final String PLACE_TEXTCODEPREFIX = "11";
private static final String EVENTUSER_TEXTCODEPREFIX = "12";
private static final String PLACE_TEXTCODEPREFIX = "11";
private static final String EVENTUSER_TEXTCODEPREFIX = "12";
private static final String TEXTCODE_CHARACTER_MAP = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
private static final int TEXTCODE_ROTATE_COUNT = 64; // 8*8
private static final int TEXTCODE_ROTATE_COUNT = 128;
//private static final String NEXT_PREFIX = "265"; //2A
......@@ -97,6 +97,34 @@ public class BarcodeBean implements BarcodeBeanLocal {
return BarcodeUtils.getBarcodeEAN(barcode);
}
public String getUserTextCode(EventUser user) {
String barcode = generateBarcodeNumbers(EVENTUSER_TEXTCODEPREFIX, user.getId(), 12);
BigInteger intCode;
try {
intCode = new BigInteger(barcode);
} catch(NumberFormatException x)
{
return "GenFail";
}
String textCode = generateTextcode(intCode, 5);
BigInteger checkCode = textcodeToNumber(textCode, 5);
logger.debug("CheckCode {} : Original {}", checkCode, intCode);
if(checkCode.compareTo(intCode) != 0) {
logger.error("CheckCode {} : Original {}", checkCode, intCode);
return "GenError"; // different error messages, so we can tell where the error was
}
// logger.debug("Geneating hexcode for place {} : {}", place.getId(), textCode);
return textCode;
}
public String getPlaceTextCode(Place place) {
String barcode = generateBarcodeNumbers(PLACE_TEXTCODEPREFIX, place.getId(), 8);
......
......@@ -206,6 +206,8 @@ public class EventBean implements EventBeanLocal {
return eventPropertyFacade.find(getCurrentEvent(), property);
}
@Override
public long getPropertyLong(LanEventPropertyKey property)
{
......@@ -233,6 +235,24 @@ public class EventBean implements EventBeanLocal {
}
@Override
public boolean getPropertyBoolean(LanEventPropertyKey property) {
LanEventProperty retProp = eventPropertyFacade.find(getCurrentEvent(), property);
boolean ret = false;
if (retProp == null) {
String def = property.getDefaultvalue();
if(def != null && !def.trim().isEmpty() && !def.trim().equals("0"))
ret = true;
} else {
ret = retProp.isBooleanValue();
}
return ret;
}
@Override
@RolesAllowed({ SpecialPermission.S_SUPERADMIN, EventPermission.S_MANAGE_EVENT })
public LanEventProperty saveOrCreateProperty(LanEventProperty property) {
LanEventProperty ret = null;
......
......@@ -149,6 +149,7 @@ public class MenuBean implements MenuBeanLocal {
userPlaces.setKey("topnavi.userplaces");
userPlaces.addPage(menuitemfacade.findOrCreate("/neomap/view"), MapPermission.VIEW);
userPlaces.addPage(menuitemfacade.findOrCreate("/place/myGroups"), MapPermission.BUY_PLACES);
userPlaces.addPage(menuitemfacade.findOrCreate("/place/myEtickets"), MapPermission.BUY_PLACES).setVisible(false);
userPlaces.addPage(menuitemfacade.findOrCreate("/place/edit"), MapPermission.MANAGE_OTHERS).setVisible(false);
MenuNavigation usercompetitions = usermenu.addPage(null, null);
......
......@@ -49,6 +49,7 @@ import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import fi.codecrew.moya.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -67,15 +68,6 @@ import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.PlaceSlotFacade;
import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
......@@ -134,6 +126,7 @@ public class PlaceBean implements PlaceBeanLocal {
@EJB
private PlaceSlotFacade placeSlotFacade;
@Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
public Place mergeChanges(Place place) {
......@@ -617,7 +610,14 @@ public class PlaceBean implements PlaceBeanLocal {
place.setPlaceReserver(null);
gmemfacade.remove(res);
}
PlaceSlot slot = placeSlotFacade.findSlotForPlace(place);
// remove also slot from place
if(slot != null) {
slot.setPlace(null);
place.setReserverSlot(null);
}
return place;
}
......@@ -750,6 +750,35 @@ public class PlaceBean implements PlaceBeanLocal {
}
@Override
public List<Place> findPlacePrintlistForUser(EventUser user) {
// TODO: get from placefacade. Sometimes it's easier to think loops then facadequeries
boolean printOnlyOwn = eventBean.getPropertyBoolean(LanEventPropertyKey.PLACECODE_PRINT_ONLY_OWN);
List<GroupMembership> gmems = gmemfacade.findMemberOrCreator(user);
List<Place> places = new ArrayList<>();
for(GroupMembership gm : gmems) {
if(gm.getPlaceReservation() != null) {
// places with no user belongs to creator
if(gm.getUser() == null || !printOnlyOwn) {
places.add(gm.getPlaceReservation());
} else if(user.equals(gm.getUser())) {
places.add(gm.getPlaceReservation());
}
}
}
return places;
}
@Override
public List<Product> getMapProducts(EventMap map) {
return placeFacade.getMapProducts(map);
}
......
......@@ -19,6 +19,7 @@
package fi.codecrew.moya.beans;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
......@@ -28,6 +29,7 @@ import javax.ejb.EJB;
import javax.ejb.EJBAccessException;
import javax.ejb.Stateless;
import fi.codecrew.moya.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -45,12 +47,6 @@ import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.BarcodeUtils;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
......@@ -161,20 +157,11 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
public void getGroupMembershipPdf(EventUser usr, OutputStream ostream) {
List<GroupMembership> memberships = getMembershipsAndCreations(usr);
LanEventProperty tmpProperty = eventbean.getProperty(LanEventPropertyKey.PLACECODE_FROM_USER);
boolean placecodeFromUser = false;
if (tmpProperty != null && tmpProperty.isBooleanValue())
{
placecodeFromUser = true;
}
boolean placecodeFromUser = eventbean.getPropertyBoolean(LanEventPropertyKey.PLACECODE_FROM_USER);
boolean printOnlyOwn = eventbean.getPropertyBoolean(LanEventPropertyKey.PLACECODE_PRINT_ONLY_OWN);
tmpProperty = eventbean.getProperty(LanEventPropertyKey.PLACECODE_PRINT_ONLY_OWN);
boolean printOnlyOwn = false;
if (tmpProperty != null && tmpProperty.isBooleanValue())
{
printOnlyOwn = true;
}
try {
PDF pdf = new PDF(ostream);
......@@ -328,4 +315,33 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
membership = gmemfacade.merge(membership);
}
@Override
public List<GroupMembership> findMembershipPrintlistForUser(EventUser user) {
// TODO: get from placefacade. Sometimes it's easier to think loops then facadequeries
boolean printOnlyOwn = eventbean.getPropertyBoolean(LanEventPropertyKey.PLACECODE_PRINT_ONLY_OWN);
List<GroupMembership> gmems = gmemfacade.findMemberOrCreator(user);
List<GroupMembership> ret = new ArrayList<>();
for(GroupMembership gm : gmems) {
if(gm.getPlaceReservation() != null) {
// places with no user belongs to creator
if(gm.getUser() == null || !printOnlyOwn) {
ret.add(gm);
} else if(user.equals(gm.getUser())) {
ret.add(gm);
}
}
}
return ret;
}
}
package fi.codecrew.moya.beans;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicLong;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.facade.PlaceSlotFacade;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.map.MapReservationQueueEntry;
/**
* Session Bean implementation class QueueBean
*/
@Singleton
@LocalBean
public class QueueBean implements QueueBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(QueueBean.class);
/**
* Default constructor.
*/
public QueueBean() {
mapqueues = new HashMap<>();
logger.info("Initialized2 QueueBean, {}", mapqueues);
}
private final Map<Integer, MapQueue> mapqueues;
private int reservingSize = 2;
private class MapQueue {
// private final Set<MapReservationQueueEntry> reserving = new HashSet<>();
private final Set<EventUser> reserving = Collections.newSetFromMap(new ConcurrentHashMap<EventUser, Boolean>());
private final LinkedBlockingQueue<EventUser> queue = new LinkedBlockingQueue<>();
private final ConcurrentMap<EventUser, MapReservationQueueEntry> queEntries = new ConcurrentHashMap<>();
// public boolean enterReserving( EventUser user) {
// timeoutReserving();
//
// if (reserving.size() < 3 && !queue.isEmpty() && queue.get(0).equals(entry)) {
// entry = queue.get(0);
// entry.removeFromQueue();
// }
// }
private void timeoutEntries() {
// give 10 seconds mercy ( and give us some time to go through all entries)
Date now = new Date(System.currentTimeMillis() + 1000 * 15);
for (EventUser r : reserving) {
MapReservationQueueEntry entry = queEntries.get(r);
if (entry.getReservationTimeout() == null || now.after(entry.getReservationTimeout())) {
this.remove(entry.getUser());
}
}
// Set idle time to the past.
// Idle timeout after 60 seconds
Date idleTimeout = new Date(System.currentTimeMillis() - 1000 * 60);
for (EventUser q : queue) {
MapReservationQueueEntry entry = queEntries.get(q);
if (entry.getSeenTime() == null) {
entry.setSeenTime(new Date());
continue;
}
if (idleTimeout.after(entry.getSeenTime())) {
remove(entry.getUser());
}
}
}
public boolean isReserving(EventUser e) {
// Check queue size and add entry to queue
if (reserving.size() < reservingSize) {
synchronized (queue) {
if (reserving.size() < reservingSize) {
EventUser queEntry = queue.poll();
if (queEntry != null) {
reserving.add(queEntry);
}
}
}
}
MapReservationQueueEntry que = queEntries.get(e);
if (que != null) {
que.setSeenTime(new Date());
}
return reserving.contains(e);
}
public MapReservationQueueEntry remove(EventUser user)
{
MapReservationQueueEntry ret = null;
synchronized (queue) {
if (reserving.remove(user)) {
logger.info("Removed user {} from reserving queue", user);
}
// There should neve be more than one instance, but make sure
while (queue.remove(user)) {
logger.info("Removed user {} from queue");
}
ret = queEntries.remove(user);
}
return ret;
}
public MapReservationQueueEntry enter(EventUser user) {
MapReservationQueueEntry ret = null;
synchronized (queue) {
if (!reserving.contains(user) && !queue.contains(user)) {
ret = new MapReservationQueueEntry();
queEntries.put(user, ret);
boolean queStat = queue.offer(user);
logger.info("User {} not in queue, offer state {}", user, queStat);
} else {
ret = queEntries.get(user);
logger.info("User {} already in queue. Not entering again {}", user, ret);
}
}
return ret;
}
public Integer getPosition(EventUser user) {
Integer ret = null;
if (reserving.contains(user)) {
ret = 0;
logger.info("User in reserving queue {}", user);
} else if (queue.contains(user)) {
ret = 1;
for (EventUser eu : queue) {
if (eu.equals(user)) {
break;
}
++ret;
}
logger.info("User is in queue {}, position {}", user, ret);
} else {
logger.info("Not in queue, while checking position");
}
logger.info("Got position {} for user {}", ret, user);
return ret;
}
public boolean isInQueue(EventUser user) {
return reserving.contains(user) || queue.contains(user);
}
public MapReservationQueueEntry getEntry(EventUser user) {
return queEntries.get(user);
}
}
@EJB
private EventBeanLocal eventbean;
private AtomicLong nextReservingTimeoutCheck = new AtomicLong();
@EJB
private PlaceSlotFacade slotfacade;
@Lock(LockType.READ)
@Override
public boolean isReserving(EventMap map, EventUser user) {
// If queue is not enabled, user can always reserve
if (!isQueueEnabled())
return true;
if (map == null || user == null)
{
logger.warn("Can not check map {}, user {}", map, user);
}
boolean ret = getMapque(map).isReserving(user);
// Do some housekeeping, but only on each 120
long now = System.currentTimeMillis();
long nextTime = nextReservingTimeoutCheck.get();
// Update next checktime to 120 seconds in to the future, so we should have plenty of time
// to do the checks we need..
if (now > nextTime && nextReservingTimeoutCheck.compareAndSet(nextTime, now + 1000 * 120)) {
logger.info("Launcing reservingTimeout check ");
checkReservingTimeouts();
logger.info("Done launching reservingTimeoutCheck");
}
return ret;
}
@Asynchronous
private void checkReservingTimeouts() {
try {
final long oldTime = nextReservingTimeoutCheck.get();
for (MapQueue m : mapqueues.values()) {
m.timeoutEntries();
}
// DO housekeeping every 10 seconds.
nextReservingTimeoutCheck.compareAndSet(oldTime, System.currentTimeMillis() + 1000 * 10);
} catch (Throwable t) {
logger.warn("Exception while checking reservingTimeouts");
}
}
private MapQueue getMapque(EventMap map) {
if (map == null) {
return null;
}
MapQueue ret = mapqueues.get(map.getId());
if (ret == null) {
logger.info("getMapqueue, {}", mapqueues);
synchronized (mapqueues) {
ret = new MapQueue();
mapqueues.put(map.getId(), ret);
}
}
logger.info("returning queue {} for map {}", ret, map);
return ret;
}
@Lock(LockType.READ)
@Override
public Integer getQueuePosition(EventMap map, EventUser user)
{
return getMapque(map).getPosition(user);
}
@Lock(LockType.READ)
@Override
public boolean isQueueEnabled() {
return eventbean.getPropertyBoolean(LanEventPropertyKey.MAP_QUEUE);
}
@Lock(LockType.READ)
@Override
public MapReservationQueueEntry remove(EventMap map, EventUser user) {
MapQueue queue = getMapque(map);
return queue.remove(user);
}
@Override
@Lock(LockType.READ)
public MapReservationQueueEntry enterQueue(EventMap map, EventUser user) {
if (!isQueueEnabled()) {
return null;
}
MapQueue queue = getMapque(map);
MapReservationQueueEntry ret = null;
if (queue.isInQueue(user)) {
logger.info("User {} already in queue");
ret = queue.getEntry(user);
} else {
List<PlaceSlot> slots = slotfacade.findFreePlaceSlots(user, null);
logger.info("User {} not yet in queue. User has {} slots", user, slots.size());
if (!slots.isEmpty()) {
ret = queue.enter(user);
logger.info("Entered queue: {}", ret);
}
}
return ret;
}
}
......@@ -174,6 +174,9 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
}
public Long findCountForProduct(Product product) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
......
......@@ -18,6 +18,7 @@
*/
package fi.codecrew.moya.facade;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
......@@ -27,6 +28,7 @@ import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.slf4j.Logger;
......@@ -67,11 +69,15 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
CriteriaQuery<PlaceSlot> q = cb.createQuery(PlaceSlot.class);
Root<PlaceSlot> root = q.from(PlaceSlot.class);
Path<Bill> bill = root.get(PlaceSlot_.bill);
q.where(cb.equal(bill.get(Bill_.user), user),
cb.isNotNull(bill.get(Bill_.paidDate)),
cb.isNull(root.get(PlaceSlot_.used)),
cb.equal(root.get(PlaceSlot_.product), product)
);
final List<Predicate> preds = new ArrayList<>();
preds.add(cb.equal(bill.get(Bill_.user), user));
preds.add(cb.isNotNull(bill.get(Bill_.paidDate)));
preds.add(cb.isNull(root.get(PlaceSlot_.used)));
if (product != null) {
preds.add(cb.equal(root.get(PlaceSlot_.product), product));
}
q.where(preds.toArray(new Predicate[preds.size()]));
return getEm().createQuery(q).getResultList();
}
......@@ -102,17 +108,15 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
q.where(cb.equal(root.get(PlaceSlot_.product), prod),
cb.or(cb.isNull(billexp),
cb.greaterThan(billexp, Calendar.getInstance())
),
cb.isNull(root.get(PlaceSlot_.place))
);
),
cb.isNull(root.get(PlaceSlot_.place)),
cb.isNull(root.get(PlaceSlot_.used))
);
Long count = super.getSingleNullableResult(getEm().createQuery(q));
return count;
}
public Long totalSlotcount(Product prod) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> q = cb.createQuery(Long.class);
......
......@@ -36,13 +36,15 @@ public enum LanEventPropertyKey {
GATHER_OTHER_BILL_INFO(Type.BOOL, null),
GATHER_SHIRT_SIZE(Type.BOOL, null),
ALLOW_BILLING(Type.BOOL, null),
BILL_EXPIRE_HOURS(Type.LONG, "168"),
BILL_EXPIRE_HOURS(Type.LONG, "1"),
TEMPLATE_PROPERTY1(Type.TEXT, null),
TEMPLATE_PROPERTY2(Type.TEXT, null),
TEMPLATE_PROPERTY3(Type.TEXT, null),
TEMPLATE_PROPERTY4(Type.TEXT, null),
TEMPLATE_PROPERTY5(Type.TEXT, null),
INVITE_ONLY_EVENT(Type.BOOL, null),
USE_ETICKET(Type.BOOL, null),
MAP_QUEUE(Type.BOOL, null),
;
......
......@@ -18,7 +18,6 @@
*/
package fi.codecrew.moya.model;
import java.awt.Color;
import java.util.Calendar;
import javax.persistence.CascadeType;
......@@ -310,6 +309,18 @@ public class Place extends GenericEntity implements Comparable<Place> {
return buyable;
}
/**
* NOTE: you can newer be sure that this is up to date
* @return
*/
public PlaceSlot getReserverSlot() {
return reserverSlot;
}
public void setReserverSlot(PlaceSlot reserverSlot) {
this.reserverSlot = reserverSlot;
}
public void setReleaseTime(Calendar releaseTime) {
this.releaseTime = releaseTime;
}
......
package fi.codecrew.moya.model.map;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.GenericEntity;
/**
*
*
*/
//mapQueGroup
//- queEnableTime
//- queDisableTime
//- maxSiultaneousPlaces
//- maxSimultaneoutUsers
//- minPlaces
//- maxPlaces
//- placecountWeight ( 1 = more places go first, 0 = fully random
//- queueTimeWeight ( 1 = fifo, 0 = fully random )
//@Entity
// @Table(name = "map_reservation_queue")
public class MapReservationQueue extends GenericEntity {
@ManyToOne
@JoinColumn(nullable = false)
private EventMap map;
private String name;
private String description;
@Temporal(TemporalType.TIMESTAMP)
private Date queueEnableTime;
@Temporal(TemporalType.TIMESTAMP)
private Date queueDisableTime;
// how many placeslots or users can be reserving places at the same time
private Integer simultaneousPlaceslots;
private Integer simultaneousUsers;
private Integer queMinPlaces;
private Integer queMaxPlaces;
// Bigger gets selected first if multiple queues apply to user
private Integer selectionPriority = 100;
// // 100 = more places go always first, 0 = fully random
// @Column(nullable = false, precision = 6, scale = 7)
// private Integer placeslotWeight;
//
// // ( 100 = fifo, 0 = fully random )
// private Integer queueTimeWeight;
// If there are multiple queues enabled, queueus with the same weight
// are evaluated against eachother. Queues with bigger priorities are always selected
// before queues with lower prorities
private Integer queueQuePriority = 10;
/**
*
*/
private static final long serialVersionUID = -6631083485543375943L;
public MapReservationQueue() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getQueueEnableTime() {
return queueEnableTime;
}
public void setQueueEnableTime(Date queueEnableTime) {
this.queueEnableTime = queueEnableTime;
}
public Date getQueueDisableTime() {
return queueDisableTime;
}
public void setQueueDisableTime(Date queueDisableTime) {
this.queueDisableTime = queueDisableTime;
}
public Integer getSimultaneousPlaceslots() {
return simultaneousPlaceslots;
}
public void setSimultaneousPlaceslots(Integer simultaneousPlaceslots) {
this.simultaneousPlaceslots = simultaneousPlaceslots;
}
public Integer getSimultaneousUsers() {
return simultaneousUsers;
}
public void setSimultaneousUsers(Integer simultaneousUsers) {
this.simultaneousUsers = simultaneousUsers;
}
public Integer getQueMinPlaces() {
return queMinPlaces;
}
public void setQueMinPlaces(Integer queMinPlaces) {
this.queMinPlaces = queMinPlaces;
}
public Integer getQueMaxPlaces() {
return queMaxPlaces;
}
public void setQueMaxPlaces(Integer queMaxPlaces) {
this.queMaxPlaces = queMaxPlaces;
}
public EventMap getMap() {
return map;
}
public void setMap(EventMap map) {
this.map = map;
}
public Integer getSelectionPriority() {
return selectionPriority;
}
public void setSelectionPriority(Integer selectionPriority) {
this.selectionPriority = selectionPriority;
}
public Integer getQueueQuePriority() {
return queueQuePriority;
}
public void setQueueQuePriority(Integer queueQuePriority) {
this.queueQuePriority = queueQuePriority;
}
}
package fi.codecrew.moya.model.map;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GenericEntity;
//userque
//- user
//- enteredQueue
//- enteredSelection
// @Entity
// @Table(name = "map_reservation_queue_entry")
public class MapReservationQueueEntry extends GenericEntity {
/**
*
*/
private static final long serialVersionUID = -1529588850152306791L;
@Column()
@JoinColumn(nullable = false)
private MapReservationQueue queue;
@ManyToOne
private EventUser user;
@Temporal(TemporalType.TIMESTAMP)
private Date created;
@Temporal(TemporalType.TIMESTAMP)
private Date reservationTimeout;
@Transient
private Date seenTime;
// @OneToOne()
// @JoinColumn(nullable = true)
// private MapReservationQueueEntry previous;
//
// @OneToOne(mappedBy = "previous")
// private MapReservationQueueEntry next;
private static final Logger logger = LoggerFactory.getLogger(MapReservationQueueEntry.class);
// public void removeFromQueue() {
// if (previous != null) {
// if (!this.equals(previous.getNext())) {
// logger.warn("WTF!! Previous entrys next value does not match this! This '{}', Previous '{}', Next of previous '{}'", this, getPrevious(), getPrevious().getNext());
// }
// previous.setNext(next);
// previous = null;
// next = null;
// }
// }
//
// public void addToQueue(MapReservationQueueEntry previous) {
// if (previous != null) {
// next = previous.getNext();
// previous.setNext(this);
// if (next != null) {
// next.setPrevious(this);
// }
// }
// }
public MapReservationQueue getQueue() {
return queue;
}
public void setQueue(MapReservationQueue queue) {
this.queue = queue;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser user) {
this.user = user;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getReservationTimeout() {
return reservationTimeout;
}
public void setReservationTimeout(Date reservationTimeout) {
this.reservationTimeout = reservationTimeout;
}
public Date getSeenTime() {
return seenTime;
}
public void setSeenTime(Date seenTime) {
this.seenTime = seenTime;
}
}
......@@ -9,10 +9,6 @@
<f:event type="preRenderView" listener="#{pageOutputView.initIndexView}" />
</f:metadata>
<ui:define name="content">
<h:outputLabel rendered="#{sessionHandler.isInDevelopmentMode()}">
Development-tilassa.
Täällä voit huoletta rikkoa.
</h:outputLabel>
<ui:fragment rendered="#{layoutView.manageContent}">
<h:link value="#{i18n['layout.editContent']}" outcome="/pages/manage">
<f:param name="pagename" value="#{layoutView.pagepath}" />
......
......@@ -22,8 +22,7 @@
action="#{ajaxMapView.placeClicked()}" />
</h:form>
-->
<p:dialog rendered="#{ajaxMapView.isMgmtPermission()}"
visible="#{!empty ajaxMapView.place}" id="fbdiag">
<p:dialog rendered="#{ajaxMapView.isMgmtPermission()}" visible="#{!empty ajaxMapView.place}" id="fbdiag">
Clicked place name : #{ajaxMapView.place.name};
<h:link rendered="#{!empty ajaxMapView.place}" outcome="/place/edit">
<f:param name="placeid" value="#{ajaxMapView.place.id}" />
......@@ -35,16 +34,27 @@
<h:outputScript target="head" library="seatjs" name="d3-tip.js" />
<h:outputScript target="head" library="seatjs" name="seatmap.js" />
<h:outputStylesheet library="seatjs" name="placemap.css" />
<div style="margin: 5px;">
<h:form id="placeselectform">
<h:commandButton rendered="#{ajaxMapView.canUserBuy()}"
<p:commandButton rendered="#{ajaxMapView.canUserBuy()}"
value="#{i18n['mapView.buyPlaces']}"
action="#{ajaxMapView.buySelectedPlaces()}" />
action="#{ajaxMapView.buySelectedPlaces()}" ajax="false" />
</h:form>
</div>
<svg id="seatmap" style="margin: auto; border: 1px solid black;"
width="#{ajaxMapView.map.width}px"
height="#{ajaxMapView.map.height}px" />
<p:outputPanel rendered="#{ajaxMapView.queueEnabled}">
<h:form>
<p:commandButton value="#{i18n['mapView.enterQueue']}" action="#{ajaxMapView.enterQueue()}" ajax="false" />
<p:commandButton value="#{i18n['mapView.check']}" action="#{ajaxMapView.checkReserving()}" />
</h:form>
queueEntry #{ajaxMapView.queueEntry} <br />
QueuePosition: #{ajaxMapView.queuePosition} <br />
Available places to select: #{ajaxMapView.placesLeftToSelect} <br />
isReserving #{ajaxMapView.reserving} <br />
</p:outputPanel>
<svg id="seatmap" style="margin: auto; border: 1px solid black;" width="#{ajaxMapView.map.width}px" height="#{ajaxMapView.map.height}px" />
<script type="text/javascript">
px = placemap({
element : document.getElementById("seatmap"),
......@@ -90,7 +100,7 @@
<h:outputLabel value="#{i18n['placeSelect.placesleft']}:" />
<h:outputText value="#{ajaxMapView.placesLeftToSelect}" />
</h:panelGrid>
</h:panelGrid>
......
<!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:products="http://java.sun.com/jsf/composite/cditools/products"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
</f:metadata>
<ui:define rendered="#{lectureUserView.lectureGroupsVisible}" name="title">
<h1>#{i18n['etickets.title']}</h1>
</ui:define>
<ui:define name="content">
<h:form id="etickets">
<br /><br />
<p:commandButton value="Print" type="button" icon="ui-icon-print" style="display:block;margin-bottom: 20px">
<p:printer target="eticketpanel"/>
</p:commandButton>&lt;--Tarvitaanko?<br/>
<p:commandButton icon="ui-icon-mail-closed" value="Send as email (TODO)"/><br/><br/><br/>
<p:outputPanel id="eticketpanel">
<p:fieldset legend="#{i18n['etickets.eticketcode']}" style="width: 250px; ">
<p:outputPanel style="text-align: center;">
<p:barcode id="userqrcode" value="#{eticketView.userTextCode}" type="qr" width="200" height="200"/><br />
<p:outputLabel for="userqrcode" value="#{eticketView.userTextCode}"/>
</p:outputPanel>
</p:fieldset>
<br /><br />
<p:fieldset legend="#{i18n['etickets.placeinfo']}">
<p:dataTable value="#{eticketView.groupMemberships}" var="member" id="placestable">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['etickets.place']}"/>
</f:facet>
<h:outputText value="#{member.placeReservation.name}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['etickets.product']}"/>
</f:facet>
<h:outputText value="#{member.placeReservation.product.name}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['etickets.user']}"/>
</f:facet>
<h:outputText value="#{member.user.wholeName} (#{member.user.nick})"/>
</p:column>
</p:dataTable>
</p:fieldset>
<br /><br />
<p:fieldset legend="#{i18n['etickets.placemap']}" style="#{eticketView.mapFieldsetStyle}">
<p:graphicImage url="/PlaceMap?mapid=#{mapView.activeMap.id}&amp;userid=#{userView.selectedUser.user.id}"/>
</p:fieldset>
</p:outputPanel>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -63,14 +63,19 @@
</p:dataTable>
<p:dialog header="Basic Dialog" widgetVar="dlg1" minHeight="40">
<h:outputText value="Resistance to PrimeFaces is futile!" />
</p:dialog>
</h:form>
<!-- TODO: button -->
<p:outputPanel rendered="#{!placeGroupView.useEticket}" >
<p>
<input type="button" onclick="location.replace('#{request.contextPath}/PlaceGroupPdf');" value="#{i18n['placegroup.printPdf']}" />
</p>
</p:outputPanel>
<p:outputPanel rendered="#{placeGroupView.useEticket}" >
<p>
<p:button outcome="/place/myEtickets" value="#{i18n['placegroup.showEticket']}" />
</p>
</p:outputPanel>
<h2>#{i18n['placetoken.pageHeader']}</h2>
<p>#{i18n['placetoken.topText']}</p>
<h:form id="placeTokenForm">
......
......@@ -35,12 +35,22 @@
<version>5.1</version>
</dependency>
<dependency>
<groupId>net.glxn</groupId>
<artifactId>qrgen</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.8</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>net.matlux</groupId>
<artifactId>jvm-breakglass</artifactId>
<version>0.0.7</version>
......
......@@ -47,7 +47,7 @@ public class SessionStore implements Serializable {
public Locale getLocale() {
Locale ret = locale;
if (ret == null)
if (ret == null || ret.toString().equals(""))
{
String retStr = eventbean.getCurrentEvent().getOrganiser().getBundleCountry();
......@@ -60,11 +60,13 @@ public class SessionStore implements Serializable {
}
}
if (ret == null) {
if (ret == null || ret.toString().equals("")) {
ret = DEFAULT_LOCALE;
}
locale = ret;
}
logger.info("Using locale {}",ret);
return ret;
}
......
......@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.QueueBeanLocal;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
......@@ -47,6 +48,9 @@ public class PlacemapRestViewV1 {
@Inject
private UserView userView;
@EJB
private QueueBeanLocal quebean;
// @GET
// @Path("/maps")
// public PlacemapMapRootPojo getMaps()
......@@ -116,6 +120,13 @@ public class PlacemapRestViewV1 {
}
Place p = placebean.find(placeId);
EventMap map = p.getMap();
if (!quebean.isReserving(map, user))
{
logger.warn("User is not in reservation order ");
return Response.status(Response.Status.FORBIDDEN).build();
}
boolean success = false;
if (p.isReservedFor(user)) {
success = placebean.releasePlace(p);
......
......@@ -29,6 +29,7 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -43,13 +44,11 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import fi.codecrew.moya.beans.*;
import fi.codecrew.moya.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.SecurityLogType;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
......@@ -75,7 +74,11 @@ public class PlaceMapServlet extends HttpServlet {
@EJB
private transient LoggingBeanLocal loggerbean;
@EJB
private UserBeanLocal userBean;
private static final String PARAMETER_EVENT_MAP_ID = "mapid";
private static final String PARAMETER_USER_ID = "userid";
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
......@@ -102,6 +105,8 @@ public class PlaceMapServlet extends HttpServlet {
// PARAMETER_SELECTED_PLACE_ID);
Integer mapId = getIntegerParameter(request, PARAMETER_EVENT_MAP_ID);
Integer userId = getIntegerParameter(request, PARAMETER_USER_ID);
// Integer userId = getIntegerParameter(request,
// PARAMETER_CURRENT_USER_ID); Tämä saadaan beaneilta.
......@@ -115,19 +120,12 @@ public class PlaceMapServlet extends HttpServlet {
ostream.print("Map error!");
} else {
response.setContentType("image/jpeg");
printPlaceMapToStream(ostream, "jpg", map);
response.setContentType("image/png");
printPlaceMapToStream(ostream, "png", map,userId);
logger.debug("Flushing ostream");
ostream.flush();
}
/*
* TODO output your page here out.println("<html>");
* out.println("<head>");
* out.println("<title>Servlet PlaceMap</title>");
* out.println("</head>"); out.println("<body>");
* out.println("<h1>Servlet PlaceMap at " + request.getContextPath
* () + "</h1>"); out.println("</body>"); out.println("</html>");
*/
} catch (EJBException e) {
logger.debug("Permission denied. Returning SC_FORBIDDEN!");
response.setContentType("text/html;charset=UTF-8");
......@@ -141,7 +139,7 @@ public class PlaceMapServlet extends HttpServlet {
}
}
private void printPlaceMapToStream(OutputStream outputStream, String filetype, EventMap map) throws IOException
private void printPlaceMapToStream(OutputStream outputStream, String filetype, EventMap map, Integer userid) throws IOException
{
if (!permbean.hasPermission(MapPermission.VIEW))
......@@ -167,6 +165,16 @@ public class PlaceMapServlet extends HttpServlet {
// logger.debug("Got map object {}", map);
List<Place> places = map.getPlaces();
List<Place> userplaces = new ArrayList<>();
if(userid != null && userid != 0) {
EventUser user = userBean.findByUserId(userid, false);
if(user != null) {
userplaces = placeBean.findPlacePrintlistForUser(user);
}
}
EventUser user = permbean.getCurrentUser();
// List<Place> selectedPlaces = placemapBean.findSelectedPlaces(map);
......@@ -175,7 +183,18 @@ public class PlaceMapServlet extends HttpServlet {
Graphics2D g2d = image.createGraphics();
for (Place place : places) {
drawPlace(place, g2d, user);
if(userplaces.size() > 0) {
if(userplaces.contains(place)) {
drawPlace(place, g2d, user, true, true);
} else {
drawPlace(place, g2d, user, true, false);
}
} else {
drawPlace(place, g2d, user, false, false);
}
}
// BufferedImage image = map.getMapWithPlaces(, selectedPlaces);
......@@ -259,41 +278,48 @@ public class PlaceMapServlet extends HttpServlet {
private static final Color LOCKED_COLOR = Color.DARK_GRAY;
private static final int BORDER_WIDTH = 2;
private static void drawPlace(Place p, Graphics2D g, EventUser user) {
private static void drawPlace(Place p, Graphics2D g, EventUser user, boolean onlyFrame, boolean hilight) {
if (p.isDisabled()) {
return;
}
Color color = null;
if (!p.isBuyable()) {
logger.debug("Setting color as locked place.");
color = LOCKED_COLOR;
}
if (p.isReservedFor(user)) {
// logger.debug("Setting place selected {}", p);
color = SELECTED_COLOR;
} else if (user.equals(p.getCurrentUser())
|| (p.getGroup() != null && user.equals(p.getGroup().getCreator()))
|| (p.getPlaceReserver() != null && user.equals(p
.getPlaceReserver().getUser()))) {
color = OWNED_COLOR;
// logger.debug("Setting place owned {}", p);
} else if (p.isTaken()) {
color = RESERVED_COLOR;
// logger.debug("Setting place Reserved {}", p);
if(!onlyFrame) {
if (!p.isBuyable()) {
logger.debug("Setting color as locked place.");
color = LOCKED_COLOR;
}
} else if (p.getProduct() != null && p.getProduct() != null && p.getProduct().getColor() != null && !p.getProduct().getColor().isEmpty()) {
if (p.isReservedFor(user)) {
// logger.debug("Setting place selected {}", p);
color = SELECTED_COLOR;
} else if (user.equals(p.getCurrentUser())
|| (p.getGroup() != null && user.equals(p.getGroup().getCreator()))
|| (p.getPlaceReserver() != null && user.equals(p
.getPlaceReserver().getUser()))) {
color = OWNED_COLOR;
// logger.debug("Setting place owned {}", p);
} else if (p.isTaken()) {
color = RESERVED_COLOR;
// logger.debug("Setting place Reserved {}", p);
} else if (p.getProduct() != null && p.getProduct() != null && p.getProduct().getColor() != null && !p.getProduct().getColor().isEmpty()) {
try {
color = Color.decode(p.getProduct().getColor());
} catch (NumberFormatException x) {
logger.error("Cannot convert string {} to color.", p.getProduct().getColor());
}
} else {
// too much debugging -TKjne
// logger.debug("Nothing special for this place. Color should be default.");
try {
color = Color.decode(p.getProduct().getColor());
} catch (NumberFormatException x) {
logger.error("Cannot convert string {} to color.", p.getProduct().getColor());
}
} else {
// too much debugging -TKjne
// logger.debug("Nothing special for this place. Color should be default.");
}
if(hilight) {
color = OWNED_COLOR;
}
g.setColor(BORDER_COLOR);
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.web.cdiview.eticket;
import fi.codecrew.moya.beans.BarcodeBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.shop.InviteView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Named
@ConversationScoped
public class EticketView extends GenericCDIView {
private static final long serialVersionUID = -3934253910818396155L;
private static final Logger logger = LoggerFactory.getLogger(EticketView.class);
// @Inject
// private UserView userview;
@Inject
@SelectedUser
private EventUser user;
@EJB
private BarcodeBeanLocal barcodeBean;
@EJB
private PlaceGroupBeanLocal placegroupBean;
@EJB
UserBeanLocal userBean;
@EJB
PlaceBeanLocal placeBean;
@Inject
private InviteView inviteView;
private Place place;
private PlaceGroup group;
private transient ListDataModel<PlaceGroup> placegroups;
private transient ListDataModel<Place> placelist;
private transient ListDataModel<GroupMembership> memberlist;
private Map<Integer, String> inviteMails = new HashMap<>();
public String getUserTextCode() {
return barcodeBean.getUserTextCode(user);
}
public ListDataModel<GroupMembership> getGroupMemberships() {
memberlist = new ListDataModel<GroupMembership>(placegroupBean.findMembershipPrintlistForUser(user));
return memberlist;
}
public String getMapFieldsetStyle() {
Integer width = placeBean.getActiveMap().getWidth();
if(width == null || width < 100)
return "";
return "width: " + (width+100) + "px;";
}
}
......@@ -5,6 +5,7 @@ import java.util.Map;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -15,25 +16,27 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.QueueBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.exceptions.BortalCatchableException;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.map.MapReservationQueueEntry;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.user.UserView;
@Named
@ConversationScoped
@RequestScoped
public class AjaxMapView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 8203589456357519480L;
@Inject
private PlaceView placeview;
// @Inject
// private PlaceView placeview;
private static final Logger logger = LoggerFactory.getLogger(AjaxMapView.class);;
private String testVal = "Testval1";
......@@ -53,6 +56,9 @@ public class AjaxMapView extends GenericCDIView {
@Inject
private UserView userview;
@EJB
private QueueBeanLocal quebean;
public void initReserveMap() {
initMap();
map = placebean.findMap(mapId);
......@@ -62,6 +68,26 @@ public class AjaxMapView extends GenericCDIView {
initMap();
}
private Boolean queEnabled = null;
private MapReservationQueueEntry queueEntry;
public boolean isQueueEnabled() {
if (queEnabled == null)
queEnabled = quebean.isQueueEnabled();
return queEnabled;
}
public String enterQueue()
{
logger.info("Entering queue");
if (isQueueEnabled())
queueEntry = quebean.enterQueue(initMap(), permbean.getCurrentUser());
else {
logger.warn("QueueNot enabled. Not entering queue");
}
return null;
}
private EventMap initMap() {
if (map == null && mapId != null) {
map = placebean.findMap(mapId);
......@@ -78,31 +104,50 @@ public class AjaxMapView extends GenericCDIView {
}
}
}
return map;
}
public Integer getQueuePosition() {
return quebean.getQueuePosition(initMap(), permbean.getCurrentUser());
}
public Long getPlacesLeftToSelect() {
Long ret = placebean.selectablePlaceCount(initMap());
logger.debug("Got {} places left for map {}", ret, initMap());
return ret;
}
public Long getAvailablePlaces() {
Long ret = placebean.availablePlaceCount(initMap());
// logger.debug("Got {} availbale places for map {}", ret, initMap());
// logger.debug("Got {} availbale places for map {}", ret, initMap());
return ret;
}
public void checkReserving() {
}
public boolean isReserving()
{
return quebean.isReserving(initMap(), permbean.getCurrentUser());
}
public boolean canUserBuy() {
return permbean.hasPermission(MapPermission.BUY_PLACES);
return permbean.hasPermission(MapPermission.BUY_PLACES) &&
(permbean.hasPermission(MapPermission.MANAGE_OTHERS) ||
quebean.isReserving(initMap(), permbean.getCurrentUser())
);
}
public String buySelectedPlaces() {
try {
EventUser user = userview.getSelectedUser();
placebean.buySelectedPlaces(user);
quebean.remove(initMap(), user);
return "/place/myGroups";
} catch (BortalCatchableException e) {
addFaceMessage("mapView.errorWhileBuyingPlaces");
......@@ -163,4 +208,12 @@ public class AjaxMapView extends GenericCDIView {
public void setContext(FacesContext context) {
this.context = context;
}
public MapReservationQueueEntry getQueueEntry() {
return queueEntry;
}
public void setQueueEntry(MapReservationQueueEntry queueEntry) {
this.queueEntry = queueEntry;
}
}
......@@ -29,13 +29,11 @@ import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.*;
import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.shop.InviteView;
......@@ -62,6 +60,9 @@ public class PlacegroupView extends GenericCDIView {
@EJB
UserBeanLocal userBean;
@EJB
EventBeanLocal eventBean;
@Inject
private InviteView inviteView;
......@@ -83,6 +84,9 @@ public class PlacegroupView extends GenericCDIView {
}
public boolean isUseEticket() {
return eventBean.getPropertyBoolean(LanEventPropertyKey.USE_ETICKET);
}
public boolean isCanModifyCurrent() {
GroupMembership row = memberlist.getRowData();
......
......@@ -58,7 +58,8 @@ public class PasswordView extends GenericCDIView {
boolean mod = permbean.hasPermission(UserPermission.MODIFY);
if (permbean.isCurrentUser(user) || mod) {
logger.debug("foo {}, {}", mod, user.checkPassword(oldPassword));
if (!mod && !user.checkPassword(oldPassword)) {
if (!user.checkPassword(oldPassword)) {
super.addFaceMessage("userview.oldPasswordError");
} else if (password == null || !password.equals(passwordcheck)) {
super.addFaceMessage("userview.passwordsDontMatch");
......
......@@ -455,3 +455,15 @@ submenu.tournaments.admin.index=
submenu.bill.billSummary=
placegroupview.reservationProduct=
bill.isNoPaid=Maksamatta
product.expired=Vanhentuneet
product.edit=
etickets.title=Lippusi
etickets.place=Paikka
etickets.user=Paikan omistaja
etickets.product=Lippu
etickets.placeinfo=Paikkatiedot
etickets.eticketcode=Lippu
etickets.placemap=Paikat kartalla
placegroup.showEticket=N\u00E4yt\u00E4 lippu
mapView.enterQueue=Liity jonoon
mapView.check=P\u00E4ivit\u00E4 jonopaikka
......@@ -1645,3 +1645,14 @@ invite.userLoginSuccessfull=Invite accepted successfully
invite.userLoginUnSuccessfull=Login unsuccessfull
placegroupview.placetransferred=Place is transferred
bill.isNoPaid=Not paid
product.expired=Expired
etickets.title=Your ticket
etickets.place=Place
etickets.user=Place owner
etickets.product=Ticket
etickets.placeinfo=Placeinfo
etickets.eticketcode=Ticket
etickets.placemap=Places on map
placegroup.showEticket=Show eticket
mapView.enterQueue=Enter queue
mapView.check=Check own queuestatus
......@@ -1626,3 +1626,14 @@ invite.userLoginSuccessfull=Kutsu vastaanotettu onnistuneesti
invite.userLoginUnSuccessfull=Kirjautuminen ep\u00E4onnistui
placegroupview.placetransferred=Paikka on annettu eteenp\u00E4in.
bill.isNoPaid=Maksamatta
product.expired=Vanhentuneet
etickets.title=Lippusi
etickets.place=Paikka
etickets.user=Paikan omistaja
etickets.product=Lippu
etickets.placeinfo=Paikkatiedot
etickets.eticketcode=Lippu
etickets.placemap=Paikat kartalla
placegroup.showEticket=N\u00E4yt\u00E4 lippu
mapView.enterQueue=Liity jonoon
mapView.check=P\u00E4ivit\u00E4 jonopaikka
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!