View Javadoc

1   package org.kuali.mobility.file.entity;
2   
3   import java.io.IOException;
4   import java.sql.Timestamp;
5   import javax.persistence.Column;
6   import javax.persistence.Entity;
7   import javax.persistence.GeneratedValue;
8   import javax.persistence.GenerationType;
9   import javax.persistence.Id;
10  import javax.persistence.Lob;
11  import javax.persistence.Table;
12  import javax.persistence.Transient;
13  import javax.persistence.Version;
14  
15  //import org.kuali.mobility.file.dao.FileDaoImpl;
16  import org.springframework.web.multipart.MultipartFile;
17  
18  // TODO: Move out of the reporting tool. 
19  
20  @Entity
21  @Table(name="KME_FILE_T")
22  public class File {
23  	
24      @Id
25  	@GeneratedValue(strategy = GenerationType.TABLE)
26      @Column(name="ID", nullable=false, updatable=false)
27      private Long id;
28  	
29      @Transient
30      private MultipartFile file;
31  
32      @Lob
33      @Column(name="FILE_DATA")
34      private byte[] bytes;
35      
36      @Column(name="CNTNT_TYP")
37      private String contentType;
38      
39      @Column(name="FILE_NM")
40      private String fileName;
41  
42      @Column(name="FILE_SZ")
43      private int fileSize;
44          
45      @Column(name="PST_TS")
46      private Timestamp postedTimestamp;
47  	
48      
49      
50      @Version
51  	@Column(name = "VER_NBR")
52  	protected Long versionNumber;
53  
54  	public File() {
55  	}
56  
57  	public File(MultipartFile file) {
58  		this.id = id;
59  		this.file = file;
60  		this.fileName = file.getOriginalFilename();
61  		this.contentType = file.getContentType();
62  		try{
63  			this.bytes = file.getBytes();
64  			this.fileSize = file.getBytes().length;
65  		}catch(IOException e){
66  			System.out.println("getBytes Error: " + e.getMessage());
67  		}
68  	}	
69  	
70  	public File(Long id, MultipartFile file) {
71  		this.id = id;
72  		this.file = file;
73  	}	
74  	
75  	public MultipartFile getFile() {
76  		return file;
77  	}
78  
79  	public void setFile(MultipartFile file) {
80  		this.file = file;
81  	}
82  
83  	public Long getId() {
84  		return id;
85  	}
86  
87  	public void setId(Long id) {
88  		this.id = id;
89  	}
90  
91  	public Long getVersionNumber() {
92  		return versionNumber;
93  	}
94  
95  	public void setVersionNumber(Long versionNumber) {
96  		this.versionNumber = versionNumber;
97  	}
98  
99  	public byte[] getBytes() {
100 		return bytes;
101 	}
102 
103 	public void setBytes(byte[] bytes) {
104 		this.bytes = bytes;
105 	}
106 
107 	public String getContentType() {
108 		return contentType;
109 	}
110 
111 	public void setContentType(String contentType) {
112 		this.contentType = contentType;
113 	}
114 
115 	public String getFileName() {
116 		return fileName;
117 	}
118 
119 	public void setFileName(String fileName) {
120 		this.fileName = fileName;
121 	}	
122 
123 	public int getFileSize() {
124 		return fileSize;
125 	}
126 
127 	public void setFileSize(int fileSize) {
128 		this.fileSize = fileSize;
129 	}
130 	
131     public Timestamp getPostedTimestamp() {
132         return postedTimestamp;
133     }
134 
135     public void setPostedTimestamp(Timestamp postedTimestamp) {
136         this.postedTimestamp = postedTimestamp;
137     }
138 	
139 	@Override
140 	public String toString() {
141     	String newline = "\r\n";
142     	String str = newline +"File Id:     " + this.getId();
143     	str = str + newline + "Filename:    " + this.getFileName();
144     	str = str + newline + "ContentType: " + this.getContentType();    
145     	str = str + newline + "Size:        " + this.getFileSize();    
146     	str = str + newline + "Timestamp:   " + this.getPostedTimestamp(); 
147     	return str;
148     }
149 	
150 }