Subversion Repositories bacoAlunos

Rev

Rev 1327 | Rev 1329 | 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;
1327 jmachado 5
import pt.estgp.estgweb.domain.dao.DaoFactory;
1326 jmachado 6
import pt.estgp.estgweb.domain.utils.SimpleClearanceRuledSupport;
1314 jmachado 7
import pt.estgp.estgweb.utils.ConfigProperties;
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
 
67
 
1325 jmachado 68
 
1314 jmachado 69
    public QuestionarioImpl() {
70
        super();
71
 
72
        setState(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.CREATED.name());
1315 jmachado 73
 
1325 jmachado 74
        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"));
75
        1.5.0/docs/api/java/lang/String.html">String month = sdf.format(new 5+0%2Fdocs%2Fapi+Date">Date());
76
        1.5.0/docs/api/java/lang/String.html">String introHtml = ConfigProperties.getProperty("questionario.intro.text");
77
 
78
        1.5.0/docs/api/java/lang/String.html">String introWithMonth = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(introHtml, month);
79
 
80
        setIntroHtml(introWithMonth);
1314 jmachado 81
        setGroup1Title(ConfigProperties.getProperty("questionario.group1.title"));
82
        setGroup2Title(ConfigProperties.getProperty("questionario.group2.title"));
83
        setGroup3Title(ConfigProperties.getProperty("questionario.group3.title"));
84
        setGroup4Title(ConfigProperties.getProperty("questionario.group4.title"));
85
        setGroup5Title(ConfigProperties.getProperty("questionario.group5.title"));
1325 jmachado 86
        setGroup6Title(ConfigProperties.getProperty("questionario.group6.title"));
87
        setGroup7Title(ConfigProperties.getProperty("questionario.group7.title"));
88
        setGroup8Title(ConfigProperties.getProperty("questionario.group8.title"));
89
        setGroup9Title(ConfigProperties.getProperty("questionario.group9.title"));
90
        setGroup10Title(ConfigProperties.getProperty("questionario.group10.title"));
1314 jmachado 91
 
92
 
1325 jmachado 93
        setGroup1Code(ConfigProperties.getProperty("questionario.group1.code"));
94
        setGroup2Code(ConfigProperties.getProperty("questionario.group2.code"));
95
        setGroup3Code(ConfigProperties.getProperty("questionario.group3.code"));
96
        setGroup4Code(ConfigProperties.getProperty("questionario.group4.code"));
97
        setGroup5Code(ConfigProperties.getProperty("questionario.group5.code"));
98
        setGroup6Code(ConfigProperties.getProperty("questionario.group6.code"));
99
        setGroup7Code(ConfigProperties.getProperty("questionario.group7.code"));
100
        setGroup8Code(ConfigProperties.getProperty("questionario.group8.code"));
101
        setGroup9Code(ConfigProperties.getProperty("questionario.group9.code"));
102
        setGroup10Code(ConfigProperties.getProperty("questionario.group10.code"));
103
 
104
 
105
        for(int i = 1; i <=40;i++)
1314 jmachado 106
        {
107
 
108
            try {
109
                1.5.0/docs/api/java/lang/String.html">String group = ConfigProperties.getProperty("questionario.p" + i + ".group");
110
                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);
111
                m.invoke(this,group);
112
 
113
                1.5.0/docs/api/java/lang/String.html">String pergunta = ConfigProperties.getProperty("questionario.p" + i);
114
                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);
115
                m2.invoke(this,pergunta);
116
            } catch (1.5.0/docs/api/java/lang/NoSuchMethodException.html">NoSuchMethodException e) {
117
                e.printStackTrace();
118
            } catch (1.5.0/docs/api/java/lang/reflect/InvocationTargetException.html">InvocationTargetException e) {
119
                e.printStackTrace();
120
            } catch (1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException e) {
121
                e.printStackTrace();
122
            }
123
        }
1325 jmachado 124
    }
1314 jmachado 125
 
1325 jmachado 126
    static List<IAnswersProcessor> answersProcessors = null;
127
 
128
    public IAnswersProcessor getiAnswersProcessorClass()
129
    {
130
        if(getiAnswersProcessor() != null)
131
        {
132
            try {
133
                return (IAnswersProcessor) 1.5.0/docs/api/java/lang/Class.html">Class.forName(getiAnswersProcessor()).newInstance();
134
            } catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) {
135
                logger.error(e,e);
136
            }
137
        }
138
 
139
        return new IAnswersProcessor() {
140
            @1.5.0/docs/api/java/lang/Override.html">Override
141
            public 1.5.0/docs/api/java/lang/String.html">String getHistoryDriveConstraint() {
142
                return null;
143
            }
144
 
145
            @1.5.0/docs/api/java/lang/Override.html">Override
146
            public 1.5.0/docs/api/java/lang/String.html">String getTitle() {
147
                return "---";
148
            }
149
 
150
            @1.5.0/docs/api/java/lang/Override.html">Override
151
            public 1.5.0/docs/api/java/lang/String.html">String getAfetacoesManagementForward() {
152
                return null;
153
            }
1328 jmachado 154
 
155
            @1.5.0/docs/api/java/lang/Override.html">Override
156
            public void initQuestionarioAfetacoesVariables(QuestionarioImpl questionario) {
157
 
158
            }
1325 jmachado 159
        };
1314 jmachado 160
    }
161
 
1325 jmachado 162
    public static List<IAnswersProcessor> getIAnswerProcessors()
163
    {
164
        if(answersProcessors == null)
165
        {
166
            answersProcessors = new ArrayList<IAnswersProcessor>();
167
            List<String> processors = ConfigProperties.getListValues("pt.estgp.estgweb.domain.IAnswersProcessor.");
168
            for(1.5.0/docs/api/java/lang/String.html">String p: processors)
169
            {
170
                try {
171
                    IAnswersProcessor iAnswersProcessor = (IAnswersProcessor) 1.5.0/docs/api/java/lang/Class.html">Class.forName(p).newInstance();
172
                    answersProcessors.add(iAnswersProcessor);
173
                } catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) {
174
                    logger.error(e, e);
175
                }
176
            }
177
        }
178
        return answersProcessors;
179
    }
180
 
1314 jmachado 181
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args)
182
    {
183
        QuestionarioImpl q =  new QuestionarioImpl();
184
        1.5.0/docs/api/java/lang/System.html">System.out.println(q);
185
    }
1315 jmachado 186
 
187
    public 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State getStateEnum()
188
    {
189
        return 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.parse(getState());
190
    }
1326 jmachado 191
 
192
    public void setStateClass(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State state) {
193
        setState(state.name());
194
    }
195
 
196
 
197
    /**CLEARANCES SUPPORT**/
198
 
199
    SimpleClearanceRuledSupport clearanceRuledSupport = null;
200
 
201
    public SimpleClearanceRuledSupport getClearanceRuledSupport() {
202
        return clearanceRuledSupport;
203
    }
204
 
205
    public void setClearanceRuledSupport(SimpleClearanceRuledSupport clearanceRuledSupport) {
206
        this.clearanceRuledSupport = clearanceRuledSupport;
207
    }
208
 
209
    @1.5.0/docs/api/java/lang/Override.html">Override
210
    public boolean isClearanceInitialized(UserSessionImpl u) {
211
        return clearanceRuledSupport == null ? false :
212
                clearanceRuledSupport.isClearanceInitialized(u);
213
    }
214
 
215
    @1.5.0/docs/api/java/lang/Override.html">Override
216
    public boolean isClear(UserSessionImpl u, 1.5.0/docs/api/java/lang/String.html">String OP) {
217
        if(clearanceRuledSupport == null)
218
            return false;
219
        return clearanceRuledSupport.isClear(u, OP);
220
    }
221
 
222
    @1.5.0/docs/api/java/lang/Override.html">Override
223
    public void initClearances(UserSessionImpl usession, boolean force) {
224
 
225
        SimpleClearanceRuledSupport s = new SimpleClearanceRuledSupport();
226
 
227
        if((usession.getUser().isSuperuserOrAdmin() || usession.getUser().hasRole(Globals.QUESTIONARIOS_ADMIN)))
228
        {
1327 jmachado 229
            s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SEE_FORM.name(),usession);
230
            s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SEE_ADMIN.name(),usession);
1326 jmachado 231
            if(getStateEnum() == QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.CREATED &&
232
                    getQuestionarioHistoryDrive() != null &&
233
                    getiAnswersProcessorClass() != null)
234
            {
235
                s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_FORM.name(),usession);
236
                s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SET_STATE_ASSIGNATION_DETAILS.name(),usession);
237
                s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_DELETE.name(),usession);
238
                s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_ANSWER_PROCESSOR.name(),usession);
239
            }
240
            //ANO SEMESTRE ESPECIFICO apenas neste estado, em atribuição de respostas e respostas atribuidas já não permite
241
            if(getStateEnum() == QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.ASSIGNATION_DETAILS)
242
            {
243
                s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_FORM.name(),usession);
244
                s.addClearance(QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SET_ANO_SEMESTRE.name(),usession);
1327 jmachado 245
                s.addClearance(QuestionarioClearancesOperation.QUESTIONARIO_SCHEDULLE_SEE_SELECT_COURSES.name(),usession);
246
                if(getCourseSelectionTaskId() <= 0)
247
                    s.addClearance(QuestionarioClearancesOperation.QUESTIONARIO_SCHEDULLE_SELECT_COURSES.name(),usession);
248
                else
249
                {
250
                    JobServiceTask task = DaoFactory.getJobServiceTaskDaoImpl().load(getCourseSelectionTaskId());
251
                    if(task.isExecuted() || (task.getSaveDate() != null &&
252
                            1.5.0/docs/api/java/lang/System.html">System.currentTimeMillis()-task.getSaveDate().getTime()>1800000)) //half hour blocked
253
                    {
254
                        task.setExecuted(true);
255
                        s.addClearance(QuestionarioClearancesOperation.QUESTIONARIO_SCHEDULLE_SELECT_COURSES.name(),usession);
256
                    }
257
                }
258
 
1326 jmachado 259
            }
1327 jmachado 260
            if(getStateEnum() == 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.ASSIGNING_ANSWERS_PROCESSEMENT)
261
            {
262
 
263
            }
1326 jmachado 264
        }
265
        setClearanceRuledSupport(s);
266
    }
267
 
268
    public static enum QuestionarioClearancesOperation
269
    {
270
 
271
        QUESTIONARIO_SAVE_FORM,
1327 jmachado 272
        QUESTIONARIO_SEE_FORM,
273
        QUESTIONARIO_SEE_ADMIN,
1326 jmachado 274
        QUESTIONARIO_SAVE_ANSWER_PROCESSOR,
275
        QUESTIONARIO_SET_STATE_ASSIGNATION_DETAILS,
276
        QUESTIONARIO_SET_ANO_SEMESTRE,
1327 jmachado 277
        QUESTIONARIO_DELETE,
1326 jmachado 278
 
1327 jmachado 279
        /*Pedagogico Cursos*/
280
        QUESTIONARIO_SCHEDULLE_SELECT_COURSES,
281
        QUESTIONARIO_SCHEDULLE_SEE_SELECT_COURSES
1326 jmachado 282
        ;
283
 
284
        public static QuestionarioClearancesOperation parse(1.5.0/docs/api/java/lang/String.html">String clearance)
285
        {
286
            if(clearance == null)
287
                return null;
288
            for(QuestionarioClearancesOperation op: QuestionarioClearancesOperation.values())
289
            {
290
                if(op.name().equals(clearance))
291
                    return op;
292
            }
293
            return null;
294
        }
295
    }
1328 jmachado 296
 
297
 
298
 
299
 
300
    1.5.0/docs/api/java/lang/String.html">String[] afetacoesVarCoursesSelectionForJob;
301
 
302
    /**
303
     * Variaveis especificas do modulo do pedagogico
304
     * ver o PedagogicoAlunosProcessor que implementa o IAnswersProcessor
305
     * que as inicia
306
     *
307
     * @return lista de cursos ids no BACO selecionados na tarefa
308
     */
309
    public 1.5.0/docs/api/java/lang/String.html">String[] getAfetacoesVarCoursesSelectionForJob() {
310
        return afetacoesVarCoursesSelectionForJob;
311
    }
312
 
313
    public void setAfetacoesVarCoursesSelectionForJob(1.5.0/docs/api/java/lang/String.html">String[] afetacoesVarCoursesSelectionForJob) {
314
        this.afetacoesVarCoursesSelectionForJob = afetacoesVarCoursesSelectionForJob;
315
    }
1314 jmachado 316
}