Commit 888c50fb by Tuukka Kivilahti, TKffTK

Merge branch 'master' of codecrew.fi:bortal

2 parents a52a96b0 aed31d97
Showing with 540 additions and 130 deletions
...@@ -40,6 +40,8 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -40,6 +40,8 @@ public class ReaderBean implements ReaderBeanLocal {
private UserBeanLocal userbean; private UserBeanLocal userbean;
@EJB @EJB
private CardTemplateBean cardTemplateBean; private CardTemplateBean cardTemplateBean;
@EJB
private ProductPBean productPBean;
private static final Logger logger = LoggerFactory.getLogger(ReaderBean.class); private static final Logger logger = LoggerFactory.getLogger(ReaderBean.class);
...@@ -62,10 +64,11 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -62,10 +64,11 @@ public class ReaderBean implements ReaderBeanLocal {
Reader reader = readerfacade.findOrCreateByIdent(readerIdent); Reader reader = readerfacade.findOrCreateByIdent(readerIdent);
logger.info("reader {}, card {}", reader, card); logger.info("reader {}, card {}", reader, card);
// RfidEvent revent = reventcontainer.foundTag(reader, tag); // RfidEvent revent = reventcontainer.foundTag(reader, tag);
List<ReaderEvent> lastevents = readerEventFacade.findLastEvents(reader, 1); List<ReaderEvent> lastevents = readerEventFacade.findLastEvents(reader, 1);
ReaderEvent ret = null; ReaderEvent ret = null;
if (!lastevents.isEmpty()) if (!lastevents.isEmpty() && !reader.isAutoproduct())
{ {
ReaderEvent lastevent = lastevents.get(0); ReaderEvent lastevent = lastevents.get(0);
if (card == null) if (card == null)
...@@ -84,6 +87,12 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -84,6 +87,12 @@ public class ReaderBean implements ReaderBeanLocal {
if (ret == null) if (ret == null)
{ {
ret = createReaderEvent(reader, card); ret = createReaderEvent(reader, card);
if (ret != null && card != null && reader.isAutoproduct())
{
productPBean.createAccountEvent(reader.getAutomaticProduct(), reader.getAutomaticProductCount(), card.getUser(), Calendar.getInstance());
ret.setNotes("Created automatic account event from reader.");
}
} else { } else {
ret.setUpdatetime(Calendar.getInstance()); ret.setUpdatetime(Calendar.getInstance());
} }
......
...@@ -48,6 +48,7 @@ import fi.insomnia.bortal.utilities.I18n; ...@@ -48,6 +48,7 @@ import fi.insomnia.bortal.utilities.I18n;
import fi.insomnia.bortal.utilities.PasswordFunctions; import fi.insomnia.bortal.utilities.PasswordFunctions;
import fi.insomnia.bortal.utilities.SearchQuery; import fi.insomnia.bortal.utilities.SearchQuery;
import fi.insomnia.bortal.utilities.SearchResult; import fi.insomnia.bortal.utilities.SearchResult;
import fi.insomnia.bortal.utilities.UserSearchQuery;
/** /**
* Session Bean implementation class UserBean * Session Bean implementation class UserBean
...@@ -502,11 +503,17 @@ public class UserBean implements UserBeanLocal { ...@@ -502,11 +503,17 @@ public class UserBean implements UserBeanLocal {
public SearchResult<User> getEventUsers(SearchQuery search) { public SearchResult<User> getEventUsers(SearchQuery search) {
if (search.getSearch() == null || search.getSearch().isEmpty()) if (search.getSearch() == null || search.getSearch().isEmpty())
{ {
return userFacade.searchEventUsers(search); throw new RuntimeException("You should be using getThisEventsUsers if not searching globally...");
// return userFacade.searchEventUsers(search);
} else { } else {
return userFacade.searchAllUsers(search); return userFacade.searchAllUsers(search);
} }
} }
@Override
public SearchResult<EventUser> getThisEventsUsers(UserSearchQuery searchQuery) {
return eventUserFacade.searchEventUsers(searchQuery);
}
} }
\ No newline at end of file
package fi.insomnia.bortal.facade; package fi.insomnia.bortal.facade;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import fi.insomnia.bortal.beans.EventBeanLocal; import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.facade.callbacks.FacadeCallback;
import fi.insomnia.bortal.facade.callbacks.OrderCallback;
import fi.insomnia.bortal.facade.tools.EventLimiter;
import fi.insomnia.bortal.facade.tools.EventUserSearchPredicate;
import fi.insomnia.bortal.model.EventUser; import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.EventUser_; import fi.insomnia.bortal.model.EventUser_;
import fi.insomnia.bortal.model.PrintedCard; import fi.insomnia.bortal.model.PrintedCard;
import fi.insomnia.bortal.model.PrintedCard_; import fi.insomnia.bortal.model.PrintedCard_;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.model.User_; import fi.insomnia.bortal.model.User_;
import fi.insomnia.bortal.utilities.SearchResult;
import fi.insomnia.bortal.utilities.UserSearchQuery;
/** /**
* Session Bean implementation class EventUserFacade * Session Bean implementation class EventUserFacade
...@@ -78,6 +86,36 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -78,6 +86,36 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
} }
public SearchResult<EventUser> searchEventUsers(UserSearchQuery query) {
ArrayList<FacadeCallback<EventUser>> callbacks = new ArrayList<FacadeCallback<EventUser>>();
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()));
}
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> listCQuery = cb.createQuery(EventUser.class);
CriteriaQuery<Long> countCQuery = cb.createQuery(Long.class);
Root<EventUser> listRoot = searchCallbacks(listCQuery, callbacks, EventUser.class);
Root<EventUser> countRoot = searchCallbacks(countCQuery, callbacks, EventUser.class);
listCQuery.select(listRoot);
countCQuery.select(cb.count(countRoot));
TypedQuery<Long> countQ = getEm().createQuery(countCQuery);
TypedQuery<EventUser> listQ = getEm().createQuery(listCQuery);
if (query.getPagesize() > 0) {
listQ.setFirstResult(query.getPage() * query.getPagesize());
listQ.setMaxResults(query.getPagesize());
}
return new SearchResult<EventUser>(listQ.getResultList(), countQ.getSingleResult());
}
// public SearchResult<EventUser> searchUser(int page, int pagesize, String // public SearchResult<EventUser> searchUser(int page, int pagesize, String
// sort, String search) { // sort, String search) {
// //
......
...@@ -7,11 +7,8 @@ import java.util.List; ...@@ -7,11 +7,8 @@ import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
...@@ -22,9 +19,6 @@ import fi.insomnia.bortal.beans.EventBeanLocal; ...@@ -22,9 +19,6 @@ import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.facade.callbacks.FacadeCallback; import fi.insomnia.bortal.facade.callbacks.FacadeCallback;
import fi.insomnia.bortal.facade.callbacks.OrderCallback; import fi.insomnia.bortal.facade.callbacks.OrderCallback;
import fi.insomnia.bortal.facade.callbacks.StringSearchPredicateCreator; import fi.insomnia.bortal.facade.callbacks.StringSearchPredicateCreator;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.EventUser_;
import fi.insomnia.bortal.model.LanEvent;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.model.User_; import fi.insomnia.bortal.model.User_;
import fi.insomnia.bortal.utilities.SearchQuery; import fi.insomnia.bortal.utilities.SearchQuery;
...@@ -148,45 +142,35 @@ public class UserFacade extends IntegerPkGenericFacade<User> { ...@@ -148,45 +142,35 @@ public class UserFacade extends IntegerPkGenericFacade<User> {
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
public SearchResult<User> searchEventUsers(SearchQuery query) // public SearchResult<User> searchEventUsers(SearchQuery query)
{ // {
ArrayList<FacadeCallback<EventUser>> callbacks = new ArrayList<FacadeCallback<EventUser>>(); // ArrayList<FacadeCallback<EventUser>> callbacks = new
callbacks.add(new OrderCallback<EventUser>(false, EventUser_.id)); // ArrayList<FacadeCallback<EventUser>>();
callbacks.add(new Eventlimiter(eventBean.getCurrentEvent())); // callbacks.add(new OrderCallback<EventUser>(false, EventUser_.id));
// callbacks.add(new EventLimiter(eventBean.getCurrentEvent()));
CriteriaBuilder cb = getEm().getCriteriaBuilder(); //
// CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<User> listCQuery = cb.createQuery(User.class); //
CriteriaQuery<Long> countCQuery = cb.createQuery(Long.class); // CriteriaQuery<User> listCQuery = cb.createQuery(User.class);
// CriteriaQuery<Long> countCQuery = cb.createQuery(Long.class);
Root<EventUser> listRoot = searchCallbacks(listCQuery, callbacks, EventUser.class); //
Root<EventUser> countRoot = searchCallbacks(countCQuery, callbacks, EventUser.class); // Root<EventUser> listRoot = searchCallbacks(listCQuery, callbacks,
// EventUser.class);
listCQuery.select(listRoot.join(EventUser_.user)); // Root<EventUser> countRoot = searchCallbacks(countCQuery, callbacks,
countCQuery.select(cb.count(countRoot.get(EventUser_.user))); // EventUser.class);
//
TypedQuery<Long> countQ = getEm().createQuery(countCQuery); // listCQuery.select(listRoot.join(EventUser_.user));
TypedQuery<User> listQ = getEm().createQuery(listCQuery); // countCQuery.select(cb.count(countRoot.get(EventUser_.user)));
//
if (query.getPagesize() > 0) { // TypedQuery<Long> countQ = getEm().createQuery(countCQuery);
listQ.setFirstResult(query.getPage() * query.getPagesize()); // TypedQuery<User> listQ = getEm().createQuery(listCQuery);
listQ.setMaxResults(query.getPagesize()); //
} // if (query.getPagesize() > 0) {
return new SearchResult<User>(listQ.getResultList(), countQ.getSingleResult()); // listQ.setFirstResult(query.getPage() * query.getPagesize());
} // listQ.setMaxResults(query.getPagesize());
// }
public class Eventlimiter implements FacadeCallback<EventUser> { // return new SearchResult<User>(listQ.getResultList(),
// countQ.getSingleResult());
private LanEvent ev; // }
public Eventlimiter(LanEvent currentEvent) {
ev = currentEvent;
}
@Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates) {
predicates.add(cb.equal(root.get(EventUser_.event), ev));
}
}
} }
package fi.insomnia.bortal.facade.tools;
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.insomnia.bortal.facade.callbacks.FacadeCallback;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.EventUser_;
import fi.insomnia.bortal.model.LanEvent;
public class EventLimiter implements FacadeCallback<EventUser> {
private LanEvent ev;
public EventLimiter(LanEvent currentEvent) {
ev = currentEvent;
}
@Override
public void exec(CriteriaBuilder cb, CriteriaQuery<?> cq, Path<EventUser> root, List<Predicate> predicates) {
predicates.add(cb.equal(root.get(EventUser_.event), ev));
}
}
\ No newline at end of file
package fi.insomnia.bortal.facade.tools;
import java.util.List;
import javax.persistence.criteria.Path;
import javax.persistence.metamodel.SingularAttribute;
import fi.insomnia.bortal.facade.callbacks.PathStringSearchPredicateCreator;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.EventUser_;
import fi.insomnia.bortal.model.User;
public class EventUserSearchPredicate extends PathStringSearchPredicateCreator<EventUser, User> {
public EventUserSearchPredicate(String search, List<SingularAttribute<User, String>> attrs) {
super(search, attrs);
}
@Override
protected Path<User> getPath(Path<EventUser> root) {
return root.get(EventUser_.user);
}
}
...@@ -12,6 +12,7 @@ import fi.insomnia.bortal.model.User; ...@@ -12,6 +12,7 @@ import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.model.UserImage; import fi.insomnia.bortal.model.UserImage;
import fi.insomnia.bortal.utilities.SearchQuery; import fi.insomnia.bortal.utilities.SearchQuery;
import fi.insomnia.bortal.utilities.SearchResult; import fi.insomnia.bortal.utilities.SearchResult;
import fi.insomnia.bortal.utilities.UserSearchQuery;
@Local @Local
public interface UserBeanLocal { public interface UserBeanLocal {
...@@ -71,4 +72,6 @@ public interface UserBeanLocal { ...@@ -71,4 +72,6 @@ public interface UserBeanLocal {
EventUser getUserByBarcode(String barcode); EventUser getUserByBarcode(String barcode);
SearchResult<EventUser> getThisEventsUsers(UserSearchQuery searchQuery);
} }
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LanBortalCardPrinter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
package fi.insomnia.bortal.cardprinter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
public class CardPrinter {
/**
* @param args
*/
protected static final DocFlavor[] IMPLEMENTED_FLAVORS = { DocFlavor.BYTE_ARRAY.PDF, DocFlavor.INPUT_STREAM.PDF };
public static void main(String[] args) {
}
protected Set<DocFlavor> supportedFlavors = new HashSet<DocFlavor>();
protected String printerName;
protected PrintService printService;
// private static final Logger logger =
// LoggerFactory.getLogger(CardPrinter.class);
public void afterPropertiesSet() throws Exception {
// Try to find a PrintService instance with the specified name if any
if (printerName != null && printerName.length() > 0) {
log.info("Looking for a printer named {}", printerName);
// Lookup all services
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService ps : printServices) {
if (ps.getName().equalsIgnoreCase(printerName)) {
log.info("Using printer {}", ps.getName());
this.printService = ps;
break;
}
}
if (printService == null) {
log.warn("Could not find printer with name {}. Will try default printer.", printerName);
}
}
// If the printService is null, we weren't configured with a printerName
// or we couldn't
// find one with the specified name
if (printService == null) {
log.info("Using default printer.");
printService = PrintServiceLookup.lookupDefaultPrintService();
}
// If the printService is null, there is no default printer installed.
if (printService == null) {
log.warn("No default printer found. Printing will not be available.");
} else {
// We have a PrintService instance. Extract the supported flavors
// out of our implemented flavors.
for (DocFlavor flavor : IMPLEMENTED_FLAVORS) {
if (printService.isDocFlavorSupported(flavor)) {
supportedFlavors.add(flavor);
}
}
if (supportedFlavors.size() > 0) {
log.info("Printer {} supports PDF printing. Printing will be available.", printService.getName());
} else {
log.warn("Printer {} does not support printing PDF files directly. Printing will not be available.", printService.getName());
printService = null;
}
}
}
public void setPrinterName(String printerName) {
this.printerName = printerName;
}
public boolean supportsByteArray() {
return supportedFlavors.contains(DocFlavor.BYTE_ARRAY.PDF);
}
public boolean supportsInputStream() {
return supportedFlavors.contains(DocFlavor.INPUT_STREAM.PDF);
}
public void printPdf(byte[] pdf) throws PrintException {
if (supportsByteArray()) {
log.debug("Sending PDF to printer as byte array");
print(pdf, DocFlavor.BYTE_ARRAY.PDF);
} else {
// Adapt the byte array if the printer supports input stream
// printing
if (supportsInputStream()) {
printPdf(new ByteArrayInputStream(pdf));
} else {
throw new PrintException("Printer does not support PDF printing");
}
}
}
public void printPdf(InputStream pdf) throws PrintException {
if (supportsInputStream()) {
log.debug("Sending PDF to printer as InputStream");
print(pdf, DocFlavor.INPUT_STREAM.PDF);
} else {
// Adapt the input stream to a byte array if the printer supports
// byte array printing
if (supportsByteArray()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
// Streams.copy(pdf, baos);
while (pdf.available() > 0) {
baos.write(pdf.read());
}
} catch (IOException e) {
throw new PrintException(e);
}
printPdf(baos.toByteArray());
} else {
throw new PrintException("Printer does not support PDF printing");
}
}
}
protected void print(Object source, DocFlavor flavor) throws PrintException {
DocPrintJob printJob = printService.createPrintJob();
printJob.print(new SimpleDoc(source, flavor, null), null);
}
}
...@@ -9,6 +9,7 @@ import static javax.persistence.CascadeType.MERGE; ...@@ -9,6 +9,7 @@ import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST; import static javax.persistence.CascadeType.PERSIST;
import static javax.persistence.CascadeType.REFRESH; import static javax.persistence.CascadeType.REFRESH;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -53,7 +54,7 @@ public class Reader extends GenericEntity { ...@@ -53,7 +54,7 @@ public class Reader extends GenericEntity {
@Column(nullable = false, name = "type") @Column(nullable = false, name = "type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private ReaderType type; private ReaderType type = ReaderType.RFID;
public static final String EVENT_ID_COLUMN = "event_id"; public static final String EVENT_ID_COLUMN = "event_id";
@ManyToOne() @ManyToOne()
...@@ -68,9 +69,13 @@ public class Reader extends GenericEntity { ...@@ -68,9 +69,13 @@ public class Reader extends GenericEntity {
@OneToOne(mappedBy = "reader") @OneToOne(mappedBy = "reader")
private SalesEntity salesEntity; private SalesEntity salesEntity;
/** @ManyToOne
* @JoinColumn(name = "automatic_product_id")
*/ private Product automaticProduct;
@Column(precision = 25, scale = 4, name = "automatic_product_count")
private BigDecimal automaticProductCount;
private static final long serialVersionUID = 616803985117256035L; private static final long serialVersionUID = 616803985117256035L;
@Column(name = "reader_ident") @Column(name = "reader_ident")
...@@ -204,4 +209,33 @@ public class Reader extends GenericEntity { ...@@ -204,4 +209,33 @@ public class Reader extends GenericEntity {
public void setSalesEntity(SalesEntity salesEntity) { public void setSalesEntity(SalesEntity salesEntity) {
this.salesEntity = salesEntity; this.salesEntity = salesEntity;
} }
public boolean isAutoproduct() {
return (automaticProduct != null && automaticProductCount != null);
}
public ReaderType getType() {
return type;
}
public void setType(ReaderType type) {
this.type = type;
}
public Product getAutomaticProduct() {
return automaticProduct;
}
public void setAutomaticProduct(Product automaticProduct) {
this.automaticProduct = automaticProduct;
}
public BigDecimal getAutomaticProductCount() {
return automaticProductCount;
}
public void setAutomaticProductCount(BigDecimal automaticProductCount) {
this.automaticProductCount = automaticProductCount;
}
} }
package fi.insomnia.bortal.utilities;
import java.util.List;
import javax.management.relation.Role;
public class UserSearchQuery extends SearchQuery {
private static final long serialVersionUID = 1383445517981308383L;
private List<Role> filterRoles;
private boolean onlyThisEvent = true;
public boolean isOnlyThisEvent() {
return onlyThisEvent;
}
public void setOnlyThisEvent(boolean onlyThisEvent) {
this.onlyThisEvent = onlyThisEvent;
}
public List<Role> getFilterRoles() {
return filterRoles;
}
public void setFilterRoles(List<Role> filterRoles) {
this.filterRoles = filterRoles;
}
}
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"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"
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">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<h:dataTable styleClass="bordertable" id="user" value="#{userSearchView.eventUserResults}" var="user">
<h:column>
<f:facet name="header">
<h:link value="#{i18n['user.nick']}" includeViewParams="true">
<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}" />
<div class="userdata_popup">
<h:panelGrid columns="2">
<img style="width: 100px;" src="#{request.contextPath}/dydata/userimage/#{user.currentImage.id}.img" alt="image" />
<h:panelGroup>
<h:outputText value="#{user.nick}" />
<br />
<h:outputText value="#{user.firstnames} #{user.lastname}" />
<br />
<hr />
<h:outputText value="#{user.address}" />
<br />
<h:outputText value="#{user.zip} #{user.postalTown}" />
<br />
<br />
<h:outputText value="#{user.phone}" />
<br />
<h:outputText value="#{user.email}" />
<br />
</h:panelGroup>
</h:panelGrid>
</div>
</h:column>
<h:column>
<f:facet name="header">
<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}" />
</h:column>
<h:column>
<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:column>
<h:column>
<button onClick="location.replace('#{request.contextPath}/useradmin/edit.jsf?userid=#{user.id}')">#{i18n['user.edit']}</button>
</h:column>
<!-- <h:column>
<h:commandButton action="#{userView.shop()}" value="#{i18n['user.shop']}" />
</h:column> -->
</h:dataTable>
<script>
jQuery(function() {
jQuery(".hoverable").hover(function () {
jQuery(this).next().fadeIn('fast');
},
function () {
jQuery(this).next().fadeOut('fast');
});
});
</script>
</composite:implementation>
</html>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
.userdata_popup { .userdata_popup {
position: absolute; position: absolute;
border: 1px solid black; border: 1px solid black;
backgrond: white; background: white;
border-radius: 3px; border-radius: 3px;
display: none; display: none;
......
...@@ -20,31 +20,7 @@ ...@@ -20,31 +20,7 @@
<h:form id="shoppingcartform"> <h:form id="shoppingcartform">
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:panelGrid columns="2">
<h:panelGroup>
<div id="shopItems">
<ui:repeat value="#{productShopView.shoppingcart}" var="cart">
<div class="shopItem">
<h:commandLink action="#{productShopView.addOne}" value="#{cart.product.name}">
<f:ajax render="@form" />
</h:commandLink>
</div>
</ui:repeat>
</div>
</h:panelGroup>
<h:panelGroup>
<h:dataGrid >
</h:dataGrid>
<h:outputLabel value="#{i18n['shop.readBarcode']}" />
<h:inputText id="barcode" value="#{productShopView.barcode}" />
<h:commandButton action="#{productShopView.readBarcode}" onclick="blip(); return true;" value="#{i18n['productShopView.readBarcode']}">
<f:ajax render="@form" onevent="barcodeReadEvent" execute="@form" />
</h:commandButton>
<h:outputLabel value="#{i18n['shop.accountBalance']}" /> <h:outputLabel value="#{i18n['shop.accountBalance']}" />
<h:outputText value="#{productShopView.accountBalance}"> <h:outputText value="#{productShopView.accountBalance}">
...@@ -61,36 +37,24 @@ ...@@ -61,36 +37,24 @@
<f:ajax render="@form" event="valueChange" /> <f:ajax render="@form" event="valueChange" />
<f:convertNumber /> <f:convertNumber />
</h:inputText> </h:inputText>
</h:panelGroup> </h:panelGrid>
<h:panelGroup>
<h:outputLabel value="#{i18n['shop.readBarcode']}" />
<h:inputText id="barcode" value="#{productShopView.barcode}" />
<h:commandButton action="#{productShopView.readBarcode}" onclick="blip(); return true;" value="#{i18n['productShopView.readBarcode']}">
<f:ajax render="@form" onevent="barcodeReadEvent" execute="@form" />
</h:commandButton>
</h:panelGroup>
</h:panelGrid> </h:panelGrid>
<h:outputText value="#{i18n['product.shopInstant']}" /> <h:outputText value="#{i18n['product.shopInstant']}" />
<h:selectBooleanCheckbox value="#{productShopView.payInstant}"> <h:selectBooleanCheckbox value="#{productShopView.payInstant}">
<f:ajax render="@form" execute="@form" /> <f:ajax render="@form" execute="@form" />
</h:selectBooleanCheckbox> </h:selectBooleanCheckbox>
<h:outputScript library="primefaces" name="jquery/jquery.js" /> <products:shop commitaction="#{productShopView.commitShoppingCart()}" items="#{productShopView.shoppingcart}" commitValue="#{i18n['productshop.commit']}" />
<div style="margin-top: 5px;">
<h:commandButton action="#{cc.attrs.commitaction}" id="commitbutton-top" value="#{cc.attrs.commitValue}" />
</div>
<div>
<h:outputText value="#{i18n['productshop.total']} " />
<h:outputText value="#{productShopView.totalPrice}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
</div>
<h:commandButton action="#{cc.attrs.commitaction}" id="commitbutton-botton" value="#{cc.attrs.commitValue}" />
</h:form> </h:form>
<script> <script>
var blipSnd = new Audio( var blipSnd = new Audio(
...@@ -98,7 +62,6 @@ ...@@ -98,7 +62,6 @@
$(function() { $(function() {
$("#shoppingcartform\\:barcode").focus(); $("#shoppingcartform\\:barcode").focus();
}); });
function blip() { function blip() {
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" <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:h="http://java.sun.com/jsf/html" xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:f="http://java.sun.com/jsf/core">
xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:f="http://java.sun.com/jsf/core"
>
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<f:metadata> <f:metadata>
...@@ -16,18 +14,22 @@ ...@@ -16,18 +14,22 @@
<f:event type="preRenderView" listener="#{userSearchView.initView}" /> <f:event type="preRenderView" listener="#{userSearchView.initView}" />
</f:metadata> </f:metadata>
<ui:param name="thispage" value="page.user.create" />
<ui:define name="content"> <ui:define name="content">
<h1>#{i18n['userlist.header']}</h1> <h1>#{i18n['userlist.header']}</h1>
<h:form> <h:form>
<h:outputLabel for="onlythisevent" value="#{i18n['userlist.onlythisevent']}" />
<h:selectBooleanCheckbox id="onlythisevent" value="#{userSearchView.searchQuery.onlyThisEvent}" />
<br />
<h:inputText value="#{userSearchView.search}" /> <h:inputText value="#{userSearchView.search}" />
<h:commandButton value="#{i18n['userlist.search']}" action="#{userSearchView.newSearch()}" /> <h:commandButton value="#{i18n['userlist.search']}" action="#{userSearchView.newSearch()}" />
</h:form> </h:form>
<p> <p>
<users:list /> <users:list rendered="#{!userSearchView.searchQuery.onlyThisEvent}" />
<users:eventuserlist rendered="#{userSearchView.searchQuery.onlyThisEvent}" />
</p> </p>
<p> <p>
<tools:paginationHeader view="#{userSearchView}" /> <tools:paginationHeader view="#{userSearchView}" />
</p> </p>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
...@@ -34,10 +34,10 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD ...@@ -34,10 +34,10 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD
public String addToPage(Integer count) { public String addToPage(Integer count) {
pagechangeCallback(); pagechangeCallback();
searchQuery.addPage(count); getSearchQuery().addPage(count);
if (searchQuery.getPage() >= pagecount) { if (getSearchQuery().getPage() >= pagecount) {
searchQuery.setPage(pagecount.intValue() - 1); getSearchQuery().setPage(pagecount.intValue() - 1);
} }
return null; return null;
} }
...@@ -51,14 +51,14 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD ...@@ -51,14 +51,14 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD
public String gotoFirstpage() { public String gotoFirstpage() {
// logger.info("Setting page to first page"); // logger.info("Setting page to first page");
pagechangeCallback(); pagechangeCallback();
searchQuery.setPage(0); getSearchQuery().setPage(0);
return null; return null;
} }
public String gotoLastpage() { public String gotoLastpage() {
// logger.info("Setting page to last page"); // logger.info("Setting page to last page");
pagechangeCallback(); pagechangeCallback();
searchQuery.setPage(pagecount.intValue() - 1); getSearchQuery().setPage(pagecount.intValue() - 1);
return null; return null;
} }
...@@ -72,20 +72,20 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD ...@@ -72,20 +72,20 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD
@Override @Override
public Integer getPage() { public Integer getPage() {
return searchQuery.getPage(); return getSearchQuery().getPage();
} }
public void setPage(Integer page) { public void setPage(Integer page) {
searchQuery.setPage(page); getSearchQuery().setPage(page);
} }
@Override @Override
public Integer getPagesize() { public Integer getPagesize() {
return searchQuery.getPagesize(); return getSearchQuery().getPagesize();
} }
public void setPagesize(Integer pagesize) { public void setPagesize(Integer pagesize) {
searchQuery.setPagesize(pagesize); getSearchQuery().setPagesize(pagesize);
} }
@Override @Override
...@@ -95,7 +95,7 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD ...@@ -95,7 +95,7 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD
public void setResultcount(Long resultcount) { public void setResultcount(Long resultcount) {
this.resultcount = resultcount; this.resultcount = resultcount;
pagecount = ((resultcount + searchQuery.getPagesize() - 1) / searchQuery.getPagesize()); pagecount = ((resultcount + getSearchQuery().getPagesize() - 1) / getSearchQuery().getPagesize());
} }
@Override @Override
...@@ -108,19 +108,19 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD ...@@ -108,19 +108,19 @@ public abstract class PaginationView<T extends ModelInterface> extends GenericCD
} }
public String getSort() { public String getSort() {
return searchQuery.getSort(); return getSearchQuery().getSort();
} }
public void setSort(String sort) { public void setSort(String sort) {
searchQuery.setSort(sort); getSearchQuery().setSort(sort);
} }
public String getSearch() { public String getSearch() {
return searchQuery.getSearch(); return getSearchQuery().getSearch();
} }
public void setSearch(String search) { public void setSearch(String search) {
searchQuery.setSearch(search); getSearchQuery().setSearch(search);
} }
public String newSearch() { public String newSearch() {
......
...@@ -62,24 +62,22 @@ public class EventPropertyView extends GenericCDIView { ...@@ -62,24 +62,22 @@ public class EventPropertyView extends GenericCDIView {
public List<LanEventPrivatePropertyKey> getAvailablePrivatePropertyKeys() { public List<LanEventPrivatePropertyKey> getAvailablePrivatePropertyKeys() {
List<LanEventPrivatePropertyKey> ret = null; List<LanEventPrivatePropertyKey> ret = null;
if (isPrivatePropertyPermission()) if (isPrivatePropertyPermission() && eventbean.getCurrentEvent().equals(eventorgview.getEvent()))
{ {
ret = new ArrayList<LanEventPrivatePropertyKey>(Arrays.asList(LanEventPrivatePropertyKey.values())); ret = new ArrayList<LanEventPrivatePropertyKey>(Arrays.asList(LanEventPrivatePropertyKey.values()));
if (createPrivateKey != null) if (createPrivateKey != null)
{ {
ret.remove(createPrivateKey); ret.remove(createPrivateKey);
} }
if (eventorgview.getEvent() != null) { for (LanEventPrivateProperty p : eventbean.getPrivateProperties()) {
for (LanEventPrivateProperty p : eventbean.getPrivateProperties()) { ret.remove(p.getKey());
ret.remove(p.getKey());
}
} }
} }
return ret; return ret;
} }
public boolean isPrivatePropertyPermission() { public boolean isPrivatePropertyPermission() {
return super.hasPermission(EventPermission.MANAGE_PRIVATE_PROPERTIES); return super.hasPermission(EventPermission.MANAGE_PRIVATE_PROPERTIES) && eventbean.getCurrentEvent().equals(eventorgview.getEvent());
} }
public String editProperty() public String editProperty()
...@@ -182,7 +180,7 @@ public class EventPropertyView extends GenericCDIView { ...@@ -182,7 +180,7 @@ public class EventPropertyView extends GenericCDIView {
} }
public ListDataModel<LanEventPrivateProperty> getPrivateProperties() { public ListDataModel<LanEventPrivateProperty> getPrivateProperties() {
if (privateProperties == null && eventorgview != null && eventorgview.getEvent() != null) if (privateProperties == null && eventorgview != null && eventbean.getCurrentEvent().equals(eventorgview.getEvent()))
{ {
privateProperties = new ListDataModel<LanEventPrivateProperty>(eventbean.getPrivateProperties()); privateProperties = new ListDataModel<LanEventPrivateProperty>(eventbean.getPrivateProperties());
} }
......
package fi.insomnia.bortal.web.cdiview.user; package fi.insomnia.bortal.web.cdiview.user;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Named; import javax.inject.Named;
import fi.insomnia.bortal.beans.UserBeanLocal; import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.enums.apps.UserPermission; import fi.insomnia.bortal.enums.apps.UserPermission;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.utilities.SearchResult;
import fi.insomnia.bortal.utilities.UserSearchQuery;
import fi.insomnia.bortal.web.cdiview.PaginationView; import fi.insomnia.bortal.web.cdiview.PaginationView;
@Named @Named
...@@ -20,12 +25,37 @@ public class UserSearchView extends PaginationView<User> { ...@@ -20,12 +25,37 @@ public class UserSearchView extends PaginationView<User> {
@EJB @EJB
private transient UserBeanLocal userbean; private transient UserBeanLocal userbean;
private List<EventUser> eventUserResults;
private UserSearchQuery usersearch = new UserSearchQuery();
public void initView() { public void initView() {
if (requirePermissions(permbean.hasPermission(UserPermission.VIEW_ALL))) { if (requirePermissions(permbean.hasPermission(UserPermission.VIEW_ALL))) {
super.setResult(userbean.getEventUsers(getSearchQuery())); if (usersearch.isOnlyThisEvent() || usersearch.getSearch() == null || usersearch.getSearch().isEmpty())
{
usersearch.setOnlyThisEvent(true);
SearchResult<EventUser> eventusers = userbean.getThisEventsUsers(getSearchQuery());
this.setResultcount(eventusers.getResultcount());
this.setEventUserResults(eventusers.getResults());
}
else {
super.setResult(userbean.getEventUsers(getSearchQuery()));
}
} }
} }
@Override
public UserSearchQuery getSearchQuery()
{
return usersearch;
}
public List<EventUser> getEventUserResults() {
return eventUserResults;
}
public void setEventUserResults(List<EventUser> eventUserResults) {
this.eventUserResults = eventUserResults;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!