Commit 8d81c876 by Tuomas Riihimäki

Add filter to user search to filter users with unused placeslots

1 parent e29088ce
Pipeline #167 passed
in 0 seconds
...@@ -36,6 +36,8 @@ public class UserSearchQuery extends SearchQuery { ...@@ -36,6 +36,8 @@ public class UserSearchQuery extends SearchQuery {
private boolean onlyThisEvent = true; private boolean onlyThisEvent = true;
private boolean placeAssoc = false; private boolean placeAssoc = false;
private boolean usersWithUnusedCodes = false; private boolean usersWithUnusedCodes = false;
private boolean usersWithUnusedPlaceslots = false;
private DatabaseHasCompare requireImage = DatabaseHasCompare.NONE; private DatabaseHasCompare requireImage = DatabaseHasCompare.NONE;
private List<CardState> hasCardState = new ArrayList<>(); private List<CardState> hasCardState = new ArrayList<>();
...@@ -46,8 +48,7 @@ public class UserSearchQuery extends SearchQuery { ...@@ -46,8 +48,7 @@ public class UserSearchQuery extends SearchQuery {
super(); super();
} }
public CardState[] getCardStates() public CardState[] getCardStates() {
{
return CardState.values(); return CardState.values();
} }
...@@ -55,8 +56,7 @@ public class UserSearchQuery extends SearchQuery { ...@@ -55,8 +56,7 @@ public class UserSearchQuery extends SearchQuery {
super(page, pagesize, sort, search, direction); super(page, pagesize, sort, search, direction);
} }
public DatabaseValueCompare[] getAccountCompareValues() public DatabaseValueCompare[] getAccountCompareValues() {
{
return DatabaseValueCompare.values(); return DatabaseValueCompare.values();
} }
...@@ -124,4 +124,11 @@ public class UserSearchQuery extends SearchQuery { ...@@ -124,4 +124,11 @@ public class UserSearchQuery extends SearchQuery {
this.hasCardState = hasCardState; this.hasCardState = hasCardState;
} }
public boolean isUsersWithUnusedPlaceslots() {
return usersWithUnusedPlaceslots;
}
public void setUsersWithUnusedPlaceslots(boolean usersWithUnusedPlaceslots) {
this.usersWithUnusedPlaceslots = usersWithUnusedPlaceslots;
}
} }
...@@ -51,7 +51,7 @@ import fi.codecrew.moya.utilities.moyamessage.MoyaEventType; ...@@ -51,7 +51,7 @@ import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
*/ */
@Stateless @Stateless
@LocalBean @LocalBean
@DeclareRoles({ BillPermission.S_CREATE_BILL, BillPermission.S_READ_ALL, BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL, SpecialPermission.S_USER, }) @DeclareRoles({BillPermission.S_CREATE_BILL, BillPermission.S_READ_ALL, BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL, SpecialPermission.S_USER,})
public class BillBean implements BillBeanLocal { public class BillBean implements BillBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(BillBean.class); private static final Logger logger = LoggerFactory.getLogger(BillBean.class);
...@@ -109,7 +109,7 @@ public class BillBean implements BillBeanLocal { ...@@ -109,7 +109,7 @@ public class BillBean implements BillBeanLocal {
logger.debug("bill {} user {}", bill, currentuser); logger.debug("bill {} user {}", bill, currentuser);
if (bill != null && !currentuser.equals(bill.getUser()) if (bill != null && !currentuser.equals(bill.getUser())
&& !permbean.hasPermission(BillPermission.READ_ALL)) { && !permbean.hasPermission(BillPermission.READ_ALL)) {
bill = null; bill = null;
} }
return bill; return bill;
...@@ -297,6 +297,12 @@ public class BillBean implements BillBeanLocal { ...@@ -297,6 +297,12 @@ public class BillBean implements BillBeanLocal {
// Not a place product. // Not a place product.
continue; continue;
} }
// If product is created when bill is paid, there is no need to create a placeslot for the product.
if (prod.getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT)) {
continue;
}
int count = bl.getQuantity().intValue(); int count = bl.getQuantity().intValue();
Date now = new Date(); Date now = new Date();
......
...@@ -643,8 +643,13 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -643,8 +643,13 @@ public class BootstrapBean implements BootstrapBeanLocal {
dbUpdates.add(new String[]{ dbUpdates.add(new String[]{
"ALTER TABLE bills ADD COLUMN payment_source TEXT NOT NULL default 'UNKNOWN'", "ALTER TABLE bills ADD COLUMN payment_source TEXT NOT NULL default 'UNKNOWN'",
}); });
dbUpdates.add(new String[]{
"UPDATE place_slots SET used = now() WHERE used is null AND product_id in (SELECT product_id FROM product_productflags WHERE productflags = 'CREATE_NEW_PLACE_WHEN_BOUGHT')"
});
} }
public BootstrapBean() { public BootstrapBean() {
} }
......
...@@ -943,9 +943,11 @@ public class UserBean implements UserBeanLocal { ...@@ -943,9 +943,11 @@ public class UserBean implements UserBeanLocal {
newSearchList.addAll(returnUsers.getResults()); newSearchList.addAll(returnUsers.getResults());
returnUsers = new SearchResult<EventUser>(newSearchList, (long) newSearchList.size()); return new SearchResult<EventUser>(newSearchList, (long) newSearchList.size());
} else if (searchQuery.isUsersWithUnusedCodes()) { }
if (searchQuery.isUsersWithUnusedCodes()) {
List<EventUser> newSearchList = new ArrayList<EventUser>(); List<EventUser> newSearchList = new ArrayList<EventUser>();
List<GroupMembership> groupMembers = new ArrayList<GroupMembership>(); List<GroupMembership> groupMembers = new ArrayList<GroupMembership>();
groupMembers = gmfacade.findAllWithoutUser(); groupMembers = gmfacade.findAllWithoutUser();
......
...@@ -33,6 +33,7 @@ import javax.persistence.criteria.From; ...@@ -33,6 +33,7 @@ import javax.persistence.criteria.From;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
import fi.codecrew.moya.facade.callbacks.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -40,14 +41,6 @@ import fi.codecrew.moya.beans.EventBeanLocal; ...@@ -40,14 +41,6 @@ import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.entitysearch.UserSearchQuery; import fi.codecrew.moya.entitysearch.UserSearchQuery;
import fi.codecrew.moya.enums.DatabaseHasCompare; import fi.codecrew.moya.enums.DatabaseHasCompare;
import fi.codecrew.moya.enums.DatabaseValueCompare; import fi.codecrew.moya.enums.DatabaseValueCompare;
import fi.codecrew.moya.facade.callbacks.EventLimiter;
import fi.codecrew.moya.facade.callbacks.EventUserAccountSaldoPredicate;
import fi.codecrew.moya.facade.callbacks.EventUserCardStateFilter;
import fi.codecrew.moya.facade.callbacks.EventUserPlacegroupPredicate;
import fi.codecrew.moya.facade.callbacks.EventUserRolefilter;
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.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;
...@@ -145,6 +138,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -145,6 +138,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
CriteriaQuery<EventUser> listCQuery = cb.createQuery(EventUser.class); CriteriaQuery<EventUser> listCQuery = cb.createQuery(EventUser.class);
CriteriaQuery<Long> countCQuery = cb.createQuery(Long.class); CriteriaQuery<Long> countCQuery = cb.createQuery(Long.class);
final LanEvent currentEvent = eventBean.getCurrentEvent();
if (query.getSort() != null) if (query.getSort() != null)
{ {
...@@ -159,7 +153,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -159,7 +153,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
callbacks.add(new OrderCallback<EventUser>(false, EventUser_.id)); callbacks.add(new OrderCallback<EventUser>(false, EventUser_.id));
} }
callbacks.add(new EventLimiter(eventBean.getCurrentEvent())); callbacks.add(new EventLimiter(currentEvent));
if (query.getSearch() != null && !query.getSearch().isEmpty()) { if (query.getSearch() != null && !query.getSearch().isEmpty()) {
callbacks.add(new EventUserSearchPredicate(query.getSearch(), UserFacade.getAttrlist())); callbacks.add(new EventUserSearchPredicate(query.getSearch(), UserFacade.getAttrlist()));
...@@ -181,6 +175,11 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -181,6 +175,11 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
{ {
callbacks.add(new EventUserAccountSaldoPredicate(query.getAccountSaldo(), query.getAccountSaldoCompare())); callbacks.add(new EventUserAccountSaldoPredicate(query.getAccountSaldo(), query.getAccountSaldoCompare()));
} }
if(query.isUsersWithUnusedPlaceslots()){
callbacks.add(new UnusedPlaceSlotFilter(currentEvent));
}
if (query.getRequireImage() != null && !query.getRequireImage().equals(DatabaseHasCompare.NONE)) if (query.getRequireImage() != null && !query.getRequireImage().equals(DatabaseHasCompare.NONE))
{ {
......
package fi.codecrew.moya.facade.callbacks;
import fi.codecrew.moya.model.*;
import javax.persistence.criteria.*;
import java.util.List;
public class UnusedPlaceSlotFilter implements fi.codecrew.moya.utilities.jpa.FacadeCallback<fi.codecrew.moya.model.EventUser> {
private final LanEvent currentEvent;
public UnusedPlaceSlotFilter(LanEvent currentEvent) {
this.currentEvent = currentEvent;
}
@Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates, boolean isFullQuery) {
Subquery<Integer> subq = cq.subquery(Integer.class);
Root<PlaceSlot> slotRoot = subq.from(PlaceSlot.class);
Path<Bill> bill = slotRoot.get(PlaceSlot_.bill);
subq.select(bill.get(Bill_.user).get(EventUser_.id));
subq.where(
cb.isNotNull(bill.get(Bill_.paidDate)),
cb.equal(bill.get(Bill_.event), currentEvent),
cb.isNull(slotRoot.get(PlaceSlot_.used))
);
predicates.add(root.get(EventUser_.id).in(subq));
}
}
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
</h:form> </h:form>
<ui:fragment rendered="#{placeView.place.reservedButNotLocked}"> <ui:fragment rendered="#{placeView.place.reservedButNotLocked}">
<h2><h:outputText value="#{i18n['place.warning.reservedNotLocked']}"</h2> <h2><h:outputText value="#{i18n['place.warning.reservedNotLocked']}" /></h2>
<h:form> <h:form>
<p:commandButton action="#{placeView.lockPlace()}" value="#{i18n['place.lockPlace']}" ajax="false"/> <p:commandButton action="#{placeView.lockPlace()}" value="#{i18n['place.lockPlace']}" ajax="false"/>
<p:commandButton action="#{placeView.releasePlace()}" value="#{i18n['place.releasePlace']}" ajax="false"/> <p:commandButton action="#{placeView.releasePlace()}" value="#{i18n['place.releasePlace']}" ajax="false"/>
......
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
<p:selectBooleanCheckbox id="userswithunusedcodes" value="#{userSearchView.searchQuery.usersWithUnusedCodes}" /> <p:selectBooleanCheckbox id="userswithunusedcodes" value="#{userSearchView.searchQuery.usersWithUnusedCodes}" />
<p:outputLabel for="userswithunusedcodes" value="#{i18n['userlist.usersWithUnusedCodes']}" /> <p:outputLabel for="userswithunusedcodes" value="#{i18n['userlist.usersWithUnusedCodes']}" />
<br />
<p:selectBooleanCheckbox id="usersWithUnusedPlaceslots" value="#{userSearchView.searchQuery.usersWithUnusedPlaceslots}" />
<p:outputLabel for="usersWithUnusedPlaceslots" value="#{i18n['userlist.usersWithUnusedPlaceslots']}" />
</div> </div>
<br /> <br />
......
...@@ -1950,3 +1950,4 @@ foodwave.updateList = Update li ...@@ -1950,3 +1950,4 @@ foodwave.updateList = Update li
place.assocUser = Associated user place.assocUser = Associated user
place.lockPlace = Lock place place.lockPlace = Lock place
place.releasePlace = Release place place.releasePlace = Release place
userlist.usersWithUnusedPlaceslots=Only users with unused placeslots
...@@ -1941,3 +1941,4 @@ foodwave.updateList = Pivit l ...@@ -1941,3 +1941,4 @@ foodwave.updateList = Pivit l
place.assocUser = Liitetty kyttj place.assocUser = Liitetty kyttj
place.lockPlace = Lukitse paikka place.lockPlace = Lukitse paikka
place.releasePlace = Vapauta paikka place.releasePlace = Vapauta paikka
userlist.usersWithUnusedPlaceslots=Vain käyttäjät joilla on käyttämättömiä paikkaslotteja
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!