CardMassPrintView.java
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package fi.codecrew.moya.web.cdiview.card;
import java.io.ByteArrayInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.CardPrintBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.util.MassPrintResult;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.user.UserCartView;
@Named
@ConversationScoped
public class CardMassPrintView extends GenericCDIView implements Serializable {
private static final long serialVersionUID = -1017243588290663967L;
@Inject
private UserCartView userCartView;
@EJB
private CardPrintBeanLocal cardPrintBean;
private StreamedContent streamedFile;
private MassPrintResult mpr = null;
private boolean waitForAcceptance = true;
private static final Logger logger = LoggerFactory.getLogger(CardMassPrintView.class);
public CardMassPrintView() {
// TODO Auto-generated constructor stub
}
public void initView() {
List<EventUser> eventUsers = userCartView.getUsercart();
ArrayList<Integer> userIdList = new ArrayList<Integer>();
for (EventUser eu : eventUsers) {
userIdList.add(eu.getId());
}
try {
mpr = cardPrintBean.getUserCardsAsPrintablePdf(userIdList);
waitForAcceptance = true;
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()));
}
}
public String acceptPrintout() {
if (mpr != null && waitForAcceptance) {
waitForAcceptance = false;
cardPrintBean.acceptMassPrintResult(mpr);
}
userCartView.setUsercart(new ArrayList<EventUser>());
return "accepted";
}
public UserCartView getUserCartView() {
return userCartView;
}
public void setUserCartView(UserCartView userCartView) {
this.userCartView = userCartView;
}
public StreamedContent getStreamedFile() {
return streamedFile;
}
public void setStreamedFile(StreamedContent streamedFile) {
this.streamedFile = streamedFile;
}
public boolean isWaitForAcceptance() {
return waitForAcceptance;
}
public void setWaitForAcceptance(boolean waitForAcceptance) {
this.waitForAcceptance = waitForAcceptance;
}
}