Rev 1232 | Rev 1245 | 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; |
||
1103 | jmachado | 8 | import org.hibernate.criterion.Projections; |
376 | jmachado | 9 | import org.hibernate.sql.JoinFragment; |
1094 | jmachado | 10 | import pt.estgp.estgweb.Globals; |
961 | jmachado | 11 | import pt.estgp.estgweb.domain.*; |
12 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
748 | jmachado | 13 | import pt.estgp.estgweb.domain.dao.DaoUtils; |
14 | import pt.estgp.estgweb.services.common.SearchTypeEnum; |
||
15 | import pt.estgp.estgweb.utils.DatesUtils; |
||
116 | jmachado | 16 | |
961 | jmachado | 17 | import java.util.ArrayList; |
125 | fvelez | 18 | import java.util.List; |
19 | |||
748 | jmachado | 20 | import static org.hibernate.criterion.Restrictions.*; |
21 | |||
110 | susana | 22 | /** |
23 | * @author Jorge Machado |
||
24 | * @date 28/Fev/2008 |
||
25 | * @time 2:51:06 |
||
26 | * @see pt.estgp.estgweb.domain.dao.impl |
||
27 | */ |
||
28 | public class CourseUnitDaoImpl extends CourseUnitDao |
||
29 | { |
||
30 | |||
219 | jmachado | 31 | 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 | 32 | |
751 | jmachado | 33 | |
202 | jmachado | 34 | private CourseUnitDaoImpl() |
35 | { |
||
110 | susana | 36 | } |
37 | |||
38 | public static CourseUnitDaoImpl getInstance() |
||
39 | { |
||
40 | if (myInstance == null) |
||
41 | myInstance = new CourseUnitDaoImpl(); |
||
42 | return (CourseUnitDaoImpl) myInstance; |
||
43 | } |
||
44 | |||
125 | fvelez | 45 | public List<CourseUnit> loadBySigesCode(1.5.0/docs/api/java/lang/String.html">String sigesCode) |
116 | jmachado | 46 | { |
202 | jmachado | 47 | return createCriteria().add(eq("code", sigesCode)).list(); |
116 | jmachado | 48 | } |
202 | jmachado | 49 | |
214 | jmachado | 50 | public List<CourseUnit> loadByCourse(long course, 1.5.0/docs/api/java/lang/String.html">String importYear) |
51 | { |
||
371 | jmachado | 52 | return createCriteria().add(eq("importYear", importYear)).add(eq("course.id", course)).list(); |
214 | jmachado | 53 | } |
54 | |||
371 | jmachado | 55 | 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 | 56 | { |
371 | jmachado | 57 | return createCriteria().add(eq("importYear", importYear)).add(eq("semestre", semestre)).list(); |
358 | jmachado | 58 | } |
59 | |||
771 | jmachado | 60 | public List<CourseUnit> loadYear(1.5.0/docs/api/java/lang/String.html">String importYear) |
61 | { |
||
62 | return createCriteria().add(eq("importYear", importYear)).list(); |
||
63 | } |
||
64 | |||
767 | jmachado | 65 | |
66 | |||
371 | jmachado | 67 | 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 | 68 | { |
371 | jmachado | 69 | 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 = ?"); |
70 | q.setString(0, importYear); |
||
71 | q.setString(1, semestre); |
||
358 | jmachado | 72 | return q.list(); |
73 | } |
||
74 | |||
995 | jmachado | 75 | public List<Long> loadIds(1.5.0/docs/api/java/lang/String.html">String importYear) |
76 | { |
||
77 | 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 = ?"); |
||
78 | q.setString(0, importYear); |
||
79 | //q.setString(1, semestre); |
||
80 | return q.list(); |
||
81 | } |
||
82 | |||
218 | jmachado | 83 | public List<CourseUnit> loadSubscribedImportYearUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
84 | { |
||
1072 | jmachado | 85 | return createCriteria() |
371 | jmachado | 86 | .createAlias("students", "st") |
1072 | jmachado | 87 | .add(eq("st.id", studentId)) |
88 | .add(eq("importYear", importYear)) |
||
89 | .addOrder(Order.asc("name")) |
||
90 | .list(); |
||
218 | jmachado | 91 | } |
420 | jmachado | 92 | 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) |
93 | { |
||
94 | Criteria c =createCriteria() |
||
1072 | jmachado | 95 | .createAlias("students", "st") |
96 | .add(eq("st.id", studentId)) |
||
97 | .add(eq("importYear", importYear)); |
||
420 | jmachado | 98 | if(semestre != null) |
99 | c.add(eq("semestre", semestre)); |
||
100 | return c.addOrder(Order.asc("name")).list(); |
||
101 | } |
||
255 | jmachado | 102 | |
103 | public List<CourseUnit> loadSubscribedOtherImportYearUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
||
104 | { |
||
371 | jmachado | 105 | return createCriteria().add(not(eq("importYear", importYear))) |
106 | .createAlias("students", "st") |
||
255 | jmachado | 107 | .add(eq("st.id", studentId)).addOrder(Order.asc("name")).list(); |
108 | } |
||
343 | jmachado | 109 | |
253 | jmachado | 110 | public List<CourseUnitImpl> loadTeachedImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
218 | jmachado | 111 | { |
371 | jmachado | 112 | return createCriteria().add(eq("importYear", importYear)) |
113 | .createAlias("teachers", "st") |
||
255 | jmachado | 114 | .add(eq("st.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
218 | jmachado | 115 | } |
116 | |||
821 | jmachado | 117 | public List<CourseUnitImpl> loadResponsableImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
118 | { |
||
119 | return createCriteria().add(eq("importYear", importYear)) |
||
120 | .add(eq("responsableTeacher.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
||
121 | } |
||
122 | |||
420 | jmachado | 123 | 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) |
124 | { |
||
125 | Criteria c =createCriteria() |
||
126 | .add(eq("importYear", importYear)) |
||
127 | .createAlias("teachers", "st") |
||
128 | .add(eq("st.id", teacherId)) |
||
129 | .add(eq("st.id", teacherId)); |
||
130 | if(semestre != null) |
||
131 | c.add(eq("semestre", semestre)); |
||
132 | return c.addOrder(Order.asc("name")).list(); |
||
133 | } |
||
134 | |||
135 | |||
136 | |||
163 | jmachado | 137 | public CourseUnit loadBySigesCodeUnique(1.5.0/docs/api/java/lang/String.html">String sigesCode) |
138 | { |
||
202 | jmachado | 139 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).uniqueResult(); |
163 | jmachado | 140 | } |
116 | jmachado | 141 | |
202 | jmachado | 142 | 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) |
143 | { |
||
144 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).add(eq("courseCode", courseCode)).uniqueResult(); |
||
145 | } |
||
163 | jmachado | 146 | |
228 | jmachado | 147 | 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 | 148 | { |
371 | jmachado | 149 | List<CourseUnit> cus = createCriteria() |
219 | jmachado | 150 | .add(eq("code", sigesCode)) |
228 | jmachado | 151 | .add(eq("importYear", year)) |
219 | jmachado | 152 | .add(eq("courseCode", courseCode)) |
228 | jmachado | 153 | .add(eq("semestre", semestre)) |
371 | jmachado | 154 | .createAlias("students", "st") |
155 | .add(eq("st.id", studentId)) |
||
219 | jmachado | 156 | .list(); |
371 | jmachado | 157 | if (cus.size() > 1) |
219 | jmachado | 158 | { |
159 | CourseUnit cu1 = cus.get(0); |
||
160 | CourseUnit cu2 = cus.get(1); |
||
371 | jmachado | 161 | if (cus.size() > 2) |
219 | jmachado | 162 | { |
163 | logger.error("CourseUnit in more than two places in a course:" + cu1.getCode()); |
||
164 | } |
||
165 | else |
||
166 | { |
||
371 | jmachado | 167 | if (cu1.getSemestre().equals("S1")) |
219 | jmachado | 168 | { |
371 | jmachado | 169 | if (cu2.getSemestre().equals("S1")) |
219 | jmachado | 170 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
171 | else |
||
172 | { |
||
173 | return cu2; |
||
174 | } |
||
175 | } |
||
176 | else |
||
177 | { |
||
371 | jmachado | 178 | if (cu2.getSemestre().equals("S2")) |
219 | jmachado | 179 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
180 | else |
||
181 | { |
||
182 | return cu1; |
||
183 | } |
||
184 | } |
||
185 | } |
||
186 | } |
||
371 | jmachado | 187 | else if (cus.size() == 1) |
219 | jmachado | 188 | return cus.get(0); |
189 | |||
190 | return null; |
||
191 | } |
||
192 | |||
751 | jmachado | 193 | |
194 | public void consistCourseUnitCourseCodes(1.5.0/docs/api/java/lang/String.html">String importYear) |
||
195 | { |
||
196 | List<CourseUnit> courseUnit = createCriteria() |
||
197 | .add(eq("importYear", importYear)).list(); |
||
198 | for(CourseUnit cu: courseUnit) |
||
199 | { |
||
200 | if(cu.getCourse() != null) |
||
201 | { |
||
202 | if(cu.getCourseCode() == null || (cu.getCourseCode() != null && !cu.getCourseCode().equals(cu.getCourse().getCode()))) |
||
203 | { |
||
204 | 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() ); |
||
205 | } |
||
206 | |||
207 | if(cu.getCourseName() == null || (cu.getCourseName() != null && !cu.getCourseName().equals(cu.getCourse().getName()))) |
||
208 | { |
||
209 | 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() ); |
||
210 | } |
||
211 | cu.setCourseCode(cu.getCourse().getCode()); |
||
212 | cu.setCourseName(cu.getCourse().getName()); |
||
213 | } |
||
214 | else |
||
215 | { |
||
216 | cu.setCourseCode(""); |
||
217 | cu.setCourseName(""); |
||
218 | } |
||
219 | } |
||
220 | } |
||
221 | |||
222 | |||
1117 | jmachado | 223 | //TODO Na actualizacao 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 | 224 | //se nao a carregar unidades vai buscar a errada |
1138 | jmachado | 225 | |
226 | /** |
||
227 | * Turma required to be unique in BACO Model |
||
228 | * @param sigesCode |
||
229 | * @param courseCode |
||
230 | * @param semestre |
||
231 | * @param year |
||
232 | * @return |
||
233 | */ |
||
234 | public List<CourseUnit> loadBySigesCode(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 | 235 | { |
1138 | jmachado | 236 | return |
225 | jmachado | 237 | createCriteria() |
238 | .add(eq("code", sigesCode)) |
||
239 | .add(eq("courseCode", courseCode)) |
||
240 | .add(eq("semestre", semestre)) |
||
241 | .add(eq("importYear", year)) |
||
1138 | jmachado | 242 | .list(); |
202 | jmachado | 243 | } |
767 | jmachado | 244 | |
1117 | jmachado | 245 | /** |
246 | * Metodo especial para a fase de transicao para terem código de turma |
||
247 | * @param sigesCode |
||
248 | * @param courseCode |
||
249 | * @param semestre |
||
250 | * @param year |
||
251 | * @return |
||
252 | */ |
||
253 | public List<CourseUnit> loadBySigesCodeTurmaNull(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) |
||
254 | { |
||
1232 | jmachado | 255 | //todo cdTurma Rollback |
1117 | jmachado | 256 | return (List<CourseUnit>) |
257 | createCriteria() |
||
258 | .add(eq("code", sigesCode)) |
||
259 | .add(eq("courseCode", courseCode)) |
||
260 | .add(eq("semestre", semestre)) |
||
261 | .add(eq("importYear", year)) |
||
262 | .add(isNull("cdTurma")) |
||
263 | .list(); |
||
264 | } |
||
265 | |||
266 | //TODO Na actualizacao 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 |
||
267 | //se nao a carregar unidades vai buscar a errada |
||
268 | 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,1.5.0/docs/api/java/lang/String.html">String turma) |
||
269 | { |
||
1232 | jmachado | 270 | //todo cdTurma Rollback |
1117 | jmachado | 271 | return (CourseUnit) |
272 | createCriteria() |
||
273 | .add(eq("code", sigesCode)) |
||
274 | .add(eq("courseCode", courseCode)) |
||
275 | .add(eq("semestre", semestre)) |
||
276 | .add(eq("importYear", year)) |
||
277 | .add(eq("cdTurma", turma)) |
||
278 | .uniqueResult(); |
||
279 | } |
||
280 | |||
1233 | jmachado | 281 | public List<CourseUnit> loadBySigesCodeUniqueAllCourses(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String semestre, 1.5.0/docs/api/java/lang/String.html">String year,1.5.0/docs/api/java/lang/String.html">String turma) |
1232 | jmachado | 282 | { |
283 | //todo cdTurma Rollback |
||
1233 | jmachado | 284 | return |
1232 | jmachado | 285 | createCriteria() |
286 | .add(eq("code", sigesCode)) |
||
287 | // REMOVED TO LET BE ALL COURSES .add(eq("courseCode", courseCode)) |
||
288 | .add(eq("semestre", semestre)) |
||
289 | .add(eq("importYear", year)) |
||
290 | .add(eq("cdTurma", turma)) |
||
1233 | jmachado | 291 | .list(); |
1232 | jmachado | 292 | } |
293 | |||
899 | jmachado | 294 | 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) |
295 | { |
||
1098 | jmachado | 296 | List<CourseUnit> cus = |
899 | jmachado | 297 | createCriteria() |
298 | .add(eq("code", sigesCode)) |
||
299 | .add(eq("courseCode", courseCode)) |
||
300 | .add(eq("semestre", semestre)) |
||
301 | .addOrder(Order.desc("importYear")) |
||
1098 | jmachado | 302 | .setMaxResults(1).list(); |
303 | if(cus.size() > 0) |
||
304 | return cus.get(0); |
||
305 | logger.warn("Accessing unit not existent with siges code " + sigesCode + " course code: " + courseCode + " semestre: " + semestre); |
||
306 | return null; |
||
899 | jmachado | 307 | } |
308 | |||
309 | |||
883 | jmachado | 310 | 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 | 311 | { |
899 | jmachado | 312 | return loadBySigesCodeUniqueMostRecent(sigesCode,courseCode,semestre); |
883 | jmachado | 313 | } |
314 | |||
315 | |||
316 | 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) |
||
317 | { |
||
767 | jmachado | 318 | return createCriteria() |
319 | .add(eq("code", sigesCode)) |
||
320 | .add(eq("courseCode", courseCode)) |
||
321 | .add(eq("importYear", year)) |
||
322 | .addOrder(Order.desc("id")) |
||
323 | .list(); |
||
324 | } |
||
325 | |||
457 | jmachado | 326 | 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) |
327 | { |
||
328 | return (List<CourseUnit>) createCriteria() |
||
329 | .add(eq("code", sigesCode)) |
||
330 | .add(eq("courseCode", courseCode)) |
||
331 | .addOrder(Order.desc("importYear")) |
||
332 | .list(); |
||
333 | } |
||
163 | jmachado | 334 | |
1077 | jmachado | 335 | /** |
336 | * Metodo usado para carregar unidades de anos anteriores que possam estar em edição |
||
337 | * para mostrar na página da unidade |
||
338 | * |
||
339 | * Este metodo nao serve para mais nada, nao é usado nas Tarefas da Home |
||
340 | * @param sigesCode |
||
341 | * @param courseCode |
||
342 | * @return |
||
343 | */ |
||
344 | public CourseUnit loadUnitInEvaluationBySigesCodes(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String courseCode) |
||
1074 | jmachado | 345 | { |
1077 | jmachado | 346 | 1.5.0/docs/api/java/lang/String.html">String activeImportYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
1074 | jmachado | 347 | |
1077 | jmachado | 348 | Criterion crtDegrees = getCourseUnitActiveDegreeCourseIdsCriterion(activeImportYear); |
349 | if(crtDegrees == null) |
||
350 | { |
||
351 | //Nao ha graus nem cursos portanto o ano não interessa |
||
352 | //o ano deve ser usado para abrir graus ou cursos senao nao |
||
353 | //abre nada |
||
354 | crtDegrees = eq("evaluationOpenByAdmin",true); |
||
355 | } |
||
356 | else |
||
357 | { |
||
358 | crtDegrees = and(eq("importYear", activeImportYear),crtDegrees); |
||
359 | crtDegrees = or(eq("evaluationOpenByAdmin",true),crtDegrees); |
||
360 | } |
||
361 | |||
1074 | jmachado | 362 | List<CourseUnit> cus = (List<CourseUnit>) createCriteria() |
363 | .createAlias("course","c") |
||
364 | .createAlias("courseUnitEvaluation","ce") |
||
365 | .add(eq("code", sigesCode)) |
||
366 | .add(eq("courseCode", courseCode)) |
||
367 | .add(crtDegrees) |
||
368 | .add(eq("ce.closed",false)) |
||
369 | .list(); |
||
1077 | jmachado | 370 | List<CourseUnit> cusNull = (List<CourseUnit>) createCriteria() |
371 | .createAlias("course","c") |
||
372 | .add(eq("code", sigesCode)) |
||
373 | .add(eq("courseCode", courseCode)) |
||
374 | .add(crtDegrees) |
||
375 | .add(isNull("courseUnitEvaluation")) |
||
376 | .list(); |
||
377 | cus.addAll(cusNull); |
||
1074 | jmachado | 378 | if(cus != null && cus.size() > 1) |
379 | { |
||
380 | logger.warn("Mais do que uma unidade do mesmo codigo em avaliacao curricular, e suposto haver apenas uma, verificar logica aplicacional"); |
||
381 | } |
||
382 | else if(cus != null && cus.size() > 0) |
||
383 | { |
||
384 | return cus.get(0); |
||
385 | } |
||
386 | |||
387 | return null; |
||
388 | } |
||
389 | |||
376 | jmachado | 390 | 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) |
391 | { |
||
392 | Criteria c = createCriteria(); |
||
393 | if(courseId > 0) |
||
394 | c.add(eq("course.id", courseId)); |
||
395 | if(semestre != null && semestre.length() > 0) |
||
396 | c.add(eq("semestre", semestre)); |
||
397 | if(year != null && year.length() > 0) |
||
398 | c.add(eq("importYear", year)); |
||
399 | if(withTeacher && !withNoTeacher) |
||
400 | { |
||
401 | c.createAlias("teachers", "th"); |
||
402 | c.add(isNotNull("th.id")); |
||
403 | } |
||
404 | else if(!withTeacher && withNoTeacher) |
||
405 | { |
||
406 | c.createAlias("teachers", "th", JoinFragment.LEFT_OUTER_JOIN); |
||
407 | c.add(isNull("th.id")); |
||
408 | } |
||
409 | return c.list(); |
||
410 | } |
||
163 | jmachado | 411 | |
376 | jmachado | 412 | |
205 | jmachado | 413 | public int countCourseUnits(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
414 | { |
||
749 | jmachado | 415 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name","code"); |
205 | jmachado | 416 | return createCriteria().add(c).list().size(); |
417 | } |
||
163 | jmachado | 418 | |
205 | jmachado | 419 | public List<CourseUnit> search(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
420 | { |
||
748 | jmachado | 421 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name","code"); |
205 | jmachado | 422 | Criteria criteria = createCriteria(); |
423 | criteria.add(c) |
||
424 | .addOrder(Order.asc("name")) |
||
425 | .setMaxResults(maxUnits) |
||
426 | .setFirstResult(page * maxUnits); |
||
427 | return criteria.list(); |
||
428 | } |
||
202 | jmachado | 429 | |
206 | jmachado | 430 | public int countCourseUnitsActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
431 | { |
||
371 | jmachado | 432 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name"); |
206 | jmachado | 433 | return createCriteria() |
434 | .add(c) |
||
995 | jmachado | 435 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 436 | .list().size(); |
437 | } |
||
438 | |||
439 | public List<CourseUnit> searchActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
||
440 | { |
||
441 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name"); |
||
442 | Criteria criteria = createCriteria(); |
||
443 | criteria.add(c) |
||
995 | jmachado | 444 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 445 | .addOrder(Order.asc("name")) |
446 | .setMaxResults(maxUnits) |
||
447 | .setFirstResult(page * maxUnits); |
||
448 | return criteria.list(); |
||
449 | } |
||
450 | |||
205 | jmachado | 451 | public List<CourseUnit> loadMissingObjectives(long teacherId) |
452 | { |
||
453 | //todo falta a projeccao do teacher id |
||
454 | return createCriteria() |
||
995 | jmachado | 455 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 456 | .add((or(isNull("objectives"), eq("objectives", "")))) |
205 | jmachado | 457 | .createAlias("teachers", "th") |
371 | jmachado | 458 | .add(eq("semestre", DatesUtils.getSemestre())) |
459 | .add(eq("th.id", teacherId)) |
||
205 | jmachado | 460 | .list(); |
461 | } |
||
462 | |||
214 | jmachado | 463 | public List<CourseUnit> loadMissingPrograms(long teacherId) |
464 | { |
||
465 | //todo falta a projeccao do teacher id |
||
466 | return createCriteria() |
||
1171 | jmachado | 467 | .createAlias("course","c") |
468 | .add(eq("c.status", true)) |
||
995 | jmachado | 469 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 470 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
214 | jmachado | 471 | .createAlias("teachers", "th") |
371 | jmachado | 472 | .add(eq("semestre", DatesUtils.getSemestre())) |
473 | .add(eq("th.id", teacherId)) |
||
214 | jmachado | 474 | .list(); |
475 | } |
||
476 | |||
343 | jmachado | 477 | public List<CourseUnit> loadMissingObjectivesOrPrograms(long teacherId) |
478 | { |
||
479 | //todo falta a projeccao do teacher id |
||
371 | jmachado | 480 | Criteria c = createCriteria() |
995 | jmachado | 481 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 482 | .add(or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", "")))); |
483 | |||
484 | DatesUtils.SemestreModerate semestreModerate = DatesUtils.getSemestreModerate(); |
||
485 | if (semestreModerate == DatesUtils.SemestreModerate.S1) |
||
486 | c.add(eq("semestre", "S1")); |
||
487 | else if (semestreModerate == DatesUtils.SemestreModerate.S2) |
||
488 | c.add(eq("semestre", "S2")); |
||
489 | else |
||
490 | c.add(or(eq("semestre", "S1"), eq("semestre", "S2"))); |
||
491 | |||
492 | return c.createAlias("teachers", "th") |
||
493 | .add(eq("th.id", teacherId)) |
||
343 | jmachado | 494 | .list(); |
495 | } |
||
214 | jmachado | 496 | |
343 | jmachado | 497 | |
214 | jmachado | 498 | public List<CourseUnit> loadMissingObjectivesGivenCourse(long courseId) |
499 | { |
||
500 | return createCriteria() |
||
501 | .createAlias("course", "c") |
||
371 | jmachado | 502 | .add(eq("c.id", courseId)) |
995 | jmachado | 503 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 504 | .add(eq("semestre", DatesUtils.getSemestre())) |
505 | .add((or(isNull("objectives"), eq("objectives", "")))) |
||
214 | jmachado | 506 | .list(); |
507 | } |
||
508 | |||
509 | public List<CourseUnit> loadMissingProgramGivenCourse(long courseId) |
||
510 | { |
||
511 | return createCriteria() |
||
512 | .createAlias("course", "c") |
||
371 | jmachado | 513 | .add(eq("c.id", courseId)) |
995 | jmachado | 514 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 515 | .add(eq("semestre", DatesUtils.getSemestre())) |
516 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
||
214 | jmachado | 517 | .list(); |
518 | } |
||
519 | |||
509 | jmachado | 520 | public List<CourseUnit> loadMissingProgramValidateGivenCourse(long courseId) |
521 | { |
||
522 | return createCriteria() |
||
523 | .createAlias("course", "c") |
||
524 | .add(eq("c.id", courseId)) |
||
995 | jmachado | 525 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
509 | jmachado | 526 | .add(eq("semestre", DatesUtils.getSemestre())) |
527 | .add((and(isNotNull("programStreamId"), not(eq("programStreamId", ""))))) |
||
528 | .add((eq("validProgram", false))) |
||
529 | .list(); |
||
530 | } |
||
531 | |||
219 | jmachado | 532 | public List<CourseUnit> loadMissingObjectivesOrProgramGivenCourse(long courseId) |
214 | jmachado | 533 | { |
534 | return createCriteria() |
||
535 | .createAlias("course", "c") |
||
371 | jmachado | 536 | .add(eq("c.id", courseId)) |
995 | jmachado | 537 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 538 | .add(eq("semestre", DatesUtils.getSemestre())) |
539 | .add((or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", ""))))) |
||
214 | jmachado | 540 | .list(); |
541 | } |
||
205 | jmachado | 542 | |
343 | jmachado | 543 | public int countMissingProgramGivenCourse(long courseId) |
544 | { |
||
545 | return loadMissingProgramGivenCourse(courseId).size(); |
||
546 | } |
||
205 | jmachado | 547 | |
509 | jmachado | 548 | public int countMissingProgramValidateCourse(long courseId) |
549 | { |
||
550 | return loadMissingProgramValidateGivenCourse(courseId).size(); |
||
551 | } |
||
751 | jmachado | 552 | |
553 | |||
554 | public List<String> getTeachersEmails(long unit) { |
||
555 | 1.5.0/docs/api/javax/management/Query.html">Query q = createQuery("select e.email from " |
||
556 | + Teacher.class.getName() + " e join e.teachedUnits as unit " |
||
557 | + " where " |
||
558 | + " unit.id = ? " |
||
559 | |||
560 | ); |
||
561 | q.setLong(0,unit); |
||
562 | return q.list(); |
||
563 | } |
||
961 | jmachado | 564 | |
565 | public static class CourseMissingValidationProgram |
||
566 | { |
||
567 | public Course course; |
||
568 | public List<CourseUnit> courseUnits; |
||
569 | } |
||
1171 | jmachado | 570 | |
571 | /** |
||
572 | * Load all programs from active courses that are for validation |
||
573 | * @param userSession |
||
574 | * @return |
||
575 | */ |
||
961 | jmachado | 576 | public List<CourseMissingValidationProgram> loadMissingProgramValidate(UserSession userSession) |
577 | { |
||
578 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
1171 | jmachado | 579 | List<Course> courses = DaoFactory.getCourseDaoImpl().findActiveCourses(DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
961 | jmachado | 580 | for(Course course: courses) |
581 | { |
||
1094 | jmachado | 582 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
961 | jmachado | 583 | { |
584 | List<CourseUnit> courseUnits = loadMissingProgramValidateGivenCourse(course.getId()); |
||
585 | if(courseUnits != null && courseUnits.size() > 0) |
||
586 | { |
||
587 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
588 | c.course = course; |
||
589 | c.courseUnits = courseUnits; |
||
590 | result.add(c); |
||
591 | } |
||
592 | } |
||
593 | } |
||
594 | return result; |
||
595 | } |
||
1103 | jmachado | 596 | |
1171 | jmachado | 597 | /** |
598 | * Load all programs missing from active courses |
||
599 | * @param userSession |
||
600 | * @return |
||
601 | */ |
||
1040 | jmachado | 602 | public List<CourseMissingValidationProgram> loadMissingPrograms(UserSession userSession) |
603 | { |
||
604 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
1171 | jmachado | 605 | List<Course> courses = DaoFactory.getCourseDaoImpl().findActiveCourses(DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
1040 | jmachado | 606 | for(Course course: courses) |
607 | { |
||
1094 | jmachado | 608 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
1040 | jmachado | 609 | { |
610 | List<CourseUnit> courseUnits = loadMissingProgramGivenCourse(course.getId()); |
||
611 | if(courseUnits != null && courseUnits.size() > 0) |
||
612 | { |
||
613 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
614 | c.course = course; |
||
615 | c.courseUnits = courseUnits; |
||
616 | result.add(c); |
||
617 | } |
||
618 | } |
||
619 | } |
||
620 | return result; |
||
621 | } |
||
961 | jmachado | 622 | public static class CourseMissingValidationEvaluation |
623 | { |
||
624 | public Course course; |
||
625 | public List<CourseUnit> courseUnits; |
||
626 | } |
||
627 | |||
628 | public List<CourseMissingValidationEvaluation> loadMissingEvaluationValidate(UserSession userSession) |
||
629 | { |
||
630 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
962 | jmachado | 631 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
961 | jmachado | 632 | for(Course course: courses) |
633 | { |
||
1094 | jmachado | 634 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
961 | jmachado | 635 | { |
636 | List<CourseUnit> courseUnits = loadMissingEvaluationValidateGivenCourse(course.getId()); |
||
637 | if(courseUnits != null && courseUnits.size() > 0) |
||
638 | { |
||
639 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
640 | c.course = course; |
||
641 | c.courseUnits = courseUnits; |
||
642 | result.add(c); |
||
643 | } |
||
644 | } |
||
645 | } |
||
646 | return result; |
||
647 | } |
||
648 | |||
1103 | jmachado | 649 | |
650 | |||
961 | jmachado | 651 | /* |
652 | * Neste caso apenas se validam as do ano anterior*/ |
||
653 | |||
654 | public List<CourseUnit> loadMissingEvaluationValidateGivenCourse(long courseId) |
||
655 | { |
||
1070 | jmachado | 656 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
1077 | jmachado | 657 | |
658 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
659 | if(degreesCrit == null) |
||
1017 | jmachado | 660 | return new ArrayList<CourseUnit>(); |
661 | |||
961 | jmachado | 662 | return createCriteria() |
663 | .createAlias("course", "c") |
||
664 | .createAlias("courseUnitEvaluation", "ce") |
||
665 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 666 | .add(eq("importYear", activeYear)) |
667 | .add(degreesCrit) |
||
961 | jmachado | 668 | .add((eq("ce.closed", false))) |
1017 | jmachado | 669 | .add((eq("ce.teacherComplete", true))) |
961 | jmachado | 670 | .list(); |
671 | } |
||
967 | jmachado | 672 | |
1077 | jmachado | 673 | /** |
1103 | jmachado | 674 | * |
675 | * @return devolve todos os ids de unidades que verifiquem a condição de avaliação |
||
676 | * do periodo actual e tenham o programa fechado pela comissão |
||
677 | */ |
||
678 | |||
679 | public List<Long> loadClosedCourseUnitsEvaluations() |
||
680 | { |
||
681 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
682 | |||
683 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
684 | if(degreesCrit == null) |
||
685 | return new ArrayList<Long>(); |
||
686 | |||
687 | return createCriteria() |
||
688 | .setProjection(Projections.property("id")) |
||
689 | .createAlias("course", "c") |
||
690 | .createAlias("courseUnitEvaluation", "ce") |
||
691 | .add(eq("importYear", activeYear)) |
||
692 | .add(degreesCrit) |
||
693 | .add((eq("ce.closed", true))) |
||
694 | .list(); |
||
695 | } |
||
696 | |||
697 | /** |
||
1077 | jmachado | 698 | * Devolve um criteio OR para todos os cursos de grau pertencente à lista de graus |
699 | * ou pertencete à lista de cursoIds |
||
700 | |||
701 | * @return |
||
702 | */ |
||
703 | private Criterion getCourseUnitActiveDegreeCourseIdsCriterion(1.5.0/docs/api/java/lang/String.html">String activeYear) |
||
1070 | jmachado | 704 | { |
1077 | jmachado | 705 | List<String> activeDegrees = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveDegrees(); |
706 | List<Long> activeCourseIds = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveCourseIds(); |
||
707 | boolean activeDegreesOff = activeDegrees == null || activeDegrees.size() == 0; |
||
708 | boolean activeCourseIdsOff = activeCourseIds == null || activeCourseIds.size() == 0; |
||
709 | if(activeYear == null || (activeDegreesOff && activeCourseIdsOff)) |
||
710 | return null; |
||
711 | |||
712 | Criterion crit = null; |
||
713 | |||
714 | if(activeDegrees != null) |
||
715 | for(1.5.0/docs/api/java/lang/String.html">String degree: activeDegrees) |
||
716 | { |
||
717 | if(crit == null) |
||
718 | crit = eq("c.degree",degree); |
||
719 | else |
||
720 | crit = or(crit,eq("c.degree",degree)); |
||
721 | } |
||
722 | if(activeCourseIds != null) |
||
723 | for(1.5.0/docs/api/java/lang/Long.html">Long courseId: activeCourseIds) |
||
724 | { |
||
725 | if(crit == null) |
||
726 | crit = eq("c.id",courseId); |
||
727 | else |
||
728 | crit = or(crit,eq("c.id",courseId)); |
||
729 | } |
||
730 | |||
731 | return crit; |
||
1070 | jmachado | 732 | } |
733 | |||
1077 | jmachado | 734 | |
1024 | jmachado | 735 | public List<CourseUnit> loadTeacherUnitsMissingEvaluation(UserSession userSession) |
736 | { |
||
737 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
1077 | jmachado | 738 | |
739 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
740 | if(degreesCrit == null) |
||
1024 | jmachado | 741 | return new ArrayList<CourseUnit>(); |
742 | |||
1070 | jmachado | 743 | |
1024 | jmachado | 744 | List<CourseUnit> nulls = |
745 | createCriteria() |
||
1070 | jmachado | 746 | .createAlias("course", "c") |
1074 | jmachado | 747 | .createAlias("teachers", "t") |
1077 | jmachado | 748 | .add(eq("importYear", activeYear)) |
1024 | jmachado | 749 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
750 | //.add(ge("importYear", "201415" )) |
||
751 | //.add(isNull("courseUnitEvaluation")) |
||
752 | //todo novo testar |
||
753 | .add(eq("t.id", userSession.getUser().getId())) |
||
1070 | jmachado | 754 | .add(degreesCrit) |
1024 | jmachado | 755 | .add(isNull("courseUnitEvaluation")) |
756 | .list(); |
||
757 | |||
758 | List<CourseUnit> teacherCompleteFalse = |
||
759 | createCriteria() |
||
1070 | jmachado | 760 | .createAlias("course", "c") |
1024 | jmachado | 761 | .createAlias("courseUnitEvaluation", "ce") |
1094 | jmachado | 762 | .createAlias("teachers", "t") |
1028 | jmachado | 763 | .add(eq("t.id", userSession.getUser().getId())) |
1077 | jmachado | 764 | .add(eq("importYear", activeYear)) |
1024 | jmachado | 765 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
766 | //.add(ge("importYear", "201415" )) |
||
767 | //.add(isNull("courseUnitEvaluation")) |
||
768 | //todo novo testar |
||
1070 | jmachado | 769 | .add(degreesCrit) |
1074 | jmachado | 770 | .add(eq("ce.teacherComplete", false)) |
1024 | jmachado | 771 | .list(); |
772 | teacherCompleteFalse.addAll(nulls); |
||
773 | return teacherCompleteFalse; |
||
774 | } |
||
775 | |||
776 | |||
967 | jmachado | 777 | public List<CourseMissingValidationEvaluation> loadMissingEvaluation(UserSession userSession) |
778 | { |
||
779 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
780 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
||
781 | for(Course course: courses) |
||
782 | { |
||
1094 | jmachado | 783 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
967 | jmachado | 784 | { |
785 | List<CourseUnit> courseUnits = loadMissingEvaluation(course.getId()); |
||
786 | if(courseUnits != null && courseUnits.size() > 0) |
||
787 | { |
||
788 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
789 | c.course = course; |
||
790 | c.courseUnits = courseUnits; |
||
791 | result.add(c); |
||
792 | } |
||
793 | } |
||
794 | } |
||
795 | return result; |
||
796 | } |
||
797 | |||
798 | public List<CourseUnit> loadMissingEvaluation(long courseId) |
||
799 | { |
||
1070 | jmachado | 800 | |
801 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
1077 | jmachado | 802 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
803 | |||
804 | if(degreesCrit == null) |
||
1017 | jmachado | 805 | return new ArrayList<CourseUnit>(); |
806 | |||
1024 | jmachado | 807 | List<CourseUnit> nulls = |
808 | createCriteria() |
||
967 | jmachado | 809 | .createAlias("course", "c") |
810 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 811 | .add(eq("importYear", activeYear)) |
812 | .add(degreesCrit) |
||
1024 | jmachado | 813 | .add(isNull("courseUnitEvaluation")) |
967 | jmachado | 814 | .list(); |
1024 | jmachado | 815 | |
816 | List<CourseUnit> teacherCompleteFalse = |
||
817 | createCriteria() |
||
818 | .createAlias("course", "c") |
||
819 | .createAlias("courseUnitEvaluation", "ce") |
||
820 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 821 | .add(degreesCrit) |
822 | .add(eq("importYear", activeYear)) |
||
1024 | jmachado | 823 | .add(eq("ce.teacherComplete", false)) |
824 | .list(); |
||
825 | teacherCompleteFalse.addAll(nulls); |
||
826 | return teacherCompleteFalse; |
||
967 | jmachado | 827 | } |
973 | jmachado | 828 | |
829 | public CourseUnit loadByEvaluationStreamId(1.5.0/docs/api/java/lang/String.html">String identifier) |
||
830 | { |
||
831 | return |
||
832 | (CourseUnit) |
||
833 | createCriteria() |
||
834 | .add(eq("evaluationStreamId",identifier)) |
||
835 | .uniqueResult(); |
||
836 | } |
||
110 | susana | 837 | } |