Rev 1379 | Rev 1393 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1314 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
1325 | jmachado | 3 | import org.apache.log4j.Logger; |
1326 | jmachado | 4 | import pt.estgp.estgweb.Globals; |
5 | import pt.estgp.estgweb.domain.utils.SimpleClearanceRuledSupport; |
||
1314 | jmachado | 6 | import pt.estgp.estgweb.utils.ConfigProperties; |
1333 | jmachado | 7 | import pt.estgp.estgweb.utils.DatesUtils; |
1314 | jmachado | 8 | |
9 | import java.lang.reflect.InvocationTargetException; |
||
10 | import java.lang.reflect.Method; |
||
1325 | jmachado | 11 | import java.text.MessageFormat; |
12 | import java.text.SimpleDateFormat; |
||
13 | import java.util.ArrayList; |
||
14 | import java.util.Date; |
||
15 | import java.util.List; |
||
16 | import java.util.Locale; |
||
1314 | jmachado | 17 | |
18 | /** |
||
19 | * Created by jorgemachado on 09/03/16. |
||
20 | */ |
||
1326 | jmachado | 21 | public class QuestionarioImpl extends Questionario implements ClearanceRuled |
1314 | jmachado | 22 | { |
23 | |||
1325 | jmachado | 24 | 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(QuestionarioImpl.class); |
25 | |||
1326 | jmachado | 26 | |
27 | |||
1314 | jmachado | 28 | public enum 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State |
29 | { |
||
1315 | jmachado | 30 | |
31 | CREATED(1), |
||
1325 | jmachado | 32 | ASSIGNATION_DETAILS(2), |
33 | ASSIGNING_ANSWERS_PROCESSEMENT(3), |
||
34 | ASSIGNED_ANSWERS(4), |
||
35 | PROCESSING(5), |
||
36 | PROCESSING_WITH_ANSWERS(6), |
||
37 | STOPED_WITH_ANSWERS(6), |
||
38 | CLOSED(7), |
||
39 | PROCESSING_OLAP(8), |
||
40 | OLAP(9); |
||
1315 | jmachado | 41 | |
42 | private int pos = 1; |
||
43 | |||
44 | 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State(int pos) |
||
45 | { |
||
46 | this.pos = pos; |
||
47 | } |
||
48 | |||
49 | public static 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State parse(1.5.0/docs/api/java/lang/String.html">String state) |
||
50 | { |
||
51 | for(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State s: 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.values()) |
||
52 | { |
||
53 | if(s.name().equals(state)) |
||
54 | return s; |
||
55 | } |
||
56 | return CREATED; |
||
57 | } |
||
58 | |||
1325 | jmachado | 59 | |
1315 | jmachado | 60 | public int getPosition() |
61 | { |
||
62 | return pos; |
||
63 | } |
||
1314 | jmachado | 64 | } |
65 | |||
1315 | jmachado | 66 | |
1329 | jmachado | 67 | //QuestionarioPedagogico SubState |
68 | public enum SubStatePedagogico |
||
69 | { |
||
70 | START(1), |
||
71 | YEAR_SEMESTRE_ASSIGNED(2), |
||
72 | ASSIGNING_COURSES(3), |
||
1378 | jmachado | 73 | COURSES_ASSIGNED(4), //ESCOLHA DE CURSOS TERMINADA pode escolher tipologias e gerar respostas |
74 | ASSIGNING_ANSWERS(5), //ESCOLHA DE CURSOS TERMINADA pode escolher tipologias e gerar respostas |
||
75 | ANSWERS_ASSIGNED(6), //ESCOLHA DE CURSOS TERMINADA pode escolher tipologias e gerar respostas |
||
76 | FINNISHED_ANSWERS_GENERATING(7); //PODE SEMPRE VOLTAR A GERAR ANTES DE TERMINAR TEM DE SER INCREMENTAL |
||
1315 | jmachado | 77 | |
1378 | jmachado | 78 | //Mas depois de clicar em Terminar muda para este estado terminado e já nao pode voltar a gerar respostas |
79 | |||
1329 | jmachado | 80 | private int pos = 1; |
1325 | jmachado | 81 | |
1329 | jmachado | 82 | SubStatePedagogico(int pos) |
83 | { |
||
84 | this.pos = pos; |
||
85 | } |
||
86 | |||
87 | public static SubStatePedagogico parse(1.5.0/docs/api/java/lang/String.html">String state) |
||
88 | { |
||
89 | for(SubStatePedagogico s: SubStatePedagogico.values()) |
||
90 | { |
||
91 | if(s.name().equals(state)) |
||
92 | return s; |
||
93 | } |
||
94 | return START; |
||
95 | } |
||
96 | |||
97 | |||
98 | public int getPosition() |
||
99 | { |
||
100 | return pos; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | public SubStatePedagogico getSubStatePedagodigoEnum() |
||
105 | { |
||
106 | return SubStatePedagogico.parse(getSubstate()); |
||
107 | } |
||
108 | |||
109 | public void setSubStatePedagogicoClass(SubStatePedagogico subState) { |
||
1333 | jmachado | 110 | setLogStates(getLogStates()+"\n"+ DatesUtils.getLogDateNow() + " changing substate: " + getState() + " sub:(" + getSubstate() + ") " + " -> " + subState.name()); |
1329 | jmachado | 111 | setSubstate(subState.name()); |
112 | } |
||
113 | |||
114 | |||
115 | |||
1314 | jmachado | 116 | public QuestionarioImpl() { |
117 | super(); |
||
118 | |||
1333 | jmachado | 119 | setStateClass(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.CREATED); |
1315 | jmachado | 120 | |
1325 | jmachado | 121 | 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat sdf = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat("MMMM yyyy",new 1.5.0/docs/api/java/util/Locale.html">Locale("pt")); |
122 | 1.5.0/docs/api/java/lang/String.html">String month = sdf.format(new 5+0%2Fdocs%2Fapi+Date">Date()); |
||
123 | 1.5.0/docs/api/java/lang/String.html">String introHtml = ConfigProperties.getProperty("questionario.intro.text"); |
||
124 | |||
125 | 1.5.0/docs/api/java/lang/String.html">String introWithMonth = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(introHtml, month); |
||
126 | |||
127 | setIntroHtml(introWithMonth); |
||
1314 | jmachado | 128 | setGroup1Title(ConfigProperties.getProperty("questionario.group1.title")); |
129 | setGroup2Title(ConfigProperties.getProperty("questionario.group2.title")); |
||
130 | setGroup3Title(ConfigProperties.getProperty("questionario.group3.title")); |
||
131 | setGroup4Title(ConfigProperties.getProperty("questionario.group4.title")); |
||
132 | setGroup5Title(ConfigProperties.getProperty("questionario.group5.title")); |
||
1325 | jmachado | 133 | setGroup6Title(ConfigProperties.getProperty("questionario.group6.title")); |
134 | setGroup7Title(ConfigProperties.getProperty("questionario.group7.title")); |
||
135 | setGroup8Title(ConfigProperties.getProperty("questionario.group8.title")); |
||
136 | setGroup9Title(ConfigProperties.getProperty("questionario.group9.title")); |
||
137 | setGroup10Title(ConfigProperties.getProperty("questionario.group10.title")); |
||
1314 | jmachado | 138 | |
139 | |||
1325 | jmachado | 140 | setGroup1Code(ConfigProperties.getProperty("questionario.group1.code")); |
141 | setGroup2Code(ConfigProperties.getProperty("questionario.group2.code")); |
||
142 | setGroup3Code(ConfigProperties.getProperty("questionario.group3.code")); |
||
143 | setGroup4Code(ConfigProperties.getProperty("questionario.group4.code")); |
||
144 | setGroup5Code(ConfigProperties.getProperty("questionario.group5.code")); |
||
145 | setGroup6Code(ConfigProperties.getProperty("questionario.group6.code")); |
||
146 | setGroup7Code(ConfigProperties.getProperty("questionario.group7.code")); |
||
147 | setGroup8Code(ConfigProperties.getProperty("questionario.group8.code")); |
||
148 | setGroup9Code(ConfigProperties.getProperty("questionario.group9.code")); |
||
149 | setGroup10Code(ConfigProperties.getProperty("questionario.group10.code")); |
||
150 | |||
151 | |||
152 | for(int i = 1; i <=40;i++) |
||
1314 | jmachado | 153 | { |
154 | |||
155 | try { |
||
156 | 1.5.0/docs/api/java/lang/String.html">String group = ConfigProperties.getProperty("questionario.p" + i + ".group"); |
||
157 | 1.5.0/docs/api/java/lang/reflect/Method.html">Method m = this.getClass().getMethod("setP" + i + "Group",1.5.0/docs/api/java/lang/String.html">String.class); |
||
158 | m.invoke(this,group); |
||
159 | |||
160 | 1.5.0/docs/api/java/lang/String.html">String pergunta = ConfigProperties.getProperty("questionario.p" + i); |
||
161 | 1.5.0/docs/api/java/lang/reflect/Method.html">Method m2 = this.getClass().getMethod("setP" + i,1.5.0/docs/api/java/lang/String.html">String.class); |
||
162 | m2.invoke(this,pergunta); |
||
163 | } catch (1.5.0/docs/api/java/lang/NoSuchMethodException.html">NoSuchMethodException e) { |
||
164 | e.printStackTrace(); |
||
165 | } catch (1.5.0/docs/api/java/lang/reflect/InvocationTargetException.html">InvocationTargetException e) { |
||
166 | e.printStackTrace(); |
||
167 | } catch (1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException e) { |
||
168 | e.printStackTrace(); |
||
169 | } |
||
170 | } |
||
1325 | jmachado | 171 | } |
1314 | jmachado | 172 | |
1325 | jmachado | 173 | static List<IAnswersProcessor> answersProcessors = null; |
174 | |||
175 | public IAnswersProcessor getiAnswersProcessorClass() |
||
176 | { |
||
177 | if(getiAnswersProcessor() != null) |
||
178 | { |
||
179 | try { |
||
180 | return (IAnswersProcessor) 1.5.0/docs/api/java/lang/Class.html">Class.forName(getiAnswersProcessor()).newInstance(); |
||
181 | } catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) { |
||
182 | logger.error(e,e); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | return new IAnswersProcessor() { |
||
187 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
188 | public 1.5.0/docs/api/java/lang/String.html">String getHistoryDriveConstraint() { |
||
189 | return null; |
||
190 | } |
||
191 | |||
192 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
193 | public 1.5.0/docs/api/java/lang/String.html">String getTitle() { |
||
194 | return "---"; |
||
195 | } |
||
196 | |||
197 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
198 | public 1.5.0/docs/api/java/lang/String.html">String getAfetacoesManagementForward() { |
||
199 | return null; |
||
200 | } |
||
1328 | jmachado | 201 | |
202 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
203 | public void initQuestionarioAfetacoesVariables(QuestionarioImpl questionario) { |
||
204 | |||
205 | } |
||
1329 | jmachado | 206 | |
207 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
208 | public void startAfetacoes(QuestionarioImpl questionario) { |
||
209 | |||
210 | } |
||
211 | |||
212 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
213 | public void initClearances(QuestionarioImpl questionario, UserSessionImpl session, SimpleClearanceRuledSupport s) { |
||
214 | |||
215 | } |
||
1385 | jmachado | 216 | |
217 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
218 | public 1.5.0/docs/api/java/lang/Class.html">Class getJobServiceTaskAnswersProcessor() { |
||
219 | return null; |
||
220 | } |
||
1325 | jmachado | 221 | }; |
1314 | jmachado | 222 | } |
223 | |||
1325 | jmachado | 224 | public static List<IAnswersProcessor> getIAnswerProcessors() |
225 | { |
||
226 | if(answersProcessors == null) |
||
227 | { |
||
228 | answersProcessors = new ArrayList<IAnswersProcessor>(); |
||
229 | List<String> processors = ConfigProperties.getListValues("pt.estgp.estgweb.domain.IAnswersProcessor."); |
||
230 | for(1.5.0/docs/api/java/lang/String.html">String p: processors) |
||
231 | { |
||
232 | try { |
||
233 | IAnswersProcessor iAnswersProcessor = (IAnswersProcessor) 1.5.0/docs/api/java/lang/Class.html">Class.forName(p).newInstance(); |
||
234 | answersProcessors.add(iAnswersProcessor); |
||
235 | } catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) { |
||
236 | logger.error(e, e); |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | return answersProcessors; |
||
241 | } |
||
242 | |||
1314 | jmachado | 243 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) |
244 | { |
||
245 | QuestionarioImpl q = new QuestionarioImpl(); |
||
246 | 1.5.0/docs/api/java/lang/System.html">System.out.println(q); |
||
247 | } |
||
1315 | jmachado | 248 | |
249 | public 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State getStateEnum() |
||
250 | { |
||
251 | return 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.parse(getState()); |
||
252 | } |
||
1326 | jmachado | 253 | |
254 | public void setStateClass(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State state) { |
||
1333 | jmachado | 255 | setLogStates(getLogStates()+"\n"+ DatesUtils.getLogDateNow() + " changing state: " + getState() + " -> " + state.name()); |
1326 | jmachado | 256 | setState(state.name()); |
257 | } |
||
258 | |||
259 | |||
260 | /**CLEARANCES SUPPORT**/ |
||
261 | |||
262 | SimpleClearanceRuledSupport clearanceRuledSupport = null; |
||
263 | |||
264 | public SimpleClearanceRuledSupport getClearanceRuledSupport() { |
||
265 | return clearanceRuledSupport; |
||
266 | } |
||
267 | |||
268 | public void setClearanceRuledSupport(SimpleClearanceRuledSupport clearanceRuledSupport) { |
||
269 | this.clearanceRuledSupport = clearanceRuledSupport; |
||
270 | } |
||
271 | |||
272 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
273 | public boolean isClearanceInitialized(UserSessionImpl u) { |
||
274 | return clearanceRuledSupport == null ? false : |
||
275 | clearanceRuledSupport.isClearanceInitialized(u); |
||
276 | } |
||
277 | |||
278 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
279 | public boolean isClear(UserSessionImpl u, 1.5.0/docs/api/java/lang/String.html">String OP) { |
||
280 | if(clearanceRuledSupport == null) |
||
281 | return false; |
||
282 | return clearanceRuledSupport.isClear(u, OP); |
||
283 | } |
||
284 | |||
285 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
286 | public void initClearances(UserSessionImpl usession, boolean force) { |
||
287 | |||
288 | SimpleClearanceRuledSupport s = new SimpleClearanceRuledSupport(); |
||
289 | |||
1346 | jmachado | 290 | if((usession.getUser().isSuperuserOrAdmin() |
291 | || usession.getUser().hasRole(Globals.QUESTIONARIOS_ADMIN)) |
||
292 | || usession.getUser().hasRole(Globals.QUESTIONARIOS_ASSIGNEMENTS_ADMIN) |
||
1378 | jmachado | 293 | || usession.getUser().hasRole(Globals.QUESTIONARIOS_TIPOLOGIAS_ADMIN) |
294 | || usession.getUser().hasRole(Globals.QUESTIONARIOS_ASSIGNEMENTS_CHECK_TEACHERS_ADMIN)) |
||
1326 | jmachado | 295 | { |
1346 | jmachado | 296 | |
1327 | jmachado | 297 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SEE_FORM.name(),usession); |
298 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SEE_ADMIN.name(),usession); |
||
1346 | jmachado | 299 | |
300 | if((usession.getUser().isSuperuserOrAdmin() |
||
301 | || usession.getUser().hasRole(Globals.QUESTIONARIOS_ADMIN))) |
||
1326 | jmachado | 302 | { |
1346 | jmachado | 303 | if(getStateEnum() == QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.CREATED && |
304 | getQuestionarioHistoryDrive() != null && |
||
305 | getiAnswersProcessorClass() != null) |
||
306 | { |
||
307 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_FORM.name(),usession); |
||
308 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SET_STATE_ASSIGNATION_DETAILS.name(),usession); |
||
309 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_DELETE.name(),usession); |
||
310 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_ANSWER_PROCESSOR.name(),usession); |
||
311 | } |
||
1326 | jmachado | 312 | } |
313 | //ANO SEMESTRE ESPECIFICO apenas neste estado, em atribuição de respostas e respostas atribuidas já não permite |
||
314 | if(getStateEnum() == QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.ASSIGNATION_DETAILS) |
||
315 | { |
||
1346 | jmachado | 316 | if((usession.getUser().isSuperuserOrAdmin() |
317 | || usession.getUser().hasRole(Globals.QUESTIONARIOS_ADMIN))) |
||
318 | { |
||
319 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_FORM.name(),usession); |
||
320 | } |
||
1329 | jmachado | 321 | s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_ASSIGNATION_OPERATIONS.name(),usession); |
1327 | jmachado | 322 | |
1329 | jmachado | 323 | getiAnswersProcessorClass().initClearances(this,usession,s); |
1326 | jmachado | 324 | } |
1327 | jmachado | 325 | if(getStateEnum() == 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.ASSIGNING_ANSWERS_PROCESSEMENT) |
326 | { |
||
327 | |||
328 | } |
||
1326 | jmachado | 329 | } |
330 | setClearanceRuledSupport(s); |
||
331 | } |
||
332 | |||
333 | public static enum QuestionarioClearancesOperation |
||
334 | { |
||
335 | |||
1346 | jmachado | 336 | QUESTIONARIO_NEW_FORM, |
1326 | jmachado | 337 | QUESTIONARIO_SAVE_FORM, |
1327 | jmachado | 338 | QUESTIONARIO_SEE_FORM, |
339 | QUESTIONARIO_SEE_ADMIN, |
||
1326 | jmachado | 340 | QUESTIONARIO_SAVE_ANSWER_PROCESSOR, |
341 | QUESTIONARIO_SET_STATE_ASSIGNATION_DETAILS, |
||
1329 | jmachado | 342 | QUESTIONARIO_ASSIGNATION_OPERATIONS, |
1327 | jmachado | 343 | QUESTIONARIO_DELETE, |
1336 | jmachado | 344 | QUESTIONARIO_REVERT_ALL_ASSIGNEMENTS, |
1326 | jmachado | 345 | |
1327 | jmachado | 346 | /*Pedagogico Cursos*/ |
1329 | jmachado | 347 | QUESTIONARIO_SET_ANO_SEMESTRE, |
1327 | jmachado | 348 | QUESTIONARIO_SCHEDULLE_SELECT_COURSES, |
1329 | jmachado | 349 | QUESTIONARIO_SCHEDULLE_SEE_SELECT_COURSES, |
350 | QUESTIONARIO_CHANGE_TIPOLOGIES, |
||
351 | QUESTIONARIO_START_ASSIGN_ANSWERS, |
||
1379 | jmachado | 352 | QUESTIONARIO_SEE_START_ASSIGN_ANSWERS, |
1346 | jmachado | 353 | QUESTIONARIO_CHANGE_ASSIGNEMENTS, |
1379 | jmachado | 354 | QUESTIONARIO_CHANGE_ASSIGNEMENTS_CHECK_TEACHERS, |
355 | QUESTIONARIO_FINNISH_ASSIGNEMENTS, |
||
1326 | jmachado | 356 | ; |
357 | |||
358 | public static QuestionarioClearancesOperation parse(1.5.0/docs/api/java/lang/String.html">String clearance) |
||
359 | { |
||
360 | if(clearance == null) |
||
361 | return null; |
||
362 | for(QuestionarioClearancesOperation op: QuestionarioClearancesOperation.values()) |
||
363 | { |
||
364 | if(op.name().equals(clearance)) |
||
365 | return op; |
||
366 | } |
||
367 | return null; |
||
368 | } |
||
369 | } |
||
1328 | jmachado | 370 | |
371 | |||
372 | |||
373 | |||
374 | 1.5.0/docs/api/java/lang/String.html">String[] afetacoesVarCoursesSelectionForJob; |
||
375 | |||
376 | /** |
||
377 | * Variaveis especificas do modulo do pedagogico |
||
378 | * ver o PedagogicoAlunosProcessor que implementa o IAnswersProcessor |
||
379 | * que as inicia |
||
380 | * |
||
381 | * @return lista de cursos ids no BACO selecionados na tarefa |
||
382 | */ |
||
383 | public 1.5.0/docs/api/java/lang/String.html">String[] getAfetacoesVarCoursesSelectionForJob() { |
||
384 | return afetacoesVarCoursesSelectionForJob; |
||
385 | } |
||
386 | |||
387 | public void setAfetacoesVarCoursesSelectionForJob(1.5.0/docs/api/java/lang/String.html">String[] afetacoesVarCoursesSelectionForJob) { |
||
388 | this.afetacoesVarCoursesSelectionForJob = afetacoesVarCoursesSelectionForJob; |
||
389 | } |
||
1333 | jmachado | 390 | |
391 | |||
392 | |||
393 | |||
394 | |||
1314 | jmachado | 395 | } |