Rev 1074 | Rev 1094 | 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 | |||
995 | jmachado | 73 | public List<Long> loadIds(1.5.0/docs/api/java/lang/String.html">String importYear) |
74 | { |
||
75 | 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 = ?"); |
||
76 | q.setString(0, importYear); |
||
77 | //q.setString(1, semestre); |
||
78 | return q.list(); |
||
79 | } |
||
80 | |||
218 | jmachado | 81 | public List<CourseUnit> loadSubscribedImportYearUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
82 | { |
||
1072 | jmachado | 83 | return createCriteria() |
371 | jmachado | 84 | .createAlias("students", "st") |
1072 | jmachado | 85 | .add(eq("st.id", studentId)) |
86 | .add(eq("importYear", importYear)) |
||
87 | .addOrder(Order.asc("name")) |
||
88 | .list(); |
||
218 | jmachado | 89 | } |
420 | jmachado | 90 | 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) |
91 | { |
||
92 | Criteria c =createCriteria() |
||
1072 | jmachado | 93 | .createAlias("students", "st") |
94 | .add(eq("st.id", studentId)) |
||
95 | .add(eq("importYear", importYear)); |
||
420 | jmachado | 96 | if(semestre != null) |
97 | c.add(eq("semestre", semestre)); |
||
98 | return c.addOrder(Order.asc("name")).list(); |
||
99 | } |
||
255 | jmachado | 100 | |
101 | public List<CourseUnit> loadSubscribedOtherImportYearUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
||
102 | { |
||
371 | jmachado | 103 | return createCriteria().add(not(eq("importYear", importYear))) |
104 | .createAlias("students", "st") |
||
255 | jmachado | 105 | .add(eq("st.id", studentId)).addOrder(Order.asc("name")).list(); |
106 | } |
||
343 | jmachado | 107 | |
253 | jmachado | 108 | public List<CourseUnitImpl> loadTeachedImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
218 | jmachado | 109 | { |
371 | jmachado | 110 | return createCriteria().add(eq("importYear", importYear)) |
111 | .createAlias("teachers", "st") |
||
255 | jmachado | 112 | .add(eq("st.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
218 | jmachado | 113 | } |
114 | |||
821 | jmachado | 115 | public List<CourseUnitImpl> loadResponsableImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
116 | { |
||
117 | return createCriteria().add(eq("importYear", importYear)) |
||
118 | .add(eq("responsableTeacher.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
||
119 | } |
||
120 | |||
420 | jmachado | 121 | 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) |
122 | { |
||
123 | Criteria c =createCriteria() |
||
124 | .add(eq("importYear", importYear)) |
||
125 | .createAlias("teachers", "st") |
||
126 | .add(eq("st.id", teacherId)) |
||
127 | .add(eq("st.id", teacherId)); |
||
128 | if(semestre != null) |
||
129 | c.add(eq("semestre", semestre)); |
||
130 | return c.addOrder(Order.asc("name")).list(); |
||
131 | } |
||
132 | |||
133 | |||
134 | |||
163 | jmachado | 135 | public CourseUnit loadBySigesCodeUnique(1.5.0/docs/api/java/lang/String.html">String sigesCode) |
136 | { |
||
202 | jmachado | 137 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).uniqueResult(); |
163 | jmachado | 138 | } |
116 | jmachado | 139 | |
202 | jmachado | 140 | 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) |
141 | { |
||
142 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).add(eq("courseCode", courseCode)).uniqueResult(); |
||
143 | } |
||
163 | jmachado | 144 | |
228 | jmachado | 145 | 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 | 146 | { |
371 | jmachado | 147 | List<CourseUnit> cus = createCriteria() |
219 | jmachado | 148 | .add(eq("code", sigesCode)) |
228 | jmachado | 149 | .add(eq("importYear", year)) |
219 | jmachado | 150 | .add(eq("courseCode", courseCode)) |
228 | jmachado | 151 | .add(eq("semestre", semestre)) |
371 | jmachado | 152 | .createAlias("students", "st") |
153 | .add(eq("st.id", studentId)) |
||
219 | jmachado | 154 | .list(); |
371 | jmachado | 155 | if (cus.size() > 1) |
219 | jmachado | 156 | { |
157 | CourseUnit cu1 = cus.get(0); |
||
158 | CourseUnit cu2 = cus.get(1); |
||
371 | jmachado | 159 | if (cus.size() > 2) |
219 | jmachado | 160 | { |
161 | logger.error("CourseUnit in more than two places in a course:" + cu1.getCode()); |
||
162 | } |
||
163 | else |
||
164 | { |
||
371 | jmachado | 165 | if (cu1.getSemestre().equals("S1")) |
219 | jmachado | 166 | { |
371 | jmachado | 167 | if (cu2.getSemestre().equals("S1")) |
219 | jmachado | 168 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
169 | else |
||
170 | { |
||
171 | return cu2; |
||
172 | } |
||
173 | } |
||
174 | else |
||
175 | { |
||
371 | jmachado | 176 | if (cu2.getSemestre().equals("S2")) |
219 | jmachado | 177 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
178 | else |
||
179 | { |
||
180 | return cu1; |
||
181 | } |
||
182 | } |
||
183 | } |
||
184 | } |
||
371 | jmachado | 185 | else if (cus.size() == 1) |
219 | jmachado | 186 | return cus.get(0); |
187 | |||
188 | return null; |
||
189 | } |
||
190 | |||
751 | jmachado | 191 | |
192 | public void consistCourseUnitCourseCodes(1.5.0/docs/api/java/lang/String.html">String importYear) |
||
193 | { |
||
194 | List<CourseUnit> courseUnit = createCriteria() |
||
195 | .add(eq("importYear", importYear)).list(); |
||
196 | for(CourseUnit cu: courseUnit) |
||
197 | { |
||
198 | if(cu.getCourse() != null) |
||
199 | { |
||
200 | if(cu.getCourseCode() == null || (cu.getCourseCode() != null && !cu.getCourseCode().equals(cu.getCourse().getCode()))) |
||
201 | { |
||
202 | 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() ); |
||
203 | } |
||
204 | |||
205 | if(cu.getCourseName() == null || (cu.getCourseName() != null && !cu.getCourseName().equals(cu.getCourse().getName()))) |
||
206 | { |
||
207 | 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() ); |
||
208 | } |
||
209 | cu.setCourseCode(cu.getCourse().getCode()); |
||
210 | cu.setCourseName(cu.getCourse().getName()); |
||
211 | } |
||
212 | else |
||
213 | { |
||
214 | cu.setCourseCode(""); |
||
215 | cu.setCourseName(""); |
||
216 | } |
||
217 | } |
||
218 | } |
||
219 | |||
220 | |||
899 | jmachado | 221 | //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 | 222 | //se nao a carregar unidades vai buscar a errada |
225 | jmachado | 223 | 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 | 224 | { |
225 | jmachado | 225 | return (CourseUnit) |
226 | createCriteria() |
||
227 | .add(eq("code", sigesCode)) |
||
228 | .add(eq("courseCode", courseCode)) |
||
229 | .add(eq("semestre", semestre)) |
||
230 | .add(eq("importYear", year)) |
||
231 | .uniqueResult(); |
||
202 | jmachado | 232 | } |
767 | jmachado | 233 | |
899 | jmachado | 234 | 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) |
235 | { |
||
236 | return (CourseUnit) |
||
237 | createCriteria() |
||
238 | .add(eq("code", sigesCode)) |
||
239 | .add(eq("courseCode", courseCode)) |
||
240 | .add(eq("semestre", semestre)) |
||
241 | .addOrder(Order.desc("importYear")) |
||
242 | .setMaxResults(1).list().get(0); |
||
243 | } |
||
244 | |||
245 | |||
883 | jmachado | 246 | 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 | 247 | { |
899 | jmachado | 248 | return loadBySigesCodeUniqueMostRecent(sigesCode,courseCode,semestre); |
883 | jmachado | 249 | } |
250 | |||
251 | |||
252 | 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) |
||
253 | { |
||
767 | jmachado | 254 | return createCriteria() |
255 | .add(eq("code", sigesCode)) |
||
256 | .add(eq("courseCode", courseCode)) |
||
257 | .add(eq("importYear", year)) |
||
258 | .addOrder(Order.desc("id")) |
||
259 | .list(); |
||
260 | } |
||
261 | |||
457 | jmachado | 262 | 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) |
263 | { |
||
264 | return (List<CourseUnit>) createCriteria() |
||
265 | .add(eq("code", sigesCode)) |
||
266 | .add(eq("courseCode", courseCode)) |
||
267 | .addOrder(Order.desc("importYear")) |
||
268 | .list(); |
||
269 | } |
||
163 | jmachado | 270 | |
1077 | jmachado | 271 | /** |
272 | * Metodo usado para carregar unidades de anos anteriores que possam estar em edição |
||
273 | * para mostrar na página da unidade |
||
274 | * |
||
275 | * Este metodo nao serve para mais nada, nao é usado nas Tarefas da Home |
||
276 | * @param sigesCode |
||
277 | * @param courseCode |
||
278 | * @return |
||
279 | */ |
||
280 | 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 | 281 | { |
1077 | jmachado | 282 | 1.5.0/docs/api/java/lang/String.html">String activeImportYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
1074 | jmachado | 283 | |
1077 | jmachado | 284 | Criterion crtDegrees = getCourseUnitActiveDegreeCourseIdsCriterion(activeImportYear); |
285 | if(crtDegrees == null) |
||
286 | { |
||
287 | //Nao ha graus nem cursos portanto o ano não interessa |
||
288 | //o ano deve ser usado para abrir graus ou cursos senao nao |
||
289 | //abre nada |
||
290 | crtDegrees = eq("evaluationOpenByAdmin",true); |
||
291 | } |
||
292 | else |
||
293 | { |
||
294 | crtDegrees = and(eq("importYear", activeImportYear),crtDegrees); |
||
295 | crtDegrees = or(eq("evaluationOpenByAdmin",true),crtDegrees); |
||
296 | } |
||
297 | |||
1074 | jmachado | 298 | List<CourseUnit> cus = (List<CourseUnit>) createCriteria() |
299 | .createAlias("course","c") |
||
300 | .createAlias("courseUnitEvaluation","ce") |
||
301 | .add(eq("code", sigesCode)) |
||
302 | .add(eq("courseCode", courseCode)) |
||
303 | .add(crtDegrees) |
||
304 | .add(eq("ce.closed",false)) |
||
305 | .list(); |
||
1077 | jmachado | 306 | List<CourseUnit> cusNull = (List<CourseUnit>) createCriteria() |
307 | .createAlias("course","c") |
||
308 | .add(eq("code", sigesCode)) |
||
309 | .add(eq("courseCode", courseCode)) |
||
310 | .add(crtDegrees) |
||
311 | .add(isNull("courseUnitEvaluation")) |
||
312 | .list(); |
||
313 | cus.addAll(cusNull); |
||
1074 | jmachado | 314 | if(cus != null && cus.size() > 1) |
315 | { |
||
316 | logger.warn("Mais do que uma unidade do mesmo codigo em avaliacao curricular, e suposto haver apenas uma, verificar logica aplicacional"); |
||
317 | } |
||
318 | else if(cus != null && cus.size() > 0) |
||
319 | { |
||
320 | return cus.get(0); |
||
321 | } |
||
322 | |||
323 | return null; |
||
324 | } |
||
325 | |||
376 | jmachado | 326 | 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) |
327 | { |
||
328 | Criteria c = createCriteria(); |
||
329 | if(courseId > 0) |
||
330 | c.add(eq("course.id", courseId)); |
||
331 | if(semestre != null && semestre.length() > 0) |
||
332 | c.add(eq("semestre", semestre)); |
||
333 | if(year != null && year.length() > 0) |
||
334 | c.add(eq("importYear", year)); |
||
335 | if(withTeacher && !withNoTeacher) |
||
336 | { |
||
337 | c.createAlias("teachers", "th"); |
||
338 | c.add(isNotNull("th.id")); |
||
339 | } |
||
340 | else if(!withTeacher && withNoTeacher) |
||
341 | { |
||
342 | c.createAlias("teachers", "th", JoinFragment.LEFT_OUTER_JOIN); |
||
343 | c.add(isNull("th.id")); |
||
344 | } |
||
345 | return c.list(); |
||
346 | } |
||
163 | jmachado | 347 | |
376 | jmachado | 348 | |
205 | jmachado | 349 | public int countCourseUnits(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
350 | { |
||
749 | jmachado | 351 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name","code"); |
205 | jmachado | 352 | return createCriteria().add(c).list().size(); |
353 | } |
||
163 | jmachado | 354 | |
205 | jmachado | 355 | public List<CourseUnit> search(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
356 | { |
||
748 | jmachado | 357 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name","code"); |
205 | jmachado | 358 | Criteria criteria = createCriteria(); |
359 | criteria.add(c) |
||
360 | .addOrder(Order.asc("name")) |
||
361 | .setMaxResults(maxUnits) |
||
362 | .setFirstResult(page * maxUnits); |
||
363 | return criteria.list(); |
||
364 | } |
||
202 | jmachado | 365 | |
206 | jmachado | 366 | public int countCourseUnitsActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
367 | { |
||
371 | jmachado | 368 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name"); |
206 | jmachado | 369 | return createCriteria() |
370 | .add(c) |
||
995 | jmachado | 371 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 372 | .list().size(); |
373 | } |
||
374 | |||
375 | public List<CourseUnit> searchActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
||
376 | { |
||
377 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name"); |
||
378 | Criteria criteria = createCriteria(); |
||
379 | criteria.add(c) |
||
995 | jmachado | 380 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 381 | .addOrder(Order.asc("name")) |
382 | .setMaxResults(maxUnits) |
||
383 | .setFirstResult(page * maxUnits); |
||
384 | return criteria.list(); |
||
385 | } |
||
386 | |||
205 | jmachado | 387 | public List<CourseUnit> loadMissingObjectives(long teacherId) |
388 | { |
||
389 | //todo falta a projeccao do teacher id |
||
390 | return createCriteria() |
||
995 | jmachado | 391 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 392 | .add((or(isNull("objectives"), eq("objectives", "")))) |
205 | jmachado | 393 | .createAlias("teachers", "th") |
371 | jmachado | 394 | .add(eq("semestre", DatesUtils.getSemestre())) |
395 | .add(eq("th.id", teacherId)) |
||
205 | jmachado | 396 | .list(); |
397 | } |
||
398 | |||
214 | jmachado | 399 | public List<CourseUnit> loadMissingPrograms(long teacherId) |
400 | { |
||
401 | //todo falta a projeccao do teacher id |
||
402 | return createCriteria() |
||
995 | jmachado | 403 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 404 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
214 | jmachado | 405 | .createAlias("teachers", "th") |
371 | jmachado | 406 | .add(eq("semestre", DatesUtils.getSemestre())) |
407 | .add(eq("th.id", teacherId)) |
||
214 | jmachado | 408 | .list(); |
409 | } |
||
410 | |||
343 | jmachado | 411 | public List<CourseUnit> loadMissingObjectivesOrPrograms(long teacherId) |
412 | { |
||
413 | //todo falta a projeccao do teacher id |
||
371 | jmachado | 414 | Criteria c = createCriteria() |
995 | jmachado | 415 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 416 | .add(or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", "")))); |
417 | |||
418 | DatesUtils.SemestreModerate semestreModerate = DatesUtils.getSemestreModerate(); |
||
419 | if (semestreModerate == DatesUtils.SemestreModerate.S1) |
||
420 | c.add(eq("semestre", "S1")); |
||
421 | else if (semestreModerate == DatesUtils.SemestreModerate.S2) |
||
422 | c.add(eq("semestre", "S2")); |
||
423 | else |
||
424 | c.add(or(eq("semestre", "S1"), eq("semestre", "S2"))); |
||
425 | |||
426 | return c.createAlias("teachers", "th") |
||
427 | .add(eq("th.id", teacherId)) |
||
343 | jmachado | 428 | .list(); |
429 | } |
||
214 | jmachado | 430 | |
343 | jmachado | 431 | |
214 | jmachado | 432 | public List<CourseUnit> loadMissingObjectivesGivenCourse(long courseId) |
433 | { |
||
434 | return createCriteria() |
||
435 | .createAlias("course", "c") |
||
371 | jmachado | 436 | .add(eq("c.id", courseId)) |
995 | jmachado | 437 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 438 | .add(eq("semestre", DatesUtils.getSemestre())) |
439 | .add((or(isNull("objectives"), eq("objectives", "")))) |
||
214 | jmachado | 440 | .list(); |
441 | } |
||
442 | |||
443 | public List<CourseUnit> loadMissingProgramGivenCourse(long courseId) |
||
444 | { |
||
445 | return createCriteria() |
||
446 | .createAlias("course", "c") |
||
371 | jmachado | 447 | .add(eq("c.id", courseId)) |
995 | jmachado | 448 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 449 | .add(eq("semestre", DatesUtils.getSemestre())) |
450 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
||
214 | jmachado | 451 | .list(); |
452 | } |
||
453 | |||
509 | jmachado | 454 | public List<CourseUnit> loadMissingProgramValidateGivenCourse(long courseId) |
455 | { |
||
456 | return createCriteria() |
||
457 | .createAlias("course", "c") |
||
458 | .add(eq("c.id", courseId)) |
||
995 | jmachado | 459 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
509 | jmachado | 460 | .add(eq("semestre", DatesUtils.getSemestre())) |
461 | .add((and(isNotNull("programStreamId"), not(eq("programStreamId", ""))))) |
||
462 | .add((eq("validProgram", false))) |
||
463 | .list(); |
||
464 | } |
||
465 | |||
219 | jmachado | 466 | public List<CourseUnit> loadMissingObjectivesOrProgramGivenCourse(long courseId) |
214 | jmachado | 467 | { |
468 | return createCriteria() |
||
469 | .createAlias("course", "c") |
||
371 | jmachado | 470 | .add(eq("c.id", courseId)) |
995 | jmachado | 471 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 472 | .add(eq("semestre", DatesUtils.getSemestre())) |
473 | .add((or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", ""))))) |
||
214 | jmachado | 474 | .list(); |
475 | } |
||
205 | jmachado | 476 | |
343 | jmachado | 477 | public int countMissingProgramGivenCourse(long courseId) |
478 | { |
||
479 | return loadMissingProgramGivenCourse(courseId).size(); |
||
480 | } |
||
205 | jmachado | 481 | |
509 | jmachado | 482 | public int countMissingProgramValidateCourse(long courseId) |
483 | { |
||
484 | return loadMissingProgramValidateGivenCourse(courseId).size(); |
||
485 | } |
||
751 | jmachado | 486 | |
487 | |||
488 | public List<String> getTeachersEmails(long unit) { |
||
489 | 1.5.0/docs/api/javax/management/Query.html">Query q = createQuery("select e.email from " |
||
490 | + Teacher.class.getName() + " e join e.teachedUnits as unit " |
||
491 | + " where " |
||
492 | + " unit.id = ? " |
||
493 | |||
494 | ); |
||
495 | q.setLong(0,unit); |
||
496 | return q.list(); |
||
497 | } |
||
961 | jmachado | 498 | |
499 | public static class CourseMissingValidationProgram |
||
500 | { |
||
501 | public Course course; |
||
502 | public List<CourseUnit> courseUnits; |
||
503 | } |
||
504 | public List<CourseMissingValidationProgram> loadMissingProgramValidate(UserSession userSession) |
||
505 | { |
||
506 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
995 | jmachado | 507 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
961 | jmachado | 508 | for(Course course: courses) |
509 | { |
||
510 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
511 | { |
||
512 | List<CourseUnit> courseUnits = loadMissingProgramValidateGivenCourse(course.getId()); |
||
513 | if(courseUnits != null && courseUnits.size() > 0) |
||
514 | { |
||
515 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
516 | c.course = course; |
||
517 | c.courseUnits = courseUnits; |
||
518 | result.add(c); |
||
519 | } |
||
520 | } |
||
521 | } |
||
522 | return result; |
||
523 | } |
||
1040 | jmachado | 524 | public List<CourseMissingValidationProgram> loadMissingPrograms(UserSession userSession) |
525 | { |
||
526 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
527 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
||
528 | for(Course course: courses) |
||
529 | { |
||
530 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
531 | { |
||
532 | List<CourseUnit> courseUnits = loadMissingProgramGivenCourse(course.getId()); |
||
533 | if(courseUnits != null && courseUnits.size() > 0) |
||
534 | { |
||
535 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
536 | c.course = course; |
||
537 | c.courseUnits = courseUnits; |
||
538 | result.add(c); |
||
539 | } |
||
540 | } |
||
541 | } |
||
542 | return result; |
||
543 | } |
||
961 | jmachado | 544 | public static class CourseMissingValidationEvaluation |
545 | { |
||
546 | public Course course; |
||
547 | public List<CourseUnit> courseUnits; |
||
548 | } |
||
549 | |||
550 | public List<CourseMissingValidationEvaluation> loadMissingEvaluationValidate(UserSession userSession) |
||
551 | { |
||
552 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
962 | jmachado | 553 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
961 | jmachado | 554 | for(Course course: courses) |
555 | { |
||
556 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
557 | { |
||
558 | List<CourseUnit> courseUnits = loadMissingEvaluationValidateGivenCourse(course.getId()); |
||
559 | if(courseUnits != null && courseUnits.size() > 0) |
||
560 | { |
||
561 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
562 | c.course = course; |
||
563 | c.courseUnits = courseUnits; |
||
564 | result.add(c); |
||
565 | } |
||
566 | } |
||
567 | } |
||
568 | return result; |
||
569 | } |
||
570 | |||
571 | /* |
||
572 | * Neste caso apenas se validam as do ano anterior*/ |
||
573 | |||
574 | public List<CourseUnit> loadMissingEvaluationValidateGivenCourse(long courseId) |
||
575 | { |
||
1070 | jmachado | 576 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
1077 | jmachado | 577 | |
578 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
579 | if(degreesCrit == null) |
||
1017 | jmachado | 580 | return new ArrayList<CourseUnit>(); |
581 | |||
961 | jmachado | 582 | return createCriteria() |
583 | .createAlias("course", "c") |
||
584 | .createAlias("courseUnitEvaluation", "ce") |
||
585 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 586 | .add(eq("importYear", activeYear)) |
587 | .add(degreesCrit) |
||
961 | jmachado | 588 | .add((eq("ce.closed", false))) |
1017 | jmachado | 589 | .add((eq("ce.teacherComplete", true))) |
961 | jmachado | 590 | .list(); |
591 | } |
||
967 | jmachado | 592 | |
1077 | jmachado | 593 | /** |
594 | * Devolve um criteio OR para todos os cursos de grau pertencente à lista de graus |
||
595 | * ou pertencete à lista de cursoIds |
||
596 | |||
597 | * @return |
||
598 | */ |
||
599 | private Criterion getCourseUnitActiveDegreeCourseIdsCriterion(1.5.0/docs/api/java/lang/String.html">String activeYear) |
||
1070 | jmachado | 600 | { |
1077 | jmachado | 601 | List<String> activeDegrees = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveDegrees(); |
602 | List<Long> activeCourseIds = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveCourseIds(); |
||
603 | boolean activeDegreesOff = activeDegrees == null || activeDegrees.size() == 0; |
||
604 | boolean activeCourseIdsOff = activeCourseIds == null || activeCourseIds.size() == 0; |
||
605 | if(activeYear == null || (activeDegreesOff && activeCourseIdsOff)) |
||
606 | return null; |
||
607 | |||
608 | Criterion crit = null; |
||
609 | |||
610 | if(activeDegrees != null) |
||
611 | for(1.5.0/docs/api/java/lang/String.html">String degree: activeDegrees) |
||
612 | { |
||
613 | if(crit == null) |
||
614 | crit = eq("c.degree",degree); |
||
615 | else |
||
616 | crit = or(crit,eq("c.degree",degree)); |
||
617 | } |
||
618 | if(activeCourseIds != null) |
||
619 | for(1.5.0/docs/api/java/lang/Long.html">Long courseId: activeCourseIds) |
||
620 | { |
||
621 | if(crit == null) |
||
622 | crit = eq("c.id",courseId); |
||
623 | else |
||
624 | crit = or(crit,eq("c.id",courseId)); |
||
625 | } |
||
626 | |||
627 | return crit; |
||
1070 | jmachado | 628 | } |
629 | |||
1077 | jmachado | 630 | |
1024 | jmachado | 631 | public List<CourseUnit> loadTeacherUnitsMissingEvaluation(UserSession userSession) |
632 | { |
||
633 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
1077 | jmachado | 634 | |
635 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
||
636 | if(degreesCrit == null) |
||
1024 | jmachado | 637 | return new ArrayList<CourseUnit>(); |
638 | |||
1070 | jmachado | 639 | |
1024 | jmachado | 640 | List<CourseUnit> nulls = |
641 | createCriteria() |
||
1070 | jmachado | 642 | .createAlias("course", "c") |
1074 | jmachado | 643 | .createAlias("teachers", "t") |
1077 | jmachado | 644 | .add(eq("importYear", activeYear)) |
1024 | jmachado | 645 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
646 | //.add(ge("importYear", "201415" )) |
||
647 | //.add(isNull("courseUnitEvaluation")) |
||
648 | //todo novo testar |
||
649 | .add(eq("t.id", userSession.getUser().getId())) |
||
1070 | jmachado | 650 | .add(degreesCrit) |
1024 | jmachado | 651 | .add(isNull("courseUnitEvaluation")) |
652 | .list(); |
||
653 | |||
654 | List<CourseUnit> teacherCompleteFalse = |
||
655 | createCriteria() |
||
1070 | jmachado | 656 | .createAlias("course", "c") |
1024 | jmachado | 657 | .createAlias("courseUnitEvaluation", "ce") |
658 | .createAlias("teachers","t") |
||
1028 | jmachado | 659 | .add(eq("t.id", userSession.getUser().getId())) |
1077 | jmachado | 660 | .add(eq("importYear", activeYear)) |
1024 | jmachado | 661 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
662 | //.add(ge("importYear", "201415" )) |
||
663 | //.add(isNull("courseUnitEvaluation")) |
||
664 | //todo novo testar |
||
1070 | jmachado | 665 | .add(degreesCrit) |
1074 | jmachado | 666 | .add(eq("ce.teacherComplete", false)) |
1024 | jmachado | 667 | .list(); |
668 | teacherCompleteFalse.addAll(nulls); |
||
669 | return teacherCompleteFalse; |
||
670 | } |
||
671 | |||
672 | |||
967 | jmachado | 673 | public List<CourseMissingValidationEvaluation> loadMissingEvaluation(UserSession userSession) |
674 | { |
||
675 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
676 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
||
677 | for(Course course: courses) |
||
678 | { |
||
679 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
680 | { |
||
681 | List<CourseUnit> courseUnits = loadMissingEvaluation(course.getId()); |
||
682 | if(courseUnits != null && courseUnits.size() > 0) |
||
683 | { |
||
684 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
685 | c.course = course; |
||
686 | c.courseUnits = courseUnits; |
||
687 | result.add(c); |
||
688 | } |
||
689 | } |
||
690 | } |
||
691 | return result; |
||
692 | } |
||
693 | |||
694 | public List<CourseUnit> loadMissingEvaluation(long courseId) |
||
695 | { |
||
1070 | jmachado | 696 | |
697 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
1077 | jmachado | 698 | Criterion degreesCrit = getCourseUnitActiveDegreeCourseIdsCriterion(activeYear); |
699 | |||
700 | if(degreesCrit == null) |
||
1017 | jmachado | 701 | return new ArrayList<CourseUnit>(); |
702 | |||
1024 | jmachado | 703 | List<CourseUnit> nulls = |
704 | createCriteria() |
||
967 | jmachado | 705 | .createAlias("course", "c") |
706 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 707 | .add(eq("importYear", activeYear)) |
708 | .add(degreesCrit) |
||
1024 | jmachado | 709 | .add(isNull("courseUnitEvaluation")) |
967 | jmachado | 710 | .list(); |
1024 | jmachado | 711 | |
712 | List<CourseUnit> teacherCompleteFalse = |
||
713 | createCriteria() |
||
714 | .createAlias("course", "c") |
||
715 | .createAlias("courseUnitEvaluation", "ce") |
||
716 | .add(eq("c.id", courseId)) |
||
1070 | jmachado | 717 | .add(degreesCrit) |
718 | .add(eq("importYear", activeYear)) |
||
1024 | jmachado | 719 | .add(eq("ce.teacherComplete", false)) |
720 | .list(); |
||
721 | teacherCompleteFalse.addAll(nulls); |
||
722 | return teacherCompleteFalse; |
||
967 | jmachado | 723 | } |
973 | jmachado | 724 | |
725 | public CourseUnit loadByEvaluationStreamId(1.5.0/docs/api/java/lang/String.html">String identifier) |
||
726 | { |
||
727 | return |
||
728 | (CourseUnit) |
||
729 | createCriteria() |
||
730 | .add(eq("evaluationStreamId",identifier)) |
||
731 | .uniqueResult(); |
||
732 | } |
||
110 | susana | 733 | } |