Rev 1353 | Rev 1731 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1350 | jmachado | 1 | package pt.estgp.estgweb.web.controllers.configuration; |
2 | |||
3 | import jomm.dao.impl.AbstractDao; |
||
4 | import org.apache.log4j.Logger; |
||
5 | import org.apache.struts.action.ActionForm; |
||
6 | import org.apache.struts.action.ActionForward; |
||
7 | import org.apache.struts.action.ActionMapping; |
||
1353 | jmachado | 8 | import pt.estgp.estgweb.domain.Configuration; |
1350 | jmachado | 9 | import pt.estgp.estgweb.domain.ConfigurationGradesEpocaAvaliacao; |
10 | import pt.estgp.estgweb.domain.ConfigurationGradesStatusEpoca; |
||
11 | import pt.estgp.estgweb.domain.DomainObjectFactory; |
||
12 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
13 | import pt.estgp.estgweb.web.UserSessionProxy; |
||
1729 | jmachado | 14 | import pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController; |
1350 | jmachado | 15 | import pt.estgp.estgweb.web.form.configuration.ConfigurationGradesForm; |
1353 | jmachado | 16 | import pt.estgp.estgweb.web.form.configuration.ConfigurationsForm; |
1350 | jmachado | 17 | |
18 | import javax.servlet.ServletException; |
||
19 | import javax.servlet.http.HttpServletRequest; |
||
20 | import javax.servlet.http.HttpServletResponse; |
||
21 | |||
22 | /** |
||
23 | * @author Jorge Machado |
||
24 | * @date 26/Fev/2008 |
||
25 | * @time 18:01:54 |
||
26 | * @see pt.estgp.estgweb.web |
||
27 | */ |
||
1729 | jmachado | 28 | public class ConfigurationsController extends AbstractWidgetAjaxController |
1350 | jmachado | 29 | { |
30 | |||
31 | 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(ConfigurationsController.class); |
||
32 | |||
33 | |||
34 | |||
35 | public ActionForward saveGrades(ActionMapping mapping, |
||
36 | ActionForm form, |
||
37 | HttpServletRequest request, |
||
38 | HttpServletResponse response) |
||
39 | throws ServletException |
||
40 | { |
||
41 | |||
42 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
43 | { |
||
44 | return mapping.findForward("error401"); |
||
45 | } |
||
46 | |||
47 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
48 | AbstractDao.getCurrentSession().beginTransaction(); |
||
49 | for(ConfigurationGradesEpocaAvaliacao a: f.getConfigurationGrades().getEpocasAvaliacao()) |
||
50 | { |
||
51 | if(a.getId() > 0) |
||
52 | { |
||
53 | ConfigurationGradesEpocaAvaliacao persist = DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().load(a.getId()); |
||
54 | persist.setCodigoEpoca(a.getCodigoEpoca()); |
||
55 | persist.setCodigoMomento(a.getCodigoMomento()); |
||
56 | persist.setObs(a.getObs()); |
||
57 | persist.setDescricao(a.getDescricao()); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | for(ConfigurationGradesStatusEpoca a: f.getConfigurationGrades().getStatusEpocas()) |
||
62 | { |
||
63 | if(a.getId() > 0) |
||
64 | { |
||
65 | ConfigurationGradesStatusEpoca persist = DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().load(a.getId()); |
||
66 | persist.setStatus(a.getStatus()); |
||
67 | persist.setObs(a.getObs()); |
||
68 | persist.setDescricao(a.getDescricao()); |
||
69 | } |
||
70 | } |
||
71 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
72 | |||
73 | return mapping.findForward("grades"); |
||
74 | } |
||
75 | |||
76 | public ActionForward addEpocaAvaliacao(ActionMapping mapping, |
||
77 | ActionForm form, |
||
78 | HttpServletRequest request, |
||
79 | HttpServletResponse response) |
||
80 | throws ServletException |
||
81 | { |
||
82 | |||
83 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
84 | { |
||
85 | return mapping.findForward("error401"); |
||
86 | } |
||
87 | AbstractDao.getCurrentSession().beginTransaction(); |
||
88 | |||
89 | ConfigurationGradesEpocaAvaliacao epoca = DomainObjectFactory.createConfigurationGradesEpocaAvaliacaoImpl(); |
||
90 | DaoFactory.getConfigurationDaoImpl().load().getConfigurationGrades().getEpocasAvaliacao().add(epoca); |
||
91 | DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().save(epoca); |
||
92 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
93 | return mapping.findForward("grades"); |
||
94 | } |
||
95 | |||
96 | public ActionForward addSatusEpoca(ActionMapping mapping, |
||
97 | ActionForm form, |
||
98 | HttpServletRequest request, |
||
99 | HttpServletResponse response) |
||
100 | throws ServletException |
||
101 | { |
||
102 | |||
103 | |||
104 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
105 | { |
||
106 | return mapping.findForward("error401"); |
||
107 | } |
||
108 | AbstractDao.getCurrentSession().beginTransaction(); |
||
109 | ConfigurationGradesStatusEpoca status = DomainObjectFactory.createConfigurationGradesStatusEpocaImpl(); |
||
110 | DaoFactory.getConfigurationDaoImpl().load().getConfigurationGrades().getStatusEpoca().add(status); |
||
111 | DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().save(status); |
||
112 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
113 | return mapping.findForward("grades"); |
||
114 | } |
||
115 | |||
116 | public ActionForward deleteEpocaAvaliacao(ActionMapping mapping, |
||
117 | ActionForm form, |
||
118 | HttpServletRequest request, |
||
119 | HttpServletResponse response) |
||
120 | throws ServletException |
||
121 | { |
||
122 | |||
123 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
124 | { |
||
125 | return mapping.findForward("error401"); |
||
126 | } |
||
127 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
128 | AbstractDao.getCurrentSession().beginTransaction(); |
||
129 | DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().delete(f.getId()); |
||
130 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
131 | return mapping.findForward("grades"); |
||
132 | } |
||
133 | |||
134 | public ActionForward deleteStatusEpoca(ActionMapping mapping, |
||
135 | ActionForm form, |
||
136 | HttpServletRequest request, |
||
137 | HttpServletResponse response) |
||
138 | throws ServletException |
||
139 | { |
||
140 | |||
141 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
142 | { |
||
143 | return mapping.findForward("error401"); |
||
144 | } |
||
145 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
146 | |||
147 | AbstractDao.getCurrentSession().beginTransaction(); |
||
148 | DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().delete(f.getId()); |
||
149 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
150 | return mapping.findForward("grades"); |
||
151 | } |
||
152 | |||
1353 | jmachado | 153 | public ActionForward saveConfigsGerais(ActionMapping mapping, |
154 | ActionForm form, |
||
155 | HttpServletRequest request, |
||
156 | HttpServletResponse response) |
||
157 | throws ServletException |
||
158 | { |
||
159 | |||
160 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
161 | { |
||
162 | return mapping.findForward("error401"); |
||
163 | } |
||
164 | |||
165 | ConfigurationsForm f = (ConfigurationsForm) form; |
||
166 | AbstractDao.getCurrentSession().beginTransaction(); |
||
167 | |||
168 | 1.5.0/docs/api/javax/security/auth/login/Configuration.html">Configuration configuration = DaoFactory.getConfigurationDaoImpl().load(); |
||
169 | |||
170 | configuration.setOpenInfoIntranet(f.getConfiguration().getOpenInfoIntranet()); |
||
171 | configuration.setInterfaceImportYear(f.getConfiguration().getInterfaceImportYear()); |
||
172 | configuration.setCursosFicticios(f.getConfiguration().getCursosFicticios()); |
||
173 | |||
174 | configuration.setCourseUnitEvaluationActiveYear(f.getConfiguration().getCourseUnitEvaluationActiveYear()); |
||
175 | configuration.setCourseUnitEvaluationActiveDegrees(f.getConfiguration().getCourseUnitEvaluationActiveDegrees()); |
||
176 | configuration.setCourseUnitEvaluationActiveCourseIds(f.getConfiguration().getCourseUnitEvaluationActiveCourseIds()); |
||
177 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
178 | |||
179 | return mapping.getInputForward(); |
||
180 | } |
||
1350 | jmachado | 181 | } |