Rev 1701 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1701 | Rev 1734 | ||
---|---|---|---|
1 | package pt.estgp.estgweb.web.form.courseunits; |
1 | package pt.estgp.estgweb.web.form.courseunits; |
2 | 2 | ||
3 | import org.apache.log4j.Logger; |
3 | import org.apache.log4j.Logger; |
4 | import org.apache.struts.action.ActionErrors; |
4 | import org.apache.struts.action.ActionErrors; |
5 | import org.apache.struts.upload.FormFile; |
5 | import org.apache.struts.upload.FormFile; |
6 | import org.apache.struts.upload.MultipartRequestHandler; |
6 | import org.apache.struts.upload.MultipartRequestHandler; |
7 | import pt.estgp.estgweb.Globals; |
7 | import pt.estgp.estgweb.Globals; |
8 | import pt.estgp.estgweb.domain.views.CourseUnitAssignementView; |
8 | import pt.estgp.estgweb.domain.views.CourseUnitAssignementView; |
9 | import pt.estgp.estgweb.domain.views.CourseUnitDeliverableView; |
9 | import pt.estgp.estgweb.domain.views.CourseUnitDeliverableView; |
10 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
10 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
11 | import pt.estgp.estgweb.services.common.SearchTypeEnum; |
11 | import pt.estgp.estgweb.services.common.SearchTypeEnum; |
12 | import pt.estgp.estgweb.utils.DatesUtils; |
12 | import pt.estgp.estgweb.utils.DatesUtils; |
13 | import pt.estgp.estgweb.web.form.commons.TeachersForm; |
13 | import pt.estgp.estgweb.web.form.commons.TeachersForm; |
14 | 14 | ||
15 | import java.util.ArrayList; |
15 | import java.util.ArrayList; |
16 | import java.util.Iterator; |
16 | import java.util.Iterator; |
17 | import java.util.List; |
17 | import java.util.List; |
18 | 18 | ||
19 | /** |
19 | /** |
20 | * @author Jorge Machado |
20 | * @author Jorge Machado |
21 | * @date 2/Jun/2008 |
21 | * @date 2/Jun/2008 |
22 | * @time 14:28:59 |
22 | * @time 14:28:59 |
23 | * @see pt.estgp.estgweb.web.form.blogs |
23 | * @see pt.estgp.estgweb.web.form.blogs |
24 | */ |
24 | */ |
25 | public class CourseUnitsForm extends TeachersForm |
25 | public class CourseUnitsForm extends TeachersForm |
26 | { |
26 | { |
27 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(CourseUnitsForm.class); |
27 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(CourseUnitsForm.class); |
28 | 28 | ||
29 | CourseUnitView courseUnitView = new CourseUnitView(); |
29 | CourseUnitView courseUnitView = new CourseUnitView(); |
30 | 30 | ||
31 | //aux |
31 | //aux |
32 | long courseId; |
32 | long courseId; |
33 | long id; |
33 | long id; |
34 | long teacherId; |
34 | long teacherId; |
35 | int studentCode; |
35 | int studentCode; |
36 | boolean showNewWorkForm = false; |
36 | boolean showNewWorkForm = false; |
37 | FormFile uploadFile; |
37 | FormFile uploadFile; |
38 | 38 | ||
39 | 1.5.0/docs/api/java/lang/String.html">String choosedTurma; |
39 | 1.5.0/docs/api/java/lang/String.html">String choosedTurma; |
40 | 1.5.0/docs/api/java/lang/String.html">String newChoosedTurma; |
40 | 1.5.0/docs/api/java/lang/String.html">String newChoosedTurma; |
41 | 41 | ||
42 | 42 | ||
43 | //courseunit |
43 | //courseunit |
44 | FormFile programFile; |
44 | FormFile programFile; |
45 | CourseUnitAssignementView courseUnitAssignementView = new CourseUnitAssignementView(); |
45 | CourseUnitAssignementView courseUnitAssignementView = new CourseUnitAssignementView(); |
46 | //search |
46 | //search |
47 | 1.5.0/docs/api/java/lang/String.html">String textToSearch; |
47 | 1.5.0/docs/api/java/lang/String.html">String textToSearch; |
48 | 1.5.0/docs/api/java/lang/String.html">String searchType = SearchTypeEnum.AllWords.getMessageKey(); |
48 | 1.5.0/docs/api/java/lang/String.html">String searchType = SearchTypeEnum.AllWords.getMessageKey(); |
49 | int page; |
49 | int page; |
50 | 50 | ||
51 | 51 | ||
52 | public CourseUnitsForm(boolean initDeliverables) |
52 | public CourseUnitsForm(boolean initDeliverables) |
53 | { |
53 | { |
54 | if(initDeliverables) |
54 | if(initDeliverables) |
55 | initDeliverables(); |
55 | initDeliverables(); |
56 | } |
56 | } |
57 | public CourseUnitsForm() |
57 | public CourseUnitsForm() |
58 | { |
58 | { |
59 | initDeliverables(); |
59 | initDeliverables(); |
60 | } |
60 | } |
61 | 61 | ||
62 | public void initDeliverables() |
62 | public void initDeliverables() |
63 | { |
63 | { |
64 | courseUnitAssignementView.setDeliverables(new ArrayList<CourseUnitDeliverableView>()); |
64 | courseUnitAssignementView.setDeliverables(new ArrayList<CourseUnitDeliverableView>()); |
65 | for(int i = 0; i < 200; i++) |
65 | for(int i = 0; i < 200; i++) |
66 | { |
66 | { |
67 | courseUnitAssignementView.getDeliverables().add(new CourseUnitDeliverableView()); |
67 | courseUnitAssignementView.getDeliverables().add(new CourseUnitDeliverableView()); |
68 | } |
68 | } |
69 | } |
69 | } |
70 | 70 | ||
71 | public CourseUnitView getCourseUnitView() |
71 | public CourseUnitView getCourseUnitView() |
72 | { |
72 | { |
73 | return courseUnitView; |
73 | return courseUnitView; |
74 | } |
74 | } |
75 | 75 | ||
76 | public void setCourseUnitView(CourseUnitView courseUnitView) |
76 | public void setCourseUnitView(CourseUnitView courseUnitView) |
77 | { |
77 | { |
78 | this.courseUnitView = courseUnitView; |
78 | this.courseUnitView = courseUnitView; |
79 | } |
79 | } |
80 | 80 | ||
81 | public FormFile getProgramFile() |
81 | public FormFile getProgramFile() |
82 | { |
82 | { |
83 | return programFile; |
83 | return programFile; |
84 | } |
84 | } |
85 | 85 | ||
86 | public void setProgramFile(FormFile programFile) |
86 | public void setProgramFile(FormFile programFile) |
87 | { |
87 | { |
88 | this.programFile = programFile; |
88 | this.programFile = programFile; |
89 | } |
89 | } |
90 | 90 | ||
91 | public List<String> getImportYears() |
91 | public List<String> getImportYears() |
92 | { |
92 | { |
93 | return DatesUtils.getImportYears(15); |
93 | return DatesUtils.getImportYears(15); |
94 | } |
94 | } |
95 | 95 | ||
96 | 96 | ||
97 | public boolean isShowNewWorkForm() |
97 | public boolean isShowNewWorkForm() |
98 | { |
98 | { |
99 | return showNewWorkForm; |
99 | return showNewWorkForm; |
100 | } |
100 | } |
101 | 101 | ||
102 | public void setShowNewWorkForm(boolean showNewWorkForm) |
102 | public void setShowNewWorkForm(boolean showNewWorkForm) |
103 | { |
103 | { |
104 | this.showNewWorkForm = showNewWorkForm; |
104 | this.showNewWorkForm = showNewWorkForm; |
105 | } |
105 | } |
106 | 106 | ||
107 | public CourseUnitAssignementView getCourseUnitAssignementView() |
107 | public CourseUnitAssignementView getCourseUnitAssignementView() |
108 | { |
108 | { |
109 | return courseUnitAssignementView; |
109 | return courseUnitAssignementView; |
110 | } |
110 | } |
111 | 111 | ||
112 | public void setCourseUnitAssignementView(CourseUnitAssignementView courseUnitAssignementView) |
112 | public void setCourseUnitAssignementView(CourseUnitAssignementView courseUnitAssignementView) |
113 | { |
113 | { |
114 | this.courseUnitAssignementView = courseUnitAssignementView; |
114 | this.courseUnitAssignementView = courseUnitAssignementView; |
115 | } |
115 | } |
116 | 116 | ||
117 | 117 | ||
118 | public long getId() |
118 | public long getId() |
119 | { |
119 | { |
120 | return id; |
120 | return id; |
121 | } |
121 | } |
122 | 122 | ||
123 | public void setId(long id) |
123 | public void setId(long id) |
124 | { |
124 | { |
125 | this.id = id; |
125 | this.id = id; |
126 | } |
126 | } |
127 | 127 | ||
128 | public long getTeacherId() |
128 | public long getTeacherId() |
129 | { |
129 | { |
130 | return teacherId; |
130 | return teacherId; |
131 | } |
131 | } |
132 | 132 | ||
133 | public void setTeacherId(long teacherId) |
133 | public void setTeacherId(long teacherId) |
134 | { |
134 | { |
135 | this.teacherId = teacherId; |
135 | this.teacherId = teacherId; |
136 | } |
136 | } |
137 | 137 | ||
138 | 138 | ||
139 | public int getStudentCode() |
139 | public int getStudentCode() |
140 | { |
140 | { |
141 | return studentCode; |
141 | return studentCode; |
142 | } |
142 | } |
143 | 143 | ||
144 | public void setStudentCode(int studentCode) |
144 | public void setStudentCode(int studentCode) |
145 | { |
145 | { |
146 | this.studentCode = studentCode; |
146 | this.studentCode = studentCode; |
147 | } |
147 | } |
148 | 148 | ||
149 | public 1.5.0/docs/api/java/lang/String.html">String getTextToSearch() |
149 | public 1.5.0/docs/api/java/lang/String.html">String getTextToSearch() |
150 | { |
150 | { |
151 | return textToSearch; |
151 | return textToSearch; |
152 | } |
152 | } |
153 | 153 | ||
154 | public void setTextToSearch(1.5.0/docs/api/java/lang/String.html">String textToSearch) |
154 | public void setTextToSearch(1.5.0/docs/api/java/lang/String.html">String textToSearch) |
155 | { |
155 | { |
156 | this.textToSearch = textToSearch; |
156 | this.textToSearch = textToSearch; |
157 | } |
157 | } |
158 | 158 | ||
159 | 159 | ||
160 | public 1.5.0/docs/api/java/lang/String.html">String getSearchType() |
160 | public 1.5.0/docs/api/java/lang/String.html">String getSearchType() |
161 | { |
161 | { |
162 | return searchType; |
162 | return searchType; |
163 | } |
163 | } |
164 | 164 | ||
165 | public void setSearchType(1.5.0/docs/api/java/lang/String.html">String searchType) |
165 | public void setSearchType(1.5.0/docs/api/java/lang/String.html">String searchType) |
166 | { |
166 | { |
167 | this.searchType = searchType; |
167 | this.searchType = searchType; |
168 | } |
168 | } |
169 | 169 | ||
170 | public SearchTypeEnum getSearchTypeEnum() |
170 | public SearchTypeEnum getSearchTypeEnum() |
171 | { |
171 | { |
172 | return SearchTypeEnum.parse(searchType); |
172 | return SearchTypeEnum.parse(searchType); |
173 | } |
173 | } |
174 | 174 | ||
175 | public void setSearchTypeEnum(SearchTypeEnum searchTypeEnum) |
175 | public void setSearchTypeEnum(SearchTypeEnum searchTypeEnum) |
176 | { |
176 | { |
177 | searchType = searchTypeEnum.getMessageKey(); |
177 | searchType = searchTypeEnum.getMessageKey(); |
178 | } |
178 | } |
179 | 179 | ||
180 | 180 | ||
181 | public int getPage() |
181 | public int getPage() |
182 | { |
182 | { |
183 | return page; |
183 | return page; |
184 | } |
184 | } |
185 | 185 | ||
186 | public void setPage(int page) |
186 | public void setPage(int page) |
187 | { |
187 | { |
188 | this.page = page; |
188 | this.page = page; |
189 | } |
189 | } |
190 | 190 | ||
191 | 191 | ||
192 | 192 | ||
193 | 193 | ||
194 | public FormFile getUploadFile() |
194 | public FormFile getUploadFile() |
195 | { |
195 | { |
196 | return uploadFile; |
196 | return uploadFile; |
197 | } |
197 | } |
198 | 198 | ||
199 | public void setUploadFile(FormFile uploadFile) |
199 | public void setUploadFile(FormFile uploadFile) |
200 | { |
200 | { |
201 | this.uploadFile = uploadFile; |
201 | this.uploadFile = uploadFile; |
202 | } |
202 | } |
203 | 203 | ||
204 | public ActionErrors validate(org.apache.struts.action.ActionMapping actionMapping, javax.servlet.http.HttpServletRequest httpServletRequest) |
204 | public ActionErrors validate(org.apache.struts.action.ActionMapping actionMapping, javax.servlet.http.HttpServletRequest httpServletRequest) |
205 | { |
205 | { |
206 | ActionErrors errors = new ActionErrors(); |
206 | ActionErrors errors = new ActionErrors(); |
207 | 207 | ||
208 | return errors; |
208 | return errors; |
209 | } |
209 | } |
210 | 210 | ||
211 | public ActionErrors validateCreateAssignement(org.apache.struts.action.ActionMapping actionMapping, javax.servlet.http.HttpServletRequest httpServletRequest) |
211 | public ActionErrors validateCreateAssignement(org.apache.struts.action.ActionMapping actionMapping, javax.servlet.http.HttpServletRequest httpServletRequest) |
212 | { |
212 | { |
213 | ActionErrors errors = new ActionErrors(); |
213 | ActionErrors errors = new ActionErrors(); |
214 | 1.5.0/docs/api/java/lang/Boolean.html">Boolean maxLengthExceeded = |
214 | 1.5.0/docs/api/java/lang/Boolean.html">Boolean maxLengthExceeded = |
215 | (1.5.0/docs/api/java/lang/Boolean.html">Boolean) httpServletRequest.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED); |
215 | (1.5.0/docs/api/java/lang/Boolean.html">Boolean) httpServletRequest.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED); |
216 | if(maxLengthExceeded != null) |
216 | if(maxLengthExceeded != null) |
217 | { |
217 | { |
218 | logger.error("MAX FILE UPLOAD EXCEEDED"); |
218 | logger.error("MAX FILE UPLOAD EXCEEDED"); |
219 | addMessage(errors, httpServletRequest, "errors.file.too.long", "20MB"); |
219 | addMessage(errors, httpServletRequest, "errors.file.too.long", "20MB"); |
220 | return errors; |
220 | return errors; |
221 | } |
221 | } |
222 | 222 | ||
223 | if(getUploadFile() == null || getUploadFile().getFileSize() == 0) |
223 | //if(getUploadFile() == null || getUploadFile().getFileSize() == 0) |
224 | { |
224 | //{ |
225 | addMessageAsString(errors,"Um Ficheiro esta Vazio"); |
225 | // addMessageAsString(errors,"Um Ficheiro esta Vazio"); |
226 | return errors; |
226 | // return errors; |
227 | } |
227 | //} |
228 | 228 | ||
229 | //tod verificar |
229 | //tod verificar |
- | 230 | if(getUploadFile() != null) |
|
230 | try{ |
231 | { |
- | 232 | try{ |
|
231 | double fileSize = getUploadFile().getFileSize(); |
233 | double fileSize = getUploadFile().getFileSize(); |
232 | fileSize = fileSize / 1024.0 / 1024.0; |
234 | fileSize = fileSize / 1024.0 / 1024.0; |
233 | if(fileSize > Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES) |
235 | if(fileSize > Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES) |
- | 236 | { |
|
- | 237 | addMessage(errors, httpServletRequest, "errors.file.too.long", Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES + "MB"); |
|
- | 238 | return errors; |
|
- | 239 | } |
|
- | 240 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
|
234 | { |
241 | { |
235 | addMessage(errors, httpServletRequest, "errors.file.too.long", Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES + "MB"); |
- | |
236 | return errors; |
242 | //muito pequeno se dividir por 0 nao faz mal |
237 | } |
243 | } |
238 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
- | |
239 | { |
- | |
240 | //muito pequeno se dividir por 0 nao faz mal |
- | |
241 | } |
244 | } |
242 | 245 | ||
243 | if(courseUnitAssignementView.getDeliverDate() == null || courseUnitAssignementView.getDeliverDate().length() == 0) |
246 | if(courseUnitAssignementView.getDeliverDate() == null || courseUnitAssignementView.getDeliverDate().length() == 0) |
244 | { |
247 | { |
245 | addMessageWithKeys(errors,httpServletRequest,"errors.required","courseunit.assignement.deliver.date"); |
248 | addMessageWithKeys(errors,httpServletRequest,"errors.required","courseunit.assignement.deliver.date"); |
246 | } |
249 | } |
247 | if(courseUnitAssignementView.getTitle() == null || courseUnitAssignementView.getTitle().trim().length() == 0) |
250 | if(courseUnitAssignementView.getTitle() == null || courseUnitAssignementView.getTitle().trim().length() == 0) |
248 | { |
251 | { |
249 | addMessageWithKeys(errors,httpServletRequest,"errors.required","courseunit.title"); |
252 | addMessageWithKeys(errors,httpServletRequest,"errors.required","courseunit.title"); |
250 | } |
253 | } |
251 | // if(uploadFile != null && uploadFile.getFileSize() > 0 && !uploadFile.getFileName().endsWith(".zip")) |
254 | // if(uploadFile != null && uploadFile.getFileSize() > 0 && !uploadFile.getFileName().endsWith(".zip")) |
252 | // { |
255 | // { |
253 | // addMessage(errors,httpServletRequest,"errors.courseunit.assignement.file.type"); |
256 | // addMessage(errors,httpServletRequest,"errors.courseunit.assignement.file.type"); |
254 | // } |
257 | // } |
255 | return errors; |
258 | return errors; |
256 | } |
259 | } |
257 | 260 | ||
258 | public ActionErrors validateDeliverWork(org.apache.struts.action.ActionMapping actionMapping, javax.servlet.http.HttpServletRequest httpServletRequest) |
261 | public ActionErrors validateDeliverWork(org.apache.struts.action.ActionMapping actionMapping, javax.servlet.http.HttpServletRequest httpServletRequest) |
259 | { |
262 | { |
260 | ActionErrors errors = new ActionErrors(); |
263 | ActionErrors errors = new ActionErrors(); |
261 | if(uploadFile == null || uploadFile.getFileSize() == 0) |
264 | if(uploadFile == null || uploadFile.getFileSize() == 0) |
262 | { |
265 | { |
263 | addMessage(errors,httpServletRequest,"errors.courseunit.assignement.deliver.file"); |
266 | addMessage(errors,httpServletRequest,"errors.courseunit.assignement.deliver.file"); |
264 | } |
267 | } |
265 | 268 | ||
266 | //tod verificar |
269 | //tod verificar |
267 | try{ |
270 | try{ |
268 | double fileSize = uploadFile.getFileSize(); |
271 | double fileSize = uploadFile.getFileSize(); |
269 | fileSize = fileSize / 1024.0 / 1024.0; |
272 | fileSize = fileSize / 1024.0 / 1024.0; |
270 | if(fileSize > Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES) |
273 | if(fileSize > Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES) |
271 | { |
274 | { |
272 | addMessage(errors, httpServletRequest, "errors.file.too.long", Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES + "MB"); |
275 | addMessage(errors, httpServletRequest, "errors.file.too.long", Globals.MAX_FILE_UPOLOAD_SIZE_MBYTES + "MB"); |
273 | return errors; |
276 | return errors; |
274 | } |
277 | } |
275 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
278 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
276 | { |
279 | { |
277 | //muito pequeno se dividir por 0 nao faz mal |
280 | //muito pequeno se dividir por 0 nao faz mal |
278 | } |
281 | } |
279 | // if(uploadFile != null && uploadFile.getFileName() !=null && !uploadFile.getFileName().endsWith(".zip")) |
282 | // if(uploadFile != null && uploadFile.getFileName() !=null && !uploadFile.getFileName().endsWith(".zip")) |
280 | // { |
283 | // { |
281 | // addMessage(errors,httpServletRequest,"errors.courseunit.assignement.deliver.zip"); |
284 | // addMessage(errors,httpServletRequest,"errors.courseunit.assignement.deliver.zip"); |
282 | // } |
285 | // } |
283 | return errors; |
286 | return errors; |
284 | } |
287 | } |
285 | 288 | ||
286 | public void validateUpdateDeliverables() |
289 | public void validateUpdateDeliverables() |
287 | { |
290 | { |
288 | Iterator<CourseUnitDeliverableView> iter = courseUnitAssignementView.getDeliverables().iterator(); |
291 | Iterator<CourseUnitDeliverableView> iter = courseUnitAssignementView.getDeliverables().iterator(); |
289 | while (iter.hasNext()) |
292 | while (iter.hasNext()) |
290 | { |
293 | { |
291 | CourseUnitDeliverableView courseUnitDeliverableView = iter.next(); |
294 | CourseUnitDeliverableView courseUnitDeliverableView = iter.next(); |
292 | if(courseUnitDeliverableView.getId() <= 0) |
295 | if(courseUnitDeliverableView.getId() <= 0) |
293 | { |
296 | { |
294 | iter.remove(); |
297 | iter.remove(); |
295 | } |
298 | } |
296 | } |
299 | } |
297 | } |
300 | } |
298 | 301 | ||
299 | public 1.5.0/docs/api/java/lang/String.html">String getChoosedTurma() { |
302 | public 1.5.0/docs/api/java/lang/String.html">String getChoosedTurma() { |
300 | return choosedTurma; |
303 | return choosedTurma; |
301 | } |
304 | } |
302 | 305 | ||
303 | public void setChoosedTurma(1.5.0/docs/api/java/lang/String.html">String choosedTurma) { |
306 | public void setChoosedTurma(1.5.0/docs/api/java/lang/String.html">String choosedTurma) { |
304 | this.choosedTurma = choosedTurma; |
307 | this.choosedTurma = choosedTurma; |
305 | } |
308 | } |
306 | 309 | ||
307 | public 1.5.0/docs/api/java/lang/String.html">String getNewChoosedTurma() { |
310 | public 1.5.0/docs/api/java/lang/String.html">String getNewChoosedTurma() { |
308 | return newChoosedTurma; |
311 | return newChoosedTurma; |
309 | } |
312 | } |
310 | 313 | ||
311 | public void setNewChoosedTurma(1.5.0/docs/api/java/lang/String.html">String newChoosedTurma) { |
314 | public void setNewChoosedTurma(1.5.0/docs/api/java/lang/String.html">String newChoosedTurma) { |
312 | this.newChoosedTurma = newChoosedTurma; |
315 | this.newChoosedTurma = newChoosedTurma; |
313 | } |
316 | } |
314 | } |
317 | } |
315 | 318 |