Rev 1098 | Rev 1117 | 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 | |||
899 | jmachado | 223 | //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 | 224 | //se nao a carregar unidades vai buscar a errada |
225 | jmachado | 225 | 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 | 226 | { |
225 | jmachado | 227 | return (CourseUnit) |
228 | createCriteria() |
||
229 | .add(eq("code", sigesCode)) |
||
230 | .add(eq("courseCode", courseCode)) |
||
231 | .add(eq("semestre", semestre)) |
||
232 | .add(eq("importYear", year)) |
||
233 | .uniqueResult(); |
||
202 | jmachado | 234 | } |
767 | jmachado | 235 | |
899 | jmachado | 236 | 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) |
237 | { |
||
1098 | jmachado | 238 | List<CourseUnit> cus = |
899 | jmachado | 239 | createCriteria() |
240 | .add(eq("code", sigesCode)) |
||
241 | .add(eq("courseCode", courseCode)) |
||
242 | .add(eq("semestre", semestre)) |
||
243 | .addOrder(Order.desc("importYear")) |
||
1098 | jmachado | 244 | .setMaxResults(1).list(); |
245 | if(cus.size() > 0) |
||
246 | return cus.get(0); |
||
247 | logger.warn("Accessing unit not existent with siges code " + sigesCode + " course code: " + courseCode + " semestre: " + semestre); |
||
248 | return null; |
||
899 | jmachado | 249 | } |
250 | |||
251 | |||
883 | jmachado | 252 | 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 | 253 | { |
899 | jmachado | 254 | return loadBySigesCodeUniqueMostRecent(sigesCode,courseCode,semestre); |
883 | jmachado | 255 | } |
256 | |||
257 | |||
258 | 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) |
||
259 | { |
||
767 | jmachado | 260 | return createCriteria() |
261 | .add(eq("code", sigesCode)) |
||
262 | .add(eq("courseCode", courseCode)) |
||
263 | .add(eq("importYear", year)) |
||
264 | .addOrder(Order.desc("id")) |
||
265 | .list(); |
||
266 | } |
||
267 | |||
457 | jmachado | 268 | 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) |
269 | { |
||
270 | return (List<CourseUnit>) createCriteria() |
||
271 | .add(eq("code", sigesCode)) |
||
272 | .add(eq("courseCode", courseCode)) |
||
273 | .addOrder(Order.desc("importYear")) |
||
274 | .list(); |
||
275 | } |
||
163 | jmachado | 276 | |
1077 | jmachado | 277 | /** |
278 | * Metodo usado para carregar unidades de anos anteriores que possam estar em edição |
||
279 | * para mostrar na página da unidade |
||
280 | * |
||
281 | * Este metodo nao serve para mais nada, nao é usado nas Tarefas da Home |
||
282 | * @param sigesCode |
||
283 | * @param courseCode |
||
284 | * @return |
||
285 | */ |
||
286 | 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 | 287 | { |
1077 | jmachado | 288 | 1.5.0/docs/api/java/lang/String.html">String activeImportYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
1074 | jmachado | 289 | |
1077 | jmachado | 290 | Criterion crtDegrees = getCourseUnitActiveDegreeCourseIdsCriterion(activeImportYear); |
291 | if(crtDegrees == null) |
||
292 | { |
||
293 | //Nao ha graus nem cursos portanto o ano não interessa |
||
294 | //o ano deve ser usado para abrir graus ou cursos senao nao |
||
295 | //abre nada |
||
296 | crtDegrees = eq("evaluationOpenByAdmin",true); |
||
297 | } |
||
298 | else |
||
299 | { |
||
300 | crtDegrees = and(eq("importYear", activeImportYear),crtDegrees); |
||
301 | crtDegrees = or(eq("evaluationOpenByAdmin",true),crtDegrees); |
||
302 | } |
||
303 | |||
1074 | jmachado | 304 | List<CourseUnit> cus = (List<CourseUnit>) createCriteria() |
305 | .createAlias("course","c") |
||
306 | .createAlias("courseUnitEvaluation","ce") |
||
307 | .add(eq("code", sigesCode)) |
||
308 | .add(eq("courseCode", courseCode)) |
||
309 | .add(crtDegrees) |
||
310 | .add(eq("ce.closed",false)) |
||
311 | .list(); |
||
1077 | jmachado | 312 | List<CourseUnit> cusNull = (List<CourseUnit>) createCriteria() |
313 | .createAlias("course","c") |
||
314 | .add(eq("code", sigesCode)) |
||
315 | .add(eq("courseCode", courseCode)) |
||
316 | .add(crtDegrees) |
||
317 | .add(isNull("courseUnitEvaluation")) |
||
318 | .list(); |
||
319 | cus.addAll(cusNull); |
||
1074 | jmachado | 320 | if(cus != null && cus.size() > 1) |
321 | { |
||
322 | logger.warn("Mais do que uma unidade do mesmo codigo em avaliacao curricular, e suposto haver apenas uma, verificar logica aplicacional"); |
||
323 | } |
||
324 | else if(cus != null && cus.size() > 0) |
||
325 | { |
||
326 | return cus.get(0); |
||
327 | } |
||
328 | |||
329 | return null; |
||
330 | } |
||
331 | |||
376 | jmachado | 332 | 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) |
333 | { |
||
334 | Criteria c = createCriteria(); |
||
335 | if(courseId > 0) |
||
336 | c.add(eq("course.id", courseId)); |
||
337 | if(semestre != null && semestre.length() > 0) |
||
338 | c.add(eq("semestre", semestre)); |
||
339 | if(year != null && year.length() > 0) |
||
340 | c.add(eq("importYear", year)); |
||
341 | if(withTeacher && !withNoTeacher) |
||
342 | { |
||
343 | c.createAlias("teachers", "th"); |
||
344 | c.add(isNotNull("th.id")); |
||
345 | } |
||
346 | else if(!withTeacher && withNoTeacher) |
||
347 | { |
||
348 | c.createAlias("teachers", "th", JoinFragment.LEFT_OUTER_JOIN); |
||
349 | c.add(isNull("th.id")); |
||
350 | } |
||
351 | return c.list(); |
||
352 | } |
||
163 | jmachado | 353 | |
376 | jmachado | 354 | |
205 | jmachado | 355 | public int countCourseUnits(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
356 | { |
||
749 | jmachado | 357 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name","code"); |
205 | jmachado | 358 | return createCriteria().add(c).list().size(); |
359 | } |
||
163 | jmachado | 360 | |
205 | jmachado | 361 | public List<CourseUnit> search(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
362 | { |
||
748 | jmachado | 363 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name","code"); |
205 | jmachado | 364 | Criteria criteria = createCriteria(); |
365 | criteria.add(c) |
||
366 | .addOrder(Order.asc("name")) |
||
367 | .setMaxResults(maxUnits) |
||
368 | .setFirstResult(page * maxUnits); |
||
369 | return criteria.list(); |
||
370 | } |
||
202 | jmachado | 371 | |
206 | jmachado | 372 | public int countCourseUnitsActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
373 | { |
||
371 | jmachado | 374 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name"); |
206 | jmachado | 375 | return createCriteria() |
376 | .add(c) |
||
995 | jmachado | 377 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 378 | .list().size(); |
379 | } |
||
380 | |||
381 | public List<CourseUnit> searchActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
||
382 | { |
||
383 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name"); |
||
384 | Criteria criteria = createCriteria(); |
||
385 | criteria.add(c) |
||
995 | jmachado | 386 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 387 | .addOrder(Order.asc("name")) |
388 | .setMaxResults(maxUnits) |
||
389 | .setFirstResult(page * maxUnits); |
||
390 | return criteria.list(); |
||
391 | } |
||
392 | |||
205 | jmachado | 393 | public List<CourseUnit> loadMissingObjectives(long teacherId) |
394 | { |
||
395 | //todo falta a projeccao do teacher id |
||
396 | return createCriteria() |
||
995 | jmachado | 397 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 398 | .add((or(isNull("objectives"), eq("objectives", "")))) |
205 | jmachado | 399 | .createAlias("teachers", "th") |
371 | jmachado | 400 | .add(eq("semestre", DatesUtils.getSemestre())) |
401 | .add(eq("th.id", teacherId)) |
||
205 | jmachado | 402 | .list(); |
403 | } |
||
404 | |||
214 | jmachado | 405 | public List<CourseUnit> loadMissingPrograms(long teacherId) |
406 | { |
||
407 | //todo falta a projeccao do teacher id |
||
408 | return createCriteria() |
||
995 | jmachado | 409 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 410 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
214 | jmachado | 411 | .createAlias("teachers", "th") |
371 | jmachado | 412 | .add(eq("semestre", DatesUtils.getSemestre())) |
413 | .add(eq("th.id", teacherId)) |
||
214 | jmachado | 414 | .list(); |
415 | } |
||
416 | |||
343 | jmachado | 417 | public List<CourseUnit> loadMissingObjectivesOrPrograms(long teacherId) |
418 | { |
||
419 | //todo falta a projeccao do teacher id |
||
371 | jmachado | 420 | Criteria c = createCriteria() |
995 | jmachado | 421 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 422 | .add(or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", "")))); |
423 | |||
424 | DatesUtils.SemestreModerate semestreModerate = DatesUtils.getSemestreModerate(); |
||
425 | if (semestreModerate == DatesUtils.SemestreModerate.S1) |
||
426 | c.add(eq("semestre", "S1")); |
||
427 | else if (semestreModerate == DatesUtils.SemestreModerate.S2) |
||
428 | c.add(eq("semestre", "S2")); |
||
429 | else |
||
430 | c.add(or(eq("semestre", "S1"), eq("semestre", "S2"))); |
||
431 | |||
432 | return c.createAlias("teachers", "th") |
||
433 | .add(eq("th.id", teacherId)) |
||
343 | jmachado | 434 | .list(); |
435 | } |
||
214 | jmachado | 436 | |
343 | jmachado | 437 | |
214 | jmachado | 438 | public List<CourseUnit> loadMissingObjectivesGivenCourse(long courseId) |
439 | { |
||
440 | return createCriteria() |
||
441 | .createAlias("course", "c") |
||
371 | jmachado | 442 | .add(eq("c.id", courseId)) |
995 | jmachado | 443 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 444 | .add(eq("semestre", DatesUtils.getSemestre())) |
445 | .add((or(isNull("objectives"), eq("objectives", "")))) |
||
214 | jmachado | 446 | .list(); |
447 | } |
||
448 | |||
449 | public List<CourseUnit> loadMissingProgramGivenCourse(long courseId) |
||
450 | { |
||
451 | return createCriteria() |
||
452 | .createAlias("course", "c") |
||
371 | jmachado | 453 | .add(eq("c.id", courseId)) |
995 | jmachado | 454 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 455 | .add(eq("semestre", DatesUtils.getSemestre())) |
456 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
||
214 | jmachado | 457 | .list(); |
458 | } |
||
459 | |||
509 | jmachado | 460 | public List<CourseUnit> loadMissingProgramValidateGivenCourse(long courseId) |
461 | { |
||
462 | return createCriteria() |
||
463 | .createAlias("course", "c") |
||
464 | .add(eq("c.id", courseId)) |
||
995 | jmachado | 465 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
509 | jmachado | 466 | .add(eq("semestre", DatesUtils.getSemestre())) |
467 | .add((and(isNotNull("programStreamId"), not(eq("programStreamId", ""))))) |
||
468 | .add((eq("validProgram", false))) |
||
469 | .list(); |
||
470 | } |
||
471 | |||
219 | jmachado | 472 | public List<CourseUnit> loadMissingObjectivesOrProgramGivenCourse(long courseId) |
214 | jmachado | 473 | { |
474 | return createCriteria() |
||
475 | .createAlias("course", "c") |
||
371 | jmachado | 476 | .add(eq("c.id", courseId)) |
995 | jmachado | 477 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 478 | .add(eq("semestre", DatesUtils.getSemestre())) |
479 | .add((or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", ""))))) |
||
214 | jmachado | 480 | .list(); |
481 | } |
||
205 | jmachado | 482 | |
343 | jmachado | 483 | public int countMissingProgramGivenCourse(long courseId) |
484 | { |
||
485 | return loadMissingProgramGivenCourse(courseId).size(); |
||
486 | } |
||
205 | jmachado | 487 | |
509 | jmachado | 488 | public int countMissingProgramValidateCourse(long courseId) |
489 | { |
||
490 | return loadMissingProgramValidateGivenCourse(courseId).size(); |
||
491 | } |
||
751 | jmachado | 492 | |
493 | |||
494 | public List<String> getTeachersEmails(long unit) { |
||
495 | 1.5.0/docs/api/javax/management/Query.html">Query q = createQuery("select e.email from " |
||
496 | + Teacher.class.getName() + " e join e.teachedUnits as unit " |
||
497 | + " where " |
||
498 | + " unit.id = ? " |
||
499 | |||
500 | ); |
||
501 | q.setLong(0,unit); |
||
502 | return q.list(); |
||
503 | } |
||
961 | jmachado | 504 | |
505 | public static class CourseMissingValidationProgram |
||
506 | { |
||
507 | public Course course; |
||
508 | public List<CourseUnit> courseUnits; |
||
509 | } |
||
510 | public List<CourseMissingValidationProgram> loadMissingProgramValidate(UserSession userSession) |
||
511 | { |
||
512 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
995 | jmachado | 513 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
961 | jmachado | 514 | for(Course course: courses) |
515 | { |
||
1094 | jmachado | 516 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
961 | jmachado | 517 | { |
518 | List<CourseUnit> courseUnits = loadMissingProgramValidateGivenCourse(course.getId()); |
||
519 | if(courseUnits != null && courseUnits.size() > 0) |
||
520 | { |
||
521 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
522 | c.course = course; |
||
523 | c.courseUnits = courseUnits; |
||
524 | result.add(c); |
||
525 | } |
||
526 | } |
||
527 | } |
||
528 | return result; |
||
529 | } |
||
1103 | jmachado | 530 | |
531 | |||
1040 | jmachado | 532 | public List<CourseMissingValidationProgram> loadMissingPrograms(UserSession userSession) |
533 | { |
||
534 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
535 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
||
536 | for(Course course: courses) |
||
537 | { |
||
1094 | jmachado | 538 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
1040 | jmachado | 539 | { |
540 | List<CourseUnit> courseUnits = loadMissingProgramGivenCourse(course.getId()); |
||
541 | if(courseUnits != null && courseUnits.size() > 0) |
||
542 | { |
||
543 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
544 | c.course = course; |
||
545 | c.courseUnits = courseUnits; |
||
546 | result.add(c); |
||
547 | } |
||
548 | } |
||
549 | } |
||
550 | return result; |
||
551 | } |
||
961 | jmachado | 552 | public static class CourseMissingValidationEvaluation |
553 | { |
||
554 | public Course course; |
||
555 | public List<CourseUnit> courseUnits; |
||
556 | } |
||
557 | |||
558 | public List<CourseMissingValidationEvaluation> loadMissingEvaluationValidate(UserSession userSession) |
||
559 | { |
||
560 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
962 | jmachado | 561 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
961 | jmachado | 562 | for(Course course: courses) |
563 | { |
||
1094 | jmachado | 564 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
961 | jmachado | 565 | { |
566 | List<CourseUnit> courseUnits = loadMissingEvaluationValidateGivenCourse(course.getId()); |
||
567 | if(courseUnits != null && courseUnits.size() > 0) |
||
568 | { |
||
569 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
570 | c.course = course; |
||
571 | c.courseUnits = courseUnits; |
||
572 | result.add(c); |
||
573 | } |
||
574 | } |
||
575 | } |
||
576 | return result; |
||
577 | } |
||
578 | |||
1103 | jmachado | 579 | |
580 | |||
961 | jmachado | 581 | /* |
582 | * Neste caso apenas se validam as do ano anterior*/ |
||
583 | |||
584 | public List<CourseUnit> loadMissingEvaluationValidateGivenCourse(long courseId) |
||
585 | { |
||
1070 | jmachado | 586 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
1077 | jmachado | 587 | |
588 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
589 | if(degreesCrit == null) |
||
1017 | jmachado | 590 | return new ArrayList<CourseUnit>(); |
591 | |||
961 | jmachado | 592 | return createCriteria() |
593 | .createAlias("course", "c") |
||
594 | .createAlias("courseUnitEvaluation", "ce") |
||
595 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 596 | .add(eq("importYear", activeYear)) |
597 | .add(degreesCrit) |
||
961 | jmachado | 598 | .add((eq("ce.closed", false))) |
1017 | jmachado | 599 | .add((eq("ce.teacherComplete", true))) |
961 | jmachado | 600 | .list(); |
601 | } |
||
967 | jmachado | 602 | |
1077 | jmachado | 603 | /** |
1103 | jmachado | 604 | * |
605 | * @return devolve todos os ids de unidades que verifiquem a condição de avaliação |
||
606 | * do periodo actual e tenham o programa fechado pela comissão |
||
607 | */ |
||
608 | |||
609 | public List<Long> loadClosedCourseUnitsEvaluations() |
||
610 | { |
||
611 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
612 | |||
613 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
614 | if(degreesCrit == null) |
||
615 | return new ArrayList<Long>(); |
||
616 | |||
617 | return createCriteria() |
||
618 | .setProjection(Projections.property("id")) |
||
619 | .createAlias("course", "c") |
||
620 | .createAlias("courseUnitEvaluation", "ce") |
||
621 | .add(eq("importYear", activeYear)) |
||
622 | .add(degreesCrit) |
||
623 | .add((eq("ce.closed", true))) |
||
624 | .list(); |
||
625 | } |
||
626 | |||
627 | /** |
||
1077 | jmachado | 628 | * Devolve um criteio OR para todos os cursos de grau pertencente à lista de graus |
629 | * ou pertencete à lista de cursoIds |
||
630 | |||
631 | * @return |
||
632 | */ |
||
633 | private Criterion getCourseUnitActiveDegreeCourseIdsCriterion(1.5.0/docs/api/java/lang/String.html">String activeYear) |
||
1070 | jmachado | 634 | { |
1077 | jmachado | 635 | List<String> activeDegrees = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveDegrees(); |
636 | List<Long> activeCourseIds = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveCourseIds(); |
||
637 | boolean activeDegreesOff = activeDegrees == null || activeDegrees.size() == 0; |
||
638 | boolean activeCourseIdsOff = activeCourseIds == null || activeCourseIds.size() == 0; |
||
639 | if(activeYear == null || (activeDegreesOff && activeCourseIdsOff)) |
||
640 | return null; |
||
641 | |||
642 | Criterion crit = null; |
||
643 | |||
644 | if(activeDegrees != null) |
||
645 | for(1.5.0/docs/api/java/lang/String.html">String degree: activeDegrees) |
||
646 | { |
||
647 | if(crit == null) |
||
648 | crit = eq("c.degree",degree); |
||
649 | else |
||
650 | crit = or(crit,eq("c.degree",degree)); |
||
651 | } |
||
652 | if(activeCourseIds != null) |
||
653 | for(1.5.0/docs/api/java/lang/Long.html">Long courseId: activeCourseIds) |
||
654 | { |
||
655 | if(crit == null) |
||
656 | crit = eq("c.id",courseId); |
||
657 | else |
||
658 | crit = or(crit,eq("c.id",courseId)); |
||
659 | } |
||
660 | |||
661 | return crit; |
||
1070 | jmachado | 662 | } |
663 | |||
1077 | jmachado | 664 | |
1024 | jmachado | 665 | public List<CourseUnit> loadTeacherUnitsMissingEvaluation(UserSession userSession) |
666 | { |
||
667 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
1077 | jmachado | 668 | |
669 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
670 | if(degreesCrit == null) |
||
1024 | jmachado | 671 | return new ArrayList<CourseUnit>(); |
672 | |||
1070 | jmachado | 673 | |
1024 | jmachado | 674 | List<CourseUnit> nulls = |
675 | createCriteria() |
||
1070 | jmachado | 676 | .createAlias("course", "c") |
1074 | jmachado | 677 | .createAlias("teachers", "t") |
1077 | jmachado | 678 | .add(eq("importYear", activeYear)) |
1024 | jmachado | 679 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
680 | //.add(ge("importYear", "201415" )) |
||
681 | //.add(isNull("courseUnitEvaluation")) |
||
682 | //todo novo testar |
||
683 | .add(eq("t.id", userSession.getUser().getId())) |
||
1070 | jmachado | 684 | .add(degreesCrit) |
1024 | jmachado | 685 | .add(isNull("courseUnitEvaluation")) |
686 | .list(); |
||
687 | |||
688 | List<CourseUnit> teacherCompleteFalse = |
||
689 | createCriteria() |
||
1070 | jmachado | 690 | .createAlias("course", "c") |
1024 | jmachado | 691 | .createAlias("courseUnitEvaluation", "ce") |
1094 | jmachado | 692 | .createAlias("teachers", "t") |
1028 | jmachado | 693 | .add(eq("t.id", userSession.getUser().getId())) |
1077 | jmachado | 694 | .add(eq("importYear", activeYear)) |
1024 | jmachado | 695 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
696 | //.add(ge("importYear", "201415" )) |
||
697 | //.add(isNull("courseUnitEvaluation")) |
||
698 | //todo novo testar |
||
1070 | jmachado | 699 | .add(degreesCrit) |
1074 | jmachado | 700 | .add(eq("ce.teacherComplete", false)) |
1024 | jmachado | 701 | .list(); |
702 | teacherCompleteFalse.addAll(nulls); |
||
703 | return teacherCompleteFalse; |
||
704 | } |
||
705 | |||
706 | |||
967 | jmachado | 707 | public List<CourseMissingValidationEvaluation> loadMissingEvaluation(UserSession userSession) |
708 | { |
||
709 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
710 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
||
711 | for(Course course: courses) |
||
712 | { |
||
1094 | jmachado | 713 | if(userSession.getUser().hasRole(course.getValidationRole()) || userSession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE)) |
967 | jmachado | 714 | { |
715 | List<CourseUnit> courseUnits = loadMissingEvaluation(course.getId()); |
||
716 | if(courseUnits != null && courseUnits.size() > 0) |
||
717 | { |
||
718 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
719 | c.course = course; |
||
720 | c.courseUnits = courseUnits; |
||
721 | result.add(c); |
||
722 | } |
||
723 | } |
||
724 | } |
||
725 | return result; |
||
726 | } |
||
727 | |||
728 | public List<CourseUnit> loadMissingEvaluation(long courseId) |
||
729 | { |
||
1070 | jmachado | 730 | |
731 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
1077 | jmachado | 732 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
733 | |||
734 | if(degreesCrit == null) |
||
1017 | jmachado | 735 | return new ArrayList<CourseUnit>(); |
736 | |||
1024 | jmachado | 737 | List<CourseUnit> nulls = |
738 | createCriteria() |
||
967 | jmachado | 739 | .createAlias("course", "c") |
740 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 741 | .add(eq("importYear", activeYear)) |
742 | .add(degreesCrit) |
||
1024 | jmachado | 743 | .add(isNull("courseUnitEvaluation")) |
967 | jmachado | 744 | .list(); |
1024 | jmachado | 745 | |
746 | List<CourseUnit> teacherCompleteFalse = |
||
747 | createCriteria() |
||
748 | .createAlias("course", "c") |
||
749 | .createAlias("courseUnitEvaluation", "ce") |
||
750 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 751 | .add(degreesCrit) |
752 | .add(eq("importYear", activeYear)) |
||
1024 | jmachado | 753 | .add(eq("ce.teacherComplete", false)) |
754 | .list(); |
||
755 | teacherCompleteFalse.addAll(nulls); |
||
756 | return teacherCompleteFalse; |
||
967 | jmachado | 757 | } |
973 | jmachado | 758 | |
759 | public CourseUnit loadByEvaluationStreamId(1.5.0/docs/api/java/lang/String.html">String identifier) |
||
760 | { |
||
761 | return |
||
762 | (CourseUnit) |
||
763 | createCriteria() |
||
764 | .add(eq("evaluationStreamId",identifier)) |
||
765 | .uniqueResult(); |
||
766 | } |
||
110 | susana | 767 | } |