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; |
01e7dc8b |
9 | import javax.persistence.EntityManager; |
01e7dc8b |
10 | import javax.servlet.http.HttpServletRequest; |
11 | import javax.servlet.http.HttpServletResponse; |
2f5d1c39 |
12 | import org.ufcspa.simdecs.entities.Log; |
13 | import org.ufcspa.simdecs.entities.SessaoUsuario; |
14 | import org.ufcspa.simdecs.entities.TipoEventoLog; |
01e7dc8b |
15 | |
16 | /** |
17 | * |
18 | * @author maroni |
19 | */ |
cff9bc95 |
20 | public class MetodoConfiancaInicial extends BaseComunicacao { |
01e7dc8b |
21 | |
cff9bc95 |
22 | @Override |
23 | protected void executaServico(EntityManager em, HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception { |
01e7dc8b |
24 | response.setContentType("text/html;charset=UTF-8"); |
cff9bc95 |
25 | response.setContentType("text/xml"); |
26 | response.setHeader("Cache-Control", "no-cache"); |
01e7dc8b |
27 | |
cff9bc95 |
28 | long pIdSessao = Long.parseLong(request.getParameter("idsessao")); |
29 | String pNivel = request.getParameter("nivelconfianca"); |
30 | String nivelConfianca; |
2f5d1c39 |
31 | |
cff9bc95 |
32 | if (pNivel.toLowerCase().equals("baixo")) { |
33 | nivelConfianca = Log.CONFIANCA_BAIXA; |
34 | } else if (pNivel.toLowerCase().equals("medio")) { |
35 | nivelConfianca = Log.CONFIANCA_MEDIA; |
36 | } else if (pNivel.toLowerCase().equals("alto")) { |
37 | nivelConfianca = Log.CONFIANCA_ALTA; |
38 | } else { |
39 | return; |
40 | } |
01e7dc8b |
41 | |
01e7dc8b |
42 | |
cff9bc95 |
43 | // Registra Log |
44 | SessaoUsuario sessaoUsuario = em.find(SessaoUsuario.class, pIdSessao); |
45 | if (sessaoUsuario == null) { |
46 | return; |
47 | } |
01e7dc8b |
48 | |
cff9bc95 |
49 | // Logo inicio do caso |
50 | if (!em.getTransaction().isActive()) { |
51 | em.getTransaction().begin(); |
01e7dc8b |
52 | } |
01e7dc8b |
53 | |
cff9bc95 |
54 | Log log = new Log(); |
55 | log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.CONFIANCA_INICIAL)); |
56 | log.setConfianca(nivelConfianca); |
57 | log.setCaso(sessaoUsuario.getCaso()); |
58 | log.setData(new Date()); |
59 | log.setSessaoUsuario(sessaoUsuario); |
01e7dc8b |
60 | |
cff9bc95 |
61 | em.persist(log); |
62 | em.getTransaction().commit(); |
01e7dc8b |
63 | |
cff9bc95 |
64 | out.println("<xml>"); |
65 | |
66 | out.println(" <nivel_confianca registrado=\"sim\" />"); |
67 | out.println(" <resposta_acao_mediador acao=\"sim\" problema=\"PROBLEMA: " + this.getClass() + "\" mensagem=\"MENSAGEM:" + this.getClass() + "\" />"); |
68 | // out.println(" <resposta_acao_mediador acao=\"nao\" />"); |
69 | |
70 | out.println("</xml>"); |
71 | } |
01e7dc8b |
72 | } |