Rev 1328 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1326 | jmachado | 1 | package pt.estgp.estgweb.services.questionarios; |
2 | |||
3 | import pt.estgp.estgweb.domain.*; |
||
4 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
5 | import pt.estgp.estgweb.domain.views.QuestionarioView; |
||
6 | import pt.estgp.estgweb.web.exceptions.NotAuthorizedException; |
||
7 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
8 | |||
9 | import java.util.List; |
||
10 | |||
11 | /** |
||
12 | * Created by jorgemachado on 21/03/16. |
||
13 | */ |
||
14 | public class QuestionariosService implements IService |
||
15 | { |
||
16 | |||
17 | //NEW QUESTIONARIOS COME BY THIS SERVICE |
||
18 | public QuestionarioImpl newQuestionarioForm(QuestionarioImpl qform, UserSession userSession) throws NotAuthorizedException |
||
19 | { |
||
20 | if(qform.getQuestionarioHistoryDrive().getId() > 0) |
||
21 | { |
||
22 | QuestionarioHistoryDrive hist = DaoFactory.getQuestionarioHistoryDriveDaoImpl().load(qform.getQuestionarioHistoryDrive().getId()); |
||
23 | qform.setQuestionarioHistoryDrive(hist); |
||
24 | } |
||
25 | else |
||
26 | { |
||
27 | qform.setQuestionarioHistoryDrive(null); |
||
28 | } |
||
29 | DaoFactory.getQuestionarioDaoImpl().save(qform); |
||
30 | return qform; |
||
31 | } |
||
32 | public QuestionarioImpl saveQuestionarioForm(QuestionarioImpl qform, UserSession userSession, QuestionarioImpl questionarioCleared) throws NotAuthorizedException { |
||
33 | if(qform.getQuestionarioHistoryDrive().getId() > 0) |
||
34 | { |
||
35 | QuestionarioHistoryDrive hist = DaoFactory.getQuestionarioHistoryDriveDaoImpl().load(qform.getQuestionarioHistoryDrive().getId()); |
||
36 | qform.setQuestionarioHistoryDrive(hist); |
||
37 | } |
||
38 | else |
||
39 | { |
||
40 | qform.setQuestionarioHistoryDrive(null); |
||
41 | } |
||
42 | Questionario qPersistent = questionarioCleared; |
||
43 | if(questionarioCleared.isClear((UserSessionImpl) userSession,QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_FORM.name())) |
||
44 | { |
||
45 | QuestionarioView qv = new QuestionarioView(qform); |
||
46 | if(questionarioCleared.isClear((UserSessionImpl) userSession, QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SAVE_ANSWER_PROCESSOR.name())) |
||
47 | { |
||
48 | qv.persistAnswersProcessor(qPersistent); |
||
49 | } |
||
50 | qv.persistViewInObjectForm(qPersistent); |
||
51 | qPersistent.setQuestionarioHistoryDrive(qform.getQuestionarioHistoryDrive()); |
||
52 | } |
||
53 | else |
||
54 | throw new NotAuthorizedException("Não pode alterar o formulário porque o questionário está num estado avançado"); |
||
55 | |||
56 | return loadInit(questionarioCleared); |
||
57 | } |
||
58 | |||
59 | public QuestionarioImpl setAssignDetailsState(long id, UserSession userSession, QuestionarioImpl questionarioCleared) throws NotAuthorizedException { |
||
60 | |||
61 | if(questionarioCleared.isClear((UserSessionImpl) userSession,QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SET_STATE_ASSIGNATION_DETAILS.name())) |
||
62 | { |
||
63 | questionarioCleared.setStateClass(QuestionarioImpl.1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.ASSIGNATION_DETAILS); |
||
64 | } |
||
65 | else |
||
66 | throw new NotAuthorizedException("Não alterar o questionário para este estado neste momento"); |
||
67 | |||
68 | return loadInit(questionarioCleared); |
||
69 | } |
||
70 | /** |
||
71 | * Questionario comes already cleared from Filter |
||
72 | * @param questionarioId |
||
73 | * @param questionarioCleared |
||
74 | * @param userSession |
||
75 | * @return |
||
76 | */ |
||
77 | public QuestionarioImpl loadQuestionario(long questionarioId,UserSession userSession,QuestionarioImpl questionarioCleared) |
||
78 | { |
||
79 | return loadInit(questionarioCleared); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * just to load proxys |
||
84 | * @param questionarioCleared |
||
85 | * @return |
||
86 | */ |
||
87 | private QuestionarioImpl loadInit(QuestionarioImpl questionarioCleared) |
||
88 | { |
||
89 | questionarioCleared.getDescription();//to load proxy just in case |
||
90 | if(questionarioCleared.getQuestionarioHistoryDrive() != null) |
||
91 | questionarioCleared.getQuestionarioHistoryDrive().getCodeName(); |
||
92 | return questionarioCleared; |
||
93 | } |
||
94 | private void loadInit(List<QuestionarioImpl> questionarioCleared) |
||
95 | { |
||
96 | for(QuestionarioImpl q: questionarioCleared) |
||
97 | { |
||
98 | q.getDescription();//to load proxy just in case |
||
99 | if(q.getQuestionarioHistoryDrive() != null) |
||
100 | q.getQuestionarioHistoryDrive().getCodeName(); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | //return similar questionarios in same year, semestre and history category |
||
105 | public List<QuestionarioImpl> setAnoSemestre(1.5.0/docs/api/java/lang/String.html">String year, 1.5.0/docs/api/java/lang/String.html">String semestre, long questionarioId, UserSession userSession,QuestionarioImpl questionarioCleared) throws NotAuthorizedException |
||
106 | { |
||
107 | if(questionarioCleared.isClear((UserSessionImpl) userSession,QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SET_ANO_SEMESTRE.name())) |
||
108 | { |
||
109 | questionarioCleared.setYear(year); |
||
110 | questionarioCleared.setSemestre(semestre); |
||
111 | List<QuestionarioImpl> similar = DaoFactory.getQuestionarioDaoImpl().findAnoSemestre(year, semestre, questionarioCleared.getQuestionarioHistoryDrive().getId()); |
||
112 | loadInit(similar); |
||
113 | return similar; |
||
114 | } |
||
115 | else |
||
116 | throw new NotAuthorizedException("Não pode alterar o formulário porque o questionário está num estado avançado"); |
||
117 | } |
||
118 | |||
119 | public void deleteQuestionario(long questionarioId, UserSession userSession,QuestionarioImpl questionarioCleared) |
||
120 | { |
||
121 | if(questionarioCleared.isClear((UserSessionImpl) userSession,QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_DELETE.name())) |
||
122 | { |
||
123 | DaoFactory.getQuestionarioDaoImpl().delete(questionarioCleared); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | } |