Subversion Repositories bacoAlunos

Rev

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