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