Commit 312eff24 by Tuomas Riihimäki

Added per event object counter to EventChildGenericFacade. Created some placemap required functions

1 parent 8fab60f7
...@@ -138,7 +138,7 @@ public class PlaceMapBean implements PlaceMapBeanLocal { ...@@ -138,7 +138,7 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
return "/PlaceMap" + parameters; return "/PlaceMap" + parameters;
} }
public int selectablePlaceCount(User user, Event currentEvent) { public long selectablePlaceCount(User user, Event currentEvent) {
throw new UnsupportedOperationException("Not supported yet."); return placeFacade.count(currentEvent);
} }
} }
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.model.Event;
import fi.insomnia.bortal.model.EventChildInterface; import fi.insomnia.bortal.model.EventChildInterface;
import fi.insomnia.bortal.model.EventPk; import fi.insomnia.bortal.model.EventPk;
...@@ -17,14 +23,25 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> ext ...@@ -17,14 +23,25 @@ public abstract class EventChildGenericFacade<T extends EventChildInterface> ext
} }
private static final Logger logger = LoggerFactory.getLogger(EventChildGenericFacade.class); private static final Logger logger = LoggerFactory.getLogger(EventChildGenericFacade.class);
public T find(Integer eventId, Integer id) { public T find(Integer eventId, Integer id) {
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); logger.debug("Fetching object {} with key {}", this.getEntityClass(), pk);
return find(pk); return find(pk);
} }
public long count(Event e) {
CriteriaBuilder builder = getEm().getCriteriaBuilder();
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<T> entity = query.from(getEntityClass());
query.where(builder.equal(entity.get("id").get("eventId"), e.getId())).select(getEm().getCriteriaBuilder().count(entity));
TypedQuery<Long> q = getEm().createQuery(query);
return q.getSingleResult();
}
} }
...@@ -21,7 +21,7 @@ public interface PlaceMapBeanLocal { ...@@ -21,7 +21,7 @@ public interface PlaceMapBeanLocal {
void printPlaceMapToStream(OutputStream outputStream, String filetype, Event event, Integer mapId, List<Integer> placeIds) throws EjbPermissionDeniedException,IOException; void printPlaceMapToStream(OutputStream outputStream, String filetype, Event event, Integer mapId, List<Integer> placeIds) throws EjbPermissionDeniedException,IOException;
public String getSelectPlaceMapUrl(EventMap activeMap, List<Place> selectedPlaces, User user); public String getSelectPlaceMapUrl(EventMap activeMap, List<Place> selectedPlaces, User user);
public int selectablePlaceCount(User user, Event currentEvent); public long selectablePlaceCount(User user, Event currentEvent);
// public EventMap findMap(int i); // public EventMap findMap(int i);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<h:form> <h:form>
<h:commandButton image="#{mapView.selectPlaceMapUrl}" actionListener="#{mapView.placeSelectActionListener}" /> <h:commandButton image="#{mapView.selectPlaceMapUrl}" actionListener="#{mapView.placeSelectActionListener}" />
<h:outputText value="#{i18n['placeSelect.left']}: #{mapView.placeLeftToSelect}" /> <h:outputText value="#{i18n['placeSelect.left']}: #{mapView.placeLeftToSelect()}" />
</h:form> </h:form>
......
...@@ -126,7 +126,7 @@ public class MapView { ...@@ -126,7 +126,7 @@ public class MapView {
} }
public String placeLeftToSelect() { public String placeLeftToSelect() {
int totalPlaces = placeMapBean.selectablePlaceCount(sessionHandler.getUser(), sessionHandler.getCurrentEvent()); long totalPlaces = placeMapBean.selectablePlaceCount(sessionHandler.getUser(), sessionHandler.getCurrentEvent());
return (totalPlaces - selectedPlaces.size()) + ""; return (totalPlaces - selectedPlaces.size()) + "";
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!