Commit f5cda4a9 by Tuukka Kivilahti

Merge branch 'credittransfer' into 'master'

Credit transfer (and some other stuff)

Tuli taas vähän turhan iso, mutta

 * Käyttäjien ID export tapahtumasta käyttäjäkorin kautta
  * Puolipisteellä erotettu lista User.Id:itä
 * Käyttäjien import edellisestä exportista tapahtumaan.
 * Tehty loppuun credittisiirto tapahtumasta toiseen. ( Käyttäjäkorin kautta. )
 * Fiksailtu ja uudelleenkirjoitettu osittain käyttäjien listaus
(paginointi ja sorttaus primefacesin päälle)
 * Pieniä viilauksia tilitapahtuman esittämiseen. ( descriptionit )
 * Ei luoda ihan aina automaattisesti uutta käyttäjää tapahtumaan.
2 parents 2b2d50ee fc521ebe
Showing with 1278 additions and 764 deletions
...@@ -189,10 +189,10 @@ public class CardTemplateBean implements CardTemplateBeanLocal { ...@@ -189,10 +189,10 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
public CardTemplate getUsersCardtype(EventUser user) { public CardTemplate getUsersCardtype(EventUser user) {
Set<Role> roles = userbean.localFindUsersRoles(user); Set<Role> roles = userbean.localFindUsersRoles(user);
logger.info("Checking roles {} against {}", user, roles); // logger.info("Checking roles {} against {}", user, roles);
CardTemplate greatestTemplate = null; CardTemplate greatestTemplate = null;
for (Role listrole : roles) { for (Role listrole : roles) {
logger.info("Checking role {}", listrole); // logger.info("Checking role {}", listrole);
if (greatestTemplate == null || (listrole.getCardTemplate() != null && greatestTemplate.getPower() < listrole.getCardTemplate().getPower())) { if (greatestTemplate == null || (listrole.getCardTemplate() != null && greatestTemplate.getPower() < listrole.getCardTemplate().getPower())) {
greatestTemplate = listrole.getCardTemplate(); greatestTemplate = listrole.getCardTemplate();
} }
......
...@@ -187,8 +187,7 @@ public class EventBean implements EventBeanLocal { ...@@ -187,8 +187,7 @@ public class EventBean implements EventBeanLocal {
public LanEventProperty getProperty(LanEventPropertyKey property) { public LanEventProperty getProperty(LanEventPropertyKey property) {
return eventPropertyFacade.find(getCurrentEvent(), property); return eventPropertyFacade.find(getCurrentEvent(), property);
} }
@Override @Override
public long getPropertyLong(LanEventPropertyKey property) public long getPropertyLong(LanEventPropertyKey property)
{ {
...@@ -201,8 +200,6 @@ public class EventBean implements EventBeanLocal { ...@@ -201,8 +200,6 @@ public class EventBean implements EventBeanLocal {
} }
return ret; return ret;
} }
@Override @Override
public String getPropertyString(LanEventPropertyKey property) public String getPropertyString(LanEventPropertyKey property)
...@@ -266,4 +263,14 @@ public class EventBean implements EventBeanLocal { ...@@ -266,4 +263,14 @@ public class EventBean implements EventBeanLocal {
return ret; return ret;
} }
/**
* If you want this event, user getCurrentEvent() This method should be used
* only in special cases...
*/
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public LanEvent getEventById(Integer id) {
return eventFacade.find(id);
}
} }
...@@ -26,6 +26,8 @@ import fi.codecrew.moya.model.ApiApplicationInstance; ...@@ -26,6 +26,8 @@ import fi.codecrew.moya.model.ApiApplicationInstance;
import fi.codecrew.moya.model.ApplicationPermission; import fi.codecrew.moya.model.ApplicationPermission;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.PasswordFunctions; import fi.codecrew.moya.utilities.PasswordFunctions;
...@@ -60,6 +62,8 @@ public class JaasBean implements MoyaRealmBeanRemote { ...@@ -60,6 +62,8 @@ public class JaasBean implements MoyaRealmBeanRemote {
private ApiApplicationFacade appfacade; private ApiApplicationFacade appfacade;
@EJB @EJB
private ApiApplicationInstanceFacade appInstanceFacade; private ApiApplicationInstanceFacade appInstanceFacade;
@EJB
private EventBean eventorgbean;
public EventUser tryLogin(String username, String password) { public EventUser tryLogin(String username, String password) {
...@@ -82,7 +86,13 @@ public class JaasBean implements MoyaRealmBeanRemote { ...@@ -82,7 +86,13 @@ public class JaasBean implements MoyaRealmBeanRemote {
eventUser = null; eventUser = null;
user = null; user = null;
} }
if (user != null && eventUser == null) LanEventProperty inviteonly = eventbean.getProperty(LanEventPropertyKey.INVITE_ONLY_EVENT);
boolean createEventuser = true;
if (inviteonly != null && inviteonly.isBooleanValue()) {
createEventuser = false;
}
if (createEventuser && user != null && eventUser == null)
{ {
LanEvent event = eventbean.getCurrentEvent(); LanEvent event = eventbean.getCurrentEvent();
eventUser = new EventUser(user, event, null); eventUser = new EventUser(user, event, null);
......
...@@ -30,7 +30,7 @@ public class ProductPBean { ...@@ -30,7 +30,7 @@ public class ProductPBean {
@EJB @EJB
private PermissionBean permbean; private PermissionBean permbean;
@EJB @EJB
private DiscountBean discountBean; private DiscountBean discountBean;
@EJB @EJB
...@@ -100,10 +100,8 @@ public class ProductPBean { ...@@ -100,10 +100,8 @@ public class ProductPBean {
// discountinstancefacade.create(discInst); // discountinstancefacade.create(discInst);
accEventdiscounts.add(new DiscountInstance(ret, d)); accEventdiscounts.add(new DiscountInstance(ret, d));
} }
if (user.getAccountEvents() == null) {
user.setAccountEvents(new ArrayList<AccountEvent>()); user.addAccountevent(ret);
}
user.getAccountEvents().add(ret);
accounteventfacade.create(ret); accounteventfacade.create(ret);
logger.debug("create ac {} for user {}", ret, user.getUser()); logger.debug("create ac {} for user {}", ret, user.getUser());
// flush changes to db. // flush changes to db.
......
...@@ -155,12 +155,13 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -155,12 +155,13 @@ public class ReaderBean implements ReaderBeanLocal {
// reader is in autoproduct-mode, create dat product // reader is in autoproduct-mode, create dat product
if (reader.isAutoproduct()) { if (reader.isAutoproduct()) {
EventUser eu = userbean.getEventUser(card.getUser().getUser()); EventUser eu = userbean.getEventUser(card.getUser().getUser(), false);
AccountEvent createAc = productPBean.createAccountEvent(reader.getAutomaticProduct(), reader.getAutomaticProductCount(), eu, Calendar.getInstance()); if (eu != null) {
readerfacade.flush(); AccountEvent createAc = productPBean.createAccountEvent(reader.getAutomaticProduct(), reader.getAutomaticProductCount(), eu, Calendar.getInstance());
logger.info("Creating new accountevent from autoproduct {}", createAc); readerfacade.flush();
event.setNotes("Created automatic account event from reader. " + createAc); logger.info("Creating new accountevent from autoproduct {}", createAc);
event.setNotes("Created automatic account event from reader. " + createAc);
}
} }
event = readerEventFacade.create(event); event = readerEventFacade.create(event);
......
...@@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream; ...@@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
...@@ -20,6 +21,7 @@ import javax.annotation.security.PermitAll; ...@@ -20,6 +21,7 @@ import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.EJBAccessException; import javax.ejb.EJBAccessException;
import javax.ejb.EJBException;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
...@@ -29,18 +31,23 @@ import javax.persistence.PersistenceContext; ...@@ -29,18 +31,23 @@ import javax.persistence.PersistenceContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission; import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.AccountEventFacade;
import fi.codecrew.moya.facade.ApprovalFacade; import fi.codecrew.moya.facade.ApprovalFacade;
import fi.codecrew.moya.facade.EventFacade;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.FeedbackFacade; import fi.codecrew.moya.facade.FeedbackFacade;
import fi.codecrew.moya.facade.GameIDFacade; import fi.codecrew.moya.facade.GameIDFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade; import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade; import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.facade.RoleFacade; import fi.codecrew.moya.facade.RoleFacade;
import fi.codecrew.moya.facade.UserApprovalFacade; import fi.codecrew.moya.facade.UserApprovalFacade;
import fi.codecrew.moya.facade.UserFacade; import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.facade.UserImageFacade; import fi.codecrew.moya.facade.UserImageFacade;
import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Approval; import fi.codecrew.moya.model.Approval;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback; import fi.codecrew.moya.model.Feedback;
...@@ -51,6 +58,7 @@ import fi.codecrew.moya.model.LanEvent; ...@@ -51,6 +58,7 @@ import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEventPropertyKey; import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup; import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PrintedCard; import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame; import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
...@@ -71,6 +79,7 @@ import fi.codecrew.moya.utilities.SearchResult; ...@@ -71,6 +79,7 @@ import fi.codecrew.moya.utilities.SearchResult;
UserPermission.S_INVITE_USERS, UserPermission.S_INVITE_USERS,
UserPermission.S_MODIFY, UserPermission.S_MODIFY,
SpecialPermission.S_USER, SpecialPermission.S_USER,
EventPermission.S_MANAGE_EVENT,
}) })
public class UserBean implements UserBeanLocal { public class UserBean implements UserBeanLocal {
...@@ -129,6 +138,14 @@ public class UserBean implements UserBeanLocal { ...@@ -129,6 +138,14 @@ public class UserBean implements UserBeanLocal {
private GameIDFacade gameIDFacade; private GameIDFacade gameIDFacade;
@EJB @EJB
private ProductBeanLocal productbean; private ProductBeanLocal productbean;
@EJB
private ProductPBean productPrivateBean;
@EJB
private AccountEventFacade accountEventFacade;
@EJB
private EventFacade eventfacade;
@EJB
private ProductFacade productFacade;
@Override @Override
@RolesAllowed(UserPermission.S_VIEW_ALL) @RolesAllowed(UserPermission.S_VIEW_ALL)
...@@ -627,29 +644,31 @@ public class UserBean implements UserBeanLocal { ...@@ -627,29 +644,31 @@ public class UserBean implements UserBeanLocal {
} }
@Override @Override
public EventUser getEventUser(User user) { public EventUser getEventUser(User user, boolean create) {
if (user == null || user.getId() == null) { if (user == null || user.getId() == null) {
return null; return null;
} }
user = userFacade.find(user.getId()); user = userFacade.find(user.getId());
EventUser ret = eventUserFacade.find(user); EventUser ret = eventUserFacade.find(user);
if (ret == null)
if (create && ret == null)
{ {
ret = new EventUser(user, eventBean.getCurrentEvent(), permbean.getCurrentUser()); ret = new EventUser(user, eventBean.getCurrentEvent(), permbean.getCurrentUser());
eventUserFacade.create(ret); eventUserFacade.create(ret);
eventUserFacade.flush(); eventUserFacade.flush();
ret.setCreator(permbean.getCurrentUser());
} }
return ret; return ret;
} }
@Override @Override
public EventUser findByUserId(Integer userid) { public EventUser findByUserId(Integer userid, boolean createEventuser) {
User user = userFacade.find(userid); User user = userFacade.find(userid);
EventUser ret = null; EventUser ret = null;
if (user != null) if (user != null) {
{ ret = this.getEventUser(user, createEventuser);
ret = this.getEventUser(user);
} }
return ret; return ret;
} }
...@@ -659,9 +678,9 @@ public class UserBean implements UserBeanLocal { ...@@ -659,9 +678,9 @@ public class UserBean implements UserBeanLocal {
{ {
User user = userFacade.findByLogin(username); User user = userFacade.findByLogin(username);
EventUser ret = null; EventUser ret = null;
if (user.checkPassword(password)) if (user != null && user.checkPassword(password))
{ {
ret = this.getEventUser(user); ret = this.getEventUser(user, false);
} }
return ret; return ret;
...@@ -785,10 +804,85 @@ public class UserBean implements UserBeanLocal { ...@@ -785,10 +804,85 @@ public class UserBean implements UserBeanLocal {
public User getUser(Integer id) { public User getUser(Integer id) {
User ret = userFacade.find(id); User ret = userFacade.find(id);
if (!permbean.getCurrentUser().getUser().equals(ret) && permbean.hasPermission(UserPermission.VIEW_ALL)) { if (!permbean.getCurrentUser().getUser().equals(ret) && !permbean.hasPermission(UserPermission.VIEW_ALL)) {
throw new EJBAccessException("Tried to fetch user with id " + id + " from database without sufficient permissions"); throw new EJBAccessException("Tried to fetch user with id " + id + " from database without sufficient permissions");
} }
return ret; return ret;
} }
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public BigDecimal transferAccountSaldoFromPreviousEvent(List<User> users, LanEvent source)
{
if (source == null || users == null || users.isEmpty())
return null;
source = eventfacade.reload(source);
LanEvent destination = eventBean.getCurrentEvent();
if (!source.getOrganiser().equals(destination.getOrganiser())) {
throw new EJBException("Trying to move credits between organisations!");
}
final Calendar time = Calendar.getInstance();
final EventUser seller = permbean.getCurrentUser();
final Product dstCredprod = productbean.findCreditProduct();
final Product srcCredprod = productFacade.findProductsByPrice(BigDecimal.ONE.negate(), source).get(0);
if (!srcCredprod.getPrice().equals(dstCredprod.getPrice())) {
throw new RuntimeException("Credit prices do not match!");
}
final BigDecimal creditPrice = srcCredprod.getPrice().negate();
BigDecimal dstTotal = BigDecimal.ZERO;
for (User user : users)
{
EventUser dstUser = eventUserFacade.find(user);
EventUser srcUser = eventUserFacade.getOtherOrganisationsEventuser(dstUser.getUser(), source);
// If source user does not exist, skip over.
if (srcUser == null) {
continue;
}
BigDecimal srcBalance = srcUser.getAccountBalance();
if (srcBalance.compareTo(BigDecimal.ZERO) == 0) {
continue;
}
BigDecimal count = srcBalance.divide(creditPrice);
if (count.compareTo(BigDecimal.ZERO) < 0) {
throw new EJBException("All users should have positive balance!. User with id: " + dstUser.getUser().getId() + " has negative balance!");
}
// Negative accountevent for source user
AccountEvent srcacc = new AccountEvent(srcUser, srcCredprod, creditPrice, count.negate(), time);
srcacc.setDescription("Credits transferred to: '" + destination.getName() + "'");
srcacc.setSeller(seller);
srcUser.addAccountevent(srcacc);
accountEventFacade.create(srcacc);
AccountEvent dstacc = new AccountEvent(dstUser, dstCredprod, creditPrice, count, time);
dstacc.setDescription("Credits transferred from: '" + source.getName() + "'");
dstacc.setSeller(seller);
dstUser.addAccountevent(dstacc);
accountEventFacade.create(dstacc);
logger.info("Transferred {} credits with price {} for user {} from {} to {}", count, creditPrice, srcUser.getUser(), srcUser, dstUser);
dstTotal = dstTotal.add(dstacc.getTotal());
}
return dstTotal;
}
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public EventUser getOtherEventsEventuser(User user, LanEvent event) {
event = eventfacade.reload(event);
if (!eventBean.getCurrentEvent().getOrganiser().equals(event.getOrganiser())) {
throw new EJBAccessException("event must be organised by the organisation as this event.");
}
return eventUserFacade.getOtherOrganisationsEventuser(user, event);
}
} }
\ No newline at end of file
...@@ -13,6 +13,10 @@ import javax.persistence.criteria.CriteriaBuilder; ...@@ -13,6 +13,10 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.From;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.enums.DatabaseHasCompare; import fi.codecrew.moya.enums.DatabaseHasCompare;
...@@ -22,6 +26,7 @@ import fi.codecrew.moya.facade.callbacks.EventUserAccountSaldoPredicate; ...@@ -22,6 +26,7 @@ import fi.codecrew.moya.facade.callbacks.EventUserAccountSaldoPredicate;
import fi.codecrew.moya.facade.callbacks.EventUserPlacegroupPredicate; import fi.codecrew.moya.facade.callbacks.EventUserPlacegroupPredicate;
import fi.codecrew.moya.facade.callbacks.EventUserRolefilter; import fi.codecrew.moya.facade.callbacks.EventUserRolefilter;
import fi.codecrew.moya.facade.callbacks.EventUserSearchPredicate; import fi.codecrew.moya.facade.callbacks.EventUserSearchPredicate;
import fi.codecrew.moya.facade.callbacks.EventuserToUserWrapper;
import fi.codecrew.moya.facade.callbacks.OrderCallback; import fi.codecrew.moya.facade.callbacks.OrderCallback;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.EventUser_; import fi.codecrew.moya.model.EventUser_;
...@@ -29,6 +34,7 @@ import fi.codecrew.moya.model.LanEvent; ...@@ -29,6 +34,7 @@ import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.User_; import fi.codecrew.moya.model.User_;
import fi.codecrew.moya.util.UserSearchQuery; import fi.codecrew.moya.util.UserSearchQuery;
import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder;
import fi.codecrew.moya.utilities.SearchResult; import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.jpa.FacadeCallback; import fi.codecrew.moya.utilities.jpa.FacadeCallback;
...@@ -47,6 +53,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -47,6 +53,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
} }
private final Map<Integer, Map<String, Integer>> logincache = new HashMap<Integer, Map<String, Integer>>(); private final Map<Integer, Map<String, Integer>> logincache = new HashMap<Integer, Map<String, Integer>>();
private static final Logger logger = LoggerFactory.getLogger(EventUserFacade.class);
public EventUser findByLogin(final String login) { public EventUser findByLogin(final String login) {
LanEvent event = eventBean.getCurrentEvent(); LanEvent event = eventBean.getCurrentEvent();
...@@ -82,10 +89,13 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -82,10 +89,13 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
} }
public EventUser find(User user) { public EventUser find(User user) {
LanEvent event = eventBean.getCurrentEvent(); return getOtherOrganisationsEventuser(user, eventBean.getCurrentEvent());
EventUser ret; }
if ((ret = checkCache(user.getLogin(), event)) == null)
{ public EventUser getOtherOrganisationsEventuser(User user, LanEvent event)
{
EventUser ret = null;
if ((ret = checkCache(user.getLogin(), event)) == null) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class); CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class);
Root<EventUser> root = cq.from(EventUser.class); Root<EventUser> root = cq.from(EventUser.class);
...@@ -108,14 +118,30 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -108,14 +118,30 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
public SearchResult<EventUser> searchEventUsers(UserSearchQuery query) { public SearchResult<EventUser> searchEventUsers(UserSearchQuery query) {
ArrayList<FacadeCallback<EventUser>> callbacks = new ArrayList<FacadeCallback<EventUser>>(); ArrayList<FacadeCallback<EventUser>> callbacks = new ArrayList<FacadeCallback<EventUser>>();
callbacks.add(new OrderCallback<EventUser>(false, EventUser_.id)); CriteriaBuilder cb = getEm().getCriteriaBuilder();
callbacks.add(new EventLimiter(eventBean.getCurrentEvent()));
if (query.getSearch() != null && !query.getSearch().isEmpty()) CriteriaQuery<EventUser> listCQuery = cb.createQuery(EventUser.class);
CriteriaQuery<Long> countCQuery = cb.createQuery(Long.class);
if (query.getSort() != null)
{ {
boolean asc = false;
if (query.getSortDirection() != null) {
asc = QuerySortOrder.ASCENDING.equals(query.getSortDirection());
}
SingularAttribute<? super User, ?> sortfield = UserFacade.getUserField(query.getSort());
logger.info("Sortig with {}, asc {} ", sortfield, asc);
callbacks.add(new EventuserToUserWrapper(new OrderCallback<User>(asc, sortfield)));
} else {
callbacks.add(new OrderCallback<EventUser>(false, EventUser_.id));
}
callbacks.add(new EventLimiter(eventBean.getCurrentEvent()));
if (query.getSearch() != null && !query.getSearch().isEmpty()) {
callbacks.add(new EventUserSearchPredicate(query.getSearch(), UserFacade.getAttrlist())); callbacks.add(new EventUserSearchPredicate(query.getSearch(), UserFacade.getAttrlist()));
} }
if (query.isPlaceAssoc()) if (query.isPlaceAssoc()) {
{
callbacks.add(new EventUserPlacegroupPredicate()); callbacks.add(new EventUserPlacegroupPredicate());
} }
if (query.getFilterRoles() != null && !query.getFilterRoles().isEmpty()) { if (query.getFilterRoles() != null && !query.getFilterRoles().isEmpty()) {
...@@ -132,11 +158,6 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -132,11 +158,6 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
} }
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> listCQuery = cb.createQuery(EventUser.class);
CriteriaQuery<Long> countCQuery = cb.createQuery(Long.class);
From<?, EventUser> listRoot = searchCallbacks(listCQuery, callbacks, EventUser.class); From<?, EventUser> listRoot = searchCallbacks(listCQuery, callbacks, EventUser.class);
From<?, EventUser> countRoot = searchCallbacks(countCQuery, callbacks, EventUser.class); From<?, EventUser> countRoot = searchCallbacks(countCQuery, callbacks, EventUser.class);
......
...@@ -12,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery; ...@@ -12,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag; import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.Product_; import fi.codecrew.moya.model.Product_;
...@@ -44,11 +45,15 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> { ...@@ -44,11 +45,15 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> {
} }
public List<Product> findProductsByPrice(BigDecimal price) { public List<Product> findProductsByPrice(BigDecimal price) {
return findProductsByPrice(price, eventbean.getCurrentEvent());
}
public List<Product> findProductsByPrice(BigDecimal price, LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Product> cq = cb.createQuery(Product.class); CriteriaQuery<Product> cq = cb.createQuery(Product.class);
Root<Product> root = cq.from(Product.class); Root<Product> root = cq.from(Product.class);
cq.where(cb.equal(root.get(Product_.event), eventbean.getCurrentEvent()), cq.where(cb.equal(root.get(Product_.event), event),
cb.equal(root.get(Product_.price), price)); cb.equal(root.get(Product_.price), price));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
......
...@@ -15,12 +15,13 @@ import javax.persistence.metamodel.SingularAttribute; ...@@ -15,12 +15,13 @@ import javax.persistence.metamodel.SingularAttribute;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.facade.callbacks.OrderCallback; import fi.codecrew.moya.facade.callbacks.OrderCallback;
import fi.codecrew.moya.facade.callbacks.StringSearchPredicateCreator; import fi.codecrew.moya.facade.callbacks.StringSearchPredicateCreator;
import fi.codecrew.moya.model.User_;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.User_;
import fi.codecrew.moya.utilities.SearchQuery; import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder;
import fi.codecrew.moya.utilities.SearchResult; import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.jpa.FacadeCallback; import fi.codecrew.moya.utilities.jpa.FacadeCallback;
...@@ -102,11 +103,11 @@ public class UserFacade extends IntegerPkGenericFacade<User> { ...@@ -102,11 +103,11 @@ public class UserFacade extends IntegerPkGenericFacade<User> {
public SearchResult<User> searchAllUsers(SearchQuery search) { public SearchResult<User> searchAllUsers(SearchQuery search) {
List<FacadeCallback<User>> callbacks = new ArrayList<FacadeCallback<User>>(); List<FacadeCallback<User>> callbacks = new ArrayList<FacadeCallback<User>>();
if (search.getSort() == null || search.getSort().isEmpty()) {
callbacks.add(new OrderCallback<User>(false, User_.id)); // Ascending if null or not descending..
} else { boolean asc = search.getSortDirection() == null || !QuerySortOrder.DESCENDING.equals(search.getSortDirection());
callbacks.add(new OrderCallback<User>(false, search.getSort())); SingularAttribute<? super User, ?> sortfield = getUserField(search.getSort());
} callbacks.add(new OrderCallback<User>(asc, sortfield));
callbacks.add(new StringSearchPredicateCreator<User>(search.getSearch(), getAttrlist())); callbacks.add(new StringSearchPredicateCreator<User>(search.getSearch(), getAttrlist()));
return super.searcher(search, callbacks); return super.searcher(search, callbacks);
...@@ -142,6 +143,68 @@ public class UserFacade extends IntegerPkGenericFacade<User> { ...@@ -142,6 +143,68 @@ public class UserFacade extends IntegerPkGenericFacade<User> {
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
/**
* For example in sorting.
*
* @param fieldname
* @return By default return "id"
*/
public static SingularAttribute<? super User, ?> getUserField(String fieldname) {
SingularAttribute<? super User, ?> sort = User_.id;
if (fieldname != null)
{
switch (fieldname) {
case "created":
sort = User_.created;
break;
case "login":
sort = User_.login;
break;
case "lastname":
sort = User_.lastname;
break;
case "firstnames":
sort = User_.firstnames;
break;
case "birthday":
sort = User_.birthday;
break;
case "nick":
sort = User_.nick;
break;
case "email":
sort = User_.email;
break;
case "address":
sort = User_.address;
break;
case "zip":
sort = User_.zip;
break;
case "postalTown":
sort = User_.postalTown;
break;
case "town":
sort = User_.town;
break;
case "phone":
sort = User_.phone;
break;
case "gender":
sort = User_.gender;
break;
case "confirmTime":
sort = User_.confirmTime;
break;
case "id":
default:
sort = User_.id;
}
}
return sort;
}
// public SearchResult<User> searchEventUsers(SearchQuery query) // public SearchResult<User> searchEventUsers(SearchQuery query)
// { // {
// ArrayList<FacadeCallback<EventUser>> callbacks = new // ArrayList<FacadeCallback<EventUser>> callbacks = new
......
...@@ -5,7 +5,7 @@ import java.util.List; ...@@ -5,7 +5,7 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
...@@ -27,7 +27,7 @@ public class AndPredicateCreator<A, T extends ModelInterface> implements FacadeC ...@@ -27,7 +27,7 @@ public class AndPredicateCreator<A, T extends ModelInterface> implements FacadeC
} }
@Override @Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, T> root, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<T> root, List<Predicate> predicates) {
if (searchval == null || attributes == null || attributes.isEmpty()) { if (searchval == null || attributes == null || attributes.isEmpty()) {
return; return;
} }
......
...@@ -4,11 +4,11 @@ import java.util.List; ...@@ -4,11 +4,11 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import fi.codecrew.moya.model.EventUser_;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.EventUser_;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.utilities.jpa.FacadeCallback; import fi.codecrew.moya.utilities.jpa.FacadeCallback;
...@@ -21,7 +21,7 @@ public class EventLimiter implements FacadeCallback<EventUser> { ...@@ -21,7 +21,7 @@ public class EventLimiter implements FacadeCallback<EventUser> {
} }
@Override @Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, EventUser> root, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates) {
predicates.add(cb.equal(root.get(EventUser_.event), ev)); predicates.add(cb.equal(root.get(EventUser_.event), ev));
} }
......
...@@ -5,14 +5,14 @@ import java.util.List; ...@@ -5,14 +5,14 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.criteria.Subquery; import javax.persistence.criteria.Subquery;
import fi.codecrew.moya.model.AccountEvent_;
import fi.codecrew.moya.enums.DatabaseValueCompare; import fi.codecrew.moya.enums.DatabaseValueCompare;
import fi.codecrew.moya.model.AccountEvent; import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.AccountEvent_;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.utilities.jpa.FacadeCallback; import fi.codecrew.moya.utilities.jpa.FacadeCallback;
...@@ -27,7 +27,7 @@ public class EventUserAccountSaldoPredicate implements FacadeCallback<EventUser> ...@@ -27,7 +27,7 @@ public class EventUserAccountSaldoPredicate implements FacadeCallback<EventUser>
} }
@Override @Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, EventUser> root, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates) {
Subquery<BigDecimal> subq = cq.subquery(BigDecimal.class); Subquery<BigDecimal> subq = cq.subquery(BigDecimal.class);
Root<AccountEvent> acRoot = subq.from(AccountEvent.class); Root<AccountEvent> acRoot = subq.from(AccountEvent.class);
subq.where(cb.equal(acRoot.get(AccountEvent_.user), root)); subq.where(cb.equal(acRoot.get(AccountEvent_.user), root));
......
...@@ -4,17 +4,17 @@ import java.util.List; ...@@ -4,17 +4,17 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import fi.codecrew.moya.model.EventUser_;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.EventUser_;
import fi.codecrew.moya.utilities.jpa.FacadeCallback; import fi.codecrew.moya.utilities.jpa.FacadeCallback;
public class EventUserPlacegroupPredicate implements FacadeCallback<EventUser> { public class EventUserPlacegroupPredicate implements FacadeCallback<EventUser> {
@Override @Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, EventUser> root, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates) {
predicates.add(cb.isNotEmpty(root.get(EventUser_.groupMemberships))); predicates.add(cb.isNotEmpty(root.get(EventUser_.groupMemberships)));
} }
......
...@@ -8,7 +8,6 @@ import java.util.Set; ...@@ -8,7 +8,6 @@ import java.util.Set;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Path; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
...@@ -18,13 +17,13 @@ import org.slf4j.Logger; ...@@ -18,13 +17,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.model.AccountEvent_; import fi.codecrew.moya.model.AccountEvent_;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.EventUser_; import fi.codecrew.moya.model.EventUser_;
import fi.codecrew.moya.model.GroupMembership_; import fi.codecrew.moya.model.GroupMembership_;
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.Role_;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.Role_;
import fi.codecrew.moya.utilities.jpa.FacadeCallback; import fi.codecrew.moya.utilities.jpa.FacadeCallback;
public class EventUserRolefilter implements FacadeCallback<EventUser> { public class EventUserRolefilter implements FacadeCallback<EventUser> {
...@@ -49,7 +48,7 @@ public class EventUserRolefilter implements FacadeCallback<EventUser> { ...@@ -49,7 +48,7 @@ public class EventUserRolefilter implements FacadeCallback<EventUser> {
return checkedRoles; return checkedRoles;
} }
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, EventUser> root, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates) {
if (roles != null && !roles.isEmpty()) if (roles != null && !roles.isEmpty())
{ {
HashSet<Integer> roleids = new HashSet<Integer>(); HashSet<Integer> roleids = new HashSet<Integer>();
......
package fi.codecrew.moya.facade.callbacks;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.EventUser_;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.jpa.FacadeCallback;
public class EventuserToUserWrapper implements FacadeCallback<EventUser> {
private final FacadeCallback<User>[] callbacks;
@SafeVarargs
public EventuserToUserWrapper(FacadeCallback<User>... wrapped)
{
this.callbacks = wrapped;
}
@Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates) {
for (FacadeCallback<User> subcallback : callbacks) {
subcallback.exec(cb, cq, root.get(EventUser_.user), predicates);
}
}
}
...@@ -4,7 +4,7 @@ import java.util.List; ...@@ -4,7 +4,7 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
...@@ -25,7 +25,7 @@ public class OrPredicateCreator<A, T extends ModelInterface> implements FacadeCa ...@@ -25,7 +25,7 @@ public class OrPredicateCreator<A, T extends ModelInterface> implements FacadeCa
} }
@Override @Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, T> root, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<T> root, List<Predicate> predicates) {
if (searchstr == null || attributes == null || attributes.isEmpty()) { if (searchstr == null || attributes == null || attributes.isEmpty()) {
return; return;
} }
......
...@@ -4,11 +4,14 @@ import java.util.List; ...@@ -4,11 +4,14 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Path; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.utilities.jpa.FacadeCallback; import fi.codecrew.moya.utilities.jpa.FacadeCallback;
import fi.codecrew.moya.utilities.jpa.ModelInterface; import fi.codecrew.moya.utilities.jpa.ModelInterface;
...@@ -17,6 +20,7 @@ public class OrderCallback<T extends ModelInterface> implements FacadeCallback<T ...@@ -17,6 +20,7 @@ public class OrderCallback<T extends ModelInterface> implements FacadeCallback<T
private final SingularAttribute<? super T, ?> sort; private final SingularAttribute<? super T, ?> sort;
private final boolean asc; private final boolean asc;
private String sortstr; private String sortstr;
private static final Logger logger = LoggerFactory.getLogger(OrderCallback.class);
public OrderCallback(boolean asc, SingularAttribute<? super T, ?> sortAttr) { public OrderCallback(boolean asc, SingularAttribute<? super T, ?> sortAttr) {
sort = sortAttr; sort = sortAttr;
...@@ -31,16 +35,15 @@ public class OrderCallback<T extends ModelInterface> implements FacadeCallback<T ...@@ -31,16 +35,15 @@ public class OrderCallback<T extends ModelInterface> implements FacadeCallback<T
} }
@Override @Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, T> root, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<T> root, List<Predicate> predicates) {
Class<?> rettype = cq.getResultType(); Class<?> rettype = cq.getResultType();
// Check if returntype is entity or are we for example counting results // Check if returntype is entity or are we for example counting results
if (!ModelInterface.class.isAssignableFrom(rettype)) if (!ModelInterface.class.isAssignableFrom(rettype)) {
{
return; return;
} }
Path<?> path = null; Expression<?> path = null;
if (sort == null) { if (sort == null) {
if (sortstr == null) { if (sortstr == null) {
return; return;
...@@ -56,6 +59,9 @@ public class OrderCallback<T extends ModelInterface> implements FacadeCallback<T ...@@ -56,6 +59,9 @@ public class OrderCallback<T extends ModelInterface> implements FacadeCallback<T
if (path == null) { if (path == null) {
return; return;
} }
if (path.getJavaType().equals(String.class)) {
path = cb.lower((Expression<String>) path);
}
if (asc) { if (asc) {
cq.orderBy(cb.asc(path)); cq.orderBy(cb.asc(path));
......
...@@ -5,7 +5,6 @@ import java.util.List; ...@@ -5,7 +5,6 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Path; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
...@@ -44,7 +43,7 @@ public abstract class PathStringSearchPredicateCreator<T extends ModelInterface, ...@@ -44,7 +43,7 @@ public abstract class PathStringSearchPredicateCreator<T extends ModelInterface,
} }
@Override @Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, T> path, List<Predicate> predicates) { public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<T> path, List<Predicate> predicates) {
if (searchstr == null || attributes == null || attributes.isEmpty()) { if (searchstr == null || attributes == null || attributes.isEmpty()) {
return; return;
} }
......
...@@ -35,7 +35,9 @@ public interface EventBeanLocal { ...@@ -35,7 +35,9 @@ public interface EventBeanLocal {
List<LanEventPrivateProperty> getPrivateProperties(); List<LanEventPrivateProperty> getPrivateProperties();
LanEventPrivateProperty saveOrCreatePrivateProperty(LanEventPrivateProperty privateProperty); LanEventPrivateProperty saveOrCreatePrivateProperty(LanEventPrivateProperty privateProperty);
long getPropertyLong(LanEventPropertyKey property); long getPropertyLong(LanEventPropertyKey property);
LanEvent getEventById(Integer id);
} }
...@@ -2,6 +2,7 @@ package fi.codecrew.moya.beans; ...@@ -2,6 +2,7 @@ package fi.codecrew.moya.beans;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
...@@ -10,6 +11,7 @@ import fi.codecrew.moya.model.EventUser; ...@@ -10,6 +11,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback; import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GameID; import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame; import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
...@@ -49,7 +51,7 @@ public interface UserBeanLocal { ...@@ -49,7 +51,7 @@ public interface UserBeanLocal {
* ID of the User entity to be searcher * ID of the User entity to be searcher
* @return * @return
*/ */
EventUser findByUserId(Integer userid); EventUser findByUserId(Integer userid, boolean createEventuser);
EventUser findByEventUserId(Integer integer); EventUser findByEventUserId(Integer integer);
...@@ -72,12 +74,13 @@ public interface UserBeanLocal { ...@@ -72,12 +74,13 @@ public interface UserBeanLocal {
List<Role> findUsersRoles(EventUser u); List<Role> findUsersRoles(EventUser u);
/** /**
* NOTICE! If the user parameter is a persisted object the returned EventUser has a reloaded user, eg changes to the User object are lost! * NOTICE! If the user parameter is a persisted object the returned
* EventUser has a reloaded user, eg changes to the User object are lost!
* *
* @param user * @param user
* @return * @return
*/ */
EventUser getEventUser(User user); EventUser getEventUser(User user, boolean create);
EventUser validateUser(String username, String password); EventUser validateUser(String username, String password);
...@@ -103,4 +106,23 @@ public interface UserBeanLocal { ...@@ -103,4 +106,23 @@ public interface UserBeanLocal {
boolean isUserInRole(EventUser user, Integer roleId); boolean isUserInRole(EventUser user, Integer roleId);
EventUser getOtherEventsEventuser(User user, LanEvent event);
/**
* Transfers account saldo from previous event. Creates negative
* accountevent for source user and positive for dst user. There are few
* requirements.
* <ul>
* <li>User must be the same.
* <li>Organisation must be the same.
* <li>All users should have positive or zero balance on source event.
* </ul>
*
* @param source
* @param dst
* @return Saldo transferred. Zero if no transfer was made, Null if there
* was error..
*/
BigDecimal transferAccountSaldoFromPreviousEvent(List<User> dstEventuser, LanEvent source);
} }
...@@ -30,208 +30,211 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -30,208 +30,211 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS) @OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class AccountEvent extends GenericEntity { public class AccountEvent extends GenericEntity {
private static final long serialVersionUID = 2588419823225148100L; private static final long serialVersionUID = 2588419823225148100L;
@Column(name = "cash", nullable = false) @Column(name = "cash", nullable = false)
private boolean cash = false; private boolean cash = false;
/** /**
* What 1 unit of this product costs. * What 1 unit of this product costs.
*/ */
@Column(name = "unit_price", nullable = false, precision = 24, scale = 4) @Column(name = "unit_price", nullable = false, precision = 24, scale = 4)
private BigDecimal unitPrice; private BigDecimal unitPrice;
/** /**
* The units of the product, eg 1.345 (l), 5 (units) 888.32 (g).. * The units of the product, eg 1.345 (l), 5 (units) 888.32 (g)..
*/ */
@Column(name = "quantity", nullable = false, precision = 24, scale = 4) @Column(name = "quantity", nullable = false, precision = 24, scale = 4)
private BigDecimal quantity; private BigDecimal quantity;
/** /**
* The time this AccountEvent is created. * The time this AccountEvent is created.
*/ */
@Column(name = "event_time", nullable = false) @Column(name = "event_time", nullable = false)
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar eventTime = Calendar.getInstance(); private Calendar eventTime = Calendar.getInstance();
/** /**
* Is the product delivered to the user. * Is the product delivered to the user.
*/ */
@Column(name = "delivered") @Column(name = "delivered")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar delivered; private Calendar delivered;
@Column(name = "delivered_count", nullable = false, precision = 24, scale = 4) @Column(name = "delivered_count", nullable = false, precision = 24, scale = 4)
private BigDecimal deliveredCount = new BigDecimal(0); private BigDecimal deliveredCount = new BigDecimal(0);
/** /**
* If this AccountEvent is a product in foodwace, this field is a reference * If this AccountEvent is a product in foodwace, this field is a reference
* to that foodwave. * to that foodwave.
*/ */
@JoinColumn(name = "food_wave_id", referencedColumnName = FoodWave.ID_COLUMN) @JoinColumn(name = "food_wave_id", referencedColumnName = FoodWave.ID_COLUMN)
@ManyToOne @ManyToOne
private FoodWave foodWave; private FoodWave foodWave;
/** /**
* The product user has acquired and this this AccountEvent is a reference * The product user has acquired and this this AccountEvent is a reference
* to. * to.
*/ */
@JoinColumn(name = "product_id", referencedColumnName = Product.ID_COLUMN, nullable = false) @JoinColumn(name = "product_id", referencedColumnName = Product.ID_COLUMN, nullable = false)
@ManyToOne(optional = false) @ManyToOne(optional = false)
private Product product; private Product product;
/** /**
* The user that bought the products. * The user that bought the products.
*/ */
@JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false) @JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
@ManyToOne(optional = false) @ManyToOne(optional = false)
private EventUser user; private EventUser user;
/** /**
* Who sold the items to the user. * Who sold the items to the user.
*/ */
@JoinColumn(name = "seller_eventuser_id", referencedColumnName = EventUser.ID_COLUMN) @JoinColumn(name = "seller_eventuser_id", referencedColumnName = EventUser.ID_COLUMN)
@ManyToOne(optional = true) @ManyToOne(optional = true)
private EventUser seller; private EventUser seller;
/** /**
* What discounts user has for this account event. Some magic is applied to * What discounts user has for this account event. Some magic is applied to
* calculate these.. :) * calculate these.. :)
*/ */
@OneToMany(mappedBy = "accountEvent", cascade = CascadeType.ALL) @OneToMany(mappedBy = "accountEvent", cascade = CascadeType.ALL)
private List<DiscountInstance> discountInstances = new ArrayList<DiscountInstance>(); private List<DiscountInstance> discountInstances = new ArrayList<DiscountInstance>();
/** /**
* When user has paid a bill a Account event for product "Credit" is created * When user has paid a bill a Account event for product "Credit" is created
* and reference to that bill is here.. * and reference to that bill is here..
*/ */
@OneToOne(mappedBy = "accountEvent") @OneToOne(mappedBy = "accountEvent")
private Bill bill; private Bill bill;
@Lob @Lob
private String description; private String description;
public BigDecimal getTotal() { public BigDecimal getTotal() {
return getQuantity().multiply(getUnitPrice()); return getQuantity().multiply(getUnitPrice());
} }
public AccountEvent() { public AccountEvent() {
} }
public AccountEvent(EventUser u, Product prod, BigDecimal unitPrice, BigDecimal quantity, Calendar eventTime) { public AccountEvent(EventUser u, Product prod, BigDecimal unitPrice, BigDecimal quantity, Calendar eventTime) {
this.setUnitPrice(unitPrice); if (!u.getEvent().equals(prod.getEvent())) {
this.setQuantity(quantity); throw new RuntimeException("User and product are not in the same event!");
this.product = prod; }
this.eventTime = eventTime; this.setUnitPrice(unitPrice);
this.user = u; this.setQuantity(quantity);
} this.product = prod;
this.eventTime = eventTime;
public Calendar getEventTime() { this.user = u;
return eventTime; }
}
public Calendar getEventTime() {
public void setEventTime(Calendar eventTime) { return eventTime;
this.eventTime = eventTime; }
}
public void setEventTime(Calendar eventTime) {
public Calendar getDelivered() { this.eventTime = eventTime;
return delivered; }
}
public Calendar getDelivered() {
public void setDelivered(Calendar delivered) { return delivered;
this.delivered = delivered; }
}
public void setDelivered(Calendar delivered) {
public EventUser getUser() { this.delivered = delivered;
return user; }
}
public EventUser getUser() {
public void setUser(EventUser usersId) { return user;
this.user = usersId; }
}
public void setUser(EventUser usersId) {
public List<DiscountInstance> getDiscountInstances() { this.user = usersId;
return discountInstances; }
}
public List<DiscountInstance> getDiscountInstances() {
public void setDiscountInstances(List<DiscountInstance> discountInstanceList) { return discountInstances;
this.discountInstances = discountInstanceList; }
}
public void setDiscountInstances(List<DiscountInstance> discountInstanceList) {
public void setFoodWave(FoodWave foodWave) { this.discountInstances = discountInstanceList;
this.foodWave = foodWave; }
}
public void setFoodWave(FoodWave foodWave) {
public FoodWave getFoodWave() { this.foodWave = foodWave;
return foodWave; }
}
public FoodWave getFoodWave() {
public void setProduct(Product product) { return foodWave;
this.product = product; }
}
public void setProduct(Product product) {
public Product getProduct() { this.product = product;
return product; }
}
public Product getProduct() {
public void setSeller(EventUser seller) { return product;
this.seller = seller; }
}
public void setSeller(EventUser seller) {
public EventUser getSeller() { this.seller = seller;
return seller; }
}
public EventUser getSeller() {
public void setBill(Bill bill) { return seller;
this.bill = bill; }
}
public void setBill(Bill bill) {
public Bill getBill() { this.bill = bill;
return bill; }
}
public Bill getBill() {
public void setUnitPrice(BigDecimal unitPrice) { return bill;
this.unitPrice = unitPrice; }
}
public void setUnitPrice(BigDecimal unitPrice) {
public BigDecimal getUnitPrice() { this.unitPrice = unitPrice;
return unitPrice; }
}
public BigDecimal getUnitPrice() {
public void setQuantity(BigDecimal quantity) { return unitPrice;
this.quantity = quantity; }
}
public void setQuantity(BigDecimal quantity) {
public BigDecimal getQuantity() { this.quantity = quantity;
return quantity; }
}
public BigDecimal getQuantity() {
public void setCash(boolean cash) { return quantity;
this.cash = cash; }
}
public void setCash(boolean cash) {
public boolean isCash() { this.cash = cash;
return cash; }
}
public boolean isCash() {
public String getDescription() { return cash;
return description; }
}
public String getDescription() {
public void setDescription(String description) { return description;
this.description = description; }
}
public void setDescription(String description) {
public BigDecimal getDeliveredCount() { this.description = description;
return deliveredCount; }
}
public BigDecimal getDeliveredCount() {
return deliveredCount;
}
public void setDeliveredCount(BigDecimal deliveredCount) { public void setDeliveredCount(BigDecimal deliveredCount) {
this.deliveredCount = deliveredCount; this.deliveredCount = deliveredCount;
} }
public boolean isEventDelivered() { public boolean isEventDelivered() {
return (delivered != null); return (delivered != null);
} }
} }
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
public enum LanEventPropertyKey { public enum LanEventPropertyKey {
EVENT_LOGO(Type.DATA, null), EVENT_LOGO(Type.DATA, null),
INVITEMAIL_SUBJECT(Type.TEXT, "Invitation to Moya Online Youth Accumulator"), INVITEMAIL_SUBJECT(Type.TEXT, "Invitation to Moya Online Youth Accumulator"),
INVITEMAIL_CONTENT(Type.TEXT, "You have been invited to an event by {1}.\n\nYou can register to intranet at: {0}."), INVITEMAIL_CONTENT(Type.TEXT, "You have been invited to an event by {1}.\n\nYou can register to intranet at: {0}."),
BILL_PAID_MAIL_SUBJECT(Type.TEXT, "[{0}] Lasku merkitty maksetuksi"), BILL_PAID_MAIL_SUBJECT(Type.TEXT, "[{0}] Lasku merkitty maksetuksi"),
BILL_PAID_MAIL_CONTENT(Type.TEXT, "Laskusi numero {0} on merkitty maksetuksi. Voit nyt siirtyä lippukauppaan varamaan haluamasi paikat. Tervetuloa tapahtumaan!"), BILL_PAID_MAIL_CONTENT(Type.TEXT, "Laskusi numero {0} on merkitty maksetuksi. Voit nyt siirtyä lippukauppaan varamaan haluamasi paikat. Tervetuloa tapahtumaan!"),
PORTAL_EMAIL_ADDRESS(Type.TEXT, "moya@codecrew.fi"), PORTAL_EMAIL_ADDRESS(Type.TEXT, "moya@codecrew.fi"),
PORTAL_EMAIL_NAME(Type.TEXT, "Moya Online Youth Accumulator"), PORTAL_EMAIL_NAME(Type.TEXT, "Moya Online Youth Accumulator"),
ADMIN_MAIL(Type.TEXT, "moya@codecrew.fi"), ADMIN_MAIL(Type.TEXT, "moya@codecrew.fi"),
EVENT_LAYOUT(Type.TEXT, "template1"), EVENT_LAYOUT(Type.TEXT, "template1"),
SHOP_DEFAULT_CASH(Type.BOOL, null), SHOP_DEFAULT_CASH(Type.BOOL, null),
PLACECODE_FROM_USER(Type.BOOL, "1"), PLACECODE_FROM_USER(Type.BOOL, "1"),
PLACECODE_PRINT_ONLY_OWN(Type.BOOL, null), PLACECODE_PRINT_ONLY_OWN(Type.BOOL, null),
CHECK_BILL_STATS_PERMISSION(Type.BOOL, null), CHECK_BILL_STATS_PERMISSION(Type.BOOL, null),
GATHER_OTHER_BILL_INFO(Type.BOOL, null), GATHER_OTHER_BILL_INFO(Type.BOOL, null),
ALLOW_BILLING(Type.BOOL, null), ALLOW_BILLING(Type.BOOL, null),
BILL_EXPIRE_HOURS(Type.LONG, "168"), BILL_EXPIRE_HOURS(Type.LONG, "168"),
TEMPLATE_PROPERTY1(Type.TEXT, null), TEMPLATE_PROPERTY1(Type.TEXT, null),
TEMPLATE_PROPERTY2(Type.TEXT, null), TEMPLATE_PROPERTY2(Type.TEXT, null),
TEMPLATE_PROPERTY3(Type.TEXT, null), TEMPLATE_PROPERTY3(Type.TEXT, null),
TEMPLATE_PROPERTY4(Type.TEXT, null), TEMPLATE_PROPERTY4(Type.TEXT, null),
TEMPLATE_PROPERTY5(Type.TEXT, null), TEMPLATE_PROPERTY5(Type.TEXT, null),
INVITE_ONLY_EVENT(Type.BOOL, null),
; ;
private enum Type { private enum Type {
TEXT, DATE, DATA, BOOL, LONG TEXT, DATE, DATA, BOOL, LONG
}; };
private final String defaultvalue; private final String defaultvalue;
private final Type type; private final Type type;
public boolean isText() { public boolean isText() {
return Type.TEXT.equals(type); return Type.TEXT.equals(type);
} }
public boolean isDate() { public boolean isDate() {
return Type.DATE.equals(type); return Type.DATE.equals(type);
} }
public boolean isData() { public boolean isData() {
return Type.DATA.equals(type); return Type.DATA.equals(type);
} }
public boolean isBoolean() { public boolean isBoolean() {
return Type.BOOL.equals(type); return Type.BOOL.equals(type);
} }
public boolean isLong() {
return Type.LONG.equals(type);
}
private LanEventPropertyKey(Type t, String def) public boolean isLong() {
{ return Type.LONG.equals(type);
this.type = t; }
defaultvalue = def;
}
public String getDefaultvalue() { private LanEventPropertyKey(Type t, String def)
return defaultvalue; {
} this.type = t;
defaultvalue = def;
}
public Type getType() { public String getDefaultvalue() {
return type; return defaultvalue;
} }
public Type getType() {
return type;
}
} }
...@@ -4,14 +4,13 @@ import java.util.List; ...@@ -4,14 +4,13 @@ import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From; import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
public interface FacadeCallback<C extends ModelInterface> { public interface FacadeCallback<C extends ModelInterface> {
// void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<C> root, // void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<C> root,
// List<Predicate> predicates); // List<Predicate> predicates);
void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, From<?, C> root, List<Predicate> predicates); void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<C> root, List<Predicate> predicates);
} }
...@@ -2,24 +2,20 @@ ...@@ -2,24 +2,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:p="http://primefaces.org/ui"> xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:p="http://primefaces.org/ui">
<composite:interface> <composite:interface>
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<p:dataTable styleClass="bordertable" id="usertable" value="#{userSearchView.eventuserModel}" rows="20" paginator="true" lazy="true" var="user"> <p:dataTable styleClass="bordertable" id="usertable" value="#{userSearchView.eventuserModel}" rows="20" paginator="true" lazy="true" var="user">
<p:column>
<f:facet name="header"> <p:column headerText="#{i18n['user.nick']}" sortBy="nick">
<h:link value="#{i18n['user.nick']}" includeViewParams="true">
<f:param name="sort" value="nick" />
</h:link>
</f:facet>
<h:outputText styleClass="hoverable" value="#{(empty user.nick)?'----':user.nick}" /> <h:outputText styleClass="hoverable" value="#{(empty user.nick)?'----':user.nick}" />
<div class="userdata_popup"> <div class="userdata_popup">
<h:panelGrid columns="3" > <h:panelGrid columns="3">
<img style="width: 100px;" src="#{request.contextPath}/dydata/userimage/#{user.currentImage.id}.img" alt="image" /> <img style="width: 100px;" src="#{request.contextPath}/dydata/userimage/#{user.currentImage.id}.img" alt="image" />
<h:panelGroup> <h:panelGroup>
...@@ -40,7 +36,7 @@ ...@@ -40,7 +36,7 @@
<h:outputText value="#{user.email}" /> <h:outputText value="#{user.email}" />
<br /> <br />
<h:outputText value="#{i18n['user.accountBalance']}: " /> <h:outputText value="#{i18n['user.accountBalance']}: " />
<h:outputText value="#{user.accountBalance}"> <h:outputText value="#{user.accountBalance}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" /> <f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</h:outputText> </h:outputText>
...@@ -49,34 +45,23 @@ ...@@ -49,34 +45,23 @@
</div> </div>
</p:column> </p:column>
<p:column> <p:column sortBy="login" headerText="#{i18n['user.login']}">
<f:facet name="header"> <h:outputText value="#{user.login}" />
<h:link value="#{i18n['user.firstNames']}" includeViewParams="true"> </p:column>
<f:param name="sort" value="firstnames" /> <p:column headerText="#{i18n['user.firstNames']}" sortBy="firstnames">
<f:param name="page" value="0" />
</h:link>
</f:facet>
<h:outputText value="#{user.firstnames}" /> <h:outputText value="#{user.firstnames}" />
</p:column> </p:column>
<p:column> <p:column headerText="#{i18n['user.lastName']}" sortBy="lastname">
<f:facet name="header">
<h:link value="#{i18n['user.lastName']}" includeViewParams="true">
<f:param name="sort" value="lastname" />
</h:link>
</f:facet>
<h:outputText value="#{user.lastname}" /> <h:outputText value="#{user.lastname}" />
</p:column> </p:column>
<p:column> <p:column headerText="#{i18n['user.email']}" sortBy="email">
<f:facet name="header">
<h:link value="#{i18n['user.email']}" includeViewParams="true" >
<f:param name="sort" value="email" />
</h:link>
</f:facet>
<h:outputText value="#{user.email}" /> <h:outputText value="#{user.email}" />
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header">
<h:outputText value="#{i18n['userlist.searchcount']}" />: <h:outputText value="#{userSearchView.resultcount}" />
</f:facet>
<button onclick="location.replace('#{request.contextPath}/useradmin/edit.jsf?userid=#{user.user.id}')">#{i18n['user.edit']}</button> <button onclick="location.replace('#{request.contextPath}/useradmin/edit.jsf?userid=#{user.user.id}')">#{i18n['user.edit']}</button>
</p:column> </p:column>
...@@ -85,15 +70,14 @@ ...@@ -85,15 +70,14 @@
</h:column> --> </h:column> -->
</p:dataTable> </p:dataTable>
<script> <script>
jQuery(function() { jQuery(function() {
jQuery(".hoverable").hover(function () { jQuery(".hoverable").hover(function() {
jQuery(this).next().fadeIn('fast'); jQuery(this).next().fadeIn('fast');
}, }, function() {
function () { jQuery(this).next().fadeOut('fast');
jQuery(this).next().fadeOut('fast'); });
}); });
}); </script>
</script>
</composite:implementation> </composite:implementation>
</html> </html>
......
...@@ -7,69 +7,65 @@ ...@@ -7,69 +7,65 @@
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" /> <h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<p:dataTable id="user" value="#{userSearchView.results}" var="user" > <p:dataTable id="user" value="#{userSearchView.userModel}" rows="20" var="wra" paginator="true" lazy="true">
<p:column>
<f:facet name="header"> <p:column sortBy="nick" headerText="#{i18n['user.nick']}">
<h:link value="#{i18n['user.nick']}" includeViewParams="true"> <h:outputText value="#{(empty wra.user.nick)?'----':wra.user.nick}" />
<f:param name="sort" value="nick" />
<f:param name="page" value="0" />
</h:link>
</f:facet>
<h:outputText styleClass="hoverable" value="#{(empty user.nick)?'----':user.nick}" />
</p:column> </p:column>
<p:column> <p:column sortBy="login" headerText="#{i18n['user.login']}">
<f:facet name="header"> <h:outputText value="#{wra.user.login}" />
<h:link value="#{i18n['user.firstnames']}" includeViewParams="true">
<f:param name="sort" value="firstnames" />
<f:param name="page" value="0" />
</h:link>
</f:facet>
<h:outputText value="#{user.firstnames}" />
</p:column> </p:column>
<p:column>
<f:facet name="header">
<h:link value="#{i18n['user.lastName']}" includeViewParams="true">
<f:param name="sort" value="lastname" />
</h:link> <p:column headerText="#{i18n['user.firstNames']}" sortBy="firstnames">
</f:facet> <h:outputText value="#{wra.user.firstnames}" />
<h:outputText value="#{user.lastname}" /> </p:column>
<p:column headerText="#{i18n['user.lastName']}" sortBy="lastname">
<h:outputText value="#{wra.user.lastname}" />
</p:column> </p:column>
<p:column headerText="#{i18n['user.email']}" sortBy="email">
<h:outputText value="#{wra.user.email}" />
</p:column>
<p:column> <p:column>
<h:link outcome="/useradmin/edit" value="#{i18n['user.edit']}"> <f:facet name="header">
<f:param name="userid" value="#{user.id}" /> <h:outputText value="#{i18n['userlist.searchcount']}" />: <h:outputText value="#{userSearchView.resultcount}" />
</f:facet>
<h:link rendered="#{!empty wra.eventuser}" outcome="/useradmin/edit" value="#{i18n['user.edit']}">
<f:param name="userid" value="#{wra.user.id}" />
</h:link>
<h:link rendered="#{empty wra.eventuser}" outcome="/useradmin/edit" value="#{i18n['user.addToEvent']}" onclick="return confirm('#{i18n['user.confirmUserToEventAdding']}')">
<f:param name="userid" value="#{wra.user.id}" />
</h:link> </h:link>
<!-- <p:commandButton onClick="location.replace('#{request.contextPath}/useradmin/edit.jsf?userid=#{user.id}')">#{i18n['user.edit']}</p:commandButton> <!-- <p:commandButton onClick="location.replace('#{request.contextPath}/useradmin/edit.jsf?userid=#{wra.user.id}')">#{i18n['user.edit']}</p:commandButton>
<p:overlayPanel for="userinfoBtn"> <p:overlayPanel for="userinfoBtn">
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<img style="width:100px;" src="#{request.contextPath}/dydata/userimage/#{user.currentImage.id}.img" alt="image" /> <img style="width:100px;" src="#{request.contextPath}/dydata/userimage/#{wra.user.currentImage.id}.img" alt="image" />
<h:panelGroup> <h:panelGroup>
<h:outputText value="#{user.nick}"/> <br /> <h:outputText value="#{wra.user.nick}"/> <br />
<h:outputText value="#{user.firstnames} #{user.lastname}"/> <br /> <h:outputText value="#{wra.user.firstnames} #{wra.user.lastname}"/> <br />
<hr /> <hr />
<h:outputText value="#{user.address}"/> <br /> <h:outputText value="#{wra.user.address}"/> <br />
<h:outputText value="#{user.zip} #{user.postalTown}"/> <br /> <h:outputText value="#{wra.user.zip} #{wra.user.postalTown}"/> <br />
<br /> <br />
<h:outputText value="#{user.phone}"/> <br /> <h:outputText value="#{wra.user.phone}"/> <br />
<h:outputText value="#{user.email}"/> <br /> <h:outputText value="#{wra.user.email}"/> <br />
</h:panelGroup> </h:panelGroup>
</h:panelGrid> </h:panelGrid>
</p:overlayPanel> </p:overlayPanel>
--> -->
</p:column> </p:column>
<!-- <h:column> <!-- <h:column>
<h:commandButton action="#{userView.shop()}" value="#{i18n['user.shop']}" /> <h:commandButton action="#{userView.shop()}" value="#{i18n['user.shop']}" />
</h:column> --> </h:column> -->
</p:dataTable> </p:dataTable>
<script> <script>
jQuery(function() { jQuery(function() {
jQuery(".hoverable").hover(function () { jQuery(".hoverable").hover(function () {
......
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
} }
.hidden {
display: none;
}
#webcamcontainer { #webcamcontainer {
} }
.noborderTable tr,.noborderTable td {
border: none;
padding: 0 0 1px 0;
}
#shopItems { #shopItems {
} }
...@@ -77,7 +79,6 @@ a.shopItem:active { ...@@ -77,7 +79,6 @@ a.shopItem:active {
background: red; background: red;
} }
.prime-menu-selected div .prime-menu-selected div {
{ display: block;
display:block;
} }
\ No newline at end of file
...@@ -8,34 +8,31 @@ ...@@ -8,34 +8,31 @@
<ui:define name="content"> <ui:define name="content">
<h:form id="wrapform"> <h:form id="wrapform">
<h:dataTable id="tbl" border="1" value="#{importView.wrapper}" var="wra">
<h:column>
<h:selectBooleanCheckbox id="skip" value="#{wra.skip}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.login}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.firstnames}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.lastname}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.email}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.accountBalance}" />
</h:column>
<h:column>
<h:selectOneRadio id="selected" value="#{wra.selected}" layout="pageDirection" converter="#{userConverter}">
<f:selectItems var="pot" value="#{wra.potential}" itemLabel="#{pot.id}/#{pot.login}/#{pot.firstnames}/#{pot.lastname}" />
</h:selectOneRadio>
</h:column>
</h:dataTable>
<h:commandButton action="#{importView.commitImport}" value="#{i18n['userImport.commit']}" /> <h:commandButton action="#{importView.commitImport}" value="#{i18n['userImport.commit']}" />
</h:form> </h:form>
<p:dataTable id="tbl" border="1" value="#{importView.users}" var="wra">
<p:column headerText="User id">
<h:outputText value="#{wra.user.id}" />
</p:column>
<p:column headerText="Eventuser id">
<h:outputText value="#{wra.eventuser.id}" />
</p:column>
<p:column headerText="Login">
<h:outputText value="#{wra.user.login}" />
</p:column>
<p:column headerText="Firstname">
<h:outputText value="#{wra.user.firstnames}" />
</p:column>
<p:column headerText="Lastname">
<h:outputText value="#{wra.user.lastname}" />
</p:column>
<p:column headerText="Email">
<h:outputText value="#{wra.user.email}" />
</p:column>
</p:dataTable>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -12,11 +12,6 @@ ...@@ -12,11 +12,6 @@
<h:form enctype="multipart/form-data"> <h:form enctype="multipart/form-data">
<h:panelGrid columns="3"> <h:panelGrid columns="3">
<h:outputLabel for="templ" value="#{i18n['importuser.template']}" />
<h:selectOneMenu id="templ" value="#{importView.template}" converter="#{cardTemplateConverter}">
<f:selectItems value="#{importView.templates}" var="templ" itemLabel="#{templ.name}" />
</h:selectOneMenu>
<h:message for="templ" />
<h:outputLabel for="file" value="#{i18n['importuser.file']}"/> <h:outputLabel for="file" value="#{i18n['importuser.file']}"/>
<p:fileUpload id="file" value="#{importView.file}" mode="simple" /> <p:fileUpload id="file" value="#{importView.file}" mode="simple" />
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
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:users="http://java.sun.com/jsf/composite/cditools/user" <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:users="http://java.sun.com/jsf/composite/cditools/user"
xmlns:f="http://java.sun.com/jsf/core"> 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}">
<f:metadata> <f:metadata>
...@@ -19,66 +19,48 @@ ...@@ -19,66 +19,48 @@
<ui:define name="content"> <ui:define name="content">
<h:outputLabel value="#{i18n['user.accountBalance']}: " for="accountbalance" /> <h:outputLabel value="#{i18n['user.accountBalance']}: " for="accountbalance" />
<h:outputText id="accountbalance" value="#{userView.user.accountBalance}" /> <h:outputText id="accountbalance" value="#{userView.user.accountBalance}" />
<h:dataTable border="1" id="ac" value="#{userView.user.accountEvents}" var="ac">
<h:column> <p:dataTable border="1" styleClass="actable" id="ac" value="#{userView.user.accountEvents}" var="ac" rowIndexVar="rowIndex">
<f:facet name="header"> <p:column headerText="#{i18n['accountEvent.productname']}">
<h:outputText value="#{i18n['accountEvent.productname']}" /> <p:tooltip for="@(.actable tr[role=row][data-ri=#{rowIndex}])" value="This is row number #{rowIndex}" />
</f:facet>
<h:outputText value="#{ac.product.name}" /> <h:outputText value="#{ac.product.name}" />
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.quantity']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.quantity']}" />
</f:facet>
<h:outputText value="#{ac.quantity}"> <h:outputText value="#{ac.quantity}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" /> <f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.unitPrice']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.unitPrice']}" />
</f:facet>
<h:outputText value="#{ac.unitPrice}"> <h:outputText value="#{ac.unitPrice}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" /> <f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.total']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.total']}" />
</f:facet>
<h:outputText value="#{ac.total}"> <h:outputText value="#{ac.total}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" /> <f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.eventTime']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.eventTime']}" />
</f:facet>
<h:outputText value="#{ac.eventTime.time}"> <h:outputText value="#{ac.eventTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.delivered']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.delivered']}" />
</f:facet>
<h:outputText rendered="#{!empty ac.delivered}" value="#{ac.delivered.time}"> <h:outputText rendered="#{!empty ac.delivered}" value="#{ac.delivered.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.foodwave']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.foodwave']}" />
</f:facet>
<h:outputText rendered="#{!empty ac.foodWave}" value="#{ac.foodWave.name}" /> <h:outputText rendered="#{!empty ac.foodWave}" value="#{ac.foodWave.name}" />
</h:column> </p:column>
<h:column> <p:column>
<h:link outcome="/useradmin/editAccountevent" value="#{i18n['accountEvent.edit']}"> <h:link outcome="/useradmin/editAccountevent" value="#{i18n['accountEvent.edit']}">
<f:param name="id" value="#{ac.id}" /> <f:param name="id" value="#{ac.id}" />
</h:link> </h:link>
</h:column> </p:column>
</h:dataTable> </p:dataTable>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -20,19 +20,19 @@ ...@@ -20,19 +20,19 @@
<h:panelGrid columns="3"> <h:panelGrid columns="3">
<h:outputLabel for="user" value="#{i18n['accountEvent.user']}" /> <h:outputLabel for="user" value="#{i18n['accountEvent.user']}" />
<h:outputText id="user" value="#{accountEventView.accountevent.user.user.id} / #{accountEventView.accountevent.user.user.wholeName}" /> <h:outputText id="user" value="#{accountEventView.accountevent.user.user.id} / #{accountEventView.accountevent.user.user.nick} /#{accountEventView.accountevent.user.user.wholeName}" />
<h:message for="user" /> <h:message for="user" />
<h:outputLabel for="price" value="#{i18n['accountEvent.price']}" /> <h:outputLabel for="price" value="#{i18n['accountEvent.price']}" />
<h:inputText id="price" value="#{accountEventView.accountevent.unitPrice}"> <p:inputText id="price" value="#{accountEventView.accountevent.unitPrice}">
<f:convertNumber minFractionDigits="0" maxFractionDigits="4" /> <f:convertNumber minFractionDigits="0" maxFractionDigits="4" />
</h:inputText> </p:inputText>
<h:message for="price" /> <h:message for="price" />
<h:outputLabel for="quantity" value="#{i18n['accountEvent.quantity']}" /> <h:outputLabel for="quantity" value="#{i18n['accountEvent.quantity']}" />
<h:inputText id="quantity" value="#{accountEventView.accountevent.quantity}"> <p:inputText id="quantity" value="#{accountEventView.accountevent.quantity}">
<f:convertNumber minFractionDigits="0" maxFractionDigits="4" /> <f:convertNumber minFractionDigits="0" maxFractionDigits="4" />
</h:inputText> </p:inputText>
<h:message for="quantity" /> <h:message for="quantity" />
<h:outputLabel for="time" value="#{i18n['accountEvent.eventTime']}" /> <h:outputLabel for="time" value="#{i18n['accountEvent.eventTime']}" />
...@@ -43,14 +43,22 @@ ...@@ -43,14 +43,22 @@
<h:link id="fw" rendered="#{!empty accountEventView.accountevent.foodWave}" value="#{accountEventView.accountevent.foodWave.name}" outcome="/foodmanager/listOrders"> <h:link id="fw" rendered="#{!empty accountEventView.accountevent.foodWave}" value="#{accountEventView.accountevent.foodWave.name}" outcome="/foodmanager/listOrders">
<f:param name="foodwaveid" value="#{accountEventView.accountevent.foodWave.id}" /> <f:param name="foodwaveid" value="#{accountEventView.accountevent.foodWave.id}" />
</h:link> </h:link>
<h:outputText rendered="#{empty accountEventView.accountevent.foodWave}"/> <h:outputText rendered="#{empty accountEventView.accountevent.foodWave}" />
<h:message for="fw" /> <h:message for="fw" />
<h:outputLabel for="delivered" value="#{i18n['accountEvent.delivered']}" /> <h:outputLabel for="delivered" value="#{i18n['accountEvent.delivered']}" />
<p:calendar rendered="#{!empty accountEventView.accountevent.delivered}" id="delivered" value="#{accountEventView.accountevent.delivered.time}" pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <p:calendar rendered="#{!empty accountEventView.accountevent.delivered}" id="delivered" value="#{accountEventView.accountevent.delivered.time}" pattern="#{sessionHandler.datetimeFormat}"
<h:outputText rendered="#{empty accountEventView.accountevent.delivered}" /> timeZone="#{sessionHandler.timezone}" />
<h:outputText rendered="#{empty accountEventView.accountevent.delivered}" />
<h:message for="delivered" /> <h:message for="delivered" />
<h:outputLabel for="seller" value="#{i18n['accountEvent.seller']}" />
<h:outputText id="seller" value="#{accountEventView.accountevent.seller.user.nick} / #{accountEventView.accountevent.seller.user.wholeName}" />
<h:message for="seller" />
<p:outputLabel for="description" value="#{i18n['accountEvent.description']}" />
<p:inputTextarea id="description" cols="30" rows="5" value="#{accountEventView.accountevent.description}" />
<p:message for="description" />
</h:panelGrid> </h:panelGrid>
<h:commandButton action="#{accountEventView.save()}" rendered="#{accountEventView.canSave}" value="#{i18n['accountEvent.save']}" /> <h:commandButton action="#{accountEventView.save()}" rendered="#{accountEventView.canSave}" value="#{i18n['accountEvent.save']}" />
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<h1>#{i18n['userlist.header']}</h1> <h1>#{i18n['userlist.header']}</h1>
<h:form> <h:form id="pageform">
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:panelGroup> <h:panelGroup>
...@@ -51,22 +51,28 @@ ...@@ -51,22 +51,28 @@
<h:commandButton value="#{i18n['userlist.search']}" action="#{userSearchView.newSearch()}" /> <h:commandButton value="#{i18n['userlist.search']}" action="#{userSearchView.newSearch()}" />
</h:panelGroup> </h:panelGroup>
<h:panelGroup> <h:panelGroup>
<a style="display: #{((userCartView.isEmpty())?'block':'none')}" onclick="$('#usercart').show(); $(this).hide();"><h:outputText value="#{i18n['usercart.showCart']}" /></a> <a onclick="$('#pageform\\:usercart').show(); $(this).hide();"><h:outputText value="#{i18n['usercart.showCart']}" /></a>
<div id="usercart" style="display: #{((userCartView.isEmpty())?'none':'block')}">
<h:outputText value="#{i18n['usercart.cartsize']}" /> <p:panelGrid columns="1" id="usercart" styleClass="noborderTable" style="display:none;">
<h:outputText value=" #{userCartView.userCartSize}" />
<h:commandButton action="#{userCartView.clearCart()}" value="#{i18n['usercart.clear']}" />
<br />
<h:commandButton actionListener="#{userSearchView.addToCart}" value="#{i18n['usercart.addSearchedUsers']}" /> <h:commandButton actionListener="#{userSearchView.addToCart}" value="#{i18n['usercart.addSearchedUsers']}" />
<h:panelGroup>
<h:outputText value="#{i18n['usercart.cartsize']} #{userCartView.userCartSize}" />
<h:commandButton action="#{userCartView.clearCart()}" value="#{i18n['usercart.clear']}" />
</h:panelGroup>
<h:commandButton action="#{userCartView.traverse}" value="#{i18n['usercart.traverse']}" /> <h:commandButton action="#{userCartView.traverse}" value="#{i18n['usercart.traverse']}" />
<h:commandButton value="#{i18n['usercart.downloadCsv']}"> <h:commandButton value="#{i18n['usercart.downloadCsv']}">
<p:fileDownload value="#{userCartView.downloadCsv}" /> <p:fileDownload value="#{userCartView.downloadCsv}" />
</h:commandButton> </h:commandButton>
<h:commandButton value="#{i18n['usercart.downloadExport']}">
<p:fileDownload value="#{userCartView.userExport}" />
</h:commandButton>
<h:commandButton action="#{userCartView.showOverview}" value="#{i18n['usercart.showoverview']}" /> <h:commandButton action="#{userCartView.showOverview}" value="#{i18n['usercart.showoverview']}" />
</div>
<h:commandButton rendered="#{creditTransferView.transferPermissions}" action="#{userCartView.transferCredits}" value="#{i18n['usercart.transferCredits']}" />
</p:panelGrid>
</h:panelGroup> </h:panelGroup>
</h:panelGrid> </h:panelGrid>
<h:outputText value="#{i18n['userlist.searchcount']}" />: <h:outputText value="#{userSearchView.resultcount}" />
</h:form> </h:form>
<p> <p>
<users:list rendered="#{!userSearchView.searchQuery.onlyThisEvent}" /> <users:list rendered="#{!userSearchView.searchQuery.onlyThisEvent}" />
......
<!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:tools="http://java.sun.com/jsf/composite/cditools" xmlns:account="http://java.sun.com/jsf/composite/cditools/account" 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:event type="preRenderView" listener="#{userCartView.initView}" />
-->
</f:metadata>
<ui:define name="title">
<h1>#{i18n['user.creditTransfer.title']}</h1>
</ui:define>
<ui:define name="content">
<h:form>
<h:outputText value="#{i18n['creditTransferView.selectEvent']}" />
<p:selectOneMenu value="#{creditTransferView.sourceEvent}" converter="#{lanEventConverter}">
<f:selectItem itemLabel="---" />
<f:selectItems value="#{creditTransferView.events}" var="ev" itemLabel="#{ev.name}" />
</p:selectOneMenu>
<h:commandButton action="#{creditTransferView.selectEvent}" value="#{i18n['creditTransfer.selectEvent']}" />
</h:form>
<h:outputText value="#{i18n['creditTransfer.totalCredits']} #{creditTransferView.totalCredits}" />
<h:form>
<h:commandButton value="#{i18n['creditTransferView.commitTransfer']}" action="#{creditTransferView.commitTransfer}" />
<p:dataTable value="#{creditTransferView.users}" var="wrap">
<p:column headerText="#{i18n['user.nick']}">
<h:outputText value="#{wrap.user.user.nick}" />
</p:column>
<p:column headerText="#{i18n['creditTransfer.dstEventuserId']}">
<h:outputText value="#{wrap.user.id}" />
</p:column>
<p:column headerText="#{i18n['creditTransfer.srcEventuserId']}">
<h:outputText value="#{wrap.sourceEventuser.id}" />
</p:column>
<p:column headerText="#{i18n['creditTransfer.credits']}">
<h:outputText value="#{wrap.credits}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -72,7 +72,7 @@ public class HostnameFilter implements Filter { ...@@ -72,7 +72,7 @@ public class HostnameFilter implements Filter {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response, public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException { FilterChain chain) throws IOException, ServletException {
logger.info("HostnameFilter called!"); // logger.info("HostnameFilter called!");
HttpServletRequest httpRequest = null; HttpServletRequest httpRequest = null;
if (request != null && request instanceof HttpServletRequest) { if (request != null && request instanceof HttpServletRequest) {
...@@ -161,14 +161,14 @@ public class HostnameFilter implements Filter { ...@@ -161,14 +161,14 @@ public class HostnameFilter implements Filter {
protected void parseHostname(HttpServletRequest httpRequest) protected void parseHostname(HttpServletRequest httpRequest)
{ {
logger.info("Path info {}", httpRequest.getPathInfo()); // logger.info("Path info {}", httpRequest.getPathInfo());
logger.info("querystring {}", httpRequest.getQueryString()); // logger.info("querystring {}", httpRequest.getQueryString());
logger.info("ctxpath {}", httpRequest.getContextPath()); // logger.info("ctxpath {}", httpRequest.getContextPath());
logger.info("pathTranslated {}", httpRequest.getPathTranslated()); // logger.info("pathTranslated {}", httpRequest.getPathTranslated());
logger.info("requestUri {}", httpRequest.getRequestURI()); // logger.info("requestUri {}", httpRequest.getRequestURI());
logger.info("URL {}", httpRequest.getRequestURL().toString()); // logger.info("URL {}", httpRequest.getRequestURL().toString());
logger.info("servletpath {}", httpRequest.getServletPath()); // logger.info("servletpath {}", httpRequest.getServletPath());
logger.info("servletCtx {}", httpRequest.getServletContext()); // logger.info("servletCtx {}", httpRequest.getServletContext());
StringBuffer url = httpRequest.getRequestURL(); StringBuffer url = httpRequest.getRequestURL();
// logger.info("Original hostname {}", url); // logger.info("Original hostname {}", url);
// Subject subj = Subject.getSubject(AccessController.getContext()); // Subject subj = Subject.getSubject(AccessController.getContext());
......
...@@ -64,7 +64,6 @@ public class SessionHandler { ...@@ -64,7 +64,6 @@ public class SessionHandler {
String retStr = "fi_FI"; String retStr = "fi_FI";
if (ret != null) { if (ret != null) {
retStr = ret.toLanguageTag(); retStr = ret.toLanguageTag();
logger.info("Got langtag {}", retStr);
} }
return retStr; return retStr;
} }
......
...@@ -1160,6 +1160,7 @@ tournaments.tournament_type = Tournament typ ...@@ -1160,6 +1160,7 @@ tournaments.tournament_type = Tournament typ
user.accountBalance = Account balance user.accountBalance = Account balance
user.accountEventHeader = Account events user.accountEventHeader = Account events
user.accountevents = Account events user.accountevents = Account events
user.addToEvent = Associate user to event
user.address = Address user.address = Address
user.age = Age user.age = Age
user.bank = Bank user.bank = Bank
...@@ -1169,6 +1170,7 @@ user.cardPower = Usertype ...@@ -1169,6 +1170,7 @@ user.cardPower = Usertype
user.changePassword = Change password user.changePassword = Change password
user.changepassword.forUser = For user user.changepassword.forUser = For user
user.changepassword.title = Change password user.changepassword.title = Change password
user.confirmUserToEventAdding = Are you sure you want to associate this user to this event?
user.create = Create user user.create = Create user
user.createdmessage = User has been created successfully. You can now login. user.createdmessage = User has been created successfully. You can now login.
user.cropImage = Crop image user.cropImage = Crop image
......
...@@ -1145,6 +1145,7 @@ tournaments.tournament_type = Turnauksen tyy ...@@ -1145,6 +1145,7 @@ tournaments.tournament_type = Turnauksen tyy
user.accountBalance = Tilin saldo user.accountBalance = Tilin saldo
user.accountEventHeader = Tilitapahtumat user.accountEventHeader = Tilitapahtumat
user.accountevents = Tilitapahtumat user.accountevents = Tilitapahtumat
user.addToEvent = Liit\u00E4 k\u00E4ytt\u00E4j\u00E4 tapahtumaan
user.address = Osoite user.address = Osoite
user.age = Ik\u00E4 user.age = Ik\u00E4
user.bank = Pankki user.bank = Pankki
...@@ -1154,6 +1155,7 @@ user.cardPower = K\u00E4ytt\u00E4j\u00E4tyyppi ...@@ -1154,6 +1155,7 @@ user.cardPower = K\u00E4ytt\u00E4j\u00E4tyyppi
user.changePassword = Vaihda salasana user.changePassword = Vaihda salasana
user.changepassword.forUser = K\u00E4ytt\u00E4j\u00E4lle user.changepassword.forUser = K\u00E4ytt\u00E4j\u00E4lle
user.changepassword.title = Vaihda salasana user.changepassword.title = Vaihda salasana
user.confirmUserToEventAdding = Oletko varma ett\u00E4 haluat liitt\u00E4\u00E4 t\u00E4m\u00E4n k\u00E4ytt\u00E4j\u00E4n t\u00E4h\u00E4n tapahtumaan?
user.create = Luo k\u00E4ytt\u00E4j\u00E4 user.create = Luo k\u00E4ytt\u00E4j\u00E4
user.createdmessage = K\u00E4ytt\u00E4j\u00E4tunnus on luotu onnistuneesti. Voit nyt kirjautua sis\u00E4\u00E4n. user.createdmessage = K\u00E4ytt\u00E4j\u00E4tunnus on luotu onnistuneesti. Voit nyt kirjautua sis\u00E4\u00E4n.
user.cropImage = Rajaa user.cropImage = Rajaa
......
...@@ -60,13 +60,15 @@ public class FileDownloadServlet extends GenericImageServlet { ...@@ -60,13 +60,15 @@ public class FileDownloadServlet extends GenericImageServlet {
private static final Logger logger = LoggerFactory.getLogger(FileDownloadServlet.class); private static final Logger logger = LoggerFactory.getLogger(FileDownloadServlet.class);
/** /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/ */
private static final Pattern URLPATTERN = Pattern.compile("([^./]+)"); private static final Pattern URLPATTERN = Pattern.compile("([^./]+)");
/** /**
* Usage MoyaWeb/dydata/format/ possible formats logo userimage/<eventuserid>.jpg cardtemplate/<cardtemplateid>.png usercard/ * Usage MoyaWeb/dydata/format/ possible formats logo
* userimage/<eventuserid>.jpg cardtemplate/<cardtemplateid>.png usercard/
*/ */
@Override @Override
protected ImageMover getImagedata() { protected ImageMover getImagedata() {
...@@ -132,7 +134,7 @@ public class FileDownloadServlet extends GenericImageServlet { ...@@ -132,7 +134,7 @@ public class FileDownloadServlet extends GenericImageServlet {
{ {
int userid = Integer.parseInt(urlparts.get(1)); int userid = Integer.parseInt(urlparts.get(1));
EventUser usr = userbean.findByUserId(userid); EventUser usr = userbean.findByUserId(userid, false);
logger.info("Trying to print usercard for user {}", usr); logger.info("Trying to print usercard for user {}", usr);
if (usr != null) { if (usr != null) {
......
...@@ -138,7 +138,7 @@ public class PlaceView extends GenericCDIView { ...@@ -138,7 +138,7 @@ public class PlaceView extends GenericCDIView {
public String reserveForUser() { public String reserveForUser() {
try { try {
EventUser user = userbean.getEventUser(userlist.getRowData()); EventUser user = userbean.getEventUser(userlist.getRowData(), true);
if (placebean.reservePlace(place, user)) { if (placebean.reservePlace(place, user)) {
PlaceGroup newgroup = placebean.buySelectedPlaces(user); PlaceGroup newgroup = placebean.buySelectedPlaces(user);
for (Place p : newgroup.getPlaces()) { for (Place p : newgroup.getPlaces()) {
......
...@@ -9,6 +9,7 @@ import java.util.Map; ...@@ -9,6 +9,7 @@ import java.util.Map;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
...@@ -54,8 +55,6 @@ public class ProductShopView extends GenericCDIView { ...@@ -54,8 +55,6 @@ public class ProductShopView extends GenericCDIView {
@EJB @EJB
private transient EventBeanLocal eventbean; private transient EventBeanLocal eventbean;
public void cashChanged() public void cashChanged()
{ {
payInstant = false; payInstant = false;
...@@ -81,10 +80,10 @@ public class ProductShopView extends GenericCDIView { ...@@ -81,10 +80,10 @@ public class ProductShopView extends GenericCDIView {
@Inject @Inject
private BillEditView billEditView; private BillEditView billEditView;
@Inject @Inject
private ProductShopItemHelper psiHelper; private ProductShopItemHelper psiHelper;
public ProductShopItemHelper getPsiHelper() { public ProductShopItemHelper getPsiHelper() {
return psiHelper; return psiHelper;
} }
...@@ -164,9 +163,18 @@ public class ProductShopView extends GenericCDIView { ...@@ -164,9 +163,18 @@ public class ProductShopView extends GenericCDIView {
} }
} }
public void countChangeListener(ValueChangeEvent e)
{
ProductShopItem item = shoppingcart.getRowData();
logger.info("Count change from event {}, from item {}", e.getNewValue(), item.getCount());
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
}
public String add(Integer count) { public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData(); ProductShopItem item = shoppingcart.getRowData();
psiHelper.setProductShopItemCount(item, item.getCount().add(BigDecimal.valueOf(count))); psiHelper.setProductShopItemCount(item, item.getCount().add(BigDecimal.valueOf(count)));
updateCartLimits(item); updateCartLimits(item);
...@@ -223,15 +231,15 @@ public class ProductShopView extends GenericCDIView { ...@@ -223,15 +231,15 @@ public class ProductShopView extends GenericCDIView {
if (l != null) { if (l != null) {
hasLimits = true; hasLimits = true;
} }
psiHelper.updateProductShopItemLimit(n,l); psiHelper.updateProductShopItemLimit(n, l);
} }
} }
public String removeBought() { public String removeBought() {
ProductShopItem row = boughtItems.getRowData(); ProductShopItem row = boughtItems.getRowData();
psiHelper.setProductShopItemCount(row, row.getCount().subtract(BigDecimal.ONE)); psiHelper.setProductShopItemCount(row, row.getCount().subtract(BigDecimal.ONE));
updateCartLimits(row); updateCartLimits(row);
return null; return null;
...@@ -428,8 +436,8 @@ public class ProductShopView extends GenericCDIView { ...@@ -428,8 +436,8 @@ public class ProductShopView extends GenericCDIView {
public String readCode() { public String readCode() {
ReaderEvent event = readerView.getReaderEvent(); ReaderEvent event = readerView.getReaderEvent();
if(event == null) { if (event == null) {
return null; return null;
} }
......
...@@ -19,7 +19,7 @@ public class UserCardWrapper implements Serializable { ...@@ -19,7 +19,7 @@ public class UserCardWrapper implements Serializable {
private transient final ListDataModel<PrintedCard> printedCards; private transient final ListDataModel<PrintedCard> printedCards;
public UserCardWrapper(User u, UserBeanLocal userbean) { public UserCardWrapper(User u, UserBeanLocal userbean) {
user = userbean.getEventUser(u); user = userbean.getEventUser(u, false);
List<PrintedCard> cards = null; List<PrintedCard> cards = null;
if (user != null) { if (user != null) {
cards = user.getPrintedCards(); cards = user.getPrintedCards();
......
package fi.codecrew.moya.web.cdiview.user;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class CreditTransferView extends GenericCDIView {
private static final long serialVersionUID = -4254396884077758765L;
private List<EventUserWrapper> users;
@EJB
private UserBeanLocal userbean;
@EJB
private EventBeanLocal eventbean;
private List<LanEvent> events;
private LanEvent sourceEvent;
private BigDecimal totalCredits;
private BigDecimal totalTransferred;
public void init(List<EventUser> users) {
ArrayList<EventUserWrapper> wrap = new ArrayList<EventUserWrapper>();
for (EventUser u : users) {
wrap.add(new EventUserWrapper(u));
}
this.users = wrap;
events = eventbean.getCurrentEvent().getOrganiser().getEvents();
}
public String selectEvent() {
BigDecimal total = BigDecimal.ZERO;
if (sourceEvent != null && !eventbean.getCurrentEvent().equals(sourceEvent))
{
for (EventUserWrapper u : users) {
u.setSourceEventuser(userbean.getOtherEventsEventuser(u.getUser().getUser(), sourceEvent));
if (u.getSourceEventuser() != null) {
u.setCredits(u.getSourceEventuser().getAccountBalance());
total = total.add(u.getCredits());
} else {
u.setCredits(BigDecimal.ZERO);
}
}
}
this.totalCredits = total;
return null;
}
public String commitTransfer() {
List<User> transfer = new ArrayList<User>();
for (EventUserWrapper u : users) {
transfer.add(u.getUser().getUser());
}
totalTransferred = userbean.transferAccountSaldoFromPreviousEvent(transfer, sourceEvent);
users = null;
return null;
}
public boolean isTransferPermissions() {
return super.hasPermission(EventPermission.MANAGE_EVENT);
}
public List<LanEvent> getEvents() {
return events;
}
public void setEvents(List<LanEvent> events) {
this.events = events;
}
public LanEvent getSourceEvent() {
return sourceEvent;
}
public void setSourceEvent(LanEvent sourceEvent) {
this.sourceEvent = sourceEvent;
}
public List<EventUserWrapper> getUsers() {
return users;
}
public void setUsers(List<EventUserWrapper> users) {
this.users = users;
}
public BigDecimal getTotalCredits() {
return totalCredits;
}
public void setTotalCredits(BigDecimal totalCredits) {
this.totalCredits = totalCredits;
}
public BigDecimal getTotalTransferred() {
return totalTransferred;
}
public void setTotalTransferred(BigDecimal totalTransferred) {
this.totalTransferred = totalTransferred;
}
public static class EventUserWrapper {
private final EventUser user;
private BigDecimal credits = BigDecimal.ZERO;
private EventUser sourceEventuser;
private EventUserWrapper(EventUser u) {
super();
this.user = u;
}
public EventUser getUser() {
return user;
}
public BigDecimal getCredits() {
return credits;
}
public void setCredits(BigDecimal credits) {
this.credits = credits;
}
public EventUser getSourceEventuser() {
return sourceEventuser;
}
public void setSourceEventuser(EventUser sourceEventuser) {
this.sourceEventuser = sourceEventuser;
}
}
}
package fi.codecrew.moya.web.cdiview.user; package fi.codecrew.moya.web.cdiview.user;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.inject.Named; import javax.inject.Named;
import org.primefaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named @Named
...@@ -10,23 +23,25 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView; ...@@ -10,23 +23,25 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
public class ImportView extends GenericCDIView { public class ImportView extends GenericCDIView {
private static final long serialVersionUID = -6212627607244029512L; private static final long serialVersionUID = -6212627607244029512L;
//
// private static final long serialVersionUID = -6212627607244029512L;
//
// private String content; // private String content;
// //
// private static final Logger logger = // private static final Logger logger =
// LoggerFactory.getLogger(ImportView.class); // LoggerFactory.getLogger(ImportView.class);
// //
// @EJB
// private UserBeanLocal userbean; @EJB
private UserBeanLocal userbean;
// @EJB // @EJB
// private EventBeanLocal eventbean; // private EventBeanLocal eventbean;
// @EJB // @EJB
// private ProductBeanLocal prodbean; // private ProductBeanLocal prodbean;
// //
// private UploadedFile file; private UploadedFile file;
private ArrayList<ImportWrapper> users;
private Charset UTF8 = Charset.forName("UTF8");
private static final Logger logger = LoggerFactory.getLogger(ImportView.class);
// //
// private ArrayList<ImportWrapper> wrapper; // private ArrayList<ImportWrapper> wrapper;
// //
...@@ -36,156 +51,77 @@ public class ImportView extends GenericCDIView { ...@@ -36,156 +51,77 @@ public class ImportView extends GenericCDIView {
// //
// private List<CardTemplate> templates; // private List<CardTemplate> templates;
// //
// public void initImport() { public void initImport() {
// if (requirePermissions(UserPermission.MODIFY)) if (requirePermissions(UserPermission.MODIFY_ACCOUNTEVENTS)) {
// { super.beginConversation();
// templates = templatebean.findAll(); }
// super.beginConversation();
// } }
//
// } public String parse()
// {
// public String parse() throws IOException ArrayList<ImportWrapper> ret = new ArrayList<ImportWrapper>();
// {
// byte[] bytes = file.getContents();
// setWrapper(new ArrayList<ImportWrapper>()); if (bytes == null && file.getSize() > 0)
// logger.warn("Got file {} from upload", file); {
// bytes = new byte[(int) file.getSize()];
// LanEvent event = eventbean.getCurrentEvent(); try {
// file.getInputstream().read(bytes);
// if (file == null) } catch (IOException e) {
// { super.addFaceMessage("import.erroruploading");
// return null; return null;
// } }
// }
// BufferedReader str = new BufferedReader(new
// InputStreamReader(file.getInputstream(), Charset.forName("ISO-8859-1"))); String content = new String(bytes, UTF8);
// String[] splittedIds = content.split(";");
// for (String line = ""; line != null; line = str.readLine()) for (String idstr : splittedIds) {
// { int id = 0;
// if (idstr != null && !idstr.isEmpty() && (id = Integer.parseInt(idstr)) > 0)
// if (line == null || line.isEmpty() || line.matches("^id\\t")) {
// { User user = userbean.getUser(id);
// logger.info("skipping line {}", line); if (user != null)
// continue; {
// } ret.add(new ImportWrapper(user, userbean.getEventUser(user, false)));
// // logger.warn("Parsing line {}", line); }
// User usr = new User(); }
// }
// String[] limatch = line.split("\\|");
// if (limatch.length != 19) users = ret;
// { return "commitImport";
// logger.warn("SPlictcount != 19: {}", limatch.length); }
// }
// public String commitImport() {
// for (int i = 0; limatch.length > i; ++i)
// { for (ImportWrapper u : users) {
// String field = limatch[i]; userbean.getEventUser(u.getUser(), true);
// // logger.info("Matched loop {}, val {}", i, field); }
//
// switch (i) return "/useradmin/list?faces-redirect=true";
// { }
// case 5:
// usr.setEmail(field); public static class ImportWrapper
// break; {
// case 9:
// usr.setPassword(field); private final EventUser eventuser;
// break; private final User user;
// case 10:
// String[] spl = field.split(" ", 2); public ImportWrapper(User user, EventUser eventUser) {
// if (spl.length != 2) { this.user = user;
// usr.setFirstnames(field); this.eventuser = eventUser;
// } else { }
// usr.setFirstnames(spl[0]);
// usr.setLastname(spl[1]); public EventUser getEventuser() {
// } return eventuser;
// }
// break;
// public User getUser() {
// case 11: return user;
// if (field != null && !field.isEmpty() && !field.equals("NULL")) }
// {
// PrintedCard card = new PrintedCard(usr, template, Calendar.getInstance(), }
// true);
// card.setRfidUid(field);
// usr.setPrintedCards(new ArrayList<PrintedCard>());
// usr.getPrintedCards().add(card);
// }
// break;
// case 12:
// usr.setPhone(field);
// break;
// case 13:
// usr.setNotes(new ArrayList<UserNote>());
// UserNote note = new UserNote();
// note.setContent(field);
// note.setEvent(event);
// note.setNotetype(UserNoteType.BANKACCOUNT);
// note.setUser(usr);
// usr.getNotes().add(note);
//
// break;
// case 14:
// usr.setNick(field);
// usr.setLogin(field);
// break;
// case 17:
// UserNote note2 = new UserNote();
// note2.setContent(field);
// note2.setEvent(event);
// note2.setNotetype(UserNoteType.ORGNOTE);
// note2.setUser(usr);
// usr.getNotes().add(note2);
// break;
//
// case 18:
// if (field == null || field.isEmpty() || field.equals("NULL")) {
// break;
// }
// if (usr.getAccountEvents() == null) {
// usr.setAccountEvents(new ArrayList<AccountEvent>());
// }
//
// try {
// AccountEvent ac = new AccountEvent(usr, prodbean.findCreditProduct(), new
// BigDecimal(field), BigDecimal.ONE, Calendar.getInstance());
// usr.getAccountEvents().add(ac);
// } catch (Throwable t) {
// logger.warn("Error parsing count: {}", t);
// }
//
// break;
// default:
// break;
// }
// if (i > 18)
// {
// logger.warn("cols not 18, {}", i);
// break;
// }
//
// }
//
// ImportWrapper wrap = new ImportWrapper(usr);
// getWrapper().add(wrap);
//
// SearchResult<User> srch = null;
// if (usr.getNick() != null && !usr.getNick().isEmpty())
// {
// srch = userbean.getUsers(0, 0, null, usr.getNick());
// wrap.add(srch.getResults());
// }
// if (usr.getEmail() != null && !usr.getEmail().isEmpty())
// {
// srch = userbean.getUsers(0, 0, null, usr.getEmail());
// wrap.add(srch.getResults());
// }
//
// } // end for split lines
// return "/user/commitImport";
//
// }
//
// public String commitImport() // public String commitImport()
// { // {
// for (ImportWrapper w : wrapper) // for (ImportWrapper w : wrapper)
...@@ -239,44 +175,21 @@ public class ImportView extends GenericCDIView { ...@@ -239,44 +175,21 @@ public class ImportView extends GenericCDIView {
// return null; // return null;
// } // }
// //
// public String getContent() {
// return content; public ArrayList<ImportWrapper> getUsers() {
// } return users;
// }
// public void setContent(String content) {
// this.content = content; public void setUsers(ArrayList<ImportWrapper> users) {
// } this.users = users;
// }
// public UploadedFile getFile() {
// return file; public UploadedFile getFile() {
// } return file;
// }
// public void setFile(UploadedFile file) {
// this.file = file; public void setFile(UploadedFile file) {
// } this.file = file;
// }
// public ArrayList<ImportWrapper> getWrapper() {
// return wrapper;
// }
//
// public void setWrapper(ArrayList<ImportWrapper> wrapper) {
// this.wrapper = wrapper;
// }
//
// public List<CardTemplate> getTemplates() {
// return templates;
// }
//
// public void setTemplates(List<CardTemplate> templates) {
// this.templates = templates;
// }
//
// public CardTemplate getTemplate() {
// return template;
// }
//
// public void setTemplate(CardTemplate template) {
// this.template = template;
// }
} }
...@@ -70,7 +70,7 @@ public class RoleView extends GenericCDIView { ...@@ -70,7 +70,7 @@ public class RoleView extends GenericCDIView {
public void addUser() public void addUser()
{ {
EventUser eu = userbean.getEventUser(addableUser); EventUser eu = userbean.getEventUser(addableUser, false);
role = rolebean.addRole(eu, role); role = rolebean.addRole(eu, role);
addableUser = null; addableUser = null;
} }
......
...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; ...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named @Named
...@@ -33,6 +34,8 @@ public class UserCartView extends GenericCDIView { ...@@ -33,6 +34,8 @@ public class UserCartView extends GenericCDIView {
@Inject @Inject
private UserView userview; private UserView userview;
@Inject
private CreditTransferView credTransfer;
@Inject @Inject
private UserOverviewView userOverviewView; private UserOverviewView userOverviewView;
...@@ -41,6 +44,23 @@ public class UserCartView extends GenericCDIView { ...@@ -41,6 +44,23 @@ public class UserCartView extends GenericCDIView {
private SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
public StreamedContent getUserExport()
{
StringBuilder sb = new StringBuilder();
DefaultStreamedContent ret = null;
if (usercart.size() > 0) {
LanEvent event = usercart.get(0).getEvent();
for (EventUser uc : usercart) {
sb.append(uc.getUser().getId()).append(";");
}
ret = new DefaultStreamedContent(new ByteArrayInputStream(sb.toString().getBytes(UTF8)));
ret.setContentType("text/csv");
ret.setName(event.getName() + "userexport.dat");
}
return ret;
}
public StreamedContent getDownloadCsv() { public StreamedContent getDownloadCsv() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -56,7 +76,7 @@ public class UserCartView extends GenericCDIView { ...@@ -56,7 +76,7 @@ public class UserCartView extends GenericCDIView {
sb.append("Zip").append(CSV_SEPARATOR); sb.append("Zip").append(CSV_SEPARATOR);
sb.append("City").append(CSV_SEPARATOR); sb.append("City").append(CSV_SEPARATOR);
sb.append("Places").append(CSV_SEPARATOR); sb.append("Places").append(CSV_SEPARATOR);
sb.append("\n"); sb.append("\n");
for (EventUser uc : usercart) for (EventUser uc : usercart)
{ {
...@@ -95,6 +115,11 @@ public class UserCartView extends GenericCDIView { ...@@ -95,6 +115,11 @@ public class UserCartView extends GenericCDIView {
return null; return null;
} }
public String transferCredits() {
credTransfer.init(usercart);
return "/useradmin/transferCredits";
}
public String prev() { public String prev() {
--current; --current;
updateCurrent(); updateCurrent();
...@@ -199,4 +224,12 @@ public class UserCartView extends GenericCDIView { ...@@ -199,4 +224,12 @@ public class UserCartView extends GenericCDIView {
this.current = current; this.current = current;
} }
public CreditTransferView getCredTransfer() {
return credTransfer;
}
public void setCredTransfer(CreditTransferView credTransfer) {
this.credTransfer = credTransfer;
}
} }
package fi.codecrew.moya.web.cdiview.user; package fi.codecrew.moya.web.cdiview.user;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -10,6 +11,8 @@ import javax.inject.Named; ...@@ -10,6 +11,8 @@ import javax.inject.Named;
import org.primefaces.model.LazyDataModel; import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder; import org.primefaces.model.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.UserBeanLocal; import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
...@@ -18,11 +21,45 @@ import fi.codecrew.moya.model.User; ...@@ -18,11 +21,45 @@ import fi.codecrew.moya.model.User;
import fi.codecrew.moya.util.UserSearchQuery; import fi.codecrew.moya.util.UserSearchQuery;
import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder; import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder;
import fi.codecrew.moya.utilities.SearchResult; import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.jpa.ModelInterface;
import fi.codecrew.moya.web.cdiview.PaginationView; import fi.codecrew.moya.web.cdiview.PaginationView;
import fi.codecrew.moya.web.cdiview.user.UserSearchView.UserWrapper;
@Named @Named
@ConversationScoped @ConversationScoped
public class UserSearchView extends PaginationView<User> { public class UserSearchView extends PaginationView<UserWrapper> {
public static class UserWrapper implements ModelInterface {
private static final long serialVersionUID = 8881170508994116964L;
private final User user;
private final EventUser eventuser;
public UserWrapper(User u, EventUser eventUser) {
this.user = u;
this.eventuser = eventUser;
}
public User getUser() {
return user;
}
public EventUser getEventuser() {
return eventuser;
}
@Override
public Integer getId() {
return user.getId();
}
@Override
public void setId(Integer id) {
user.setId(id);
}
}
/** /**
* *
...@@ -38,6 +75,9 @@ public class UserSearchView extends PaginationView<User> { ...@@ -38,6 +75,9 @@ public class UserSearchView extends PaginationView<User> {
private UserSearchQuery usersearch = new UserSearchQuery(); private UserSearchQuery usersearch = new UserSearchQuery();
private LazyDataModel<EventUser> eventuserModel; private LazyDataModel<EventUser> eventuserModel;
private LazyDataModel<UserWrapper> userModel;
private static final Logger logger = LoggerFactory.getLogger(UserSearchView.class);
public void addToCart() public void addToCart()
{ {
...@@ -56,6 +96,7 @@ public class UserSearchView extends PaginationView<User> { ...@@ -56,6 +96,7 @@ public class UserSearchView extends PaginationView<User> {
public void initView() { public void initView() {
if (requirePermissions(permbean.hasPermission(UserPermission.VIEW_ALL))) { if (requirePermissions(permbean.hasPermission(UserPermission.VIEW_ALL))) {
super.setSort("id");
eventuserModel = new LazyDataModel<EventUser>() { eventuserModel = new LazyDataModel<EventUser>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -65,15 +106,18 @@ public class UserSearchView extends PaginationView<User> { ...@@ -65,15 +106,18 @@ public class UserSearchView extends PaginationView<User> {
SortOrder sortOrder, Map<String, String> filters) { SortOrder sortOrder, Map<String, String> filters) {
UserSearchQuery sq = getSearchQuery(); UserSearchQuery sq = getSearchQuery();
sq.setPagesize(pageSize); sq.setPagesize(pageSize);
if (pageSize > 0) if (pageSize > 0) {
{
sq.setPage(first / pageSize); sq.setPage(first / pageSize);
} }
sq.setSort(sortField); sq.setSort(sortField);
sq.setSortDirection(SortOrder.ASCENDING.equals(sortOrder) ? QuerySortOrder.ASCENDING : (SortOrder.DESCENDING.equals(sortOrder) ? QuerySortOrder.DESCENDING : QuerySortOrder.UNSORTED)); sq.setSortDirection(SortOrder.ASCENDING.equals(sortOrder) ? QuerySortOrder.ASCENDING : (SortOrder.DESCENDING.equals(sortOrder) ? QuerySortOrder.DESCENDING : QuerySortOrder.UNSORTED));
SearchResult<EventUser> sr = userbean.getThisEventsUsers(sq); SearchResult<EventUser> sr = userbean.getThisEventsUsers(sq);
logger.info("sortfield {}, order {}, querysort: {}", sortField, sortOrder, sq.getSortDirection());
this.setRowCount(new Long(sr.getResultcount()).intValue()); this.setRowCount(new Long(sr.getResultcount()).intValue());
this.setWrappedData(sr.getResults());
setResultcount(sr.getResultcount()); setResultcount(sr.getResultcount());
setEventUserResults(sr.getResults()); setEventUserResults(sr.getResults());
...@@ -91,21 +135,67 @@ public class UserSearchView extends PaginationView<User> { ...@@ -91,21 +135,67 @@ public class UserSearchView extends PaginationView<User> {
}; };
if (usersearch.isOnlyThisEvent() || usersearch.getSearch() == null || usersearch.getSearch().isEmpty()) userModel = new LazyDataModel<UserWrapper>() {
{
usersearch.setOnlyThisEvent(true); private static final long serialVersionUID = 1L;
SearchResult<EventUser> eventusers = userbean.getThisEventsUsers(getSearchQuery());
this.setResultcount(eventusers.getResultcount()); @Override
this.setEventUserResults(eventusers.getResults()); public List<UserWrapper> load(int first, int pageSize, String sortField,
} SortOrder sortOrder, Map<String, String> filters) {
else {
super.setResult(userbean.getUsers(getSearchQuery())); UserSearchQuery sq = getSearchQuery();
} sq.setPagesize(pageSize);
if (pageSize > 0) {
sq.setPage(first / pageSize);
}
if (sortField == null || sortField.isEmpty()) {
sortField = "id";
}
sq.setSort(sortField);
sq.setSortDirection(SortOrder.ASCENDING.equals(sortOrder) ? QuerySortOrder.ASCENDING : (SortOrder.DESCENDING.equals(sortOrder) ? QuerySortOrder.DESCENDING : QuerySortOrder.UNSORTED));
SearchResult<User> sr = userbean.getUsers(sq);
this.setRowCount(new Long(sr.getResultcount()).intValue());
setResultcount(sr.getResultcount());
List<UserWrapper> wrappers = getUserWrappers(sr.getResults());
setResults(wrappers);
this.setWrappedData(wrappers);
return wrappers;
}
@Override
public void setRowIndex(int rowIndex) {
if (getPageSize() == 0) {
rowIndex = -1;
}
super.setRowIndex(rowIndex);
}
};
super.beginConversation(); super.beginConversation();
} }
} }
@Override @Override
public String newSearch() {
String ret = super.newSearch();
return ret;
}
private List<UserWrapper> getUserWrappers(List<User> users)
{
ArrayList<UserWrapper> res = new ArrayList<UserWrapper>();
for (User u : users) {
res.add(new UserWrapper(u, userbean.getEventUser(u, false)));
}
return res;
}
@Override
public UserSearchQuery getSearchQuery() public UserSearchQuery getSearchQuery()
{ {
return usersearch; return usersearch;
...@@ -127,4 +217,12 @@ public class UserSearchView extends PaginationView<User> { ...@@ -127,4 +217,12 @@ public class UserSearchView extends PaginationView<User> {
this.eventuserModel = eventuserModel; this.eventuserModel = eventuserModel;
} }
public LazyDataModel<UserWrapper> getUserModel() {
return userModel;
}
public void setUserModel(LazyDataModel<UserWrapper> userModel) {
this.userModel = userModel;
}
} }
...@@ -39,7 +39,6 @@ import fi.codecrew.moya.model.Role; ...@@ -39,7 +39,6 @@ import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.UserImage; import fi.codecrew.moya.model.UserImage;
import fi.codecrew.moya.util.MassPrintResult; import fi.codecrew.moya.util.MassPrintResult;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.annotations.LoggedIn; import fi.codecrew.moya.web.annotations.LoggedIn;
import fi.codecrew.moya.web.annotations.SelectedUser; import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
...@@ -142,7 +141,7 @@ public class UserView extends GenericCDIView { ...@@ -142,7 +141,7 @@ public class UserView extends GenericCDIView {
ByteArrayInputStream data = new ByteArrayInputStream(captureEvent.getData()); ByteArrayInputStream data = new ByteArrayInputStream(captureEvent.getData());
UserImage img = userbean.uploadImage(user, "image/png", data, "userimage.png", "Uploaded image"); UserImage img = userbean.uploadImage(user, "image/png", data, "userimage.png", "Uploaded image");
user = userbean.getEventUser(img.getUser()); user = userbean.getEventUser(img.getUser(), false);
// super.navihandler.forward("/admin/adduser/capturesuccess"); // super.navihandler.forward("/admin/adduser/capturesuccess");
if (getCaptureForwardUrl() != null && !getCaptureForwardUrl().isEmpty()) if (getCaptureForwardUrl() != null && !getCaptureForwardUrl().isEmpty())
super.navihandler.forward(getCaptureForwardUrl()); super.navihandler.forward(getCaptureForwardUrl());
...@@ -154,7 +153,7 @@ public class UserView extends GenericCDIView { ...@@ -154,7 +153,7 @@ public class UserView extends GenericCDIView {
public EventUser getSelectedUser() { public EventUser getSelectedUser() {
if (user == null) { if (user == null) {
if (userid != null && permbean.hasPermission(UserPermission.VIEW_ALL)) { if (userid != null && permbean.hasPermission(UserPermission.VIEW_ALL)) {
user = userbean.findByUserId(userid); user = userbean.findByUserId(userid, true);
} else { } else {
user = getCurrentUser(); user = getCurrentUser();
} }
...@@ -200,7 +199,7 @@ public class UserView extends GenericCDIView { ...@@ -200,7 +199,7 @@ public class UserView extends GenericCDIView {
croppedImage.getLeft(), croppedImage.getTop(), croppedImage.getLeft(), croppedImage.getTop(),
croppedImage.getWidth(), croppedImage.getHeight()); croppedImage.getWidth(), croppedImage.getHeight());
user = userbean.getEventUser(newImage.getUser()); user = userbean.getEventUser(newImage.getUser(), false);
} catch (IOException e) { } catch (IOException e) {
logger.info("Error converting image", e); logger.info("Error converting image", e);
super.addFaceMessage("user.errorConvertingImage"); super.addFaceMessage("user.errorConvertingImage");
...@@ -247,7 +246,7 @@ public class UserView extends GenericCDIView { ...@@ -247,7 +246,7 @@ public class UserView extends GenericCDIView {
InputStream istr = getImage().getInputstream(); InputStream istr = getImage().getInputstream();
UserImage userimage = userbean.uploadImage(user, getImage().getContentType(), getImage().getInputstream(), getImage().getFileName(), ""); UserImage userimage = userbean.uploadImage(user, getImage().getContentType(), getImage().getInputstream(), getImage().getFileName(), "");
user = userbean.getEventUser(userimage.getUser()); user = userbean.getEventUser(userimage.getUser(), false);
super.addFaceMessage("user.imageUploaded"); super.addFaceMessage("user.imageUploaded");
} }
printedCard = null; printedCard = null;
...@@ -277,7 +276,8 @@ public class UserView extends GenericCDIView { ...@@ -277,7 +276,8 @@ public class UserView extends GenericCDIView {
canSave = getCurrentUser().equals(user) || permbean.hasPermission(UserPermission.MODIFY); canSave = getCurrentUser().equals(user) || permbean.hasPermission(UserPermission.MODIFY);
this.beginConversation(); this.beginConversation();
logger.debug("Accountevents for user {}", user.getAccountEvents().size()); if (user.getAccountEvents() != null)
logger.debug("Accountevents for user {}", user.getAccountEvents().size());
} }
...@@ -351,23 +351,22 @@ public class UserView extends GenericCDIView { ...@@ -351,23 +351,22 @@ public class UserView extends GenericCDIView {
public String attachCodeToCard() { public String attachCodeToCard() {
return attachCodeToCard(readerView.getReaderEvent()); return attachCodeToCard(readerView.getReaderEvent());
} }
public String attachCodeToCard(ReaderEvent event ) {
public String attachCodeToCard(ReaderEvent event) {
if(event == null)
if (event == null)
return null; return null;
// already attached // already attached
if (event.getPrintedCard() != null) { if (event.getPrintedCard() != null) {
super.addFaceMessage("usercard.alreadyassociated"); super.addFaceMessage("usercard.alreadyassociated");
return null; return null;
} }
// still there, we can get real card and update it's barcodes // still there, we can get real card and update it's barcodes
PrintedCard card = cardBean.checkPrintedCard(user); PrintedCard card = cardBean.checkPrintedCard(user);
readerbean.assocCodeToCard(event , card); readerbean.assocCodeToCard(event, card);
return null; return null;
} }
......
package fi.codecrew.moya.web.converter;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.utilities.jsf.GenericIntegerEntityConverter;
@Named
@RequestScoped
public class LanEventConverter extends GenericIntegerEntityConverter<LanEvent> {
@EJB
private EventBeanLocal eventbean;
@Override
protected LanEvent find(Integer id) {
return eventbean.getEventById(id);
}
}
...@@ -89,7 +89,7 @@ public class LayoutView implements Serializable { ...@@ -89,7 +89,7 @@ public class LayoutView implements Serializable {
return null; return null;
while (selectedTop.getParent() != null) { while (selectedTop.getParent() != null) {
logger.info("Traversing to top {}, key {}", selectedTop, selectedTop.getKey()); logger.debug("Traversing to top {}, key {}", selectedTop, selectedTop.getKey());
selectedSet.add(selectedTop); selectedSet.add(selectedTop);
selectedTop = selectedTop.getParent(); selectedTop = selectedTop.getParent();
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!