Commit b29b2bde by Tuomas Riihimäki

Add ability to fetch all users slots

1 parent 0adebf2f
......@@ -124,4 +124,6 @@ public interface PlaceBeanLocal {
List<PlaceSlot> getFreePlaceslots(EventUser u, EventMap map);
List<PlaceSlot> getPlaceslots(EventUser user);
}
......@@ -128,7 +128,6 @@ public class PlaceBean implements PlaceBeanLocal {
@EJB
private PlaceSlotFacade placeSlotFacade;
@Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
public Place mergeChanges(Place place) {
......@@ -255,7 +254,7 @@ public class PlaceBean implements PlaceBeanLocal {
logger.warn("Reserving place {} with placeslot {}", place, slot);
slot.setPlace(place);
slot.setUsed(new Date());
} else if(!permbean.hasPermission(MapPermission.MANAGE_OTHERS)) { // we still can reserve places to other people
} else if (!permbean.hasPermission(MapPermission.MANAGE_OTHERS)) { // we still can reserve places to other people
logger.warn("Not enough slots to reserve place {}", place);
// Not enough slots to reserve place
return false;
......@@ -617,7 +616,7 @@ public class PlaceBean implements PlaceBeanLocal {
PlaceSlot slot = placeSlotFacade.findSlotForPlace(place);
// remove also slot from place
if(slot != null) {
if (slot != null) {
slot.setPlace(null);
place.setReserverSlot(null);
}
......@@ -759,17 +758,15 @@ public class PlaceBean implements PlaceBeanLocal {
List<GroupMembership> gmems = gmemfacade.findMemberOrCreator(user);
List<Place> places = new ArrayList<>();
for(GroupMembership gm : gmems) {
for (GroupMembership gm : gmems) {
if(gm.getPlaceReservation() != null) {
if (gm.getPlaceReservation() != null) {
// places with no user belongs to creator
if(gm.getUser() == null || !printOnlyOwn) {
if (gm.getUser() == null || !printOnlyOwn) {
places.add(gm.getPlaceReservation());
} else if(user.equals(gm.getUser())) {
} else if (user.equals(gm.getUser())) {
places.add(gm.getPlaceReservation());
}
......@@ -794,4 +791,13 @@ public class PlaceBean implements PlaceBeanLocal {
return placeSlotFacade.findFreePlaceSlots(user, map);
}
@Override
public List<PlaceSlot> getPlaceslots(EventUser user) {
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) {
throw new EJBAccessException("User " + permbean.getCurrentUser() + "tried to get slots for user " + user);
}
return placeSlotFacade.finForUser(user);
}
}
......@@ -35,6 +35,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventMap_;
import fi.codecrew.moya.model.EventUser;
......@@ -44,6 +45,7 @@ import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Place_;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.Product_;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Stateless
@LocalBean
......@@ -57,6 +59,9 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
@EJB
private PlaceSlotFacade placeslotfacade;
@EJB
private LoggingBeanLocal logbean;
public PlaceFacade() {
super(Place.class);
......@@ -77,6 +82,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
int updated = 0;
for (Place p : q.getResultList()) {
logger.debug("Releasing place {} at automagic timed place check.", p);
final EventUser cu = p.getCurrentUser();
if (p.checkReleased()) {
PlaceSlot slot = placeslotfacade.findSlotForPlace(p);
......@@ -84,6 +90,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
slot.setPlace(null);
slot.setUsed(null);
}
logbean.sendMessage(MoyaEventType.PLACE_ERROR, cu, "Automatically release unlocked place ", p.getName());
++updated;
}
}
......
......@@ -103,6 +103,14 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return slot;
}
public List<PlaceSlot> finForUser(EventUser user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PlaceSlot> q = cb.createQuery(PlaceSlot.class);
Root<PlaceSlot> root = q.from(PlaceSlot.class);
q.where(cb.equal(root.get(PlaceSlot_.bill).get(Bill_.user), user));
return getEm().createQuery(q).getResultList();
}
public Long findUnusedSlotsCount(Product prod) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> q = cb.createQuery(Long.class);
......@@ -161,4 +169,5 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return getEm().createQuery(q).getResultList();
}
}
<!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:c="http://java.sun.com/jsp/jstl/core"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:f="http://java.sun.com/jsf/core">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<ui:param name="thispage" value="page.place.mygroups" />
......@@ -65,6 +70,11 @@
<h:commandButton id="commitbtn" action="#{tokenView.saveToken()}" value="#{i18n['placetoken.commit']}" />
</h:form>
<h2>Place slots</h2>
<p:dataTable var="slot" value="#{placeGroupView.placeslots}>
</p:dataTable>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!