01e7dc8b |
1 | /* |
2 | * To change this template, choose Tools | Templates |
3 | * and open the template in the editor. |
4 | */ |
5 | package org.ufcspa.simdecs.comunicacao; |
6 | |
01e7dc8b |
7 | import java.io.PrintWriter; |
2f5d1c39 |
8 | import java.util.Date; |
56f36e0a |
9 | import java.util.List; |
01e7dc8b |
10 | import javax.persistence.EntityManager; |
01e7dc8b |
11 | import javax.servlet.http.HttpServletRequest; |
12 | import javax.servlet.http.HttpServletResponse; |
2f5d1c39 |
13 | import org.ufcspa.simdecs.entities.Log; |
56f36e0a |
14 | import org.ufcspa.simdecs.entities.Paciente; |
2f5d1c39 |
15 | import org.ufcspa.simdecs.entities.SessaoUsuario; |
16 | import org.ufcspa.simdecs.entities.TipoEventoLog; |
56f36e0a |
17 | import org.ufcspa.simdecs.mediador.NegociacaoPedagogica; |
01e7dc8b |
18 | |
19 | /** |
20 | * |
21 | * @author maroni |
22 | */ |
cff9bc95 |
23 | public class MetodoFimCaso extends BaseComunicacao { |
01e7dc8b |
24 | |
cff9bc95 |
25 | @Override |
26 | protected void executaServico(EntityManager em, HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception { |
01e7dc8b |
27 | response.setContentType("text/html;charset=UTF-8"); |
cff9bc95 |
28 | response.setContentType("text/xml"); |
29 | response.setHeader("Cache-Control", "no-cache"); |
01e7dc8b |
30 | |
cff9bc95 |
31 | long pIdSessao = Long.parseLong(request.getParameter("idsessao")); |
01e7dc8b |
32 | |
cff9bc95 |
33 | // Registra Log |
34 | SessaoUsuario sessaoUsuario = em.find(SessaoUsuario.class, pIdSessao); |
35 | if (sessaoUsuario == null) { |
36 | return; |
37 | } |
2f5d1c39 |
38 | |
cff9bc95 |
39 | if (!em.getTransaction().isActive()) { |
40 | em.getTransaction().begin(); |
41 | } |
2f5d1c39 |
42 | |
cff9bc95 |
43 | Log log = new Log(); |
44 | log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.FIM_CASO)); |
45 | log.setCaso(sessaoUsuario.getCaso()); |
46 | log.setData(new Date()); |
47 | log.setSessaoUsuario(sessaoUsuario); |
2f5d1c39 |
48 | |
cff9bc95 |
49 | em.persist(log); |
50 | em.getTransaction().commit(); |
01e7dc8b |
51 | |
cff9bc95 |
52 | out.println("<xml>"); |
01e7dc8b |
53 | |
56f36e0a |
54 | List<Paciente> pacientes = em.createQuery("From Paciente where caso.id=:pIdCaso") |
55 | .setParameter("pIdCaso", sessaoUsuario.getCaso().getId()) |
56 | .getResultList(); |
57 | |
58 | out.print(" <resposta_final_mediador mensagem=\""); |
59 | // Busca os pacientes |
60 | for(Paciente paciente : pacientes) { |
61 | NegociacaoPedagogica negociacao = new NegociacaoPedagogica(pIdSessao, paciente); |
e1005ea9 |
62 | out.println(clear(negociacao.getMensagemFinal())); |
56f36e0a |
63 | } |
64 | out.print("\" />"); |
65 | |
28042ed9 |
66 | out.println(" <execucao sucesso=\"sim\" />" ); |
cff9bc95 |
67 | out.println("</xml>"); |
01e7dc8b |
68 | } |
01e7dc8b |
69 | } |