Rev 1573 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1574 | jmachado | 1 | package pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.queries; |
1567 | jmachado | 2 | |
3 | import jomm.dao.impl.AbstractDao; |
||
1573 | jmachado | 4 | import org.apache.log4j.Logger; |
1567 | jmachado | 5 | import org.hibernate.Query; |
6 | import pt.estgp.estgweb.domain.OlapStarFactQuestionarioAnswer; |
||
1568 | jmachado | 7 | import pt.estgp.estgweb.services.questionarios.PedagogicoAlunosProcessor; |
1567 | jmachado | 8 | |
1571 | jmachado | 9 | import java.util.ArrayList; |
1567 | jmachado | 10 | import java.util.List; |
11 | |||
12 | /** |
||
13 | * Created by jorgemachado on 30/11/16. |
||
14 | */ |
||
15 | public class QueryDaoUtils |
||
16 | { |
||
17 | |||
1573 | jmachado | 18 | 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(QueryDaoUtils.class); |
1567 | jmachado | 19 | /** |
20 | * creates a where clause for periodos S1, S2, A, T1, T2, T3, T4 |
||
21 | * @param periodos |
||
22 | * @param questVar |
||
23 | * @param useAndConcat |
||
24 | * @return |
||
25 | */ |
||
26 | public static 1.5.0/docs/api/java/lang/String.html">String createPeriodosQuery(1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String questVar, boolean useAndConcat) { |
||
27 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = ""; |
||
28 | if(periodos != null && periodos.length > 0) |
||
29 | { |
||
30 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder periodosFilter = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
31 | |||
32 | 1.5.0/docs/api/java/lang/String.html">String union = " "; |
||
33 | for(1.5.0/docs/api/java/lang/String.html">String periodo : periodos) |
||
34 | { |
||
35 | periodosFilter.append(union).append(questVar + ".semestre = '" + periodo + "'"); |
||
36 | union = " or "; |
||
37 | } |
||
38 | periodosQuery = " (" + periodosFilter.toString() + ")"; |
||
39 | if(useAndConcat) |
||
40 | periodosQuery = " and " + periodosQuery; |
||
41 | } |
||
42 | return periodosQuery; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Create a where clause for degrees query L, T, M etc |
||
47 | * @param degrees |
||
48 | * @param cursoVar |
||
49 | * @param useAndConcat |
||
50 | * @return |
||
51 | */ |
||
52 | |||
53 | public static 1.5.0/docs/api/java/lang/String.html">String createDegreesQuery(1.5.0/docs/api/java/lang/String.html">String[] degrees, 1.5.0/docs/api/java/lang/String.html">String cursoVar, boolean useAndConcat) { |
||
54 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = ""; |
||
55 | if(degrees != null && degrees.length > 0) |
||
56 | { |
||
57 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder degreesFilter = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
58 | |||
59 | 1.5.0/docs/api/java/lang/String.html">String union = " "; |
||
60 | for(1.5.0/docs/api/java/lang/String.html">String degree : degrees) |
||
61 | { |
||
62 | degreesFilter.append(union).append(cursoVar + ".degree = '" + degree + "'"); |
||
63 | union = " or "; |
||
64 | } |
||
65 | degreesQuery = " (" + degreesFilter.toString() + ") "; |
||
66 | if(useAndConcat) |
||
67 | degreesQuery = " and " + degreesQuery; |
||
68 | } |
||
69 | return degreesQuery; |
||
70 | } |
||
71 | |||
72 | public static 1.5.0/docs/api/java/lang/String.html">String createCursosQuery(List<String> codigosCurso,boolean addAndConcat) |
||
73 | { |
||
74 | if(codigosCurso == null || codigosCurso.size() == 0) |
||
75 | return ""; |
||
76 | |||
77 | //GET QUERY PARCIAL DE CURSOS ONDE LECCIONA O DOCENTE |
||
78 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryCurso = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
79 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
80 | for( 1.5.0/docs/api/java/lang/String.html">String codigoCurso: codigosCurso ) |
||
81 | { |
||
82 | queryCurso.append(union).append(" curso.codigoCurso = '" + codigoCurso + "' "); |
||
83 | union = " or "; |
||
84 | } |
||
85 | |||
86 | 1.5.0/docs/api/java/lang/String.html">String queryFilter = " (" + queryCurso.toString() + ") "; |
||
87 | if(addAndConcat) |
||
88 | queryFilter = " and " + queryFilter; |
||
89 | return queryFilter; |
||
90 | } |
||
91 | |||
92 | public static 1.5.0/docs/api/java/lang/String.html">String createEscolasQuery(List<String> codigosEscolas,boolean addAndConcat) |
||
93 | { |
||
94 | if(codigosEscolas == null || codigosEscolas.size() == 0) |
||
95 | return ""; |
||
96 | |||
97 | //GET QUERY PARCIAL DE CURSOS ONDE LECCIONA O DOCENTE |
||
98 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryEscolas = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
99 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
100 | for( 1.5.0/docs/api/java/lang/String.html">String codigoEscola: codigosEscolas ) |
||
101 | { |
||
102 | queryEscolas.append(union).append(" curso.codigoInstituicao = '" + codigoEscola + "'"); |
||
103 | union = " or "; |
||
104 | } |
||
105 | |||
106 | 1.5.0/docs/api/java/lang/String.html">String queryFilter = " (" + queryEscolas.toString() + ")"; |
||
107 | if(addAndConcat) |
||
108 | queryFilter+= " and " + queryFilter; |
||
109 | return queryFilter; |
||
110 | } |
||
111 | |||
1568 | jmachado | 112 | public static double getMediaCursos(List<String> codigosCurso, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String numeroPergunta, double tempoMinimo, 1.5.0/docs/api/java/lang/String.html">String grupo, 1.5.0/docs/api/java/lang/String.html">String subGrupo,1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
1567 | jmachado | 113 | |
114 | |||
115 | |||
116 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
117 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
118 | |||
119 | //GET QUERY PARCIAL DE CURSOS ONDE LECCIONA O DOCENTE |
||
120 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryCurso = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
121 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
122 | int count = 1; |
||
123 | for(1.5.0/docs/api/java/lang/String.html">String codigoCurso: codigosCurso) |
||
124 | { |
||
125 | queryCurso.append(union).append(" curso.codigoCurso = :curso" + count + " "); |
||
126 | union = " or "; |
||
127 | count++; |
||
128 | } |
||
129 | |||
130 | |||
131 | |||
132 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
133 | "SELECT " + |
||
134 | "avg(fc.intResposta) as media " + |
||
135 | |||
136 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
137 | "JOIN fc.olapPergunta prgp " + |
||
138 | "JOIN fc.olapQuestionario quest " + |
||
139 | "JOIN fc.olapCurso curso " + |
||
1568 | jmachado | 140 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 141 | |
142 | "where " + |
||
1568 | jmachado | 143 | "quest.ano = :ano " + |
1567 | jmachado | 144 | (numeroPergunta!=null? "and prgp.numero = :numero " : "") + |
145 | "and (" + queryCurso.toString() + ") " + |
||
1568 | jmachado | 146 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
1567 | jmachado | 147 | (tempoMinimo > 0 ? " and fc.tempoLevado > :tempoLevado " : "" ) + |
148 | periodosQuery + |
||
149 | degreesQuery + |
||
1568 | jmachado | 150 | (grupo == null ? "" : " and prgp.grupoCode = :grupoCode ") + |
151 | (subGrupo == null ? "" : " and prgp.subGrupoCode = :subGrupoCode ") + |
||
1567 | jmachado | 152 | ""); |
1568 | jmachado | 153 | |
154 | if(grupo != null) |
||
155 | query.setString("grupoCode",grupo); |
||
156 | if(subGrupo != null) |
||
157 | query.setString("subGrupoCode",subGrupo); |
||
1567 | jmachado | 158 | query.setString("ano",anoLectivo); |
1568 | jmachado | 159 | |
1567 | jmachado | 160 | if(numeroPergunta != null) |
161 | query.setString("numero",numeroPergunta); |
||
162 | if(tempoMinimo > 0) |
||
163 | { |
||
164 | query.setDouble("tempoLevado",tempoMinimo); |
||
165 | } |
||
166 | count = 1; |
||
167 | for(1.5.0/docs/api/java/lang/String.html">String codigoCurso: codigosCurso) |
||
168 | { |
||
169 | query.setString("curso" + count,codigoCurso); |
||
170 | count++; |
||
171 | } |
||
172 | 1.5.0/docs/api/java/lang/Double.html">Double mediaCurso = (1.5.0/docs/api/java/lang/Double.html">Double) query.uniqueResult(); |
||
173 | |||
174 | |||
175 | |||
176 | return mediaCurso; |
||
177 | } |
||
178 | |||
179 | public static List<String> getCodigosEscolaDocente(1.5.0/docs/api/java/lang/String.html">String teacherCode, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) |
||
180 | { |
||
181 | |||
182 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
183 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
184 | //GET CODIGOS DE ESCOLAS ONDE LECCIONA O DOCENTE |
||
185 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
186 | "SELECT " + |
||
187 | "distinct(curso.codigoInstituicao) as codigoInst " + |
||
188 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
189 | "JOIN fc.olapPergunta prgp " + |
||
190 | "JOIN fc.olapTipologia tipo " + |
||
191 | "JOIN fc.olapQuestionario quest " + |
||
192 | "JOIN fc.olapCurso curso " + |
||
1568 | jmachado | 193 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 194 | "where " + |
195 | "quest.ano = :ano " + |
||
196 | "and tipo.codigoSiges = :codigoSiges " + |
||
1568 | jmachado | 197 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
1567 | jmachado | 198 | periodosQuery + |
199 | degreesQuery + |
||
200 | ""); |
||
201 | query.setString("codigoSiges",teacherCode); |
||
202 | query.setString("ano",anoLectivo); |
||
203 | List<String> codigosEscola = query.list(); |
||
204 | return codigosEscola; |
||
205 | } |
||
206 | |||
207 | public static List<String> getCodigosCursoDocente(1.5.0/docs/api/java/lang/String.html">String teacherCode, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) |
||
208 | { |
||
209 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
210 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
211 | //GET CODIGOS DE CURSOS ONDE LECCIONA O DOCENTE |
||
212 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
213 | "SELECT " + |
||
214 | "distinct(curso.codigoCurso) as codigoCurso " + |
||
215 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
216 | "JOIN fc.olapPergunta prgp " + |
||
217 | "JOIN fc.olapTipologia tipo " + |
||
218 | "JOIN fc.olapQuestionario quest " + |
||
219 | "JOIN fc.olapCurso curso " + |
||
1568 | jmachado | 220 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 221 | |
222 | "where " + |
||
223 | "quest.ano = :ano " + |
||
224 | "and tipo.codigoSiges = :codigoSiges " + |
||
1568 | jmachado | 225 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
1567 | jmachado | 226 | periodosQuery + |
227 | degreesQuery + |
||
228 | ""); |
||
229 | query.setString("codigoSiges",teacherCode); |
||
230 | query.setString("ano",anoLectivo); |
||
231 | List<String> codigosCurso = query.list(); |
||
232 | |||
233 | return codigosCurso; |
||
234 | } |
||
235 | |||
1569 | jmachado | 236 | public static List<String> getCodigosCursosEscola(1.5.0/docs/api/java/lang/String.html">String codigoInstituicao,1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) |
237 | { |
||
238 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
239 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
240 | //GET CODIGOS DE CURSOS ONDE LECCIONA O DOCENTE |
||
241 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
242 | "SELECT " + |
||
243 | "distinct(curso.codigoCurso) as codigoCurso " + |
||
244 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
245 | "JOIN fc.olapPergunta prgp " + |
||
246 | "JOIN fc.olapTipologia tipo " + |
||
247 | "JOIN fc.olapQuestionario quest " + |
||
248 | "JOIN fc.olapCurso curso " + |
||
249 | "JOIN fc.olapTimeLine timeLine " + |
||
250 | |||
251 | "where " + |
||
252 | "quest.ano = :ano " + |
||
253 | "and curso.codigoInstituicao = :codigoInstituicao " + |
||
254 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
||
255 | periodosQuery + |
||
256 | degreesQuery + |
||
257 | ""); |
||
258 | query.setString("codigoInstituicao",codigoInstituicao); |
||
259 | query.setString("ano",anoLectivo); |
||
260 | List<String> codigosCurso = query.list(); |
||
261 | |||
262 | return codigosCurso; |
||
263 | } |
||
264 | |||
1571 | jmachado | 265 | public static long countDocentesNosCursos(1.5.0/docs/api/java/lang/String.html">String codigoCurso, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) |
266 | { |
||
267 | List<String> codigos = new ArrayList<String>(); |
||
268 | codigos.add(codigoCurso); |
||
269 | return countDocentesNosCursos(codigos, anoLectivo, periodos, degrees); |
||
270 | } |
||
1567 | jmachado | 271 | public static long countDocentesNosCursos(List<String> codigosCurso, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
272 | |||
273 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
274 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
275 | //GET QUERY PARCIAL DE CURSOS ONDE LECCIONA O DOCENTE |
||
276 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryCurso = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
277 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
278 | int count = 1; |
||
1573 | jmachado | 279 | if(codigosCurso == null || codigosCurso.size() == 0) |
280 | { |
||
281 | logger.warn("Docente nao tem cursos atribuidos, nao tem quaisquer respostas, devolvendo media de docentes nos cursos = 0"); |
||
282 | return 0; |
||
283 | } |
||
1567 | jmachado | 284 | for(1.5.0/docs/api/java/lang/String.html">String codigoCurso: codigosCurso) |
285 | { |
||
286 | queryCurso.append(union).append(" curso.codigoCurso = :curso" + count + " "); |
||
287 | union = " or "; |
||
288 | count++; |
||
289 | } |
||
290 | |||
291 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
292 | "SELECT " + |
||
293 | "count(distinct tipo.codigoSiges) as profs " + |
||
294 | |||
295 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
296 | "JOIN fc.olapTipologia tipo " + |
||
297 | "JOIN fc.olapQuestionario quest " + |
||
298 | "JOIN fc.olapCurso curso " + |
||
1568 | jmachado | 299 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 300 | |
301 | "where " + |
||
302 | "quest.ano = :ano " + |
||
303 | "and (" + queryCurso.toString() + ") " + |
||
1568 | jmachado | 304 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
1567 | jmachado | 305 | periodosQuery + |
306 | degreesQuery + |
||
307 | ""); |
||
308 | |||
309 | query.setString("ano",anoLectivo); |
||
310 | |||
311 | count = 1; |
||
312 | for(1.5.0/docs/api/java/lang/String.html">String codigoCurso: codigosCurso) |
||
313 | { |
||
314 | query.setString("curso" + count,codigoCurso); |
||
315 | count++; |
||
316 | } |
||
317 | 1.5.0/docs/api/java/lang/Long.html">Long profs = (1.5.0/docs/api/java/lang/Long.html">Long) query.uniqueResult(); |
||
318 | |||
319 | return profs; |
||
320 | } |
||
321 | |||
1571 | jmachado | 322 | public static long countDocentesNasEscolas(1.5.0/docs/api/java/lang/String.html">String codigoEscola, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
323 | List<String> codigos = new ArrayList<String>(); |
||
324 | codigos.add(codigoEscola); |
||
325 | return countDocentesNasEscolas(codigos,anoLectivo,periodos,degrees); |
||
326 | } |
||
1567 | jmachado | 327 | public static long countDocentesNasEscolas(List<String> codigosEscola, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
328 | |||
329 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
330 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
331 | |||
1573 | jmachado | 332 | if(codigosEscola == null || codigosEscola.size() == 0) |
333 | { |
||
334 | logger.warn("Docente nao tem escolas atribuidas, nao tem quaisquer respostas, devolvendo media de docentes nas escolas = 0"); |
||
335 | return 0; |
||
336 | } |
||
1567 | jmachado | 337 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryEscolas = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
338 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
339 | int count = 1; |
||
340 | for(1.5.0/docs/api/java/lang/String.html">String codigoEscola: codigosEscola) |
||
341 | { |
||
342 | queryEscolas.append(union).append(" curso.codigoInstituicao = :inst" + count + " "); |
||
343 | union = " or "; |
||
344 | count++; |
||
345 | } |
||
346 | |||
347 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
348 | "SELECT " + |
||
349 | "count(distinct tipo.codigoSiges) as profs " + |
||
350 | |||
351 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
352 | "JOIN fc.olapTipologia tipo " + |
||
353 | "JOIN fc.olapQuestionario quest " + |
||
354 | "JOIN fc.olapCurso curso " + |
||
1568 | jmachado | 355 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 356 | |
357 | "where " + |
||
358 | "quest.ano = :ano " + |
||
359 | "and (" + queryEscolas.toString() + ") " + |
||
1568 | jmachado | 360 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
1567 | jmachado | 361 | periodosQuery + |
362 | degreesQuery + |
||
363 | ""); |
||
364 | |||
365 | query.setString("ano",anoLectivo); |
||
366 | |||
367 | count = 1; |
||
368 | for(1.5.0/docs/api/java/lang/String.html">String codigoEscola: codigosEscola) |
||
369 | { |
||
370 | query.setString("inst" + count,codigoEscola); |
||
371 | count++; |
||
372 | } |
||
373 | 1.5.0/docs/api/java/lang/Long.html">Long profs = (1.5.0/docs/api/java/lang/Long.html">Long) query.uniqueResult(); |
||
374 | |||
375 | return profs; |
||
376 | } |
||
377 | |||
1571 | jmachado | 378 | public static long countUnidadesNosCursos(1.5.0/docs/api/java/lang/String.html">String codigoCurso,1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos,1.5.0/docs/api/java/lang/String.html">String[] degrees) |
379 | { |
||
380 | List<String> codigos = new ArrayList<String>(); |
||
381 | codigos.add(codigoCurso); |
||
382 | return countUnidadesNosCursos(codigos,anoLectivo,periodos,degrees); |
||
383 | } |
||
384 | |||
385 | |||
1567 | jmachado | 386 | public static long countUnidadesNosCursos(List<String> codigosCurso,1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos,1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
387 | |||
388 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
389 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
390 | //GET QUERY PARCIAL DE CURSOS ONDE LECCIONA O DOCENTE |
||
391 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryCurso = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
392 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
393 | int count = 1; |
||
1573 | jmachado | 394 | |
395 | if(codigosCurso == null || codigosCurso.size() == 0) |
||
396 | { |
||
397 | logger.warn("Docente nao tem cursos atribuidos, nao tem quaisquer respostas, devolvendo numero de docentes nos cursos = 0"); |
||
398 | return 0; |
||
399 | } |
||
1567 | jmachado | 400 | for(1.5.0/docs/api/java/lang/String.html">String codigoCurso: codigosCurso) |
401 | { |
||
402 | queryCurso.append(union).append(" curso.codigoCurso = :curso" + count + " "); |
||
403 | union = " or "; |
||
404 | count++; |
||
405 | } |
||
406 | |||
407 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
408 | "SELECT " + |
||
409 | "count(distinct unidade.codigo) as unidades " + |
||
410 | |||
411 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
412 | "JOIN fc.olapQuestionario quest " + |
||
413 | "JOIN fc.olapCurso curso " + |
||
414 | "JOIN fc.olapUnidade unidade " + |
||
1568 | jmachado | 415 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 416 | |
417 | "where " + |
||
418 | "quest.ano = :ano " + |
||
419 | "and (" + queryCurso.toString() + ") " + |
||
1568 | jmachado | 420 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
1567 | jmachado | 421 | periodosQuery + |
422 | degreesQuery + |
||
423 | ""); |
||
424 | |||
425 | query.setString("ano",anoLectivo); |
||
426 | |||
427 | count = 1; |
||
428 | for(1.5.0/docs/api/java/lang/String.html">String codigoCurso: codigosCurso) |
||
429 | { |
||
430 | query.setString("curso" + count,codigoCurso); |
||
431 | count++; |
||
432 | } |
||
433 | 1.5.0/docs/api/java/lang/Long.html">Long unidades = (1.5.0/docs/api/java/lang/Long.html">Long) query.uniqueResult(); |
||
434 | |||
435 | return unidades; |
||
436 | } |
||
437 | |||
1571 | jmachado | 438 | public static long countUnidadesNasEscolas(1.5.0/docs/api/java/lang/String.html">String codigoEscola, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) |
439 | { |
||
440 | List<String> codigosEscola = new ArrayList<String>(); |
||
441 | codigosEscola.add(codigoEscola); |
||
442 | return countUnidadesNasEscolas( codigosEscola, anoLectivo, periodos, degrees) ; |
||
443 | } |
||
1567 | jmachado | 444 | public static long countUnidadesNasEscolas(List<String> codigosEscola, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
445 | |||
446 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
447 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
448 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryEscolas = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
449 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
450 | int count = 1; |
||
1573 | jmachado | 451 | if(codigosEscola == null || codigosEscola.size() == 0) |
452 | { |
||
453 | logger.warn("Docente nao tem escolas atribuidas, nao tem quaisquer respostas, devolvendo numero de docentes nas escolas = 0"); |
||
454 | return 0; |
||
455 | } |
||
1567 | jmachado | 456 | for(1.5.0/docs/api/java/lang/String.html">String codigoEscola: codigosEscola) |
457 | { |
||
458 | queryEscolas.append(union).append(" curso.codigoInstituicao = :inst" + count + " "); |
||
459 | union = " or "; |
||
460 | count++; |
||
461 | } |
||
462 | |||
463 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
464 | "SELECT " + |
||
465 | "count(distinct unidade.codigo) as unidades " + |
||
466 | |||
467 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
468 | "JOIN fc.olapUnidade unidade " + |
||
469 | "JOIN fc.olapQuestionario quest " + |
||
470 | "JOIN fc.olapCurso curso " + |
||
1568 | jmachado | 471 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 472 | |
473 | "where " + |
||
474 | "quest.ano = :ano " + |
||
475 | "and (" + queryEscolas.toString() + ") " + |
||
1568 | jmachado | 476 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
1567 | jmachado | 477 | periodosQuery + |
478 | degreesQuery + |
||
479 | ""); |
||
480 | |||
481 | query.setString("ano",anoLectivo); |
||
482 | |||
483 | count = 1; |
||
484 | for(1.5.0/docs/api/java/lang/String.html">String codigoEscola: codigosEscola) |
||
485 | { |
||
486 | query.setString("inst" + count,codigoEscola); |
||
487 | count++; |
||
488 | } |
||
489 | 1.5.0/docs/api/java/lang/Long.html">Long unidades = (1.5.0/docs/api/java/lang/Long.html">Long) query.uniqueResult(); |
||
490 | |||
491 | return unidades; |
||
492 | } |
||
493 | |||
1568 | jmachado | 494 | public static double getMediaCursos(List<String> codigosCurso,1.5.0/docs/api/java/lang/String.html">String anoLectivo,1.5.0/docs/api/java/lang/String.html">String grupo,1.5.0/docs/api/java/lang/String.html">String subGrupo, 1.5.0/docs/api/java/lang/String.html">String[] periodos,1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
1567 | jmachado | 495 | |
1568 | jmachado | 496 | return getMediaCursos(codigosCurso, anoLectivo, null, 0, grupo, subGrupo, periodos, degrees); |
1567 | jmachado | 497 | } |
498 | |||
1568 | jmachado | 499 | public static double getMediaEscolas(List<String> codigosEscola,1.5.0/docs/api/java/lang/String.html">String anoLectivo,1.5.0/docs/api/java/lang/String.html">String grupo,1.5.0/docs/api/java/lang/String.html">String subGrupo, 1.5.0/docs/api/java/lang/String.html">String[] periodos,1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
1567 | jmachado | 500 | |
1568 | jmachado | 501 | return getMediaEscolas(codigosEscola, anoLectivo, null, 0,grupo,subGrupo,periodos,degrees); |
1567 | jmachado | 502 | } |
503 | |||
1568 | jmachado | 504 | public static double getMediaEscolas(List<String> codigosEscola, 1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String numeroPergunta, double tempoMinimo, 1.5.0/docs/api/java/lang/String.html">String grupo, 1.5.0/docs/api/java/lang/String.html">String subGrupo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees) { |
1567 | jmachado | 505 | |
506 | 1.5.0/docs/api/java/lang/String.html">String periodosQuery = createPeriodosQuery(periodos, "quest", true); |
||
507 | 1.5.0/docs/api/java/lang/String.html">String degreesQuery = createDegreesQuery(degrees, "curso", true); |
||
508 | |||
509 | //GET QUERY PARCIAL DE ESCOLAS ONDE LECCIONA O DOCENTE |
||
510 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder queryEscolas = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
511 | 1.5.0/docs/api/java/lang/String.html">String union = ""; |
||
512 | int count = 1; |
||
513 | for(1.5.0/docs/api/java/lang/String.html">String codigoEscola: codigosEscola) |
||
514 | { |
||
515 | queryEscolas.append(union).append(" curso.codigoInstituicao = :inst" + count + " "); |
||
516 | union = " or "; |
||
517 | count++; |
||
518 | } |
||
519 | |||
520 | 1.5.0/docs/api/javax/management/Query.html">Query query = AbstractDao.getCurrentSession().createQuery("" + |
||
521 | "SELECT " + |
||
522 | "avg(fc.intResposta) as media " + |
||
523 | |||
524 | "FROM " + OlapStarFactQuestionarioAnswer.class.getName() + " fc " + |
||
525 | "JOIN fc.olapPergunta prgp " + |
||
526 | "JOIN fc.olapQuestionario quest " + |
||
527 | "JOIN fc.olapCurso curso " + |
||
1568 | jmachado | 528 | "JOIN fc.olapTimeLine timeLine " + |
1567 | jmachado | 529 | |
530 | "where " + |
||
1568 | jmachado | 531 | "quest.ano = :ano " + |
532 | (numeroPergunta!=null ? " and prgp.numero = :numero " : "") + |
||
533 | "and " + queryEscolas.toString() + " " + |
||
534 | "and timeLine.nome = '" + PedagogicoAlunosProcessor.getHistoryDriveConstraintStatic() + "' " + |
||
1567 | jmachado | 535 | (tempoMinimo > 0 ? " and fc.tempoLevado > :tempoLevado " : "" ) + |
536 | periodosQuery + |
||
537 | degreesQuery + |
||
1568 | jmachado | 538 | (grupo == null ? "" : " and prgp.grupoCode = :grupoCode ") + |
539 | (subGrupo == null ? "" : " and prgp.subGrupoCode = :subGrupoCode ") + |
||
1567 | jmachado | 540 | ""); |
1568 | jmachado | 541 | if(grupo != null) |
542 | query.setString("grupoCode",grupo); |
||
543 | if(subGrupo != null) |
||
544 | query.setString("subGrupoCode",subGrupo); |
||
1567 | jmachado | 545 | query.setString("ano",anoLectivo); |
546 | if(numeroPergunta != null) |
||
547 | query.setString("numero",numeroPergunta); |
||
548 | if(tempoMinimo > 0) |
||
549 | { |
||
550 | query.setDouble("tempoLevado",tempoMinimo); |
||
551 | } |
||
552 | count = 1; |
||
553 | for(1.5.0/docs/api/java/lang/String.html">String codigoEscola: codigosEscola) |
||
554 | { |
||
555 | query.setString("inst" + count,codigoEscola); |
||
556 | count++; |
||
557 | } |
||
558 | 1.5.0/docs/api/java/lang/Double.html">Double mediaEscola = (1.5.0/docs/api/java/lang/Double.html">Double) query.uniqueResult(); |
||
559 | return mediaEscola; |
||
560 | } |
||
561 | } |