Commit 684279e7 by Tuukka Kivilahti

Merge branch 'master' of codecrew.fi:codecrew/moya into calendarForLectures

2 parents 620e1532 8c4347c3
...@@ -79,7 +79,7 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -79,7 +79,7 @@ public class BootstrapBean implements BootstrapBeanLocal {
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"alter table compos add hidden boolean default false not null" "alter table compos add hidden boolean default false not null"
}); });
dbUpdates.add(alterTables("ADD COLUMN meta json", dbUpdates.add(alterTables("ADD COLUMN meta json",
"account_events", "account_events",
"actionlog_message_responses", "actionlog_message_responses",
...@@ -151,49 +151,47 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -151,49 +151,47 @@ public class BootstrapBean implements BootstrapBeanLocal {
"user_notes", "user_notes",
"users")); "users"));
dbUpdates.add(new String[] { "CREATE TABLE network_associations (id SERIAL NOT NULL, create_time TIMESTAMPTZ NOT NULL, ip TEXT, mac TEXT, meta TEXT, modify_time TIMESTAMPTZ NOT NULL, status TEXT NOT NULL, event INTEGER, event_user INTEGER, place INTEGER, PRIMARY KEY (id))" });
dbUpdates.add(new String[]{"CREATE TABLE network_associations (id SERIAL NOT NULL, create_time TIMESTAMPTZ NOT NULL, ip TEXT, mac TEXT, meta TEXT, modify_time TIMESTAMPTZ NOT NULL, status TEXT NOT NULL, event INTEGER, event_user INTEGER, place INTEGER, PRIMARY KEY (id))"});
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"CREATE TABLE card_text_data (id SERIAL NOT NULL, font_name TEXT NOT NULL, font_style INTEGER NOT NULL, size INTEGER NOT NULL, text TEXT, text_alignment TEXT NOT NULL, card_text_data_type TEXT NOT NULL, x INTEGER NOT NULL, y INTEGER NOT NULL, z_index INTEGER NOT NULL, PRIMARY KEY (id));" "CREATE TABLE card_text_data (id SERIAL NOT NULL, font_name TEXT NOT NULL, font_style INTEGER NOT NULL, size INTEGER NOT NULL, text TEXT, text_alignment TEXT NOT NULL, card_text_data_type TEXT NOT NULL, x INTEGER NOT NULL, y INTEGER NOT NULL, z_index INTEGER NOT NULL, PRIMARY KEY (id));"
}); });
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"CREATE TABLE card_object_data (id SERIAL NOT NULL, card_object_data_type TEXT NOT NULL, size INTEGER NOT NULL, x INTEGER NOT NULL, y INTEGER NOT NULL, z_index INTEGER NOT NULL, PRIMARY KEY (id));" "CREATE TABLE card_object_data (id SERIAL NOT NULL, card_object_data_type TEXT NOT NULL, size INTEGER NOT NULL, x INTEGER NOT NULL, y INTEGER NOT NULL, z_index INTEGER NOT NULL, PRIMARY KEY (id));"
}); });
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"ALTER TABLE card_text_data ADD COLUMN card_templates_id integer REFERENCES card_templates(id) DEFAULT null;", "ALTER TABLE card_text_data ADD COLUMN card_templates_id integer REFERENCES card_templates(id) DEFAULT null;",
"ALTER TABLE card_object_data ADD COLUMN card_templates_id integer REFERENCES card_templates(id) DEFAULT null;" "ALTER TABLE card_object_data ADD COLUMN card_templates_id integer REFERENCES card_templates(id) DEFAULT null;"
}); });
dbUpdates.add(alterTables("ADD COLUMN meta json", dbUpdates.add(alterTables("ADD COLUMN meta json",
"card_text_data", "card_text_data",
"card_object_data" "card_object_data"
)); ));
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"ALTER TABLE card_text_data ADD COLUMN font_color_r integer DEFAULT 0;", "ALTER TABLE card_text_data ADD COLUMN font_color_r integer DEFAULT 0;",
"ALTER TABLE card_text_data ADD COLUMN font_color_g integer DEFAULT 0;", "ALTER TABLE card_text_data ADD COLUMN font_color_g integer DEFAULT 0;",
"ALTER TABLE card_text_data ADD COLUMN font_color_b integer DEFAULT 0;" "ALTER TABLE card_text_data ADD COLUMN font_color_b integer DEFAULT 0;"
}); });
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"ALTER TABLE card_text_data ALTER COLUMN size TYPE numeric(5,2);", "ALTER TABLE card_text_data ALTER COLUMN size TYPE numeric(5,2);",
"ALTER TABLE card_object_data ALTER COLUMN size TYPE numeric(5,2);" "ALTER TABLE card_object_data ALTER COLUMN size TYPE numeric(5,2);"
}); });
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"ALTER TABLE card_text_data DROP COLUMN font_style;", "ALTER TABLE card_text_data DROP COLUMN font_style;",
"ALTER TABLE card_text_data ADD COLUMN font_style TEXT NOT NULL DEFAULT 'PLAIN';" "ALTER TABLE card_text_data ADD COLUMN font_style TEXT NOT NULL DEFAULT 'PLAIN';"
}); });
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"ALTER TABLE event_log RENAME log_id TO id;" "ALTER TABLE event_log RENAME log_id TO id;"
}); });
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"ALTER TABLE network_associations ALTER COLUMN meta TYPE json USING (meta::json);" "ALTER TABLE network_associations ALTER COLUMN meta TYPE json USING (meta::json);"
}); });
dbUpdates.add(new String[] { "CREATE TABLE lecture_groups (id SERIAL NOT NULL, event_id integer NOT NULL, description TEXT, name TEXT, select_count INTEGER, meta json, PRIMARY KEY (id))",
dbUpdates.add(new String[] {"CREATE TABLE lecture_groups (id SERIAL NOT NULL, event_id integer NOT NULL, description TEXT, name TEXT, select_count INTEGER, meta json, PRIMARY KEY (id))",
"CREATE TABLE lectures (id SERIAL NOT NULL, description TEXT, hours numeric(10,2), max_participants_count INTEGER, name TEXT, start_time TIMESTAMPTZ, lecture_group_id INTEGER, meta json, PRIMARY KEY (id))", "CREATE TABLE lectures (id SERIAL NOT NULL, description TEXT, hours numeric(10,2), max_participants_count INTEGER, name TEXT, start_time TIMESTAMPTZ, lecture_group_id INTEGER, meta json, PRIMARY KEY (id))",
"CREATE TABLE lecture_roles (role_id INTEGER NOT NULL, lecture_id INTEGER NOT NULL, PRIMARY KEY (role_id, lecture_id))", "CREATE TABLE lecture_roles (role_id INTEGER NOT NULL, lecture_id INTEGER NOT NULL, PRIMARY KEY (role_id, lecture_id))",
"CREATE TABLE lecture_participants (eventuser_id INTEGER NOT NULL, lecture_id INTEGER NOT NULL, PRIMARY KEY (eventuser_id, lecture_id))", "CREATE TABLE lecture_participants (eventuser_id INTEGER NOT NULL, lecture_id INTEGER NOT NULL, PRIMARY KEY (eventuser_id, lecture_id))",
...@@ -201,9 +199,14 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -201,9 +199,14 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE lecture_roles ADD CONSTRAINT FK_lecture_roles_lecture_id FOREIGN KEY (lecture_id) REFERENCES lectures (id)", "ALTER TABLE lecture_roles ADD CONSTRAINT FK_lecture_roles_lecture_id FOREIGN KEY (lecture_id) REFERENCES lectures (id)",
"ALTER TABLE lecture_roles ADD CONSTRAINT FK_lecture_roles_role_id FOREIGN KEY (role_id) REFERENCES roles (id)", "ALTER TABLE lecture_roles ADD CONSTRAINT FK_lecture_roles_role_id FOREIGN KEY (role_id) REFERENCES roles (id)",
"ALTER TABLE lecture_participants ADD CONSTRAINT FK_lecture_participants_eventuser_id FOREIGN KEY (eventuser_id) REFERENCES event_users (id)", "ALTER TABLE lecture_participants ADD CONSTRAINT FK_lecture_participants_eventuser_id FOREIGN KEY (eventuser_id) REFERENCES event_users (id)",
"ALTER TABLE lecture_participants ADD CONSTRAINT FK_lecture_participants_lecture_id FOREIGN KEY (lecture_id) REFERENCES lectures (id)"}); "ALTER TABLE lecture_participants ADD CONSTRAINT FK_lecture_participants_lecture_id FOREIGN KEY (lecture_id) REFERENCES lectures (id)" });
dbUpdates.add(new String[] { "ALTER TABLE roles ADD COLUMN user_selectable_role boolean DEFAULT false;" }); dbUpdates.add(new String[] { "ALTER TABLE roles ADD COLUMN user_selectable_role boolean DEFAULT false;" });
dbUpdates.add(new String[] {
"ALTER TABLE group_memberships ADD COLUMN place_product INTEGER",
"ALTER TABLE group_memberships ADD CONSTRAINT FK_group_memberships_place_product FOREIGN KEY (place_product) REFERENCES products (id)"
});
} }
@EJB @EJB
......
...@@ -10,7 +10,6 @@ import java.util.ArrayList; ...@@ -10,7 +10,6 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -42,6 +41,7 @@ import com.pdfjet.TextLine; ...@@ -42,6 +41,7 @@ import com.pdfjet.TextLine;
import fi.codecrew.moya.enums.apps.MapPermission; import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission; import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.exceptions.BortalCatchableException; import fi.codecrew.moya.exceptions.BortalCatchableException;
import fi.codecrew.moya.facade.EventMapFacade;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade; import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceFacade; import fi.codecrew.moya.facade.PlaceFacade;
...@@ -107,6 +107,8 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -107,6 +107,8 @@ public class PlaceBean implements PlaceBeanLocal {
@EJB @EJB
private BarcodeBeanLocal barcodeBean; private BarcodeBeanLocal barcodeBean;
@EJB
private EventMapFacade eventMapFacade;
@Override @Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS) @RolesAllowed(MapPermission.S_MANAGE_MAPS)
...@@ -626,9 +628,9 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -626,9 +628,9 @@ public class PlaceBean implements PlaceBeanLocal {
try { try {
List<Place> places = placeFacade.findAll(); List<Place> places = placeFacade.findAll();
Collections.sort(places); Collections.sort(places);
logger.info("sorting places etc."); logger.info("sorting places etc.");
return generatePlacesPdf(width, height, font1, font1, places); return generatePlacesPdf(width, height, font1, font1, places);
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception from place pdf generation.", e); logger.error("Exception from place pdf generation.", e);
...@@ -637,4 +639,33 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -637,4 +639,33 @@ public class PlaceBean implements PlaceBeanLocal {
} }
} }
@Override
public Long selectablePlaceCount(EventMap map) {
return placeFacade.countSelectable(map);
}
@Override
public EventMap findMap(Integer mapId) {
return eventMapFacade.find(mapId);
}
@Override
public Long availablePlaceCount(EventMap map) {
return placeFacade.countAvailable(map);
}
@Override
public EventMap getActiveMap() {
LanEvent event = eventBean.getCurrentEvent();
logger.info("Current event: {}, maps {}", event, event.getEventMaps());
for (EventMap map : event.getEventMaps()) {
logger.info("Checking active map {}, is active {}", map, map.isActive());
if (map.isActive()) {
return map;
}
}
return null;
}
} }
package fi.codecrew.moya.beans;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.imageio.ImageIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.pdfjet.CoreFont;
import com.pdfjet.Image;
import com.pdfjet.ImageType;
import com.pdfjet.PDF;
import com.pdfjet.Page;
import com.pdfjet.TextLine;
import fi.codecrew.moya.facade.EventMapFacade;
import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.model.CardTemplate;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.util.MassPrintResult;
/**
* Session Bean implementation class PlaceMapBean
*/
@Stateless
public class PlaceMapBean implements PlaceMapBeanLocal {
/**
* Default constructor.
*/
public PlaceMapBean() {
// TODO Auto-generated constructor stub
}
@EJB
private PlaceFacade placeFacade;
@EJB
// private EventMapBean eventmapBean;
private EventMapFacade eventMapFacade;
@EJB
private EventBeanLocal eventbean;
private static final Logger logger = LoggerFactory.getLogger(PlaceMapBean.class);
@Override
public Long selectablePlaceCount(EventMap map) {
return eventMapFacade.countSelectable(map);
}
@Override
public EventMap findMap(Integer mapId) {
return eventMapFacade.find(mapId);
}
@Override
public Long availablePlaceCount(EventMap map) {
return eventMapFacade.countAvailable(map);
}
@Override
public EventMap getActiveMap() {
LanEvent event = eventbean.getCurrentEvent();
logger.info("Current event: {}, maps {}", event, event.getEventMaps());
for (EventMap map : event.getEventMaps()) {
logger.info("Checking active map {}, is active {}", map, map.isActive());
if (map.isActive()) {
return map;
}
}
return null;
}
}
...@@ -28,8 +28,11 @@ import fi.codecrew.moya.enums.apps.UserPermission; ...@@ -28,8 +28,11 @@ import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.AccountEventFacade; import fi.codecrew.moya.facade.AccountEventFacade;
import fi.codecrew.moya.facade.BillLineFacade; import fi.codecrew.moya.facade.BillLineFacade;
import fi.codecrew.moya.facade.DiscountFacade; import fi.codecrew.moya.facade.DiscountFacade;
import fi.codecrew.moya.facade.EventMapFacade;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.InventoryEventFacade; import fi.codecrew.moya.facade.InventoryEventFacade;
import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.facade.ProductFacade; import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.facade.UserFacade; import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.AccountEvent; import fi.codecrew.moya.model.AccountEvent;
...@@ -107,6 +110,14 @@ public class ProductBean implements ProductBeanLocal { ...@@ -107,6 +110,14 @@ public class ProductBean implements ProductBeanLocal {
@EJB @EJB
private CardTemplateBean cardTemplateBean; private CardTemplateBean cardTemplateBean;
@EJB
private PlaceFacade placeFacade;
@EJB
private EventMapFacade mapfacade;
@EJB
private GroupMembershipFacade gmfacade;
private static final Logger logger = LoggerFactory.getLogger(ProductBean.class); private static final Logger logger = LoggerFactory.getLogger(ProductBean.class);
/** /**
...@@ -188,6 +199,15 @@ public class ProductBean implements ProductBeanLocal { ...@@ -188,6 +199,15 @@ public class ProductBean implements ProductBeanLocal {
return getPrivateProductLimit(product, user, prodCounts, userroles); return getPrivateProductLimit(product, user, prodCounts, userroles);
} }
/**
* Returns available products to be bought for the user.
*
* @param product
* @param user
* @param prodCounts
* @param userroles
* @return Number of buyable products
*/
private BigDecimal getPrivateProductLimit(Product product, EventUser user, Map<Integer, BigDecimal> prodCounts, Set<Role> userroles) private BigDecimal getPrivateProductLimit(Product product, EventUser user, Map<Integer, BigDecimal> prodCounts, Set<Role> userroles)
{ {
BigDecimal ret = null; BigDecimal ret = null;
...@@ -222,15 +242,26 @@ public class ProductBean implements ProductBeanLocal { ...@@ -222,15 +242,26 @@ public class ProductBean implements ProductBeanLocal {
switch (limit.getType()) switch (limit.getType())
{ {
case GLOBAL_BILLED: case PLACE: {
Long reserved = 0L;
Long available = 0L;
for (Product p : limit.getProducts()) {
reserved += gmfacade.findPlaceProductCount(p);
available += placeFacade.findCountForProduct(p);
}
ret = BigDecimal.valueOf(available - reserved).subtract(count);
break;
}
case GLOBAL_BILLED: {
BigDecimal globBillTot = BigDecimal.ZERO; BigDecimal globBillTot = BigDecimal.ZERO;
for (Product p : limit.getProducts()) { for (Product p : limit.getProducts()) {
BillSummary globBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent()); BillSummary globBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent());
globBillTot = globBillTot.add(globBilledSummary.getTotal()); globBillTot = globBillTot.add(globBilledSummary.getActive());
} }
count = count.add(globBillTot); count = count.add(globBillTot);
ret = limit.getUpperLimit().subtract(count); ret = limit.getUpperLimit().subtract(count);
break; break;
}
case GLOBAL_BILL_PAID: case GLOBAL_BILL_PAID:
BigDecimal globBillPaid = BigDecimal.ZERO; BigDecimal globBillPaid = BigDecimal.ZERO;
for (Product p : limit.getProducts()) { for (Product p : limit.getProducts()) {
...@@ -258,7 +289,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -258,7 +289,7 @@ public class ProductBean implements ProductBeanLocal {
BigDecimal userBillTot = BigDecimal.ZERO; BigDecimal userBillTot = BigDecimal.ZERO;
for (Product p : limit.getProducts()) { for (Product p : limit.getProducts()) {
BillSummary userBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user); BillSummary userBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user);
userBillTot = userBillTot.add(userBilledSummary.getTotal()); userBillTot = userBillTot.add(userBilledSummary.getActive());
} }
count = count.add(userBillTot); count = count.add(userBillTot);
ret = limit.getUpperLimit().subtract(count); ret = limit.getUpperLimit().subtract(count);
......
...@@ -2,13 +2,8 @@ package fi.codecrew.moya.facade; ...@@ -2,13 +2,8 @@ package fi.codecrew.moya.facade;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.model.Place_;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Place;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -18,43 +13,4 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> { ...@@ -18,43 +13,4 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
super(EventMap.class); super(EventMap.class);
} }
public Long countAvailable(EventMap map) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Place> root = cq.from(Place.class);
cq.select(cb.count(root));
cq.where(
cb.equal(root.get(Place_.map), map),
cb.isFalse(root.get(Place_.disabled))
);
return getSingleNullableResult(getEm().createQuery(cq));
}
public Long countSelectable(EventMap map) {
if (map == null) {
return null;
}
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Place> root = cq.from(Place.class);
cq.select(cb.count(root));
cq.where(
cb.equal(root.get(Place_.map), map),
cb.isNull(root.get(Place_.releaseTime)),
cb.isNull(root.get(Place_.group)),
cb.isFalse(root.get(Place_.disabled))
);
return getSingleNullableResult(getEm().createQuery(cq));
}
} }
...@@ -20,6 +20,7 @@ import fi.codecrew.moya.model.GroupMembership_; ...@@ -20,6 +20,7 @@ import fi.codecrew.moya.model.GroupMembership_;
import fi.codecrew.moya.model.PlaceGroup; import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceGroup_; import fi.codecrew.moya.model.PlaceGroup_;
import fi.codecrew.moya.model.Place_; import fi.codecrew.moya.model.Place_;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.utilities.PasswordFunctions; import fi.codecrew.moya.utilities.PasswordFunctions;
@Stateless @Stateless
...@@ -65,13 +66,13 @@ public class GroupMembershipFacade extends IntegerPkGenericFacade<GroupMembershi ...@@ -65,13 +66,13 @@ public class GroupMembershipFacade extends IntegerPkGenericFacade<GroupMembershi
// q.setParameter("token", token); // q.setParameter("token", token);
return getSingleNullableResult(getEm().createQuery(cq)); return getSingleNullableResult(getEm().createQuery(cq));
} }
public List<GroupMembership> matchByToken(String token) { public List<GroupMembership> matchByToken(String token) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<GroupMembership> cq = cb.createQuery(GroupMembership.class); CriteriaQuery<GroupMembership> cq = cb.createQuery(GroupMembership.class);
Root<GroupMembership> root = cq.from(GroupMembership.class); Root<GroupMembership> root = cq.from(GroupMembership.class);
cq.where(cb.like(root.get(GroupMembership_.inviteToken), "%"+token+"%"), cq.where(cb.like(root.get(GroupMembership_.inviteToken), "%" + token + "%"),
cb.equal(root.get(GroupMembership_.placeGroup).get(PlaceGroup_.event), eventbean.getCurrentEvent()) cb.equal(root.get(GroupMembership_.placeGroup).get(PlaceGroup_.event), eventbean.getCurrentEvent())
); );
...@@ -123,7 +124,7 @@ public class GroupMembershipFacade extends IntegerPkGenericFacade<GroupMembershi ...@@ -123,7 +124,7 @@ public class GroupMembershipFacade extends IntegerPkGenericFacade<GroupMembershi
// p.setParameter("user", user); // p.setParameter("user", user);
// return p.getResultList(); // return p.getResultList();
} }
public List<GroupMembership> findAllWithoutUser() { public List<GroupMembership> findAllWithoutUser() {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<GroupMembership> cq = cb.createQuery(GroupMembership.class); CriteriaQuery<GroupMembership> cq = cb.createQuery(GroupMembership.class);
...@@ -137,4 +138,16 @@ public class GroupMembershipFacade extends IntegerPkGenericFacade<GroupMembershi ...@@ -137,4 +138,16 @@ public class GroupMembershipFacade extends IntegerPkGenericFacade<GroupMembershi
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
public Long findPlaceProductCount(Product product) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<GroupMembership> root = cq.from(GroupMembership.class);
cq.select(cb.count(root));
cq.where(cb.equal(root.get(GroupMembership_.placeProduct), product));
return super.getSingleNullableResult(getEm().createQuery(cq));
}
} }
...@@ -22,13 +22,14 @@ import fi.codecrew.moya.model.EventUser; ...@@ -22,13 +22,14 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place; import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.Place_; import fi.codecrew.moya.model.Place_;
import fi.codecrew.moya.model.Product;
@Stateless @Stateless
@LocalBean @LocalBean
public class PlaceFacade extends IntegerPkGenericFacade<Place> { public class PlaceFacade extends IntegerPkGenericFacade<Place> {
private static final Logger logger = LoggerFactory.getLogger(PlaceFacade.class); private static final Logger logger = LoggerFactory.getLogger(PlaceFacade.class);
@EJB @EJB
EventBeanLocal eventBean; EventBeanLocal eventBean;
...@@ -127,18 +128,66 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -127,18 +128,66 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
); );
return getSingleNullableResult(getEm().createQuery(cq)); return getSingleNullableResult(getEm().createQuery(cq));
} }
public List<Place> findAll() { public List<Place> findAll() {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Place> cq = cb.createQuery(Place.class); CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(Place.class); Root<Place> root = cq.from(Place.class);
cq.where( cb.equal(root.get(Place_.map).get(EventMap_.event), eventBean.getCurrentEvent())); cq.where(cb.equal(root.get(Place_.map).get(EventMap_.event), eventBean.getCurrentEvent()));
cq.orderBy(cb.asc(root.get(Place_.name))); cq.orderBy(cb.asc(root.get(Place_.name)));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
}
public Long findCountForProduct(Product product) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Place> root = cq.from(Place.class);
cq.select(cb.count(root));
cq.where(
cb.equal(root.get(Place_.product), product),
cb.isFalse(root.get(Place_.disabled))
);
return super.getSingleNullableResult(getEm().createQuery(cq));
}
public Long countAvailable(EventMap map) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Place> root = cq.from(Place.class);
cq.select(cb.count(root));
cq.where(
cb.equal(root.get(Place_.map), map),
cb.isFalse(root.get(Place_.disabled))
);
return getSingleNullableResult(getEm().createQuery(cq));
}
public Long countSelectable(EventMap map) {
if (map == null) {
return null;
}
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Place> root = cq.from(Place.class);
cq.select(cb.count(root));
cq.where(
cb.equal(root.get(Place_.map), map),
cb.isNull(root.get(Place_.releaseTime)),
cb.isNull(root.get(Place_.group)),
cb.isFalse(root.get(Place_.disabled))
);
return getSingleNullableResult(getEm().createQuery(cq));
}
}
...@@ -72,4 +72,12 @@ public interface PlaceBeanLocal { ...@@ -72,4 +72,12 @@ public interface PlaceBeanLocal {
PlaceGroup reserveSelectedPlaces(EventUser eventuser) throws BortalCatchableException; PlaceGroup reserveSelectedPlaces(EventUser eventuser) throws BortalCatchableException;
public Long selectablePlaceCount(EventMap activeMap);
public EventMap findMap(Integer mapId);
public Long availablePlaceCount(EventMap activeMap);
public EventMap getActiveMap();
} }
package fi.codecrew.moya.beans;
import java.util.List;
import javax.ejb.Local;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Place;
@Local
public interface PlaceMapBeanLocal {
// public String getSelectPlaceMapUrl(EventMap activeMap, List<Place>
// selectedPlaces, User user);
public Long selectablePlaceCount(EventMap activeMap);
public EventMap findMap(Integer mapId);
public Long availablePlaceCount(EventMap activeMap);
public EventMap getActiveMap();
// wanha poistoon, see placebean
// public byte[] placeCodesPdf(List<Place> places);
// public List<Place> findSelectedPlaces(EventMap map);
// public EventMap findMap(int i);
}
...@@ -6,31 +6,40 @@ import fi.codecrew.moya.model.BillLine; ...@@ -6,31 +6,40 @@ import fi.codecrew.moya.model.BillLine;
public class BillSummary { public class BillSummary {
public BillSummary(String name) { public BillSummary(String name) {
this.name = name; this.name = name;
} }
private String name; private String name;
private BigDecimal total = BigDecimal.ZERO; private BigDecimal active = BigDecimal.ZERO;
private BigDecimal paid = BigDecimal.ZERO; private BigDecimal paid = BigDecimal.ZERO;
private BigDecimal expired = BigDecimal.ZERO;
public String getName() {
return name; public String getName() {
} return name;
}
public BigDecimal getTotal() {
return total; public BigDecimal getActive() {
} return active;
}
public void addLine(BillLine bl) {
total = getTotal().add(bl.getQuantity()); public void addLine(BillLine bl) {
if (bl.getBill().getPaidDate() != null) { if (bl.getBill().isExpired()) {
paid = getPaid().add(bl.getQuantity()); expired = getExpired().add(bl.getQuantity());
} } else {
} active = getActive().add(bl.getQuantity());
if (bl.getBill().getPaidDate() != null) {
public BigDecimal getPaid() { paid = getPaid().add(bl.getQuantity());
return paid; }
} }
}
public BigDecimal getPaid() {
return paid;
}
public BigDecimal getExpired() {
return expired;
}
} }
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
*/ */
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
import java.beans.Transient;
import java.util.Calendar; import java.util.Calendar;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
...@@ -54,8 +53,11 @@ public class GroupMembership extends GenericEntity { ...@@ -54,8 +53,11 @@ public class GroupMembership extends GenericEntity {
@JoinColumn(name = "place_reservation_id", referencedColumnName = "id", nullable = true, unique = true) @JoinColumn(name = "place_reservation_id", referencedColumnName = "id", nullable = true, unique = true)
private Place placeReservation; private Place placeReservation;
@ManyToOne
@JoinColumn(name = "place_product")
private Product placeProduct;
@JoinColumn(name = EVENTUSER_ID, referencedColumnName = EventUser.ID_COLUMN) @JoinColumn(name = EVENTUSER_ID, referencedColumnName = EventUser.ID_COLUMN)
@ManyToOne @ManyToOne
private EventUser user; private EventUser user;
...@@ -143,4 +145,12 @@ public class GroupMembership extends GenericEntity { ...@@ -143,4 +145,12 @@ public class GroupMembership extends GenericEntity {
public String getInviteToken() { public String getInviteToken() {
return inviteToken; return inviteToken;
} }
public Product getPlaceProduct() {
return placeProduct;
}
public void setPlaceProduct(Product placeProduct) {
this.placeProduct = placeProduct;
}
} }
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -134,9 +132,9 @@ public class Product extends GenericEntity { ...@@ -134,9 +132,9 @@ public class Product extends GenericEntity {
} }
private Product(String string) { private Product(String name) {
super(); super();
name = "----"; this.name = name;
} }
public BigDecimal getSoldCash() { public BigDecimal getSoldCash() {
......
...@@ -2,5 +2,5 @@ package fi.codecrew.moya.model; ...@@ -2,5 +2,5 @@ package fi.codecrew.moya.model;
public enum ProductLimitationType { public enum ProductLimitationType {
GLOBAL_BILLED, GLOBAL_BILL_PAID, GLOBAL_ACCOUNTEVENTS, USER_BILLED, USER_BILL_PAID, USER_ACCOUNTEVENTS, GLOBAL_BILLED, GLOBAL_BILL_PAID, GLOBAL_ACCOUNTEVENTS, USER_BILLED, USER_BILL_PAID, USER_ACCOUNTEVENTS, PLACE
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['product.boughtTotal']}" /> <h:outputText value="${i18n['product.boughtTotal']}" />
</f:facet> </f:facet>
<h:outputText value="#{sumline.total}"> <h:outputText value="#{sumline.active}">
<f:convertNumber /> <f:convertNumber />
</h:outputText> </h:outputText>
</h:column> </h:column>
...@@ -32,6 +32,14 @@ ...@@ -32,6 +32,14 @@
<f:convertNumber /> <f:convertNumber />
</h:outputText> </h:outputText>
</h:column> </h:column>
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['product.expired']}" />
</f:facet>
<h:outputText value="#{sumline.expired}">
<f:convertNumber />
</h:outputText>
</h:column>
</h:dataTable> </h:dataTable>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
...@@ -15,7 +15,6 @@ import javax.ws.rs.Produces; ...@@ -15,7 +15,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal; import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.PlaceMapBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal; import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.model.AccountEvent; import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
...@@ -29,8 +28,6 @@ import fi.codecrew.moya.rest.highcharts.HcSeriesRoot; ...@@ -29,8 +28,6 @@ import fi.codecrew.moya.rest.highcharts.HcSeriesRoot;
public class AccountEventRestView { public class AccountEventRestView {
@EJB @EJB
private PlaceMapBeanLocal placemapbean;
@EJB
private PlaceGroupBeanLocal pgbean; private PlaceGroupBeanLocal pgbean;
@EJB @EJB
private ProductBeanLocal productBean; private ProductBeanLocal productBean;
......
...@@ -24,7 +24,6 @@ import fi.codecrew.moya.beans.EventBeanLocal; ...@@ -24,7 +24,6 @@ import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.EventMapBeanLocal; import fi.codecrew.moya.beans.EventMapBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal; import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal; import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.PlaceMapBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal; import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal; import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.exceptions.BortalCatchableException; import fi.codecrew.moya.exceptions.BortalCatchableException;
...@@ -46,8 +45,6 @@ public class MapAdminView { ...@@ -46,8 +45,6 @@ public class MapAdminView {
@EJB @EJB
private EventMapBeanLocal eventmapbean; private EventMapBeanLocal eventmapbean;
@EJB @EJB
private PlaceMapBeanLocal placemapbean;
@EJB
private PlaceGroupBeanLocal pgbean; private PlaceGroupBeanLocal pgbean;
@EJB @EJB
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
...@@ -64,7 +61,7 @@ public class MapAdminView { ...@@ -64,7 +61,7 @@ public class MapAdminView {
@Path("/background/{mapId}") @Path("/background/{mapId}")
public Response getMapBg(@PathParam("mapId") Integer mapid) public Response getMapBg(@PathParam("mapId") Integer mapid)
{ {
EventMap map = placemapbean.findMap(mapid); EventMap map = placebean.findMap(mapid);
ByteArrayInputStream istream = new ByteArrayInputStream(map.getMapData()); ByteArrayInputStream istream = new ByteArrayInputStream(map.getMapData());
return Response.ok().entity(istream).type("image/jpeg").build(); return Response.ok().entity(istream).type("image/jpeg").build();
} }
...@@ -80,7 +77,7 @@ public class MapAdminView { ...@@ -80,7 +77,7 @@ public class MapAdminView {
@GET @GET
@Path("/places/{mapId}") @Path("/places/{mapId}")
public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) { public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) {
EventMap map = placemapbean.findMap(mapid); EventMap map = placebean.findMap(mapid);
PlaceRoot ret = new PlaceRoot(map); PlaceRoot ret = new PlaceRoot(map);
logger.info("returning map {} entity {}", mapid, ret); logger.info("returning map {} entity {}", mapid, ret);
return ret; return ret;
......
...@@ -13,8 +13,8 @@ import javax.ws.rs.Path; ...@@ -13,8 +13,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal; import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.PlaceMapBeanLocal;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Place; import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup; import fi.codecrew.moya.model.PlaceGroup;
...@@ -26,14 +26,14 @@ import fi.codecrew.moya.model.PlaceGroup; ...@@ -26,14 +26,14 @@ import fi.codecrew.moya.model.PlaceGroup;
public class MapRestView { public class MapRestView {
@EJB @EJB
private PlaceMapBeanLocal placemapbean; private PlaceBeanLocal placebean;
@EJB @EJB
private PlaceGroupBeanLocal pgbean; private PlaceGroupBeanLocal pgbean;
@GET @GET
@Path("/dateJson") @Path("/dateJson")
public String getAllCards() { public String getAllCards() {
EventMap map = placemapbean.getActiveMap(); EventMap map = placebean.getActiveMap();
Map<Integer, Map<Integer, Map<Integer, Integer>>> counts = new HashMap<>(); Map<Integer, Map<Integer, Map<Integer, Integer>>> counts = new HashMap<>();
......
...@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; ...@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.LoggingBeanLocal; import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceMapBeanLocal; import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.SecurityLogType; import fi.codecrew.moya.beans.SecurityLogType;
import fi.codecrew.moya.enums.apps.MapPermission; import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
...@@ -49,7 +49,7 @@ public class PlaceMap extends HttpServlet { ...@@ -49,7 +49,7 @@ public class PlaceMap extends HttpServlet {
private static final long serialVersionUID = 8769688627918936258L; private static final long serialVersionUID = 8769688627918936258L;
@EJB @EJB
private transient PlaceMapBeanLocal placemapBean; private transient PlaceBeanLocal placeBean;
@EJB @EJB
private transient PermissionBeanLocal permbean; private transient PermissionBeanLocal permbean;
...@@ -87,7 +87,7 @@ public class PlaceMap extends HttpServlet { ...@@ -87,7 +87,7 @@ public class PlaceMap extends HttpServlet {
// Integer userId = getIntegerParameter(request, // Integer userId = getIntegerParameter(request,
// PARAMETER_CURRENT_USER_ID); Tämä saadaan beaneilta. // PARAMETER_CURRENT_USER_ID); Tämä saadaan beaneilta.
EventMap map = placemapBean.findMap(mapId); EventMap map = placeBean.findMap(mapId);
logger.debug("Mapid: {}", mapId); logger.debug("Mapid: {}", mapId);
ostream = response.getOutputStream(); ostream = response.getOutputStream();
......
...@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory; ...@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal; import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.PlaceMapBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission; import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
...@@ -25,8 +24,6 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView; ...@@ -25,8 +24,6 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
public class MapView extends GenericCDIView { public class MapView extends GenericCDIView {
private static final long serialVersionUID = 2374905512998240551L; private static final long serialVersionUID = 2374905512998240551L;
@EJB
private transient PlaceMapBeanLocal placeMapBean;
@Inject @Inject
@SelectedUser @SelectedUser
...@@ -79,7 +76,7 @@ public class MapView extends GenericCDIView { ...@@ -79,7 +76,7 @@ public class MapView extends GenericCDIView {
} }
public Long getPlacesLeftToSelect() { public Long getPlacesLeftToSelect() {
Long ret = placeMapBean.selectablePlaceCount(getActiveMap()); Long ret = placeBean.selectablePlaceCount(getActiveMap());
logger.debug("Got {} places left for map {}", ret, getActiveMap()); logger.debug("Got {} places left for map {}", ret, getActiveMap());
return ret; return ret;
...@@ -88,7 +85,7 @@ public class MapView extends GenericCDIView { ...@@ -88,7 +85,7 @@ public class MapView extends GenericCDIView {
public Long getAvailablePlaces() public Long getAvailablePlaces()
{ {
Long ret = placeMapBean.availablePlaceCount(getActiveMap()); Long ret = placeBean.availablePlaceCount(getActiveMap());
logger.debug("Got {} availbale places for map {}", ret, getActiveMap()); logger.debug("Got {} availbale places for map {}", ret, getActiveMap());
return ret; return ret;
...@@ -98,7 +95,7 @@ public class MapView extends GenericCDIView { ...@@ -98,7 +95,7 @@ public class MapView extends GenericCDIView {
@Produces @Produces
public EventMap getActiveMap() { public EventMap getActiveMap() {
if (activeMap == null) { if (activeMap == null) {
activeMap = placeMapBean.getActiveMap(); activeMap = placeBean.getActiveMap();
} }
return activeMap; return activeMap;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!