-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileUploadBean.java
87 lines (70 loc) · 2.85 KB
/
FileUploadBean.java
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
package technology.touchmars.jsf;
import technology.touchmars.model.PayoutRequestWeb;
import technology.touchmars.service.PayoutRequestService;
import technology.touchmars.util.FileUtil;
import technology.touchmars.util.PayoutRequestConverter;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
@Named("fileUploadBean")
@RequestScoped
public class FileUploadBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private PayoutRequestConverter payoutRequestConverter;
@Inject
private PayoutRequestService payoutRequestService;
// @Inject Logger log;
private static final Logger log = Logger.getLogger(FileUploadBean.class.getSimpleName());
// @Inject
// username should be able to inject from Authentication module
private String username = "dummyUser";
private Part file;
private Long reqId = 8L;
public String upload(){
log.info("call upload...");
log.log(Level.INFO, "content-type:{0}", file.getContentType());
log.log(Level.INFO, "filename:{0}", file.getName());
log.log(Level.INFO, "submitted filename:{0}", file.getSubmittedFileName());
log.log(Level.INFO, "size:{0}", file.getSize());
try {
byte[] results=new byte[(int)file.getSize()];
InputStream in=file.getInputStream();
File file1 = FileUtil.allocateFile4User(username, file.getSubmittedFileName());
file1 = FileUtil.writeInputStream2File(in, file1);
//TODO: handle validation errors
// PayoutRequestWeb payoutRequestWeb = payoutRequestConverter.convertCsv2PayoutRequestWeb(file1);
// payoutRequestWeb = payoutRequestService.persistPayoutRequestWeb(payoutRequestWeb);
// reqId = payoutRequestWeb.getId();
return "good";
} catch (IOException ex) {
log.log(Level.SEVERE, " ex @{0}", ex);
}
return null;
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(String.format("File %s Uploaded!", file.getSubmittedFileName())));
}
public Part getFile() {
return file;
}
public void setFile(Part file) {
this.file = file;
log.info("call setFile");
log.log(Level.INFO, "content-type:{0}", file.getContentType());
log.log(Level.INFO, "filename:{0}", file.getName());
log.log(Level.INFO, "submitted filename:{0}", file.getSubmittedFileName());
log.log(Level.INFO, "size:{0}", file.getSize());
}
public Long getReqId() {
return reqId;
}
public void setReqId(Long reqId) {
this.reqId = reqId;
}
}