Commit b29b2bde by Tuomas Riihimäki

Add ability to fetch all users slots

1 parent 0adebf2f
...@@ -124,4 +124,6 @@ public interface PlaceBeanLocal { ...@@ -124,4 +124,6 @@ public interface PlaceBeanLocal {
List<PlaceSlot> getFreePlaceslots(EventUser u, EventMap map); List<PlaceSlot> getFreePlaceslots(EventUser u, EventMap map);
List<PlaceSlot> getPlaceslots(EventUser user);
} }
...@@ -128,7 +128,6 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -128,7 +128,6 @@ public class PlaceBean implements PlaceBeanLocal {
@EJB @EJB
private PlaceSlotFacade placeSlotFacade; private PlaceSlotFacade placeSlotFacade;
@Override @Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS) @RolesAllowed(MapPermission.S_MANAGE_MAPS)
public Place mergeChanges(Place place) { public Place mergeChanges(Place place) {
...@@ -255,7 +254,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -255,7 +254,7 @@ public class PlaceBean implements PlaceBeanLocal {
logger.warn("Reserving place {} with placeslot {}", place, slot); logger.warn("Reserving place {} with placeslot {}", place, slot);
slot.setPlace(place); slot.setPlace(place);
slot.setUsed(new Date()); 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); logger.warn("Not enough slots to reserve place {}", place);
// Not enough slots to reserve place // Not enough slots to reserve place
return false; return false;
...@@ -615,9 +614,9 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -615,9 +614,9 @@ public class PlaceBean implements PlaceBeanLocal {
} }
PlaceSlot slot = placeSlotFacade.findSlotForPlace(place); PlaceSlot slot = placeSlotFacade.findSlotForPlace(place);
// remove also slot from place // remove also slot from place
if(slot != null) { if (slot != null) {
slot.setPlace(null); slot.setPlace(null);
place.setReserverSlot(null); place.setReserverSlot(null);
} }
...@@ -759,17 +758,15 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -759,17 +758,15 @@ public class PlaceBean implements PlaceBeanLocal {
List<GroupMembership> gmems = gmemfacade.findMemberOrCreator(user); List<GroupMembership> gmems = gmemfacade.findMemberOrCreator(user);
List<Place> places = new ArrayList<>(); 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 // places with no user belongs to creator
if(gm.getUser() == null || !printOnlyOwn) { if (gm.getUser() == null || !printOnlyOwn) {
places.add(gm.getPlaceReservation()); places.add(gm.getPlaceReservation());
} else if(user.equals(gm.getUser())) { } else if (user.equals(gm.getUser())) {
places.add(gm.getPlaceReservation()); places.add(gm.getPlaceReservation());
} }
...@@ -792,6 +789,15 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -792,6 +789,15 @@ public class PlaceBean implements PlaceBeanLocal {
throw new EJBAccessException("User " + permbean.getCurrentUser() + "tried to fetch free places for user " + user); throw new EJBAccessException("User " + permbean.getCurrentUser() + "tried to fetch free places for user " + user);
return placeSlotFacade.findFreePlaceSlots(user, map); 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; ...@@ -35,6 +35,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal; 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.EventMap_; import fi.codecrew.moya.model.EventMap_;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
...@@ -44,6 +45,7 @@ import fi.codecrew.moya.model.PlaceSlot; ...@@ -44,6 +45,7 @@ import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Place_; import fi.codecrew.moya.model.Place_;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.Product_; import fi.codecrew.moya.model.Product_;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -57,6 +59,9 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -57,6 +59,9 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
@EJB @EJB
private PlaceSlotFacade placeslotfacade; private PlaceSlotFacade placeslotfacade;
@EJB
private LoggingBeanLocal logbean;
public PlaceFacade() { public PlaceFacade() {
super(Place.class); super(Place.class);
...@@ -77,6 +82,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -77,6 +82,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
int updated = 0; int updated = 0;
for (Place p : q.getResultList()) { for (Place p : q.getResultList()) {
logger.debug("Releasing place {} at automagic timed place check.", p); logger.debug("Releasing place {} at automagic timed place check.", p);
final EventUser cu = p.getCurrentUser();
if (p.checkReleased()) { if (p.checkReleased()) {
PlaceSlot slot = placeslotfacade.findSlotForPlace(p); PlaceSlot slot = placeslotfacade.findSlotForPlace(p);
...@@ -84,6 +90,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -84,6 +90,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
slot.setPlace(null); slot.setPlace(null);
slot.setUsed(null); slot.setUsed(null);
} }
logbean.sendMessage(MoyaEventType.PLACE_ERROR, cu, "Automatically release unlocked place ", p.getName());
++updated; ++updated;
} }
} }
......
...@@ -103,6 +103,14 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> { ...@@ -103,6 +103,14 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return slot; 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) { public Long findUnusedSlotsCount(Product prod) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> q = cb.createQuery(Long.class); CriteriaQuery<Long> q = cb.createQuery(Long.class);
...@@ -161,4 +169,5 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> { ...@@ -161,4 +169,5 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return getEm().createQuery(q).getResultList(); return getEm().createQuery(q).getResultList();
} }
} }
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core" <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:f="http://java.sun.com/jsf/core"> 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> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<ui:param name="thispage" value="page.place.mygroups" /> <ui:param name="thispage" value="page.place.mygroups" />
...@@ -64,6 +69,11 @@ ...@@ -64,6 +69,11 @@
<h:inputText value="#{tokenView.token}" /> <h:inputText value="#{tokenView.token}" />
<h:commandButton id="commitbtn" action="#{tokenView.saveToken()}" value="#{i18n['placetoken.commit']}" /> <h:commandButton id="commitbtn" action="#{tokenView.saveToken()}" value="#{i18n['placetoken.commit']}" />
</h:form> </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!