Rev 1353 | Go to most recent revision | Details | 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; |
||
8 | import pt.estgp.estgweb.domain.ConfigurationGradesEpocaAvaliacao; |
||
9 | import pt.estgp.estgweb.domain.ConfigurationGradesStatusEpoca; |
||
10 | import pt.estgp.estgweb.domain.DomainObjectFactory; |
||
11 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
12 | import pt.estgp.estgweb.web.UserSessionProxy; |
||
13 | import pt.estgp.estgweb.web.controllers.ApplicationDispatchController; |
||
14 | import pt.estgp.estgweb.web.form.configuration.ConfigurationGradesForm; |
||
15 | |||
16 | import javax.servlet.ServletException; |
||
17 | import javax.servlet.http.HttpServletRequest; |
||
18 | import javax.servlet.http.HttpServletResponse; |
||
19 | |||
20 | /** |
||
21 | * @author Jorge Machado |
||
22 | * @date 26/Fev/2008 |
||
23 | * @time 18:01:54 |
||
24 | * @see pt.estgp.estgweb.web |
||
25 | */ |
||
26 | public class ConfigurationsController extends ApplicationDispatchController |
||
27 | { |
||
28 | |||
29 | 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); |
||
30 | |||
31 | |||
32 | |||
33 | public ActionForward saveGrades(ActionMapping mapping, |
||
34 | ActionForm form, |
||
35 | HttpServletRequest request, |
||
36 | HttpServletResponse response) |
||
37 | throws ServletException |
||
38 | { |
||
39 | |||
40 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
41 | { |
||
42 | return mapping.findForward("error401"); |
||
43 | } |
||
44 | |||
45 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
46 | AbstractDao.getCurrentSession().beginTransaction(); |
||
47 | for(ConfigurationGradesEpocaAvaliacao a: f.getConfigurationGrades().getEpocasAvaliacao()) |
||
48 | { |
||
49 | if(a.getId() > 0) |
||
50 | { |
||
51 | ConfigurationGradesEpocaAvaliacao persist = DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().load(a.getId()); |
||
52 | persist.setCodigoEpoca(a.getCodigoEpoca()); |
||
53 | persist.setCodigoMomento(a.getCodigoMomento()); |
||
54 | persist.setObs(a.getObs()); |
||
55 | persist.setDescricao(a.getDescricao()); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | for(ConfigurationGradesStatusEpoca a: f.getConfigurationGrades().getStatusEpocas()) |
||
60 | { |
||
61 | if(a.getId() > 0) |
||
62 | { |
||
63 | ConfigurationGradesStatusEpoca persist = DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().load(a.getId()); |
||
64 | persist.setStatus(a.getStatus()); |
||
65 | persist.setObs(a.getObs()); |
||
66 | persist.setDescricao(a.getDescricao()); |
||
67 | } |
||
68 | } |
||
69 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
70 | |||
71 | return mapping.findForward("grades"); |
||
72 | } |
||
73 | |||
74 | public ActionForward addEpocaAvaliacao(ActionMapping mapping, |
||
75 | ActionForm form, |
||
76 | HttpServletRequest request, |
||
77 | HttpServletResponse response) |
||
78 | throws ServletException |
||
79 | { |
||
80 | |||
81 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
82 | { |
||
83 | return mapping.findForward("error401"); |
||
84 | } |
||
85 | AbstractDao.getCurrentSession().beginTransaction(); |
||
86 | |||
87 | ConfigurationGradesEpocaAvaliacao epoca = DomainObjectFactory.createConfigurationGradesEpocaAvaliacaoImpl(); |
||
88 | DaoFactory.getConfigurationDaoImpl().load().getConfigurationGrades().getEpocasAvaliacao().add(epoca); |
||
89 | DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().save(epoca); |
||
90 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
91 | return mapping.findForward("grades"); |
||
92 | } |
||
93 | |||
94 | public ActionForward addSatusEpoca(ActionMapping mapping, |
||
95 | ActionForm form, |
||
96 | HttpServletRequest request, |
||
97 | HttpServletResponse response) |
||
98 | throws ServletException |
||
99 | { |
||
100 | |||
101 | |||
102 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
103 | { |
||
104 | return mapping.findForward("error401"); |
||
105 | } |
||
106 | AbstractDao.getCurrentSession().beginTransaction(); |
||
107 | ConfigurationGradesStatusEpoca status = DomainObjectFactory.createConfigurationGradesStatusEpocaImpl(); |
||
108 | DaoFactory.getConfigurationDaoImpl().load().getConfigurationGrades().getStatusEpoca().add(status); |
||
109 | DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().save(status); |
||
110 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
111 | return mapping.findForward("grades"); |
||
112 | } |
||
113 | |||
114 | public ActionForward deleteEpocaAvaliacao(ActionMapping mapping, |
||
115 | ActionForm form, |
||
116 | HttpServletRequest request, |
||
117 | HttpServletResponse response) |
||
118 | throws ServletException |
||
119 | { |
||
120 | |||
121 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
122 | { |
||
123 | return mapping.findForward("error401"); |
||
124 | } |
||
125 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
126 | AbstractDao.getCurrentSession().beginTransaction(); |
||
127 | DaoFactory.getConfigurationGradesEpocaAvaliacaoDaoImpl().delete(f.getId()); |
||
128 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
129 | return mapping.findForward("grades"); |
||
130 | } |
||
131 | |||
132 | public ActionForward deleteStatusEpoca(ActionMapping mapping, |
||
133 | ActionForm form, |
||
134 | HttpServletRequest request, |
||
135 | HttpServletResponse response) |
||
136 | throws ServletException |
||
137 | { |
||
138 | |||
139 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("services")) |
||
140 | { |
||
141 | return mapping.findForward("error401"); |
||
142 | } |
||
143 | ConfigurationGradesForm f = (ConfigurationGradesForm) form; |
||
144 | |||
145 | AbstractDao.getCurrentSession().beginTransaction(); |
||
146 | DaoFactory.getConfigurationGradesStatusEpocaDaoImpl().delete(f.getId()); |
||
147 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
148 | return mapping.findForward("grades"); |
||
149 | } |
||
150 | |||
151 | } |