Rev 1857 | 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; |
||
1731 | jmachado | 8 | import org.json.JSONObject; |
9 | import pt.estgp.estgweb.domain.*; |
||
1350 | jmachado | 10 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
11 | import pt.estgp.estgweb.web.UserSessionProxy; |
||
1729 | jmachado | 12 | import pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController; |
1350 | jmachado | 13 | import pt.estgp.estgweb.web.form.configuration.ConfigurationGradesForm; |
1353 | jmachado | 14 | import pt.estgp.estgweb.web.form.configuration.ConfigurationsForm; |
1731 | jmachado | 15 | import pt.estgp.estgweb.web.utils.RequestUtils; |
16 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
||
17 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
1350 | jmachado | 18 | |
19 | import javax.servlet.ServletException; |
||
20 | import javax.servlet.http.HttpServletRequest; |
||
21 | import javax.servlet.http.HttpServletResponse; |
||
22 | |||
23 | /** |
||
24 | * @author Jorge Machado |
||
25 | * @date 26/Fev/2008 |
||
26 | * @time 18:01:54 |
||
27 | * @see pt.estgp.estgweb.web |
||
28 | */ |
||
1729 | jmachado | 29 | public class ConfigurationsController extends AbstractWidgetAjaxController |
1350 | jmachado | 30 | { |
31 | |||
32 | 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); |
||
33 | |||
34 | |||
35 | |||
36 | public ActionForward saveGrades(ActionMapping mapping, |
||
37 | ActionForm form, |
||
38 | HttpServletRequest request, |
||
39 | HttpServletResponse response) |
||
40 | throws ServletException |
||
41 | { |
||
42 | |||
43 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
44 | { |
||
45 | return mapping.findForward("error401"); |
||
46 | } |
||
47 | |||
48 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
49 | AbstractDao.getCurrentSession().beginTransaction(); |
||
50 | for(ConfigurationGradesEpocaAvaliacao a: f.getConfigurationGrades().getEpocasAvaliacao()) |
||
51 | { |
||
52 | if(a.getId() > 0) |
||
53 | { |
||
54 | ConfigurationGradesEpocaAvaliacao persist = DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().load(a.getId()); |
||
55 | persist.setCodigoEpoca(a.getCodigoEpoca()); |
||
56 | persist.setCodigoMomento(a.getCodigoMomento()); |
||
57 | persist.setObs(a.getObs()); |
||
58 | persist.setDescricao(a.getDescricao()); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | for(ConfigurationGradesStatusEpoca a: f.getConfigurationGrades().getStatusEpocas()) |
||
63 | { |
||
64 | if(a.getId() > 0) |
||
65 | { |
||
66 | ConfigurationGradesStatusEpoca persist = DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().load(a.getId()); |
||
67 | persist.setStatus(a.getStatus()); |
||
68 | persist.setObs(a.getObs()); |
||
69 | persist.setDescricao(a.getDescricao()); |
||
70 | } |
||
71 | } |
||
72 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
73 | |||
74 | return mapping.findForward("grades"); |
||
75 | } |
||
76 | |||
77 | public ActionForward addEpocaAvaliacao(ActionMapping mapping, |
||
78 | ActionForm form, |
||
79 | HttpServletRequest request, |
||
80 | HttpServletResponse response) |
||
81 | throws ServletException |
||
82 | { |
||
83 | |||
84 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
85 | { |
||
86 | return mapping.findForward("error401"); |
||
87 | } |
||
88 | AbstractDao.getCurrentSession().beginTransaction(); |
||
89 | |||
90 | ConfigurationGradesEpocaAvaliacao epoca = DomainObjectFactory.createConfigurationGradesEpocaAvaliacaoImpl(); |
||
91 | DaoFactory.getConfigurationDaoImpl().load().getConfigurationGrades().getEpocasAvaliacao().add(epoca); |
||
92 | DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().save(epoca); |
||
93 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
94 | return mapping.findForward("grades"); |
||
95 | } |
||
96 | |||
97 | public ActionForward addSatusEpoca(ActionMapping mapping, |
||
98 | ActionForm form, |
||
99 | HttpServletRequest request, |
||
100 | HttpServletResponse response) |
||
101 | throws ServletException |
||
102 | { |
||
103 | |||
104 | |||
105 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
106 | { |
||
107 | return mapping.findForward("error401"); |
||
108 | } |
||
109 | AbstractDao.getCurrentSession().beginTransaction(); |
||
110 | ConfigurationGradesStatusEpoca status = DomainObjectFactory.createConfigurationGradesStatusEpocaImpl(); |
||
111 | DaoFactory.getConfigurationDaoImpl().load().getConfigurationGrades().getStatusEpoca().add(status); |
||
112 | DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().save(status); |
||
113 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
114 | return mapping.findForward("grades"); |
||
115 | } |
||
116 | |||
117 | public ActionForward deleteEpocaAvaliacao(ActionMapping mapping, |
||
118 | ActionForm form, |
||
119 | HttpServletRequest request, |
||
120 | HttpServletResponse response) |
||
121 | throws ServletException |
||
122 | { |
||
123 | |||
124 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
125 | { |
||
126 | return mapping.findForward("error401"); |
||
127 | } |
||
128 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
129 | AbstractDao.getCurrentSession().beginTransaction(); |
||
130 | DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().delete(f.getId()); |
||
131 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
132 | return mapping.findForward("grades"); |
||
133 | } |
||
134 | |||
135 | public ActionForward deleteStatusEpoca(ActionMapping mapping, |
||
136 | ActionForm form, |
||
137 | HttpServletRequest request, |
||
138 | HttpServletResponse response) |
||
139 | throws ServletException |
||
140 | { |
||
141 | |||
142 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
143 | { |
||
144 | return mapping.findForward("error401"); |
||
145 | } |
||
146 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
147 | |||
148 | AbstractDao.getCurrentSession().beginTransaction(); |
||
149 | DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().delete(f.getId()); |
||
150 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
151 | return mapping.findForward("grades"); |
||
152 | } |
||
153 | |||
1353 | jmachado | 154 | public ActionForward saveConfigsGerais(ActionMapping mapping, |
155 | ActionForm form, |
||
156 | HttpServletRequest request, |
||
157 | HttpServletResponse response) |
||
158 | throws ServletException |
||
159 | { |
||
160 | |||
161 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
162 | { |
||
163 | return mapping.findForward("error401"); |
||
164 | } |
||
165 | |||
166 | ConfigurationsForm f = (ConfigurationsForm) form; |
||
167 | AbstractDao.getCurrentSession().beginTransaction(); |
||
168 | |||
169 | 1.5.0/docs/api/javax/security/auth/login/Configuration.html">Configuration configuration = DaoFactory.getConfigurationDaoImpl().load(); |
||
170 | |||
171 | configuration.setOpenInfoIntranet(f.getConfiguration().getOpenInfoIntranet()); |
||
172 | configuration.setInterfaceImportYear(f.getConfiguration().getInterfaceImportYear()); |
||
1916 | grupo1 | 173 | configuration.setCourseReportImportYear(f.getConfiguration().getCourseReportImportYear()); |
1353 | jmachado | 174 | configuration.setCursosFicticios(f.getConfiguration().getCursosFicticios()); |
175 | |||
176 | configuration.setCourseUnitEvaluationActiveYear(f.getConfiguration().getCourseUnitEvaluationActiveYear()); |
||
177 | configuration.setCourseUnitEvaluationActiveDegrees(f.getConfiguration().getCourseUnitEvaluationActiveDegrees()); |
||
178 | configuration.setCourseUnitEvaluationActiveCourseIds(f.getConfiguration().getCourseUnitEvaluationActiveCourseIds()); |
||
179 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
180 | |||
181 | return mapping.getInputForward(); |
||
182 | } |
||
1731 | jmachado | 183 | |
184 | |||
185 | |||
186 | public JSONObject newConfigSeparator(ActionForm form, HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
187 | IServiceManager sm = ServiceManager.getInstance(); |
||
188 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
189 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{}; |
||
190 | ConfigurationSeparatorImpl c = (ConfigurationSeparatorImpl) sm.execute(RequestUtils.getRequester(request, response), "NewConfigurationSeparator", args, names); |
||
1779 | jmachado | 191 | JSONObject tJson = c.toJsonObject(); |
1731 | jmachado | 192 | addMessage(request,"config.new.configuration.separator.success"); |
193 | return tJson; |
||
194 | } |
||
195 | |||
196 | public JSONObject updateConfigSeparator(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
197 | 1.5.0/docs/api/java/lang/String.html">String configSeparatorJson = request.getParameter("separatorJson"); |
||
198 | IServiceManager sm = ServiceManager.getInstance(); |
||
199 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
200 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{configSeparatorJson}; |
||
201 | ConfigurationSeparatorImpl s = (ConfigurationSeparatorImpl) sm.execute(RequestUtils.getRequester(request, response), "UpdateConfigurationSeparator", args, names); |
||
1779 | jmachado | 202 | JSONObject tJson = s.toJsonObject(); |
1731 | jmachado | 203 | addMessage(request,"config.update.configuration.separator.success",s.getName()); |
204 | return tJson; |
||
205 | } |
||
206 | |||
207 | public JSONObject removeConfigSeparator(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
208 | 1.5.0/docs/api/java/lang/String.html">String configSeparatorJson = request.getParameter("separatorJson"); |
||
209 | IServiceManager sm = ServiceManager.getInstance(); |
||
210 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
211 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{configSeparatorJson}; |
||
212 | ConfigurationSeparatorImpl s = (ConfigurationSeparatorImpl) sm.execute(RequestUtils.getRequester(request, response), "RemoveConfigurationSeparator", args, names); |
||
1779 | jmachado | 213 | JSONObject tJson = s.toJsonObject(); |
1731 | jmachado | 214 | addMessage(request, "config.removed.configuration.separator.success", s.getName()); |
215 | return tJson; |
||
216 | } |
||
217 | |||
1350 | jmachado | 218 | } |