Rev 962 | Rev 970 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
110 | susana | 1 | package pt.estgp.estgweb.domain.dao.impl; |
2 | |||
748 | jmachado | 3 | import org.apache.log4j.Logger; |
205 | jmachado | 4 | import org.hibernate.Criteria; |
358 | jmachado | 5 | import org.hibernate.Query; |
748 | jmachado | 6 | import org.hibernate.criterion.Criterion; |
7 | import org.hibernate.criterion.Order; |
||
376 | jmachado | 8 | import org.hibernate.sql.JoinFragment; |
961 | jmachado | 9 | import pt.estgp.estgweb.domain.*; |
10 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
748 | jmachado | 11 | import pt.estgp.estgweb.domain.dao.DaoUtils; |
12 | import pt.estgp.estgweb.services.common.SearchTypeEnum; |
||
13 | import pt.estgp.estgweb.utils.DatesUtils; |
||
116 | jmachado | 14 | |
961 | jmachado | 15 | import java.util.ArrayList; |
125 | fvelez | 16 | import java.util.List; |
17 | |||
748 | jmachado | 18 | import static org.hibernate.criterion.Restrictions.*; |
19 | |||
110 | susana | 20 | /** |
21 | * @author Jorge Machado |
||
22 | * @date 28/Fev/2008 |
||
23 | * @time 2:51:06 |
||
24 | * @see pt.estgp.estgweb.domain.dao.impl |
||
25 | */ |
||
26 | public class CourseUnitDaoImpl extends CourseUnitDao |
||
27 | { |
||
28 | |||
219 | jmachado | 29 | 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(CourseUnitDaoImpl.class); |
110 | susana | 30 | |
751 | jmachado | 31 | |
202 | jmachado | 32 | private CourseUnitDaoImpl() |
33 | { |
||
110 | susana | 34 | } |
35 | |||
36 | public static CourseUnitDaoImpl getInstance() |
||
37 | { |
||
38 | if (myInstance == null) |
||
39 | myInstance = new CourseUnitDaoImpl(); |
||
40 | return (CourseUnitDaoImpl) myInstance; |
||
41 | } |
||
42 | |||
125 | fvelez | 43 | public List<CourseUnit> loadBySigesCode(1.5.0/docs/api/java/lang/String.html">String sigesCode) |
116 | jmachado | 44 | { |
202 | jmachado | 45 | return createCriteria().add(eq("code", sigesCode)).list(); |
116 | jmachado | 46 | } |
202 | jmachado | 47 | |
214 | jmachado | 48 | public List<CourseUnit> loadByCourse(long course, 1.5.0/docs/api/java/lang/String.html">String importYear) |
49 | { |
||
371 | jmachado | 50 | return createCriteria().add(eq("importYear", importYear)).add(eq("course.id", course)).list(); |
214 | jmachado | 51 | } |
52 | |||
371 | jmachado | 53 | public List<CourseUnit> load(1.5.0/docs/api/java/lang/String.html">String importYear, 1.5.0/docs/api/java/lang/String.html">String semestre) |
358 | jmachado | 54 | { |
371 | jmachado | 55 | return createCriteria().add(eq("importYear", importYear)).add(eq("semestre", semestre)).list(); |
358 | jmachado | 56 | } |
57 | |||
771 | jmachado | 58 | public List<CourseUnit> loadYear(1.5.0/docs/api/java/lang/String.html">String importYear) |
59 | { |
||
60 | return createCriteria().add(eq("importYear", importYear)).list(); |
||
61 | } |
||
62 | |||
767 | jmachado | 63 | |
64 | |||
371 | jmachado | 65 | public List<Long> loadIds(1.5.0/docs/api/java/lang/String.html">String importYear, 1.5.0/docs/api/java/lang/String.html">String semestre) |
358 | jmachado | 66 | { |
371 | jmachado | 67 | 1.5.0/docs/api/javax/management/Query.html">Query q = createQuery("select c.id from c in class " + CourseUnit.class.getName() + " where c.importYear = ? and c.semestre = ?"); |
68 | q.setString(0, importYear); |
||
69 | q.setString(1, semestre); |
||
358 | jmachado | 70 | return q.list(); |
71 | } |
||
72 | |||
218 | jmachado | 73 | public List<CourseUnit> loadSubscribedImportYearUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
74 | { |
||
371 | jmachado | 75 | return createCriteria().add(eq("importYear", importYear)) |
76 | .createAlias("students", "st") |
||
255 | jmachado | 77 | .add(eq("st.id", studentId)).addOrder(Order.asc("name")).list(); |
218 | jmachado | 78 | } |
420 | jmachado | 79 | public List<CourseUnit> loadSubscribedImportYearSemestreUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear, 1.5.0/docs/api/java/lang/String.html">String semestre) |
80 | { |
||
81 | Criteria c =createCriteria() |
||
82 | .add(eq("importYear", importYear)) |
||
83 | .createAlias("students", "st") |
||
84 | .add(eq("st.id", studentId)); |
||
85 | if(semestre != null) |
||
86 | c.add(eq("semestre", semestre)); |
||
87 | return c.addOrder(Order.asc("name")).list(); |
||
88 | } |
||
255 | jmachado | 89 | |
90 | public List<CourseUnit> loadSubscribedOtherImportYearUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
||
91 | { |
||
371 | jmachado | 92 | return createCriteria().add(not(eq("importYear", importYear))) |
93 | .createAlias("students", "st") |
||
255 | jmachado | 94 | .add(eq("st.id", studentId)).addOrder(Order.asc("name")).list(); |
95 | } |
||
343 | jmachado | 96 | |
253 | jmachado | 97 | public List<CourseUnitImpl> loadTeachedImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
218 | jmachado | 98 | { |
371 | jmachado | 99 | return createCriteria().add(eq("importYear", importYear)) |
100 | .createAlias("teachers", "st") |
||
255 | jmachado | 101 | .add(eq("st.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
218 | jmachado | 102 | } |
103 | |||
821 | jmachado | 104 | public List<CourseUnitImpl> loadResponsableImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
105 | { |
||
106 | return createCriteria().add(eq("importYear", importYear)) |
||
107 | .add(eq("responsableTeacher.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
||
108 | } |
||
109 | |||
420 | jmachado | 110 | public List<CourseUnit> loadTeachedImportYearSemestreUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear, 1.5.0/docs/api/java/lang/String.html">String semestre) |
111 | { |
||
112 | Criteria c =createCriteria() |
||
113 | .add(eq("importYear", importYear)) |
||
114 | .createAlias("teachers", "st") |
||
115 | .add(eq("st.id", teacherId)) |
||
116 | .add(eq("st.id", teacherId)); |
||
117 | if(semestre != null) |
||
118 | c.add(eq("semestre", semestre)); |
||
119 | return c.addOrder(Order.asc("name")).list(); |
||
120 | } |
||
121 | |||
122 | |||
123 | |||
163 | jmachado | 124 | public CourseUnit loadBySigesCodeUnique(1.5.0/docs/api/java/lang/String.html">String sigesCode) |
125 | { |
||
202 | jmachado | 126 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).uniqueResult(); |
163 | jmachado | 127 | } |
116 | jmachado | 128 | |
202 | jmachado | 129 | public CourseUnit loadBySigesCodeUnique(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String courseCode) |
130 | { |
||
131 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).add(eq("courseCode", courseCode)).uniqueResult(); |
||
132 | } |
||
163 | jmachado | 133 | |
228 | jmachado | 134 | public CourseUnit loadBySigesCodeUniqueSubscribed(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String year, 1.5.0/docs/api/java/lang/String.html">String courseCode, long studentId, 1.5.0/docs/api/java/lang/String.html">String semestre) |
219 | jmachado | 135 | { |
371 | jmachado | 136 | List<CourseUnit> cus = createCriteria() |
219 | jmachado | 137 | .add(eq("code", sigesCode)) |
228 | jmachado | 138 | .add(eq("importYear", year)) |
219 | jmachado | 139 | .add(eq("courseCode", courseCode)) |
228 | jmachado | 140 | .add(eq("semestre", semestre)) |
371 | jmachado | 141 | .createAlias("students", "st") |
142 | .add(eq("st.id", studentId)) |
||
219 | jmachado | 143 | .list(); |
371 | jmachado | 144 | if (cus.size() > 1) |
219 | jmachado | 145 | { |
146 | CourseUnit cu1 = cus.get(0); |
||
147 | CourseUnit cu2 = cus.get(1); |
||
371 | jmachado | 148 | if (cus.size() > 2) |
219 | jmachado | 149 | { |
150 | logger.error("CourseUnit in more than two places in a course:" + cu1.getCode()); |
||
151 | } |
||
152 | else |
||
153 | { |
||
371 | jmachado | 154 | if (cu1.getSemestre().equals("S1")) |
219 | jmachado | 155 | { |
371 | jmachado | 156 | if (cu2.getSemestre().equals("S1")) |
219 | jmachado | 157 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
158 | else |
||
159 | { |
||
160 | return cu2; |
||
161 | } |
||
162 | } |
||
163 | else |
||
164 | { |
||
371 | jmachado | 165 | if (cu2.getSemestre().equals("S2")) |
219 | jmachado | 166 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
167 | else |
||
168 | { |
||
169 | return cu1; |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 | } |
||
371 | jmachado | 174 | else if (cus.size() == 1) |
219 | jmachado | 175 | return cus.get(0); |
176 | |||
177 | return null; |
||
178 | } |
||
179 | |||
751 | jmachado | 180 | |
181 | public void consistCourseUnitCourseCodes(1.5.0/docs/api/java/lang/String.html">String importYear) |
||
182 | { |
||
183 | List<CourseUnit> courseUnit = createCriteria() |
||
184 | .add(eq("importYear", importYear)).list(); |
||
185 | for(CourseUnit cu: courseUnit) |
||
186 | { |
||
187 | if(cu.getCourse() != null) |
||
188 | { |
||
189 | if(cu.getCourseCode() == null || (cu.getCourseCode() != null && !cu.getCourseCode().equals(cu.getCourse().getCode()))) |
||
190 | { |
||
191 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Course code wrong: " + cu.getId() + " - " + cu.getName() + " old CourseCode " + cu.getCourseCode() + " now:" + cu.getCourse().getCode() ); |
||
192 | } |
||
193 | |||
194 | if(cu.getCourseName() == null || (cu.getCourseName() != null && !cu.getCourseName().equals(cu.getCourse().getName()))) |
||
195 | { |
||
196 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Course name wrong: " + cu.getId() + " - " + cu.getName() + " old CourseCode " + cu.getCourseName() + " now:" + cu.getCourse().getName() ); |
||
197 | } |
||
198 | cu.setCourseCode(cu.getCourse().getCode()); |
||
199 | cu.setCourseName(cu.getCourse().getName()); |
||
200 | } |
||
201 | else |
||
202 | { |
||
203 | cu.setCourseCode(""); |
||
204 | cu.setCourseName(""); |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | |||
209 | |||
899 | jmachado | 210 | //TODO Na actualiza��o de uma cadeira para o curso de TESTE mudar o coursecode para o o coursecode desse curso para nao deixar os dados duplicados e mal |
748 | jmachado | 211 | //se nao a carregar unidades vai buscar a errada |
225 | jmachado | 212 | public CourseUnit loadBySigesCodeUnique(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String semestre, 1.5.0/docs/api/java/lang/String.html">String year) |
202 | jmachado | 213 | { |
225 | jmachado | 214 | return (CourseUnit) |
215 | createCriteria() |
||
216 | .add(eq("code", sigesCode)) |
||
217 | .add(eq("courseCode", courseCode)) |
||
218 | .add(eq("semestre", semestre)) |
||
219 | .add(eq("importYear", year)) |
||
220 | .uniqueResult(); |
||
202 | jmachado | 221 | } |
767 | jmachado | 222 | |
899 | jmachado | 223 | public CourseUnit loadBySigesCodeUniqueMostRecent(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String semestre) |
224 | { |
||
225 | return (CourseUnit) |
||
226 | createCriteria() |
||
227 | .add(eq("code", sigesCode)) |
||
228 | .add(eq("courseCode", courseCode)) |
||
229 | .add(eq("semestre", semestre)) |
||
230 | .addOrder(Order.desc("importYear")) |
||
231 | .setMaxResults(1).list().get(0); |
||
232 | } |
||
233 | |||
234 | |||
883 | jmachado | 235 | public CourseUnit loadBySigesCodeUniqueLastYear(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String semestre) |
767 | jmachado | 236 | { |
899 | jmachado | 237 | return loadBySigesCodeUniqueMostRecent(sigesCode,courseCode,semestre); |
883 | jmachado | 238 | } |
239 | |||
240 | |||
241 | public List<CourseUnit> loadBySigesCodeUnique(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String year) |
||
242 | { |
||
767 | jmachado | 243 | return createCriteria() |
244 | .add(eq("code", sigesCode)) |
||
245 | .add(eq("courseCode", courseCode)) |
||
246 | .add(eq("importYear", year)) |
||
247 | .addOrder(Order.desc("id")) |
||
248 | .list(); |
||
249 | } |
||
250 | |||
457 | jmachado | 251 | public List<CourseUnit> loadBySigesCodes(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String courseCode) |
252 | { |
||
253 | return (List<CourseUnit>) createCriteria() |
||
254 | .add(eq("code", sigesCode)) |
||
255 | .add(eq("courseCode", courseCode)) |
||
256 | .addOrder(Order.desc("importYear")) |
||
257 | .list(); |
||
258 | } |
||
163 | jmachado | 259 | |
376 | jmachado | 260 | public List<CourseUnit> loadCourseUnits(long courseId, 1.5.0/docs/api/java/lang/String.html">String semestre, 1.5.0/docs/api/java/lang/String.html">String year, boolean withTeacher, boolean withNoTeacher) |
261 | { |
||
262 | Criteria c = createCriteria(); |
||
263 | if(courseId > 0) |
||
264 | c.add(eq("course.id", courseId)); |
||
265 | if(semestre != null && semestre.length() > 0) |
||
266 | c.add(eq("semestre", semestre)); |
||
267 | if(year != null && year.length() > 0) |
||
268 | c.add(eq("importYear", year)); |
||
269 | if(withTeacher && !withNoTeacher) |
||
270 | { |
||
271 | c.createAlias("teachers", "th"); |
||
272 | c.add(isNotNull("th.id")); |
||
273 | } |
||
274 | else if(!withTeacher && withNoTeacher) |
||
275 | { |
||
276 | c.createAlias("teachers", "th", JoinFragment.LEFT_OUTER_JOIN); |
||
277 | c.add(isNull("th.id")); |
||
278 | } |
||
279 | return c.list(); |
||
280 | } |
||
163 | jmachado | 281 | |
376 | jmachado | 282 | |
205 | jmachado | 283 | public int countCourseUnits(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
284 | { |
||
749 | jmachado | 285 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name","code"); |
205 | jmachado | 286 | return createCriteria().add(c).list().size(); |
287 | } |
||
163 | jmachado | 288 | |
205 | jmachado | 289 | public List<CourseUnit> search(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
290 | { |
||
748 | jmachado | 291 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name","code"); |
205 | jmachado | 292 | Criteria criteria = createCriteria(); |
293 | criteria.add(c) |
||
294 | .addOrder(Order.asc("name")) |
||
295 | .setMaxResults(maxUnits) |
||
296 | .setFirstResult(page * maxUnits); |
||
297 | return criteria.list(); |
||
298 | } |
||
202 | jmachado | 299 | |
206 | jmachado | 300 | public int countCourseUnitsActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
301 | { |
||
371 | jmachado | 302 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name"); |
206 | jmachado | 303 | return createCriteria() |
304 | .add(c) |
||
305 | .add(eq("importYear", DatesUtils.getImportYear())) |
||
306 | .list().size(); |
||
307 | } |
||
308 | |||
309 | public List<CourseUnit> searchActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
||
310 | { |
||
311 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name"); |
||
312 | Criteria criteria = createCriteria(); |
||
313 | criteria.add(c) |
||
314 | .add(eq("importYear", DatesUtils.getImportYear())) |
||
315 | .addOrder(Order.asc("name")) |
||
316 | .setMaxResults(maxUnits) |
||
317 | .setFirstResult(page * maxUnits); |
||
318 | return criteria.list(); |
||
319 | } |
||
320 | |||
205 | jmachado | 321 | public List<CourseUnit> loadMissingObjectives(long teacherId) |
322 | { |
||
323 | //todo falta a projeccao do teacher id |
||
324 | return createCriteria() |
||
206 | jmachado | 325 | .add(eq("importYear", DatesUtils.getImportYear())) |
371 | jmachado | 326 | .add((or(isNull("objectives"), eq("objectives", "")))) |
205 | jmachado | 327 | .createAlias("teachers", "th") |
371 | jmachado | 328 | .add(eq("semestre", DatesUtils.getSemestre())) |
329 | .add(eq("th.id", teacherId)) |
||
205 | jmachado | 330 | .list(); |
331 | } |
||
332 | |||
214 | jmachado | 333 | public List<CourseUnit> loadMissingPrograms(long teacherId) |
334 | { |
||
335 | //todo falta a projeccao do teacher id |
||
336 | return createCriteria() |
||
337 | .add(eq("importYear", DatesUtils.getImportYear())) |
||
371 | jmachado | 338 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
214 | jmachado | 339 | .createAlias("teachers", "th") |
371 | jmachado | 340 | .add(eq("semestre", DatesUtils.getSemestre())) |
341 | .add(eq("th.id", teacherId)) |
||
214 | jmachado | 342 | .list(); |
343 | } |
||
344 | |||
343 | jmachado | 345 | public List<CourseUnit> loadMissingObjectivesOrPrograms(long teacherId) |
346 | { |
||
347 | //todo falta a projeccao do teacher id |
||
371 | jmachado | 348 | Criteria c = createCriteria() |
343 | jmachado | 349 | .add(eq("importYear", DatesUtils.getImportYear())) |
371 | jmachado | 350 | .add(or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", "")))); |
351 | |||
352 | DatesUtils.SemestreModerate semestreModerate = DatesUtils.getSemestreModerate(); |
||
353 | if (semestreModerate == DatesUtils.SemestreModerate.S1) |
||
354 | c.add(eq("semestre", "S1")); |
||
355 | else if (semestreModerate == DatesUtils.SemestreModerate.S2) |
||
356 | c.add(eq("semestre", "S2")); |
||
357 | else |
||
358 | c.add(or(eq("semestre", "S1"), eq("semestre", "S2"))); |
||
359 | |||
360 | return c.createAlias("teachers", "th") |
||
361 | .add(eq("th.id", teacherId)) |
||
343 | jmachado | 362 | .list(); |
363 | } |
||
214 | jmachado | 364 | |
343 | jmachado | 365 | |
214 | jmachado | 366 | public List<CourseUnit> loadMissingObjectivesGivenCourse(long courseId) |
367 | { |
||
368 | return createCriteria() |
||
369 | .createAlias("course", "c") |
||
371 | jmachado | 370 | .add(eq("c.id", courseId)) |
214 | jmachado | 371 | .add(eq("importYear", DatesUtils.getImportYear())) |
371 | jmachado | 372 | .add(eq("semestre", DatesUtils.getSemestre())) |
373 | .add((or(isNull("objectives"), eq("objectives", "")))) |
||
214 | jmachado | 374 | .list(); |
375 | } |
||
376 | |||
377 | public List<CourseUnit> loadMissingProgramGivenCourse(long courseId) |
||
378 | { |
||
379 | return createCriteria() |
||
380 | .createAlias("course", "c") |
||
371 | jmachado | 381 | .add(eq("c.id", courseId)) |
214 | jmachado | 382 | .add(eq("importYear", DatesUtils.getImportYear())) |
371 | jmachado | 383 | .add(eq("semestre", DatesUtils.getSemestre())) |
384 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
||
214 | jmachado | 385 | .list(); |
386 | } |
||
387 | |||
509 | jmachado | 388 | public List<CourseUnit> loadMissingProgramValidateGivenCourse(long courseId) |
389 | { |
||
390 | return createCriteria() |
||
391 | .createAlias("course", "c") |
||
392 | .add(eq("c.id", courseId)) |
||
393 | .add(eq("importYear", DatesUtils.getImportYear())) |
||
394 | .add(eq("semestre", DatesUtils.getSemestre())) |
||
395 | .add((and(isNotNull("programStreamId"), not(eq("programStreamId", ""))))) |
||
396 | .add((eq("validProgram", false))) |
||
397 | .list(); |
||
398 | } |
||
399 | |||
219 | jmachado | 400 | public List<CourseUnit> loadMissingObjectivesOrProgramGivenCourse(long courseId) |
214 | jmachado | 401 | { |
402 | return createCriteria() |
||
403 | .createAlias("course", "c") |
||
371 | jmachado | 404 | .add(eq("c.id", courseId)) |
214 | jmachado | 405 | .add(eq("importYear", DatesUtils.getImportYear())) |
371 | jmachado | 406 | .add(eq("semestre", DatesUtils.getSemestre())) |
407 | .add((or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", ""))))) |
||
214 | jmachado | 408 | .list(); |
409 | } |
||
205 | jmachado | 410 | |
343 | jmachado | 411 | public int countMissingProgramGivenCourse(long courseId) |
412 | { |
||
413 | return loadMissingProgramGivenCourse(courseId).size(); |
||
414 | } |
||
205 | jmachado | 415 | |
509 | jmachado | 416 | public int countMissingProgramValidateCourse(long courseId) |
417 | { |
||
418 | return loadMissingProgramValidateGivenCourse(courseId).size(); |
||
419 | } |
||
751 | jmachado | 420 | |
421 | |||
422 | public List<String> getTeachersEmails(long unit) { |
||
423 | 1.5.0/docs/api/javax/management/Query.html">Query q = createQuery("select e.email from " |
||
424 | + Teacher.class.getName() + " e join e.teachedUnits as unit " |
||
425 | + " where " |
||
426 | + " unit.id = ? " |
||
427 | |||
428 | ); |
||
429 | q.setLong(0,unit); |
||
430 | return q.list(); |
||
431 | } |
||
961 | jmachado | 432 | |
433 | public static class CourseMissingValidationProgram |
||
434 | { |
||
435 | public Course course; |
||
436 | public List<CourseUnit> courseUnits; |
||
437 | } |
||
438 | public List<CourseMissingValidationProgram> loadMissingProgramValidate(UserSession userSession) |
||
439 | { |
||
440 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
441 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(DatesUtils.getImportYear()); |
||
442 | for(Course course: courses) |
||
443 | { |
||
444 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
445 | { |
||
446 | List<CourseUnit> courseUnits = loadMissingProgramValidateGivenCourse(course.getId()); |
||
447 | if(courseUnits != null && courseUnits.size() > 0) |
||
448 | { |
||
449 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
450 | c.course = course; |
||
451 | c.courseUnits = courseUnits; |
||
452 | result.add(c); |
||
453 | } |
||
454 | } |
||
455 | } |
||
456 | return result; |
||
457 | } |
||
458 | public static class CourseMissingValidationEvaluation |
||
459 | { |
||
460 | public Course course; |
||
461 | public List<CourseUnit> courseUnits; |
||
462 | } |
||
463 | |||
464 | public List<CourseMissingValidationEvaluation> loadMissingEvaluationValidate(UserSession userSession) |
||
465 | { |
||
466 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
962 | jmachado | 467 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
961 | jmachado | 468 | for(Course course: courses) |
469 | { |
||
470 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
471 | { |
||
472 | List<CourseUnit> courseUnits = loadMissingEvaluationValidateGivenCourse(course.getId()); |
||
473 | if(courseUnits != null && courseUnits.size() > 0) |
||
474 | { |
||
475 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
476 | c.course = course; |
||
477 | c.courseUnits = courseUnits; |
||
478 | result.add(c); |
||
479 | } |
||
480 | } |
||
481 | } |
||
482 | return result; |
||
483 | } |
||
484 | |||
485 | /* |
||
486 | * Neste caso apenas se validam as do ano anterior*/ |
||
487 | |||
488 | public List<CourseUnit> loadMissingEvaluationValidateGivenCourse(long courseId) |
||
489 | { |
||
490 | return createCriteria() |
||
491 | .createAlias("course", "c") |
||
492 | .createAlias("courseUnitEvaluation", "ce") |
||
493 | .add(eq("c.id", courseId)) |
||
494 | .add(not(eq("importYear", DatesUtils.getImportYear()))) |
||
495 | .add((and(isNotNull("evaluationStreamId"), not(eq("evaluationStreamId", ""))))) |
||
496 | .add((eq("ce.closed", false))) |
||
497 | .list(); |
||
498 | } |
||
967 | jmachado | 499 | |
500 | public List<CourseMissingValidationEvaluation> loadMissingEvaluation(UserSession userSession) |
||
501 | { |
||
502 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
503 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
||
504 | for(Course course: courses) |
||
505 | { |
||
506 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
507 | { |
||
508 | List<CourseUnit> courseUnits = loadMissingEvaluation(course.getId()); |
||
509 | if(courseUnits != null && courseUnits.size() > 0) |
||
510 | { |
||
511 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
512 | c.course = course; |
||
513 | c.courseUnits = courseUnits; |
||
514 | result.add(c); |
||
515 | } |
||
516 | } |
||
517 | } |
||
518 | return result; |
||
519 | } |
||
520 | |||
521 | public List<CourseUnit> loadMissingEvaluation(long courseId) |
||
522 | { |
||
523 | return createCriteria() |
||
524 | .createAlias("course", "c") |
||
525 | .createAlias("courseUnitEvaluation", "ce") |
||
526 | .add(eq("c.id", courseId)) |
||
527 | .add(not(eq("importYear", DatesUtils.getImportYear()))) |
||
528 | .add((or(isNull("evaluationStreamId"), eq("evaluationStreamId", "")))) |
||
529 | .list(); |
||
530 | } |
||
110 | susana | 531 | } |