Commit 86c88cdf by Tuomas Riihimäki

Merge branch 'master' of codecrew.fi:bortal

2 parents 5345e25e 18458a23
...@@ -23,6 +23,7 @@ import fi.insomnia.bortal.facade.EventUserFacade; ...@@ -23,6 +23,7 @@ import fi.insomnia.bortal.facade.EventUserFacade;
import fi.insomnia.bortal.model.CardTemplate; import fi.insomnia.bortal.model.CardTemplate;
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.util.MassPrintResult;
import fi.insomnia.bortal.utilities.BarcodeUtils; import fi.insomnia.bortal.utilities.BarcodeUtils;
/** /**
...@@ -45,27 +46,33 @@ public class CardPrintBean implements CardPrintBeanLocal { ...@@ -45,27 +46,33 @@ public class CardPrintBean implements CardPrintBeanLocal {
//TODO: Roles? //TODO: Roles?
public byte[] getUserCardsAsPrintablePdf(List<Integer> userIdList) throws Exception { public MassPrintResult getUserCardsAsPrintablePdf(List<Integer> userIdList) throws Exception {
ArrayList<EventUser> listOfEventUsers = new ArrayList<EventUser>(); ArrayList<EventUser> listOfEventUsers = new ArrayList<EventUser>();
for(Integer userId : userIdList) { for(Integer userId : userIdList) {
listOfEventUsers.add(eventUserFacade.find(userId)); listOfEventUsers.add(eventUserFacade.find(userId));
} }
byte[] pdfData = constructPdf(listOfEventUsers); return constructPdf(listOfEventUsers);
return pdfData;
} }
public byte[] getUserCardAsPrintablePdf(Integer userId) throws Exception { public MassPrintResult getUserCardAsPrintablePdf(Integer userId) throws Exception {
ArrayList<EventUser> listOfEventUsers = new ArrayList<EventUser>(); ArrayList<EventUser> listOfEventUsers = new ArrayList<EventUser>();
listOfEventUsers.add(eventUserFacade.find(userId)); listOfEventUsers.add(eventUserFacade.find(userId));
byte[] pdfData = constructPdf(listOfEventUsers); return constructPdf(listOfEventUsers);
return pdfData;
} }
private byte[] constructPdf(List<EventUser> users) throws Exception { public void acceptMassPrintResult(MassPrintResult mpr) {
for(EventUser eu : mpr.getAffectedUsers()) {
PrintedCard printedCard = cardTemplateBean.checkPrintedCard(eu);
printedCard.setPrintCount(printedCard.getPrintCount()+1);
System.out.println("Print count "+printedCard.getPrintCount());
}
}
private MassPrintResult constructPdf(List<EventUser> users) throws Exception {
// double[] pageSize = new double[] { cardBackground.getWidth(), // double[] pageSize = new double[] { cardBackground.getWidth(),
// cardBackground.getHeight() }; // cardBackground.getHeight() };
...@@ -78,13 +85,14 @@ public class CardPrintBean implements CardPrintBeanLocal { ...@@ -78,13 +85,14 @@ public class CardPrintBean implements CardPrintBeanLocal {
double pagex = 155.52; // 54,0 mm double pagex = 155.52; // 54,0 mm
double pagey = 243.84; // 85,5 mm double pagey = 243.84; // 85,5 mm
int numCards = 0; MassPrintResult mpr = new MassPrintResult();
for(EventUser user : users) { for(EventUser user : users) {
PrintedCard printedCard = cardTemplateBean.checkPrintedCard(user); PrintedCard printedCard = cardTemplateBean.checkPrintedCard(user);
if(printedCard == null) continue;
else numCards++; if(printedCard == null)
continue;
CardTemplate cardTemplate = printedCard.getTemplate(); CardTemplate cardTemplate = printedCard.getTemplate();
...@@ -154,14 +162,15 @@ public class CardPrintBean implements CardPrintBeanLocal { ...@@ -154,14 +162,15 @@ public class CardPrintBean implements CardPrintBeanLocal {
barCodeImage.setPosition(0.0, 243.5); barCodeImage.setPosition(0.0, 243.5);
barCodeImage.scaleBy(0.7); barCodeImage.scaleBy(0.7);
barCodeImage.drawOn(page); barCodeImage.drawOn(page);
mpr.getAffectedUsers().add(user);
} }
pdf.flush(); pdf.flush();
outputStream.close(); outputStream.close();
if(numCards == 0) throw new Exception("No cards generated"); if(mpr.getAffectedUsers().size() == 0) throw new Exception("No cards generated");
mpr.setPdf(outputStream.toByteArray());
return outputStream.toByteArray(); return mpr;
} }
private ByteArrayInputStream convertBufferedImageToPng(BufferedImage img) private ByteArrayInputStream convertBufferedImageToPng(BufferedImage img)
......
...@@ -82,6 +82,8 @@ public class MenuBean implements MenuBeanLocal { ...@@ -82,6 +82,8 @@ public class MenuBean implements MenuBeanLocal {
frontTopnavi.addPage(menuitemfacade.findOrCreate("/auth/passwordChanged"), null).setVisible(false); frontTopnavi.addPage(menuitemfacade.findOrCreate("/auth/passwordChanged"), null).setVisible(false);
frontTopnavi.addPage(menuitemfacade.findOrCreate("/auth/notauthorized"), null).setVisible(false); frontTopnavi.addPage(menuitemfacade.findOrCreate("/auth/notauthorized"), null).setVisible(false);
MenuNavigation userTopnavi = usernavi.addPage(null, null); MenuNavigation userTopnavi = usernavi.addPage(null, null);
userTopnavi.setKey("topnavi.user"); userTopnavi.setKey("topnavi.user");
userTopnavi.addPage(menuitemfacade.findOrCreate("/user/edit"), UserPermission.VIEW_SELF).setHeader("submenu.user.userlinks"); userTopnavi.addPage(menuitemfacade.findOrCreate("/user/edit"), UserPermission.VIEW_SELF).setHeader("submenu.user.userlinks");
...@@ -93,6 +95,10 @@ public class MenuBean implements MenuBeanLocal { ...@@ -93,6 +95,10 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation placemapTopmenu = usernavi.addPage(null, null); MenuNavigation placemapTopmenu = usernavi.addPage(null, null);
placemapTopmenu.setKey("topnavi.placemap"); placemapTopmenu.setKey("topnavi.placemap");
placemapTopmenu.addPage(menuitemfacade.findOrCreate("/place/placemap"), MapPermission.VIEW); placemapTopmenu.addPage(menuitemfacade.findOrCreate("/place/placemap"), MapPermission.VIEW);
MenuNavigation actionlogTopmenu = usernavi.addPage(null,null);
actionlogTopmenu.setKey("topnavi.actionlog");
actionlogTopmenu.addPage(menuitemfacade.findOrCreate("/actionlog/messagelist"), ContentPermission.MANAGE_ACTIONLOG);
MenuNavigation shopTopmenu = usernavi.addPage(null, null); MenuNavigation shopTopmenu = usernavi.addPage(null, null);
shopTopmenu.setKey("topnavi.shop"); shopTopmenu.setKey("topnavi.shop");
......
...@@ -4,8 +4,11 @@ import java.util.List; ...@@ -4,8 +4,11 @@ import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
import fi.insomnia.bortal.util.MassPrintResult;
@Local @Local
public interface CardPrintBeanLocal { public interface CardPrintBeanLocal {
public byte[] getUserCardsAsPrintablePdf(List<Integer> userIdList) throws Exception; public MassPrintResult getUserCardsAsPrintablePdf(List<Integer> userIdList) throws Exception;
public byte[] getUserCardAsPrintablePdf(Integer userId) throws Exception; public MassPrintResult getUserCardAsPrintablePdf(Integer userId) throws Exception;
public void acceptMassPrintResult(MassPrintResult mpr);
} }
package fi.insomnia.bortal.util;
import java.util.ArrayList;
import java.util.List;
import fi.insomnia.bortal.model.EventUser;
public class MassPrintResult {
private byte[] pdf;
private List<EventUser> affectedUsers = new ArrayList<EventUser>();
public byte[] getPdf() {
return pdf;
}
public void setPdf(byte[] pdf) {
this.pdf = pdf;
}
public List<EventUser> getAffectedUsers() {
return affectedUsers;
}
public void setAffectedUsers(List<EventUser> affectedUsers) {
this.affectedUsers = affectedUsers;
}
}
...@@ -123,6 +123,15 @@ ...@@ -123,6 +123,15 @@
</navigation-case> </navigation-case>
</navigation-rule> </navigation-rule>
<navigation-rule> <navigation-rule>
<display-name>card/massprint</display-name>
<from-view-id>/card/massprint.xhtml</from-view-id>
<navigation-case>
<from-outcome>accepted</from-outcome>
<to-view-id>/useradmin/list.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
<navigation-rule>
<display-name>voting/create</display-name> <display-name>voting/create</display-name>
<from-view-id>/voting/create.xhtml</from-view-id> <from-view-id>/voting/create.xhtml</from-view-id>
<navigation-case> <navigation-case>
......
...@@ -14,10 +14,12 @@ ...@@ -14,10 +14,12 @@
<h1>#{i18n['card.massprint.title']}</h1> <h1>#{i18n['card.massprint.title']}</h1>
</ui:define> </ui:define>
<ui:define name="content"> <ui:define name="content">
<h:form> <h:form rendered="#{cardMassPrintView.file!=null}">
<p:commandButton rendered="#{cardMassPrintView.file!=null}" id="downloadLink" value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)" icon="ui-icon-arrowthichk-s"> <p:commandButton id="downloadLink" value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)" icon="ui-icon-arrowthichk-s">
<p:fileDownload value="#{cardMassPrintView.streamedFile}" /> <p:fileDownload value="#{cardMassPrintView.streamedFile}" />
</p:commandButton> </p:commandButton>
<p:commandButton value="Accept printout" action="#{cardMassPrintView.acceptPrintout()}" rendered="#{cardMassPrintView.waitForAcceptance}" />
</h:form> </h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
...@@ -3,22 +3,26 @@ ...@@ -3,22 +3,26 @@
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"> xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head> <h:head>
<title></title> <title>Error</title>
</h:head> </h:head>
<h:body> <h:body>
<br/> <!-- <c:if test="#{sessionHandler.isInDevelopmentMode() eq true}"> -->
<center> <h1>#{i18n['error.error']}</h1>
<img src="#{request.contextPath}/resources/media/error.jpg" /> <p>${i18n['error.contact']}
<h1>LOL, ERROR!</h1> <br/><h:outputText escape="false" style="color: red;" value="#{errorPageView.time}" /><br/><br/>
<br/> <!-- Trail:<br/><h:outputText escape="false" style="color: red;" value="#{errorPageView.trail}" /> -->
<c:if test="#{sessionHandler.isInDevelopmentMode() eq false}"> <a href="#{request.contextPath}">Home</a>
<h:outputText escape="false" style="color: red;" value="ERR##{errorPageView.time}" /> </p>
</c:if> <!-- </c:if> -->
<br/><br/> <br/><br/>
</center>
<c:when test="#{sessionHandler.isInDevelopmentMode()}"> <c:when test="#{sessionHandler.isInDevelopmentMode()}">
<br/>
<center>
<img src="#{request.contextPath}/resources/media/error.jpg" />
<h1>LOL, ERROR!</h1>
<br/>
</center>
<h:outputText escape="false" value="#{errorPageView.stackTrace}" /> <h:outputText escape="false" value="#{errorPageView.stackTrace}" />
</c:when> </c:when>
</h:body> </h:body>
</html> </html>
\ No newline at end of file
package fi.insomnia.bortal; package fi.insomnia.bortal;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList;
import java.util.Queue;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
...@@ -45,7 +48,8 @@ public class HostnameFilter implements Filter { ...@@ -45,7 +48,8 @@ public class HostnameFilter implements Filter {
public void destroy() { public void destroy() {
// Nothing... // Nothing...
} }
@SessionScoped
Queue<String> trail = new LinkedList<String>();
/** /**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/ */
...@@ -113,6 +117,13 @@ public class HostnameFilter implements Filter { ...@@ -113,6 +117,13 @@ public class HostnameFilter implements Filter {
{ {
sessionmgmt.updateSessionUser(httpRequest.getSession().getId(), httpRequest.getUserPrincipal().getName()); sessionmgmt.updateSessionUser(httpRequest.getSession().getId(), httpRequest.getUserPrincipal().getName());
} }
if (trail.size() == 10) {
trail.remove();
}
if (!httpRequest.getRequestURI().matches(".*(resource).*")) {
trail.add(httpRequest.getRequestURI());
httpRequest.getSession().setAttribute("trail", trail);
}
} }
// pass the request along the filter chain // pass the request along the filter chain
......
...@@ -71,6 +71,9 @@ bortalApplication.user.WRITE_ROLES = Modify roles ...@@ -71,6 +71,9 @@ bortalApplication.user.WRITE_ROLES = Modify roles
cardTemplate.emptyCardTemplate = ---- cardTemplate.emptyCardTemplate = ----
error.contact = If this happens again, contact Info with the following code:
error.error = You have encountered an error.
eventorg.create = Create eventorg.create = Create
global.cancel = Cancel global.cancel = Cancel
......
...@@ -125,6 +125,9 @@ editplacegroup.header = Placegroup information ...@@ -125,6 +125,9 @@ editplacegroup.header = Placegroup information
entry.edit = Edit entry entry.edit = Edit entry
error.contact = If this happens again, contact Info with the following code:
error.error = You have encountered an error.
event.defaultRole = Default user role event.defaultRole = Default user role
event.edit = Edit event.edit = Edit
event.endTime = End time event.endTime = End time
......
...@@ -20,6 +20,9 @@ actionlog.user = User ...@@ -20,6 +20,9 @@ actionlog.user = User
bill.billMarkedPaidMail.message = Your deposit number {0} has been marked as paid. bill.billMarkedPaidMail.message = Your deposit number {0} has been marked as paid.
bill.billMarkedPaidMail.subject = [Streamparty] Your credits have been updated bill.billMarkedPaidMail.subject = [Streamparty] Your credits have been updated
error.contact = If this happens again, contact Info with the following code:
error.error = You have encountered an error.
eventorg.create = Create eventorg.create = Create
eventorg.edit = Edit eventorg.edit = Edit
......
...@@ -123,6 +123,9 @@ editplacegroup.header = Paikkaryhm\u00E4n tiedot ...@@ -123,6 +123,9 @@ editplacegroup.header = Paikkaryhm\u00E4n tiedot
entry.edit = Muokkaa entry.edit = Muokkaa
error.contact = Jos t\u00E4m\u00E4 toistuu, ota seuraava koodi talteen ja ota yhteys Infoon:
error.error = Olet kohdannut virheen.
event.defaultRole = K\u00E4ytt\u00E4jien oletusrooli event.defaultRole = K\u00E4ytt\u00E4jien oletusrooli
event.edit = Muokkaa event.edit = Muokkaa
event.endTime = Lopetusp\u00E4iv\u00E4 event.endTime = Lopetusp\u00E4iv\u00E4
......
...@@ -20,6 +20,9 @@ actionlog.user = Tekij\u00E4 ...@@ -20,6 +20,9 @@ actionlog.user = Tekij\u00E4
bill.billMarkedPaidMail.message = Laskusi numero {0} on merkitty maksetuksi. Voit nyt siirty\u00E4 lippukauppaan varamaamaan haluamasi paikat. \nTervetuloa tapahtumaan!\n\nTerveisin,\nInsomnia lippupalvelu\nwww.insomnia.fi bill.billMarkedPaidMail.message = Laskusi numero {0} on merkitty maksetuksi. Voit nyt siirty\u00E4 lippukauppaan varamaamaan haluamasi paikat. \nTervetuloa tapahtumaan!\n\nTerveisin,\nInsomnia lippupalvelu\nwww.insomnia.fi
bill.billMarkedPaidMail.subject = [INSOMNIA] Lasku merkitty maksetuksi bill.billMarkedPaidMail.subject = [INSOMNIA] Lasku merkitty maksetuksi
error.contact = Jos t\u00E4m\u00E4 toistuu, ota seuraava koodi talteen ja ota yhteys Infoon:
error.error = Olet kohdannut virheen.
eventorg.create = Luo eventorg.create = Luo
eventorg.edit = Muokkaa eventorg.edit = Muokkaa
......
package fi.insomnia.bortal.web; package fi.insomnia.bortal.web;
import javax.enterprise.context.SessionScoped; import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import sun.misc.Queue; import java.util.Queue;
import java.io.PrintWriter; import java.io.PrintWriter;
...@@ -17,7 +19,7 @@ import java.util.Calendar; ...@@ -17,7 +19,7 @@ import java.util.Calendar;
import java.util.Map; import java.util.Map;
@Named @Named
@SessionScoped @RequestScoped
public class ErrorPageView implements Serializable { public class ErrorPageView implements Serializable {
/** /**
...@@ -27,8 +29,8 @@ public class ErrorPageView implements Serializable { ...@@ -27,8 +29,8 @@ public class ErrorPageView implements Serializable {
// private static final long serialVersionUID = -2179309061036632342L; // private static final long serialVersionUID = -2179309061036632342L;
String trace; String trace;
// maintain a trail of pages visited (10?) @Inject
Queue trail = new Queue(); private transient FacesContext context;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class); private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class);
...@@ -49,8 +51,21 @@ public class ErrorPageView implements Serializable { ...@@ -49,8 +51,21 @@ public class ErrorPageView implements Serializable {
} }
public Long getTime(){ public String getTime(){
return Calendar.getInstance().getTimeInMillis(); return "0x" + Long.toHexString(Calendar.getInstance().getTimeInMillis());
}
public String getTrail() {
HttpServletRequest req = (HttpServletRequest) getContext().getExternalContext().getRequest();
Object trail = req.getSession().getAttribute("trail");
return trail != null ? trail.toString().replace(", ", "\n") : "u gots no trail!";
} }
public FacesContext getContext() {
return context;
}
public void setContext(FacesContext context) {
this.context = context;
}
} }
\ No newline at end of file
...@@ -13,6 +13,8 @@ import org.primefaces.model.StreamedContent; ...@@ -13,6 +13,8 @@ import org.primefaces.model.StreamedContent;
import fi.insomnia.bortal.beans.CardPrintBeanLocal; import fi.insomnia.bortal.beans.CardPrintBeanLocal;
import fi.insomnia.bortal.model.EventUser; import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.util.MassPrintResult;
import fi.insomnia.bortal.web.cdiview.GenericCDIView;
import fi.insomnia.bortal.web.cdiview.user.UserCartView; import fi.insomnia.bortal.web.cdiview.user.UserCartView;
import java.io.File; import java.io.File;
...@@ -25,7 +27,7 @@ import java.util.List; ...@@ -25,7 +27,7 @@ import java.util.List;
@Named @Named
@ConversationScoped @ConversationScoped
public class CardMassPrintView implements Serializable { public class CardMassPrintView extends GenericCDIView implements Serializable {
private static final long serialVersionUID = -1017243588290663967L; private static final long serialVersionUID = -1017243588290663967L;
@Inject private UserCartView userCartView; @Inject private UserCartView userCartView;
...@@ -33,6 +35,9 @@ public class CardMassPrintView implements Serializable { ...@@ -33,6 +35,9 @@ public class CardMassPrintView implements Serializable {
private File file; private File file;
private StreamedContent streamedFile; private StreamedContent streamedFile;
private MassPrintResult mpr = null;
private boolean waitForAcceptance = true;
public CardMassPrintView() { public CardMassPrintView() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
...@@ -48,10 +53,11 @@ public class CardMassPrintView implements Serializable { ...@@ -48,10 +53,11 @@ public class CardMassPrintView implements Serializable {
file = null; file = null;
try { try {
byte[] printout = cardPrintBean.getUserCardsAsPrintablePdf(userIdList); mpr = cardPrintBean.getUserCardsAsPrintablePdf(userIdList);
waitForAcceptance = true;
file = File.createTempFile("cardprintout",null); file = File.createTempFile("cardprintout",null);
FileOutputStream fostream = new FileOutputStream(file); FileOutputStream fostream = new FileOutputStream(file);
fostream.write(printout); fostream.write(mpr.getPdf());
fostream.close(); fostream.close();
setStreamedFile(new DefaultStreamedContent(new FileInputStream(this.file))); setStreamedFile(new DefaultStreamedContent(new FileInputStream(this.file)));
...@@ -60,6 +66,17 @@ public class CardMassPrintView implements Serializable { ...@@ -60,6 +66,17 @@ public class CardMassPrintView implements Serializable {
} }
} }
public String acceptPrintout() {
if(mpr != null && waitForAcceptance) {
waitForAcceptance = false;
cardPrintBean.acceptMassPrintResult(mpr);
}
userCartView.setUsercart(new ArrayList<EventUser>());
return "accepted";
}
public UserCartView getUserCartView() { public UserCartView getUserCartView() {
return userCartView; return userCartView;
} }
...@@ -83,4 +100,12 @@ public class CardMassPrintView implements Serializable { ...@@ -83,4 +100,12 @@ public class CardMassPrintView implements Serializable {
public void setStreamedFile(StreamedContent streamedFile) { public void setStreamedFile(StreamedContent streamedFile) {
this.streamedFile = streamedFile; this.streamedFile = streamedFile;
} }
public boolean isWaitForAcceptance() {
return waitForAcceptance;
}
public void setWaitForAcceptance(boolean waitForAcceptance) {
this.waitForAcceptance = waitForAcceptance;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!