Rev 2009 | Rev 2049 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2009 | Rev 2018 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | import pt.estgp.es.exemplos.hibernate.Seccao; |
6 | import pt.estgp.es.exemplos.hibernate.Seccao; |
7 | import pt.estgp.es.exemplos.hibernate.SeccaoImpl; |
7 | import pt.estgp.es.exemplos.hibernate.SeccaoImpl; |
8 | import pt.estgp.es.exemplos.hibernate.security.logic.HasRole; |
8 | import pt.estgp.es.exemplos.hibernate.security.logic.HasRole; |
9 | import pt.estgp.es.exemplos.hibernate.security.logic.IsAuthenticated; |
9 | import pt.estgp.es.exemplos.hibernate.security.logic.IsAuthenticated; |
10 | import pt.estgp.es.exemplos.hibernate.security.logic.Transaction; |
10 | import pt.estgp.es.exemplos.hibernate.security.logic.Transaction; |
- | 11 | import pt.estgp.es.exemplos.hibernate.web.PaginasServlet; |
|
- | 12 | ||
- | 13 | import javax.servlet.ServletException; |
|
11 | 14 | ||
12 | public class ServicoPaginas |
15 | public class ServicoPaginas |
13 | { |
16 | { |
14 | 17 | ||
15 | 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(ServicoPaginas.class); |
18 | 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(ServicoPaginas.class); |
Line 17... | Line 20... | ||
17 | @Transaction |
20 | @Transaction |
18 | @IsAuthenticated |
21 | @IsAuthenticated |
19 | @HasRole(role = "admin") |
22 | @HasRole(role = "admin") |
20 | public void criaSeccaoService(1.5.0/docs/api/java/lang/String.html">String idPagina, 1.5.0/docs/api/java/lang/String.html">String titulo) |
23 | public void criaSeccaoService(1.5.0/docs/api/java/lang/String.html">String idPagina, 1.5.0/docs/api/java/lang/String.html">String titulo) |
21 | { |
24 | { |
- | 25 | try { |
|
- | 26 | new PaginasServlet().init(); |
|
- | 27 | } catch (ServletException e) { |
|
- | 28 | e.printStackTrace(); |
|
- | 29 | } |
|
- | 30 | ||
22 | Pagina p = (Pagina) HibernateUtils.getCurrentSession().load(Pagina.class, new 1.5.0/docs/api/java/lang/Long.html">Long(idPagina)); |
31 | Pagina p = (Pagina) HibernateUtils.getCurrentSession().load(Pagina.class, new 1.5.0/docs/api/java/lang/Long.html">Long(idPagina)); |
23 | Seccao seccao = new SeccaoImpl(); |
32 | Seccao seccao = new SeccaoImpl(); |
24 | seccao.setTitulo(titulo); |
33 | seccao.setTitulo(titulo); |
25 | p.getSeccoes().add(seccao); |
34 | p.getSeccoes().add(seccao); |
26 | seccao.setPagina(p); |
35 | seccao.setPagina(p); |
27 | 36 | ||
28 | HibernateUtils.getCurrentSession().save(seccao); |
37 | HibernateUtils.getCurrentSession().save(seccao); |
29 | } |
38 | } |
- | 39 | ||
- | 40 | @Transaction |
|
- | 41 | @IsAuthenticated |
|
- | 42 | @HasRole(role = "admin") |
|
30 | public long deleteSeccaoService(1.5.0/docs/api/java/lang/String.html">String idSeccao) |
43 | public long deleteSeccaoService(1.5.0/docs/api/java/lang/String.html">String idSeccao) |
31 | { |
44 | { |
32 | Seccao seccao = (Seccao) HibernateUtils.getCurrentSession().load(Seccao.class, new 1.5.0/docs/api/java/lang/Long.html">Long(idSeccao)); |
45 | Seccao seccao = (Seccao) HibernateUtils.getCurrentSession().load(Seccao.class, new 1.5.0/docs/api/java/lang/Long.html">Long(idSeccao)); |
33 | long id = seccao.getPagina().getId(); |
46 | long id = seccao.getPagina().getId(); |
34 | seccao.getPagina().getSeccoes().remove(seccao); |
47 | seccao.getPagina().getSeccoes().remove(seccao); |