Rev 1457 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1457 | Rev 1471 | ||
---|---|---|---|
1 | package pt.estgp.estgweb.domain.dao.impl; |
1 | package pt.estgp.estgweb.domain.dao.impl; |
2 | 2 | ||
3 | import jomm.dao.DaoException; |
3 | import jomm.dao.DaoException; |
4 | import jomm.dao.impl.AbstractDao; |
4 | import jomm.dao.impl.AbstractDao; |
5 | import org.apache.log4j.Logger; |
5 | import org.apache.log4j.Logger; |
6 | import org.hibernate.Criteria; |
6 | import org.hibernate.Criteria; |
7 | import org.hibernate.HibernateException; |
7 | import org.hibernate.HibernateException; |
8 | import org.hibernate.Query; |
8 | import org.hibernate.Query; |
9 | import org.hibernate.criterion.Order; |
9 | import org.hibernate.criterion.Order; |
10 | import pt.estgp.estgweb.domain.*; |
10 | import pt.estgp.estgweb.domain.*; |
11 | 11 | ||
12 | import java.util.ArrayList; |
12 | import java.util.ArrayList; |
13 | import java.util.List; |
13 | import java.util.List; |
14 | 14 | ||
15 | import static org.hibernate.criterion.Restrictions.*; |
15 | import static org.hibernate.criterion.Restrictions.*; |
16 | 16 | ||
17 | /** |
17 | /** |
18 | * @author Jorge Machado |
18 | * @author Jorge Machado |
19 | * @date 28/Fev/2008 |
19 | * @date 28/Fev/2008 |
20 | * @time 2:51:06 |
20 | * @time 2:51:06 |
21 | * @see pt.estgp.estgweb.domain.dao.impl |
21 | * @see pt.estgp.estgweb.domain.dao.impl |
22 | */ |
22 | */ |
23 | public class QuestionarioDaoImpl extends QuestionarioDao |
23 | public class QuestionarioDaoImpl extends QuestionarioDao |
24 | { |
24 | { |
25 | 25 | ||
26 | 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(QuestionarioDaoImpl.class); |
26 | 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(QuestionarioDaoImpl.class); |
27 | 27 | ||
28 | public static QuestionarioDaoImpl getInstance() |
28 | public static QuestionarioDaoImpl getInstance() |
29 | { |
29 | { |
30 | if (myInstance == null) |
30 | if (myInstance == null) |
31 | myInstance = new QuestionarioDaoImpl(); |
31 | myInstance = new QuestionarioDaoImpl(); |
32 | return (QuestionarioDaoImpl) myInstance; |
32 | return (QuestionarioDaoImpl) myInstance; |
33 | } |
33 | } |
34 | 34 | ||
35 | public List<QuestionarioImpl> findSortedBy(int pageIndex, int sizeOfPage,1.5.0/docs/api/java/lang/String.html">String field) |
35 | public List<QuestionarioImpl> findSortedBy(int pageIndex, int sizeOfPage,1.5.0/docs/api/java/lang/String.html">String field) |
36 | { |
36 | { |
37 | try |
37 | try |
38 | { |
38 | { |
39 | Criteria criteria = createCriteria(); |
39 | Criteria criteria = createCriteria(); |
40 | 40 | ||
41 | criteria.setFirstResult(pageIndex * sizeOfPage); |
41 | criteria.setFirstResult(pageIndex * sizeOfPage); |
42 | criteria.setMaxResults(sizeOfPage); |
42 | criteria.setMaxResults(sizeOfPage); |
43 | criteria.addOrder(Order.desc(field)); |
43 | criteria.addOrder(Order.desc(field)); |
44 | 44 | ||
45 | return criteria.list(); |
45 | return criteria.list(); |
46 | } |
46 | } |
47 | catch (HibernateException e) |
47 | catch (HibernateException e) |
48 | { |
48 | { |
49 | throw new DaoException(e); |
49 | throw new DaoException(e); |
50 | } |
50 | } |
51 | } |
51 | } |
52 | 52 | ||
53 | public List<QuestionarioImpl> findAnoSemestre(1.5.0/docs/api/java/lang/String.html">String year, 1.5.0/docs/api/java/lang/String.html">String semestre,long historyDriveId ) |
53 | public List<QuestionarioImpl> findAnoSemestre(1.5.0/docs/api/java/lang/String.html">String year, 1.5.0/docs/api/java/lang/String.html">String semestre,long historyDriveId ) |
54 | { |
54 | { |
55 | try |
55 | try |
56 | { |
56 | { |
57 | Criteria criteria = createCriteria(); |
57 | Criteria criteria = createCriteria(); |
58 | criteria.add(eq("year",year)) |
58 | criteria.add(eq("year",year)) |
59 | .add(eq("semestre", semestre)) |
59 | .add(eq("semestre", semestre)) |
60 | .add(eq("questionarioHistoryDrive.id",historyDriveId)); |
60 | .add(eq("questionarioHistoryDrive.id",historyDriveId)); |
61 | return criteria.list(); |
61 | return criteria.list(); |
62 | } |
62 | } |
63 | catch (HibernateException e) |
63 | catch (HibernateException e) |
64 | { |
64 | { |
65 | throw new DaoException(e); |
65 | throw new DaoException(e); |
66 | } |
66 | } |
67 | } |
67 | } |
68 | 68 | ||
69 | public List<QuestionarioImpl> findProcessing() |
69 | public List<QuestionarioImpl> findProcessing() |
70 | { |
70 | { |
71 | try |
71 | try |
72 | { |
72 | { |
73 | Criteria criteria = createCriteria(); |
73 | Criteria criteria = createCriteria(); |
74 | criteria.add(or(eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING.name()),eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING_WITH_ANSWERS.name()))); |
74 | criteria.add(or(eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING.name()),eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING_WITH_ANSWERS.name()))); |
75 | return criteria.list(); |
75 | return criteria.list(); |
76 | } |
76 | } |
77 | catch (HibernateException e) |
77 | catch (HibernateException e) |
78 | { |
78 | { |
79 | throw new DaoException(e); |
79 | throw new DaoException(e); |
80 | } |
80 | } |
81 | } |
81 | } |
82 | 82 | ||
83 | public List<QuestionarioImpl> findNotClosed() |
83 | public List<QuestionarioImpl> findNotClosed() |
84 | { |
84 | { |
85 | try |
85 | try |
86 | { |
86 | { |
87 | Criteria criteria = createCriteria(); |
87 | Criteria criteria = createCriteria(); |
88 | criteria.add(not(or(or(eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.CLOSED.name()),eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING_OLAP.name())), |
88 | criteria.add(not(or(or(eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.CLOSED.name()),eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING_OLAP.name())), |
89 | eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.OLAP.name())))) |
89 | eq("state",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.OLAP.name())))) |
90 | .addOrder(Order.desc("id")); |
90 | .addOrder(Order.desc("id")); |
91 | return criteria.list(); |
91 | return criteria.list(); |
92 | } |
92 | } |
93 | catch (HibernateException e) |
93 | catch (HibernateException e) |
94 | { |
94 | { |
95 | throw new DaoException(e); |
95 | throw new DaoException(e); |
96 | } |
96 | } |
97 | } |
97 | } |
98 | 98 | ||
99 | 99 | ||
100 | public long getNumeroRespostas(long questionarioId) |
100 | public long getNumeroRespostas(long questionarioId) |
101 | { |
101 | { |
102 | 1.5.0/docs/api/javax/management/Query.html">Query q = getCurrentSession().createQuery |
102 | 1.5.0/docs/api/javax/management/Query.html">Query q = getCurrentSession().createQuery |
103 | ("select count(r.id) from r in class " + QuestionarioResposta.class.getName() + " " + |
103 | ("select count(r.id) from r in class " + QuestionarioResposta.class.getName() + " " + |
104 | " JOIN r.questionario q " + |
104 | " JOIN r.questionario q " + |
105 | " where q.id = " + questionarioId); |
105 | " where q.id = " + questionarioId); |
106 | 5+0%2Fdocs%2Fapi+Object">Object result = q.uniqueResult(); |
106 | 5+0%2Fdocs%2Fapi+Object">Object result = q.uniqueResult(); |
107 | if(result != null && ((1.5.0/docs/api/java/lang/Long.html">Long)result) > 0) |
107 | if(result != null && ((1.5.0/docs/api/java/lang/Long.html">Long)result) > 0) |
108 | { |
108 | { |
109 | return (1.5.0/docs/api/java/lang/Long.html">Long)result; |
109 | return (1.5.0/docs/api/java/lang/Long.html">Long)result; |
110 | } |
110 | } |
111 | else |
111 | else |
112 | return 0; |
112 | return 0; |
113 | } |
113 | } |
- | 114 | public long getNumeroAlunosComRespostas(long questionarioId) |
|
- | 115 | { |
|
- | 116 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
|
- | 117 | " count(distinct a.aluno.id) AS respostasAlunos " + |
|
- | 118 | "from " + QuestionarioPedagogicoCursoAfeto.class.getName() + " c " + |
|
- | 119 | "JOIN c.questionario q " + |
|
- | 120 | "JOIN c.unidadesAfetas u " + |
|
- | 121 | "JOIN u.tipologiasRequisitadas t " + |
|
- | 122 | "JOIN t.alunosRequisitados a " + |
|
- | 123 | "JOIN a.respostaRequisitada rR " + |
|
- | 124 | "JOIN rR.resposta r " + |
|
- | 125 | "WHERE q.id = :id "); |
|
- | 126 | ||
- | 127 | q.setLong("id",questionarioId); |
|
- | 128 | 5+0%2Fdocs%2Fapi+Object">Object result = q.uniqueResult(); |
|
- | 129 | if(result != null) |
|
- | 130 | return (1.5.0/docs/api/java/lang/Long.html">Long) result; |
|
- | 131 | return 0; |
|
- | 132 | } |
|
114 | public long getNumeroUnidadesUsadas(long questionarioId) |
133 | public long getNumeroUnidadesUsadas(long questionarioId) |
115 | { |
134 | { |
116 | 1.5.0/docs/api/javax/management/Query.html">Query q = getCurrentSession().createQuery |
135 | 1.5.0/docs/api/javax/management/Query.html">Query q = getCurrentSession().createQuery |
117 | ("select count(u.id) from u in class " + QuestionarioPedagogicoUnidadeCurricularAfeta.class.getName() + " " + |
136 | ("select count(u.id) from u in class " + QuestionarioPedagogicoUnidadeCurricularAfeta.class.getName() + " " + |
118 | " JOIN u.cursoAfeto c " + |
137 | " JOIN u.cursoAfeto c " + |
119 | " JOIN c.questionario q " + |
138 | " JOIN c.questionario q " + |
120 | " where u.usar = true AND q.id = " + questionarioId); |
139 | " where u.usar = true AND q.id = " + questionarioId); |
121 | 5+0%2Fdocs%2Fapi+Object">Object result = q.uniqueResult(); |
140 | 5+0%2Fdocs%2Fapi+Object">Object result = q.uniqueResult(); |
122 | if(result != null && ((1.5.0/docs/api/java/lang/Long.html">Long)result) > 0) |
141 | if(result != null && ((1.5.0/docs/api/java/lang/Long.html">Long)result) > 0) |
123 | { |
142 | { |
124 | return (1.5.0/docs/api/java/lang/Long.html">Long)result; |
143 | return (1.5.0/docs/api/java/lang/Long.html">Long)result; |
125 | } |
144 | } |
126 | else |
145 | else |
127 | return 0; |
146 | return 0; |
128 | } |
147 | } |
129 | 148 | ||
130 | public long getNumeroRespostasRequisitadas(long questionarioId) |
149 | public long getNumeroRespostasRequisitadas(long questionarioId) |
131 | { |
150 | { |
132 | 1.5.0/docs/api/javax/management/Query.html">Query q = getCurrentSession().createQuery |
151 | 1.5.0/docs/api/javax/management/Query.html">Query q = getCurrentSession().createQuery |
133 | ("select count(r.id) from r in class " + QuestionarioRespostaRequisitada.class.getName() + " " + |
152 | ("select count(r.id) from r in class " + QuestionarioRespostaRequisitada.class.getName() + " " + |
134 | " JOIN r.questionario q " + |
153 | " JOIN r.questionario q " + |
135 | " where q.id = " + questionarioId); |
154 | " where q.id = " + questionarioId); |
136 | 5+0%2Fdocs%2Fapi+Object">Object result = q.uniqueResult(); |
155 | 5+0%2Fdocs%2Fapi+Object">Object result = q.uniqueResult(); |
137 | if(result != null && ((1.5.0/docs/api/java/lang/Long.html">Long)result) > 0) |
156 | if(result != null && ((1.5.0/docs/api/java/lang/Long.html">Long)result) > 0) |
138 | { |
157 | { |
139 | return (1.5.0/docs/api/java/lang/Long.html">Long)result; |
158 | return (1.5.0/docs/api/java/lang/Long.html">Long)result; |
140 | } |
159 | } |
141 | else |
160 | else |
142 | return 0; |
161 | return 0; |
143 | } |
162 | } |
144 | 163 | ||
145 | /* |
164 | /* |
146 | public AnnouncementDaoImpl.FindUsersResult findUsersEmails(Long id,boolean onlyNotAnswered) |
165 | public AnnouncementDaoImpl.FindUsersResult findUsersEmails(Long id,boolean onlyNotAnswered) |
147 | { |
166 | { |
148 | 167 | ||
149 | AnnouncementDaoImpl.FindUsersResult findUsersResult = new AnnouncementDaoImpl.FindUsersResult(); |
168 | AnnouncementDaoImpl.FindUsersResult findUsersResult = new AnnouncementDaoImpl.FindUsersResult(); |
150 | List<String> users = new ArrayList<String>(); |
169 | List<String> users = new ArrayList<String>(); |
151 | findUsersResult.emails = users; |
170 | findUsersResult.emails = users; |
152 | 171 | ||
153 | 172 | ||
154 | Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
173 | Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
155 | " u.outEmail, u.preferrefEmail, u.email " + |
174 | " u.outEmail, u.preferrefEmail, u.email " + |
156 | "from " + QuestionarioRespostaRequisitada.class.getName() + " rR " + |
175 | "from " + QuestionarioRespostaRequisitada.class.getName() + " rR " + |
157 | "JOIN rR.questionario q " + |
176 | "JOIN rR.questionario q " + |
158 | "JOIN rR.user u " + |
177 | "JOIN rR.user u " + |
159 | "WHERE q.id = :id " + |
178 | "WHERE q.id = :id " + |
160 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
179 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
161 | "GROUP BY u.id"); |
180 | "GROUP BY u.id"); |
162 | 181 | ||
163 | q.setLong("id",id); |
182 | q.setLong("id",id); |
164 | List<Object[]> results = (List<Object[]>) q.list(); |
183 | List<Object[]> results = (List<Object[]>) q.list(); |
165 | 184 | ||
166 | fullFillResults(findUsersResult, results); |
185 | fullFillResults(findUsersResult, results); |
167 | 186 | ||
168 | return findUsersResult; |
187 | return findUsersResult; |
169 | 188 | ||
170 | 189 | ||
171 | } |
190 | } |
172 | */ |
191 | */ |
173 | 192 | ||
174 | public AnnouncementDaoImpl.FindUsersIdResult findUsersIds(1.5.0/docs/api/java/lang/Long.html">Long id,boolean onlyNotAnswered) |
193 | public AnnouncementDaoImpl.FindUsersIdResult findUsersIds(1.5.0/docs/api/java/lang/Long.html">Long id,boolean onlyNotAnswered) |
175 | { |
194 | { |
176 | 195 | ||
177 | AnnouncementDaoImpl.FindUsersIdResult findUsersResult = new AnnouncementDaoImpl.FindUsersIdResult(); |
196 | AnnouncementDaoImpl.FindUsersIdResult findUsersResult = new AnnouncementDaoImpl.FindUsersIdResult(); |
178 | List<Long> users = new ArrayList<Long>(); |
197 | List<Long> users = new ArrayList<Long>(); |
179 | findUsersResult.userIds = users; |
198 | findUsersResult.userIds = users; |
180 | 199 | ||
181 | 200 | ||
182 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
201 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
183 | " u.id " + |
202 | " u.id " + |
184 | "from " + QuestionarioRespostaRequisitada.class.getName() + " rR " + |
203 | "from " + QuestionarioRespostaRequisitada.class.getName() + " rR " + |
185 | "JOIN rR.questionario q " + |
204 | "JOIN rR.questionario q " + |
186 | "JOIN rR.user u " + |
205 | "JOIN rR.user u " + |
187 | "WHERE q.id = :id " + |
206 | "WHERE q.id = :id " + |
188 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
207 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
189 | "GROUP BY u.id"); |
208 | "GROUP BY u.id"); |
190 | 209 | ||
191 | q.setLong("id",id); |
210 | q.setLong("id",id); |
192 | List<Object> results = (List<Object>) q.list(); |
211 | List<Object> results = (List<Object>) q.list(); |
193 | 212 | ||
194 | 213 | ||
195 | for(5+0%2Fdocs%2Fapi+Object">Object result: results) |
214 | for(5+0%2Fdocs%2Fapi+Object">Object result: results) |
196 | { |
215 | { |
197 | findUsersResult.userIds.add((1.5.0/docs/api/java/lang/Long.html">Long) result); |
216 | findUsersResult.userIds.add((1.5.0/docs/api/java/lang/Long.html">Long) result); |
198 | } |
217 | } |
199 | findUsersResult.users = results.size(); |
218 | findUsersResult.users = results.size(); |
200 | return findUsersResult; |
219 | return findUsersResult; |
201 | } |
220 | } |
202 | 221 | ||
203 | public AnnouncementDaoImpl.FindUsersIdResult findUsersIdsPedagogico(boolean onlyNotAnswered,long cursoAfetoId,long unidadeAfetaId) |
222 | public AnnouncementDaoImpl.FindUsersIdResult findUsersIdsPedagogico(boolean onlyNotAnswered,long cursoAfetoId,long unidadeAfetaId) |
204 | { |
223 | { |
205 | 224 | ||
206 | AnnouncementDaoImpl.FindUsersIdResult findUsersResult = new AnnouncementDaoImpl.FindUsersIdResult(); |
225 | AnnouncementDaoImpl.FindUsersIdResult findUsersResult = new AnnouncementDaoImpl.FindUsersIdResult(); |
207 | List<Long> users = new ArrayList<Long>(); |
226 | List<Long> users = new ArrayList<Long>(); |
208 | findUsersResult.userIds = users; |
227 | findUsersResult.userIds = users; |
209 | 228 | ||
210 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
229 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
211 | " u.id " + |
230 | " u.id " + |
212 | "from " + QuestionarioPedagogicoAlunoRequisitado.class.getName() + " aR " + |
231 | "from " + QuestionarioPedagogicoAlunoRequisitado.class.getName() + " aR " + |
213 | "JOIN aR.respostaRequisitada rR " + |
232 | "JOIN aR.respostaRequisitada rR " + |
214 | "JOIN rR.user u " + |
233 | "JOIN rR.user u " + |
215 | "WHERE " + |
234 | "WHERE " + |
216 | (cursoAfetoId > 0 ? |
235 | (cursoAfetoId > 0 ? |
217 | " aR.tipologiaRequisitada.unidadeAfeta.cursoAfeto.id = " + cursoAfetoId : |
236 | " aR.tipologiaRequisitada.unidadeAfeta.cursoAfeto.id = " + cursoAfetoId : |
218 | " aR.tipologiaRequisitada.unidadeAfeta.id = " + unidadeAfetaId) + |
237 | " aR.tipologiaRequisitada.unidadeAfeta.id = " + unidadeAfetaId) + |
219 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
238 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
220 | "GROUP BY u.id"); |
239 | "GROUP BY u.id"); |
221 | 240 | ||
222 | List<Object> results = (List<Object>) q.list(); |
241 | List<Object> results = (List<Object>) q.list(); |
223 | 242 | ||
224 | for(5+0%2Fdocs%2Fapi+Object">Object result: results) |
243 | for(5+0%2Fdocs%2Fapi+Object">Object result: results) |
225 | { |
244 | { |
226 | findUsersResult.userIds.add((1.5.0/docs/api/java/lang/Long.html">Long) result); |
245 | findUsersResult.userIds.add((1.5.0/docs/api/java/lang/Long.html">Long) result); |
227 | } |
246 | } |
228 | findUsersResult.users = results.size(); |
247 | findUsersResult.users = results.size(); |
229 | return findUsersResult; |
248 | return findUsersResult; |
230 | 249 | ||
231 | 250 | ||
232 | } |
251 | } |
233 | 252 | ||
234 | 253 | ||
235 | public AnnouncementDaoImpl.FindUsersIdResult findUsersIdsPedagogicoAllProcessing(boolean onlyNotAnswered) |
254 | public AnnouncementDaoImpl.FindUsersIdResult findUsersIdsPedagogicoAllProcessing(boolean onlyNotAnswered) |
236 | { |
255 | { |
237 | 256 | ||
238 | AnnouncementDaoImpl.FindUsersIdResult findUsersResult = new AnnouncementDaoImpl.FindUsersIdResult(); |
257 | AnnouncementDaoImpl.FindUsersIdResult findUsersResult = new AnnouncementDaoImpl.FindUsersIdResult(); |
239 | List<Long> users = new ArrayList<Long>(); |
258 | List<Long> users = new ArrayList<Long>(); |
240 | findUsersResult.userIds = users; |
259 | findUsersResult.userIds = users; |
241 | 260 | ||
242 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
261 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
243 | " u.id " + |
262 | " u.id " + |
244 | "from " + QuestionarioPedagogicoAlunoRequisitado.class.getName() + " aR " + |
263 | "from " + QuestionarioPedagogicoAlunoRequisitado.class.getName() + " aR " + |
245 | "JOIN aR.respostaRequisitada rR " + |
264 | "JOIN aR.respostaRequisitada rR " + |
246 | "JOIN rR.user u " + |
265 | "JOIN rR.user u " + |
247 | "WHERE " + |
266 | "WHERE " + |
248 | 267 | ||
249 | "( " + |
268 | "( " + |
250 | " aR.tipologiaRequisitada.unidadeAfeta.cursoAfeto.questionario.state = :sP1 " + |
269 | " aR.tipologiaRequisitada.unidadeAfeta.cursoAfeto.questionario.state = :sP1 " + |
251 | " OR " + |
270 | " OR " + |
252 | " aR.tipologiaRequisitada.unidadeAfeta.cursoAfeto.questionario.state = :sP2 " + |
271 | " aR.tipologiaRequisitada.unidadeAfeta.cursoAfeto.questionario.state = :sP2 " + |
253 | ")" + |
272 | ")" + |
254 | 273 | ||
255 | 274 | ||
256 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
275 | (onlyNotAnswered? " AND rR.resposta is null " : "" ) + |
257 | "GROUP BY u.id"); |
276 | "GROUP BY u.id"); |
258 | 277 | ||
259 | q.setString("sP1",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING.name()); |
278 | q.setString("sP1",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING.name()); |
260 | q.setString("sP2",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING_WITH_ANSWERS.name()); |
279 | q.setString("sP2",QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.PROCESSING_WITH_ANSWERS.name()); |
261 | 280 | ||
262 | List<Object> results = (List<Object>) q.list(); |
281 | List<Object> results = (List<Object>) q.list(); |
263 | 282 | ||
264 | for(5+0%2Fdocs%2Fapi+Object">Object result: results) |
283 | for(5+0%2Fdocs%2Fapi+Object">Object result: results) |
265 | { |
284 | { |
266 | findUsersResult.userIds.add((1.5.0/docs/api/java/lang/Long.html">Long) result); |
285 | findUsersResult.userIds.add((1.5.0/docs/api/java/lang/Long.html">Long) result); |
267 | } |
286 | } |
268 | findUsersResult.users = results.size(); |
287 | findUsersResult.users = results.size(); |
269 | return findUsersResult; |
288 | return findUsersResult; |
270 | 289 | ||
271 | 290 | ||
272 | } |
291 | } |
273 | 292 | ||
274 | public static class QuestionarioStatsVars |
293 | public static class QuestionarioStatsVars |
275 | { |
294 | { |
276 | public long cursos; |
295 | public long cursos; |
277 | public long unidades; |
296 | public long unidades; |
278 | public long profs; |
297 | public long profs; |
279 | public long alunos; |
298 | public long alunos; |
280 | public long turmas; |
299 | public long turmas; |
281 | public long alunosDeUsadas; |
300 | public long alunosDeUsadas; |
282 | public long profsDeUsadas; |
301 | public long profsDeUsadas; |
283 | public long unidadesUsadas; |
302 | public long unidadesUsadas; |
284 | public long tipologiasUsadas; |
303 | public long tipologiasUsadas; |
285 | public long profsTimeStudents; |
304 | public long profsTimeStudents; |
286 | public long respostasRequisitadas; |
305 | public long respostasRequisitadas; |
287 | public long respostasObtidas; |
306 | public long respostasObtidas; |
- | 307 | public long alunosQueResponderam; |
|
288 | } |
308 | } |
289 | 309 | ||
290 | 310 | ||
291 | 311 | ||
292 | 312 | ||
293 | public QuestionarioStatsVars loadQuestionarioStatsPedagogico(long questionarioId) |
313 | public QuestionarioStatsVars loadQuestionarioStatsPedagogico(long questionarioId) |
294 | { |
314 | { |
295 | QuestionarioStatsVars questionarioStatsVars = new QuestionarioStatsVars(); |
315 | QuestionarioStatsVars questionarioStatsVars = new QuestionarioStatsVars(); |
296 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
316 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
297 | " count(distinct c.id) AS cursos " + |
317 | " count(distinct c.id) AS cursos " + |
298 | ",count(distinct u.id) AS unidades " + |
318 | ",count(distinct u.id) AS unidades " + |
299 | ",sum (u.profs) AS profs " + |
319 | ",sum (u.profs) AS profs " + |
300 | ",count(distinct t.cdTurma) AS turmas " + |
320 | ",count(distinct t.cdTurma) AS turmas " + |
301 | ",sum (u.students) AS students " + |
321 | ",sum (u.students) AS students " + |
302 | ",count(distinct a.aluno.id) AS alunosDeUsadas " + |
322 | ",count(distinct a.aluno.id) AS alunosDeUsadas " + |
303 | ",count(distinct t.docenteAfeto.id) AS profsDeUsadas " + |
323 | ",count(distinct t.docenteAfeto.id) AS profsDeUsadas " + |
304 | ",count(distinct t.id) AS tipologiasRequisitadas " + |
324 | ",count(distinct t.id) AS tipologiasRequisitadas " + |
305 | ",sum (case when u.usar = true then (u.profs * u.students) else 0 end) AS respostasEsperadas " + |
325 | ",sum (case when u.usar = true then (u.profs * u.students) else 0 end) AS respostasEsperadas " + |
306 | "from " + QuestionarioPedagogicoCursoAfeto.class.getName() + " c " + |
326 | "from " + QuestionarioPedagogicoCursoAfeto.class.getName() + " c " + |
307 | "JOIN c.questionario q " + |
327 | "JOIN c.questionario q " + |
308 | "JOIN c.unidadesAfetas u " + |
328 | "JOIN c.unidadesAfetas u " + |
309 | "JOIN u.tipologiasRequisitadas t " + |
329 | "JOIN u.tipologiasRequisitadas t " + |
310 | "JOIN t.alunosRequisitados a " + |
330 | "JOIN t.alunosRequisitados a " + |
311 | 331 | ||
312 | "WHERE q.id = :id " + |
332 | "WHERE q.id = :id " + |
313 | "GROUP BY q.id"); |
333 | "GROUP BY q.id"); |
314 | 334 | ||
315 | q.setLong("id",questionarioId); |
335 | q.setLong("id",questionarioId); |
316 | 5+0%2Fdocs%2Fapi+Object">Object[] results = (5+0%2Fdocs%2Fapi+Object">Object[]) q.uniqueResult(); |
336 | 5+0%2Fdocs%2Fapi+Object">Object[] results = (5+0%2Fdocs%2Fapi+Object">Object[]) q.uniqueResult(); |
317 | 337 | ||
318 | if(results != null && results[0] != null) |
338 | if(results != null && results[0] != null) |
319 | { |
339 | { |
320 | questionarioStatsVars.cursos = (1.5.0/docs/api/java/lang/Long.html">Long) results[0]; |
340 | questionarioStatsVars.cursos = (1.5.0/docs/api/java/lang/Long.html">Long) results[0]; |
321 | questionarioStatsVars.unidades = (1.5.0/docs/api/java/lang/Long.html">Long) results[1]; |
341 | questionarioStatsVars.unidades = (1.5.0/docs/api/java/lang/Long.html">Long) results[1]; |
322 | questionarioStatsVars.profs = (1.5.0/docs/api/java/lang/Long.html">Long) results[2]; |
342 | questionarioStatsVars.profs = (1.5.0/docs/api/java/lang/Long.html">Long) results[2]; |
323 | questionarioStatsVars.turmas = (1.5.0/docs/api/java/lang/Long.html">Long) results[3]; |
343 | questionarioStatsVars.turmas = (1.5.0/docs/api/java/lang/Long.html">Long) results[3]; |
324 | questionarioStatsVars.alunos = (1.5.0/docs/api/java/lang/Long.html">Long) results[4]; |
344 | questionarioStatsVars.alunos = (1.5.0/docs/api/java/lang/Long.html">Long) results[4]; |
325 | questionarioStatsVars.alunosDeUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[5]; |
345 | questionarioStatsVars.alunosDeUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[5]; |
326 | questionarioStatsVars.profsDeUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[6]; |
346 | questionarioStatsVars.profsDeUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[6]; |
327 | questionarioStatsVars.tipologiasUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[7]; |
347 | questionarioStatsVars.tipologiasUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[7]; |
328 | questionarioStatsVars.profsTimeStudents = (1.5.0/docs/api/java/lang/Long.html">Long) results[8]; |
348 | questionarioStatsVars.profsTimeStudents = (1.5.0/docs/api/java/lang/Long.html">Long) results[8]; |
- | 349 | questionarioStatsVars.alunosQueResponderam = getNumeroAlunosComRespostas(questionarioId); |
|
329 | questionarioStatsVars.respostasRequisitadas = getNumeroRespostasRequisitadas(questionarioId); |
350 | questionarioStatsVars.respostasRequisitadas = getNumeroRespostasRequisitadas(questionarioId); |
330 | questionarioStatsVars.respostasObtidas = getNumeroRespostas(questionarioId); |
351 | questionarioStatsVars.respostasObtidas = getNumeroRespostas(questionarioId); |
331 | questionarioStatsVars.unidadesUsadas = getNumeroUnidadesUsadas(questionarioId); |
352 | questionarioStatsVars.unidadesUsadas = getNumeroUnidadesUsadas(questionarioId); |
332 | if(questionarioStatsVars.unidadesUsadas > questionarioStatsVars.unidades) |
353 | if(questionarioStatsVars.unidadesUsadas > questionarioStatsVars.unidades) |
333 | logger.error("TEM UM ERRO NA QUERY, a contagem de usadas com o distinct da diferente de com o SUM"); |
354 | logger.error("TEM UM ERRO NA QUERY, a contagem de usadas com o distinct da diferente de com o SUM"); |
334 | 355 | ||
335 | } |
356 | } |
336 | 357 | ||
337 | return questionarioStatsVars; |
358 | return questionarioStatsVars; |
338 | } |
359 | } |
339 | } |
360 | } |
340 | 361 |