Rev 1018 | Rev 1028 | 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 | { |
||
371 | jmachado | 83 | return createCriteria().add(eq("importYear", importYear)) |
84 | .createAlias("students", "st") |
||
255 | jmachado | 85 | .add(eq("st.id", studentId)).addOrder(Order.asc("name")).list(); |
218 | jmachado | 86 | } |
420 | jmachado | 87 | 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) |
88 | { |
||
89 | Criteria c =createCriteria() |
||
90 | .add(eq("importYear", importYear)) |
||
91 | .createAlias("students", "st") |
||
92 | .add(eq("st.id", studentId)); |
||
93 | if(semestre != null) |
||
94 | c.add(eq("semestre", semestre)); |
||
95 | return c.addOrder(Order.asc("name")).list(); |
||
96 | } |
||
255 | jmachado | 97 | |
98 | public List<CourseUnit> loadSubscribedOtherImportYearUnits(long studentId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
||
99 | { |
||
371 | jmachado | 100 | return createCriteria().add(not(eq("importYear", importYear))) |
101 | .createAlias("students", "st") |
||
255 | jmachado | 102 | .add(eq("st.id", studentId)).addOrder(Order.asc("name")).list(); |
103 | } |
||
343 | jmachado | 104 | |
253 | jmachado | 105 | public List<CourseUnitImpl> loadTeachedImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
218 | jmachado | 106 | { |
371 | jmachado | 107 | return createCriteria().add(eq("importYear", importYear)) |
108 | .createAlias("teachers", "st") |
||
255 | jmachado | 109 | .add(eq("st.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
218 | jmachado | 110 | } |
111 | |||
821 | jmachado | 112 | public List<CourseUnitImpl> loadResponsableImportYearUnits(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear) |
113 | { |
||
114 | return createCriteria().add(eq("importYear", importYear)) |
||
115 | .add(eq("responsableTeacher.id", teacherId)).addOrder(Order.asc("importYear")).addOrder(Order.asc("name")).list(); |
||
116 | } |
||
117 | |||
420 | jmachado | 118 | 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) |
119 | { |
||
120 | Criteria c =createCriteria() |
||
121 | .add(eq("importYear", importYear)) |
||
122 | .createAlias("teachers", "st") |
||
123 | .add(eq("st.id", teacherId)) |
||
124 | .add(eq("st.id", teacherId)); |
||
125 | if(semestre != null) |
||
126 | c.add(eq("semestre", semestre)); |
||
127 | return c.addOrder(Order.asc("name")).list(); |
||
128 | } |
||
129 | |||
130 | |||
131 | |||
163 | jmachado | 132 | public CourseUnit loadBySigesCodeUnique(1.5.0/docs/api/java/lang/String.html">String sigesCode) |
133 | { |
||
202 | jmachado | 134 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).uniqueResult(); |
163 | jmachado | 135 | } |
116 | jmachado | 136 | |
202 | jmachado | 137 | 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) |
138 | { |
||
139 | return (CourseUnit) createCriteria().add(eq("code", sigesCode)).add(eq("courseCode", courseCode)).uniqueResult(); |
||
140 | } |
||
163 | jmachado | 141 | |
228 | jmachado | 142 | 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 | 143 | { |
371 | jmachado | 144 | List<CourseUnit> cus = createCriteria() |
219 | jmachado | 145 | .add(eq("code", sigesCode)) |
228 | jmachado | 146 | .add(eq("importYear", year)) |
219 | jmachado | 147 | .add(eq("courseCode", courseCode)) |
228 | jmachado | 148 | .add(eq("semestre", semestre)) |
371 | jmachado | 149 | .createAlias("students", "st") |
150 | .add(eq("st.id", studentId)) |
||
219 | jmachado | 151 | .list(); |
371 | jmachado | 152 | if (cus.size() > 1) |
219 | jmachado | 153 | { |
154 | CourseUnit cu1 = cus.get(0); |
||
155 | CourseUnit cu2 = cus.get(1); |
||
371 | jmachado | 156 | if (cus.size() > 2) |
219 | jmachado | 157 | { |
158 | logger.error("CourseUnit in more than two places in a course:" + cu1.getCode()); |
||
159 | } |
||
160 | else |
||
161 | { |
||
371 | jmachado | 162 | if (cu1.getSemestre().equals("S1")) |
219 | jmachado | 163 | { |
371 | jmachado | 164 | if (cu2.getSemestre().equals("S1")) |
219 | jmachado | 165 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
166 | else |
||
167 | { |
||
168 | return cu2; |
||
169 | } |
||
170 | } |
||
171 | else |
||
172 | { |
||
371 | jmachado | 173 | if (cu2.getSemestre().equals("S2")) |
219 | jmachado | 174 | logger.error("CourseUnit in more than two places in a semestre:" + cu1.getCode()); |
175 | else |
||
176 | { |
||
177 | return cu1; |
||
178 | } |
||
179 | } |
||
180 | } |
||
181 | } |
||
371 | jmachado | 182 | else if (cus.size() == 1) |
219 | jmachado | 183 | return cus.get(0); |
184 | |||
185 | return null; |
||
186 | } |
||
187 | |||
751 | jmachado | 188 | |
189 | public void consistCourseUnitCourseCodes(1.5.0/docs/api/java/lang/String.html">String importYear) |
||
190 | { |
||
191 | List<CourseUnit> courseUnit = createCriteria() |
||
192 | .add(eq("importYear", importYear)).list(); |
||
193 | for(CourseUnit cu: courseUnit) |
||
194 | { |
||
195 | if(cu.getCourse() != null) |
||
196 | { |
||
197 | if(cu.getCourseCode() == null || (cu.getCourseCode() != null && !cu.getCourseCode().equals(cu.getCourse().getCode()))) |
||
198 | { |
||
199 | 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() ); |
||
200 | } |
||
201 | |||
202 | if(cu.getCourseName() == null || (cu.getCourseName() != null && !cu.getCourseName().equals(cu.getCourse().getName()))) |
||
203 | { |
||
204 | 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() ); |
||
205 | } |
||
206 | cu.setCourseCode(cu.getCourse().getCode()); |
||
207 | cu.setCourseName(cu.getCourse().getName()); |
||
208 | } |
||
209 | else |
||
210 | { |
||
211 | cu.setCourseCode(""); |
||
212 | cu.setCourseName(""); |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | |||
217 | |||
899 | jmachado | 218 | //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 | 219 | //se nao a carregar unidades vai buscar a errada |
225 | jmachado | 220 | 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 | 221 | { |
225 | jmachado | 222 | return (CourseUnit) |
223 | createCriteria() |
||
224 | .add(eq("code", sigesCode)) |
||
225 | .add(eq("courseCode", courseCode)) |
||
226 | .add(eq("semestre", semestre)) |
||
227 | .add(eq("importYear", year)) |
||
228 | .uniqueResult(); |
||
202 | jmachado | 229 | } |
767 | jmachado | 230 | |
899 | jmachado | 231 | 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) |
232 | { |
||
233 | return (CourseUnit) |
||
234 | createCriteria() |
||
235 | .add(eq("code", sigesCode)) |
||
236 | .add(eq("courseCode", courseCode)) |
||
237 | .add(eq("semestre", semestre)) |
||
238 | .addOrder(Order.desc("importYear")) |
||
239 | .setMaxResults(1).list().get(0); |
||
240 | } |
||
241 | |||
242 | |||
883 | jmachado | 243 | 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 | 244 | { |
899 | jmachado | 245 | return loadBySigesCodeUniqueMostRecent(sigesCode,courseCode,semestre); |
883 | jmachado | 246 | } |
247 | |||
248 | |||
249 | 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) |
||
250 | { |
||
767 | jmachado | 251 | return createCriteria() |
252 | .add(eq("code", sigesCode)) |
||
253 | .add(eq("courseCode", courseCode)) |
||
254 | .add(eq("importYear", year)) |
||
255 | .addOrder(Order.desc("id")) |
||
256 | .list(); |
||
257 | } |
||
258 | |||
457 | jmachado | 259 | 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) |
260 | { |
||
261 | return (List<CourseUnit>) createCriteria() |
||
262 | .add(eq("code", sigesCode)) |
||
263 | .add(eq("courseCode", courseCode)) |
||
264 | .addOrder(Order.desc("importYear")) |
||
265 | .list(); |
||
266 | } |
||
163 | jmachado | 267 | |
376 | jmachado | 268 | 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) |
269 | { |
||
270 | Criteria c = createCriteria(); |
||
271 | if(courseId > 0) |
||
272 | c.add(eq("course.id", courseId)); |
||
273 | if(semestre != null && semestre.length() > 0) |
||
274 | c.add(eq("semestre", semestre)); |
||
275 | if(year != null && year.length() > 0) |
||
276 | c.add(eq("importYear", year)); |
||
277 | if(withTeacher && !withNoTeacher) |
||
278 | { |
||
279 | c.createAlias("teachers", "th"); |
||
280 | c.add(isNotNull("th.id")); |
||
281 | } |
||
282 | else if(!withTeacher && withNoTeacher) |
||
283 | { |
||
284 | c.createAlias("teachers", "th", JoinFragment.LEFT_OUTER_JOIN); |
||
285 | c.add(isNull("th.id")); |
||
286 | } |
||
287 | return c.list(); |
||
288 | } |
||
163 | jmachado | 289 | |
376 | jmachado | 290 | |
205 | jmachado | 291 | public int countCourseUnits(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
292 | { |
||
749 | jmachado | 293 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name","code"); |
205 | jmachado | 294 | return createCriteria().add(c).list().size(); |
295 | } |
||
163 | jmachado | 296 | |
205 | jmachado | 297 | public List<CourseUnit> search(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
298 | { |
||
748 | jmachado | 299 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name","code"); |
205 | jmachado | 300 | Criteria criteria = createCriteria(); |
301 | criteria.add(c) |
||
302 | .addOrder(Order.asc("name")) |
||
303 | .setMaxResults(maxUnits) |
||
304 | .setFirstResult(page * maxUnits); |
||
305 | return criteria.list(); |
||
306 | } |
||
202 | jmachado | 307 | |
206 | jmachado | 308 | public int countCourseUnitsActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchType) |
309 | { |
||
371 | jmachado | 310 | Criterion c = DaoUtils.createSearchQuery(query, searchType, "objectives", "name"); |
206 | jmachado | 311 | return createCriteria() |
312 | .add(c) |
||
995 | jmachado | 313 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 314 | .list().size(); |
315 | } |
||
316 | |||
317 | public List<CourseUnit> searchActualYear(1.5.0/docs/api/java/lang/String.html">String query, SearchTypeEnum searchTypeEnum, int maxUnits, int page) |
||
318 | { |
||
319 | Criterion c = DaoUtils.createSearchQuery(query, searchTypeEnum, "objectives", "name"); |
||
320 | Criteria criteria = createCriteria(); |
||
321 | criteria.add(c) |
||
995 | jmachado | 322 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
206 | jmachado | 323 | .addOrder(Order.asc("name")) |
324 | .setMaxResults(maxUnits) |
||
325 | .setFirstResult(page * maxUnits); |
||
326 | return criteria.list(); |
||
327 | } |
||
328 | |||
205 | jmachado | 329 | public List<CourseUnit> loadMissingObjectives(long teacherId) |
330 | { |
||
331 | //todo falta a projeccao do teacher id |
||
332 | return createCriteria() |
||
995 | jmachado | 333 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 334 | .add((or(isNull("objectives"), eq("objectives", "")))) |
205 | jmachado | 335 | .createAlias("teachers", "th") |
371 | jmachado | 336 | .add(eq("semestre", DatesUtils.getSemestre())) |
337 | .add(eq("th.id", teacherId)) |
||
205 | jmachado | 338 | .list(); |
339 | } |
||
340 | |||
214 | jmachado | 341 | public List<CourseUnit> loadMissingPrograms(long teacherId) |
342 | { |
||
343 | //todo falta a projeccao do teacher id |
||
344 | return createCriteria() |
||
995 | jmachado | 345 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 346 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
214 | jmachado | 347 | .createAlias("teachers", "th") |
371 | jmachado | 348 | .add(eq("semestre", DatesUtils.getSemestre())) |
349 | .add(eq("th.id", teacherId)) |
||
214 | jmachado | 350 | .list(); |
351 | } |
||
352 | |||
343 | jmachado | 353 | public List<CourseUnit> loadMissingObjectivesOrPrograms(long teacherId) |
354 | { |
||
355 | //todo falta a projeccao do teacher id |
||
371 | jmachado | 356 | Criteria c = createCriteria() |
995 | jmachado | 357 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 358 | .add(or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", "")))); |
359 | |||
360 | DatesUtils.SemestreModerate semestreModerate = DatesUtils.getSemestreModerate(); |
||
361 | if (semestreModerate == DatesUtils.SemestreModerate.S1) |
||
362 | c.add(eq("semestre", "S1")); |
||
363 | else if (semestreModerate == DatesUtils.SemestreModerate.S2) |
||
364 | c.add(eq("semestre", "S2")); |
||
365 | else |
||
366 | c.add(or(eq("semestre", "S1"), eq("semestre", "S2"))); |
||
367 | |||
368 | return c.createAlias("teachers", "th") |
||
369 | .add(eq("th.id", teacherId)) |
||
343 | jmachado | 370 | .list(); |
371 | } |
||
214 | jmachado | 372 | |
343 | jmachado | 373 | |
214 | jmachado | 374 | public List<CourseUnit> loadMissingObjectivesGivenCourse(long courseId) |
375 | { |
||
376 | return createCriteria() |
||
377 | .createAlias("course", "c") |
||
371 | jmachado | 378 | .add(eq("c.id", courseId)) |
995 | jmachado | 379 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 380 | .add(eq("semestre", DatesUtils.getSemestre())) |
381 | .add((or(isNull("objectives"), eq("objectives", "")))) |
||
214 | jmachado | 382 | .list(); |
383 | } |
||
384 | |||
385 | public List<CourseUnit> loadMissingProgramGivenCourse(long courseId) |
||
386 | { |
||
387 | return createCriteria() |
||
388 | .createAlias("course", "c") |
||
371 | jmachado | 389 | .add(eq("c.id", courseId)) |
995 | jmachado | 390 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 391 | .add(eq("semestre", DatesUtils.getSemestre())) |
392 | .add((or(isNull("programStreamId"), eq("programStreamId", "")))) |
||
214 | jmachado | 393 | .list(); |
394 | } |
||
395 | |||
509 | jmachado | 396 | public List<CourseUnit> loadMissingProgramValidateGivenCourse(long courseId) |
397 | { |
||
398 | return createCriteria() |
||
399 | .createAlias("course", "c") |
||
400 | .add(eq("c.id", courseId)) |
||
995 | jmachado | 401 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
509 | jmachado | 402 | .add(eq("semestre", DatesUtils.getSemestre())) |
403 | .add((and(isNotNull("programStreamId"), not(eq("programStreamId", ""))))) |
||
404 | .add((eq("validProgram", false))) |
||
405 | .list(); |
||
406 | } |
||
407 | |||
219 | jmachado | 408 | public List<CourseUnit> loadMissingObjectivesOrProgramGivenCourse(long courseId) |
214 | jmachado | 409 | { |
410 | return createCriteria() |
||
411 | .createAlias("course", "c") |
||
371 | jmachado | 412 | .add(eq("c.id", courseId)) |
995 | jmachado | 413 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear())) |
371 | jmachado | 414 | .add(eq("semestre", DatesUtils.getSemestre())) |
415 | .add((or(or(isNull("objectives"), eq("objectives", "")), or(isNull("programStreamId"), eq("programStreamId", ""))))) |
||
214 | jmachado | 416 | .list(); |
417 | } |
||
205 | jmachado | 418 | |
343 | jmachado | 419 | public int countMissingProgramGivenCourse(long courseId) |
420 | { |
||
421 | return loadMissingProgramGivenCourse(courseId).size(); |
||
422 | } |
||
205 | jmachado | 423 | |
509 | jmachado | 424 | public int countMissingProgramValidateCourse(long courseId) |
425 | { |
||
426 | return loadMissingProgramValidateGivenCourse(courseId).size(); |
||
427 | } |
||
751 | jmachado | 428 | |
429 | |||
430 | public List<String> getTeachersEmails(long unit) { |
||
431 | 1.5.0/docs/api/javax/management/Query.html">Query q = createQuery("select e.email from " |
||
432 | + Teacher.class.getName() + " e join e.teachedUnits as unit " |
||
433 | + " where " |
||
434 | + " unit.id = ? " |
||
435 | |||
436 | ); |
||
437 | q.setLong(0,unit); |
||
438 | return q.list(); |
||
439 | } |
||
961 | jmachado | 440 | |
441 | public static class CourseMissingValidationProgram |
||
442 | { |
||
443 | public Course course; |
||
444 | public List<CourseUnit> courseUnits; |
||
445 | } |
||
446 | public List<CourseMissingValidationProgram> loadMissingProgramValidate(UserSession userSession) |
||
447 | { |
||
448 | List<CourseMissingValidationProgram> result = new ArrayList<CourseMissingValidationProgram>(); |
||
995 | jmachado | 449 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
961 | jmachado | 450 | for(Course course: courses) |
451 | { |
||
452 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
453 | { |
||
454 | List<CourseUnit> courseUnits = loadMissingProgramValidateGivenCourse(course.getId()); |
||
455 | if(courseUnits != null && courseUnits.size() > 0) |
||
456 | { |
||
457 | CourseMissingValidationProgram c = new CourseMissingValidationProgram(); |
||
458 | c.course = course; |
||
459 | c.courseUnits = courseUnits; |
||
460 | result.add(c); |
||
461 | } |
||
462 | } |
||
463 | } |
||
464 | return result; |
||
465 | } |
||
466 | public static class CourseMissingValidationEvaluation |
||
467 | { |
||
468 | public Course course; |
||
469 | public List<CourseUnit> courseUnits; |
||
470 | } |
||
471 | |||
472 | public List<CourseMissingValidationEvaluation> loadMissingEvaluationValidate(UserSession userSession) |
||
473 | { |
||
474 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
962 | jmachado | 475 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
961 | jmachado | 476 | for(Course course: courses) |
477 | { |
||
478 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
479 | { |
||
480 | List<CourseUnit> courseUnits = loadMissingEvaluationValidateGivenCourse(course.getId()); |
||
481 | if(courseUnits != null && courseUnits.size() > 0) |
||
482 | { |
||
483 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
484 | c.course = course; |
||
485 | c.courseUnits = courseUnits; |
||
486 | result.add(c); |
||
487 | } |
||
488 | } |
||
489 | } |
||
490 | return result; |
||
491 | } |
||
492 | |||
493 | /* |
||
494 | * Neste caso apenas se validam as do ano anterior*/ |
||
495 | |||
496 | public List<CourseUnit> loadMissingEvaluationValidateGivenCourse(long courseId) |
||
497 | { |
||
1017 | jmachado | 498 | if(DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear()==null) |
499 | return new ArrayList<CourseUnit>(); |
||
500 | |||
961 | jmachado | 501 | return createCriteria() |
502 | .createAlias("course", "c") |
||
503 | .createAlias("courseUnitEvaluation", "ce") |
||
504 | .add(eq("c.id", courseId)) |
||
1017 | jmachado | 505 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear())) |
506 | //.add(ge("importYear", "201415"))//FirstYear where there was configurations |
||
961 | jmachado | 507 | .add((eq("ce.closed", false))) |
1017 | jmachado | 508 | .add((eq("ce.teacherComplete", true))) |
961 | jmachado | 509 | .list(); |
510 | } |
||
967 | jmachado | 511 | |
1024 | jmachado | 512 | public List<CourseUnit> loadTeacherUnitsMissingEvaluation(UserSession userSession) |
513 | { |
||
514 | 1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear(); |
||
515 | if(activeYear == null) |
||
516 | return new ArrayList<CourseUnit>(); |
||
517 | |||
518 | List<CourseUnit> nulls = |
||
519 | createCriteria() |
||
520 | .createAlias("teachers","t") |
||
521 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear())) |
||
522 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
||
523 | //.add(ge("importYear", "201415" )) |
||
524 | //.add(isNull("courseUnitEvaluation")) |
||
525 | //todo novo testar |
||
526 | .add(eq("t.id", userSession.getUser().getId())) |
||
527 | .add(isNull("courseUnitEvaluation")) |
||
528 | .list(); |
||
529 | |||
530 | List<CourseUnit> teacherCompleteFalse = |
||
531 | createCriteria() |
||
532 | .createAlias("courseUnitEvaluation", "ce") |
||
533 | .createAlias("teachers","t") |
||
534 | .add(eq("t.id",userSession.getUser().getId())) |
||
535 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear())) |
||
536 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
||
537 | //.add(ge("importYear", "201415" )) |
||
538 | //.add(isNull("courseUnitEvaluation")) |
||
539 | //todo novo testar |
||
540 | .add(eq("ce.teacherComplete",false)) |
||
541 | .list(); |
||
542 | teacherCompleteFalse.addAll(nulls); |
||
543 | return teacherCompleteFalse; |
||
544 | } |
||
545 | |||
546 | |||
967 | jmachado | 547 | public List<CourseMissingValidationEvaluation> loadMissingEvaluation(UserSession userSession) |
548 | { |
||
549 | List<CourseMissingValidationEvaluation> result = new ArrayList<CourseMissingValidationEvaluation>(); |
||
550 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(); |
||
551 | for(Course course: courses) |
||
552 | { |
||
553 | if(userSession.getUser().hasRole(course.getValidationRole())) |
||
554 | { |
||
555 | List<CourseUnit> courseUnits = loadMissingEvaluation(course.getId()); |
||
556 | if(courseUnits != null && courseUnits.size() > 0) |
||
557 | { |
||
558 | CourseMissingValidationEvaluation c = new CourseMissingValidationEvaluation(); |
||
559 | c.course = course; |
||
560 | c.courseUnits = courseUnits; |
||
561 | result.add(c); |
||
562 | } |
||
563 | } |
||
564 | } |
||
565 | return result; |
||
566 | } |
||
567 | |||
568 | public List<CourseUnit> loadMissingEvaluation(long courseId) |
||
569 | { |
||
1017 | jmachado | 570 | if(DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear()==null) |
571 | return new ArrayList<CourseUnit>(); |
||
572 | |||
1024 | jmachado | 573 | List<CourseUnit> nulls = |
574 | createCriteria() |
||
967 | jmachado | 575 | .createAlias("course", "c") |
576 | .add(eq("c.id", courseId)) |
||
1017 | jmachado | 577 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear())) |
578 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
||
579 | //.add(ge("importYear", "201415" )) |
||
580 | //.add(isNull("courseUnitEvaluation")) |
||
581 | //todo novo testar |
||
1024 | jmachado | 582 | .add(isNull("courseUnitEvaluation")) |
967 | jmachado | 583 | .list(); |
1024 | jmachado | 584 | |
585 | List<CourseUnit> teacherCompleteFalse = |
||
586 | createCriteria() |
||
587 | .createAlias("course", "c") |
||
588 | .createAlias("courseUnitEvaluation", "ce") |
||
589 | .add(eq("c.id", courseId)) |
||
590 | .add(eq("importYear", DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear())) |
||
591 | //.add(not(eq("importYear", DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()))) |
||
592 | //.add(ge("importYear", "201415" )) |
||
593 | //.add(isNull("courseUnitEvaluation")) |
||
594 | //todo novo testar |
||
595 | .add(eq("ce.teacherComplete", false)) |
||
596 | .list(); |
||
597 | teacherCompleteFalse.addAll(nulls); |
||
598 | return teacherCompleteFalse; |
||
967 | jmachado | 599 | } |
973 | jmachado | 600 | |
601 | public CourseUnit loadByEvaluationStreamId(1.5.0/docs/api/java/lang/String.html">String identifier) |
||
602 | { |
||
603 | return |
||
604 | (CourseUnit) |
||
605 | createCriteria() |
||
606 | .add(eq("evaluationStreamId",identifier)) |
||
607 | .uniqueResult(); |
||
608 | } |
||
110 | susana | 609 | } |