Commit 9c27721e by Antti Tönkyrä

Merge branch 'master' of codecrew.fi:bortal

2 parents 3fab346e 863ff474
package fi.insomnia.bortal.web.cdiview.card; package fi.insomnia.bortal.web.cdiview.card;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage; import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -17,25 +22,19 @@ import fi.insomnia.bortal.util.MassPrintResult; ...@@ -17,25 +22,19 @@ import fi.insomnia.bortal.util.MassPrintResult;
import fi.insomnia.bortal.web.cdiview.GenericCDIView; 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.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Named @Named
@ConversationScoped @ConversationScoped
public class CardMassPrintView extends GenericCDIView 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;
@EJB private CardPrintBeanLocal cardPrintBean;
@EJB
private CardPrintBeanLocal cardPrintBean;
private File file; private File file;
private StreamedContent streamedFile; private StreamedContent streamedFile;
private MassPrintResult mpr = null; private MassPrintResult mpr = null;
private boolean waitForAcceptance = true; private boolean waitForAcceptance = true;
...@@ -43,40 +42,45 @@ public class CardMassPrintView extends GenericCDIView implements Serializable { ...@@ -43,40 +42,45 @@ public class CardMassPrintView extends GenericCDIView implements Serializable {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public void initView() { public void initView() {
List<EventUser> eventUsers = userCartView.getUsercart(); List<EventUser> eventUsers = userCartView.getUsercart();
ArrayList<Integer> userIdList = new ArrayList<Integer>(); ArrayList<Integer> userIdList = new ArrayList<Integer>();
for(EventUser eu : eventUsers) { for (EventUser eu : eventUsers) {
userIdList.add(eu.getId()); userIdList.add(eu.getId());
} }
file = null; file = null;
try { try {
mpr = cardPrintBean.getUserCardsAsPrintablePdf(userIdList); mpr = cardPrintBean.getUserCardsAsPrintablePdf(userIdList);
waitForAcceptance = true; waitForAcceptance = true;
file = File.createTempFile("cardprintout",null);
FileOutputStream fostream = new FileOutputStream(file);
fostream.write(mpr.getPdf());
fostream.close();
setStreamedFile(new DefaultStreamedContent(new FileInputStream(this.file)));
} catch(Exception e) { ByteArrayInputStream pdfstream = new ByteArrayInputStream(mpr.getPdf());
//
// file = File.createTempFile("cardprintout",null);
// FileOutputStream fostream = new FileOutputStream(file);
// fostream.write(mpr.getPdf());
// fostream.close();
// setStreamedFile(new DefaultStreamedContent(new
// FileInputStream(this.file)));
setStreamedFile(new DefaultStreamedContent(pdfstream));
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
} }
} }
public String acceptPrintout() { public String acceptPrintout() {
if(mpr != null && waitForAcceptance) { if (mpr != null && waitForAcceptance) {
waitForAcceptance = false; waitForAcceptance = false;
cardPrintBean.acceptMassPrintResult(mpr); cardPrintBean.acceptMassPrintResult(mpr);
} }
userCartView.setUsercart(new ArrayList<EventUser>()); userCartView.setUsercart(new ArrayList<EventUser>());
return "accepted"; return "accepted";
} }
public UserCartView getUserCartView() { public UserCartView getUserCartView() {
return userCartView; return userCartView;
} }
......
package fi.insomnia.bortal.web.cdiview.user; package fi.insomnia.bortal.web.cdiview.user;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
...@@ -166,11 +165,15 @@ public class UserView extends GenericCDIView { ...@@ -166,11 +165,15 @@ public class UserView extends GenericCDIView {
try { try {
mpr = cardPrintBean.getUserCardAsPrintablePdf(this.user.getId()); mpr = cardPrintBean.getUserCardAsPrintablePdf(this.user.getId());
file = File.createTempFile("cardprintout", null); ByteArrayInputStream pdfstream = new ByteArrayInputStream(mpr.getPdf());
FileOutputStream fostream = new FileOutputStream(file);
fostream.write(mpr.getPdf()); // file = File.createTempFile("cardprintout", null);
fostream.close(); // FileOutputStream fostream = new FileOutputStream(file);
setStreamedFile(new DefaultStreamedContent(new FileInputStream(this.file))); // fostream.write(mpr.getPdf());
// fostream.close();
// setStreamedFile(new DefaultStreamedContent(new
// FileInputStream(this.file)));
setStreamedFile(new DefaultStreamedContent(pdfstream));
} catch (Exception e) { } catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!