Rev 2069 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2009 | es | 1 | package pt.estgp.es.exemplos.hibernate.services; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
2069 | es | 4 | import pt.estgp.es.exemplos.hibernate.*; |
5 | import pt.estgp.es.exemplos.hibernate.security.SecurityContextProvider; |
||
2009 | es | 6 | import pt.estgp.es.exemplos.hibernate.security.logic.HasRole; |
7 | import pt.estgp.es.exemplos.hibernate.security.logic.IsAuthenticated; |
||
2069 | es | 8 | import pt.estgp.es.exemplos.hibernate.security.logic.PrintParameterExample; |
2009 | es | 9 | import pt.estgp.es.exemplos.hibernate.security.logic.Transaction; |
2018 | es | 10 | import pt.estgp.es.exemplos.hibernate.web.PaginasServlet; |
2072 | es | 11 | import pt.estgp.es.exemplos.hibernate.web.SeccaoServlet; |
2009 | es | 12 | |
2018 | es | 13 | import javax.servlet.ServletException; |
14 | |||
2009 | es | 15 | public class ServicoPaginas |
16 | { |
||
17 | |||
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); |
||
19 | |||
2069 | es | 20 | @Transaction @IsAuthenticated @HasRole(role = "admin") @PrintParameterExample(paramName = "idPagina") |
2009 | es | 21 | 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) |
22 | { |
||
2018 | es | 23 | try { |
24 | new PaginasServlet().init(); |
||
25 | } catch (ServletException e) { |
||
26 | e.printStackTrace(); |
||
27 | } |
||
2049 | es | 28 | Pagina p = (Pagina) HibernateUtils.getCurrentSession().load(Pagina.class,new 1.5.0/docs/api/java/lang/Long.html">Long(idPagina)); |
2009 | es | 29 | Seccao seccao = new SeccaoImpl(); |
30 | seccao.setTitulo(titulo); |
||
31 | p.getSeccoes().add(seccao); |
||
32 | seccao.setPagina(p); |
||
33 | |||
2049 | es | 34 | |
2009 | es | 35 | HibernateUtils.getCurrentSession().save(seccao); |
36 | } |
||
2018 | es | 37 | |
2072 | es | 38 | @Transaction @IsAuthenticated |
39 | public void criaComponenteTextoService(1.5.0/docs/api/java/lang/String.html">String idSeccao, 1.5.0/docs/api/java/lang/String.html">String texto, 1.5.0/docs/api/java/lang/String.html">String titulo) |
||
40 | { |
||
41 | try { |
||
42 | new SeccaoServlet().init(); |
||
43 | } catch (ServletException e) { |
||
44 | e.printStackTrace(); |
||
45 | } |
||
46 | Seccao seccao = (Seccao) HibernateUtils.getCurrentSession().load(Seccao.class,new 1.5.0/docs/api/java/lang/Long.html">Long(idSeccao)); |
||
47 | |||
48 | long id = seccao.getPagina().getId(); |
||
49 | |||
50 | |||
51 | ConteudoTexto conteudoTexto= new ConteudoTextoImpl(); |
||
52 | conteudoTexto.setTitulo(titulo); |
||
53 | conteudoTexto.setTexto(texto); |
||
54 | |||
55 | seccao.getConteudoTexto().add(conteudoTexto); |
||
56 | conteudoTexto.setSeccao(seccao); |
||
57 | |||
58 | HibernateUtils.getCurrentSession().save(conteudoTexto); |
||
59 | } |
||
60 | |||
2049 | es | 61 | @Transaction @IsAuthenticated @HasRole(role = "admin") |
2009 | es | 62 | public long deleteSeccaoService(1.5.0/docs/api/java/lang/String.html">String idSeccao) |
63 | { |
||
2049 | es | 64 | Seccao seccao = (Seccao) HibernateUtils.getCurrentSession().load(Seccao.class,new 1.5.0/docs/api/java/lang/Long.html">Long(idSeccao)); |
65 | |||
66 | |||
2009 | es | 67 | long id = seccao.getPagina().getId(); |
68 | seccao.getPagina().getSeccoes().remove(seccao); |
||
69 | seccao.setPagina(null); |
||
70 | HibernateUtils.getCurrentSession().delete(seccao); |
||
71 | |||
72 | return id; |
||
2049 | es | 73 | |
2009 | es | 74 | } |
2049 | es | 75 | |
2069 | es | 76 | @Transaction @IsAuthenticated |
2072 | es | 77 | public long deleteConteudoTextoService(1.5.0/docs/api/java/lang/String.html">String idConteudoTexto) { |
78 | ConteudoTexto conteudoTexto = (ConteudoTexto) HibernateUtils.getCurrentSession().load(ConteudoTexto.class, new 1.5.0/docs/api/java/lang/Long.html">Long(idConteudoTexto)); |
||
79 | |||
80 | long id = conteudoTexto.getSeccao().getId(); |
||
81 | conteudoTexto.getSeccao().getConteudoTexto().remove(conteudoTexto); |
||
82 | conteudoTexto.setSeccao(null); |
||
83 | HibernateUtils.getCurrentSession().delete(conteudoTexto); |
||
84 | |||
85 | return id; |
||
86 | } |
||
87 | |||
88 | @Transaction @IsAuthenticated |
||
2069 | es | 89 | public Pagina criaPaginaService(1.5.0/docs/api/java/lang/String.html">String titulo) |
90 | { |
||
91 | 1.5.0/docs/api/java/lang/String.html">String cookie = SecurityContextProvider.getInstance().getSecuritySessionContext().getRequester(); |
||
92 | UserSession session = (UserSession) HibernateUtils.getCurrentSession().load(UserSession.class,cookie); |
||
93 | |||
94 | Pagina p = new PaginaImpl(); |
||
95 | |||
96 | p.setDono(session.getUser()); |
||
97 | p.setNome(titulo); |
||
98 | |||
99 | HibernateUtils.getCurrentSession().save(p); |
||
100 | return p; |
||
101 | } |
||
102 | |||
2009 | es | 103 | } |