1 package ecar.servlet.componente;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.Date;
6 import java.util.Enumeration;
7 import java.util.List;
8 import java.util.StringTokenizer;
9
10 import javax.servlet.ServletException;
11 import javax.servlet.http.HttpServlet;
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14
15 import org.apache.log4j.Logger;
16
17 import comum.util.Pagina;
18 import comum.util.Util;
19
20 import ecar.dao.ItemEstrtIndResulDao;
21 import ecar.dao.ItemEstrtIndResultLocalIettirlDao;
22 import ecar.dao.ItemEstrutFisicoDao;
23 import ecar.pojo.ItemEstrtIndResulIettr;
24 import ecar.pojo.ItemEstrutFisicoIettf;
25 import comum.util.Util;
26
27 public class SalvarIndicadorPorLocalServlet extends HttpServlet{
28
29
30 private static final long serialVersionUID = 8006183415879658218L;
31
32 private Logger logger = Logger.getLogger(this.getClass());
33
34 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
35 logger.info("request :: GET:: Classe:: " + this.getClass().getName() );
36 StringBuilder conteudo = new StringBuilder();
37 conteudo.append("false");
38 logger.error("Acesso nao autorizado:: acesso GET ao servico de salvar indicador por local");
39 responseToHTML( response, conteudo.toString());
40 }
41
42 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
43 logger.info("request :: POST:: Classe:: " + this.getClass().getName() );
44 execute(request,response);
45
46 }
47
48 private void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
49
50 StringBuilder conteudo = new StringBuilder();
51
52 try {
53 Long codIettirLong = Pagina.getParamLong(request, "codIettir");
54 Enumeration a = request.getParameterNames();
55
56
57 ItemEstrtIndResulDao itemEstrtIndResulDao = new ItemEstrtIndResulDao(request);
58 ItemEstrtIndResulIettr itemEstrtIndResulOriginal = (ItemEstrtIndResulIettr) itemEstrtIndResulDao.buscar(ItemEstrtIndResulIettr.class, Long.valueOf(Pagina.getParamStr(request, "codIettir")));
59 List listaQtd = itemEstrtIndResulDao.getListaQuantidadePrevista(request);
60 itemEstrtIndResulOriginal.setDataUltManutencao(new Date());
61 itemEstrtIndResulOriginal.setUsuarioUsuManutencao(((ecar.login.SegurancaECAR)request.getSession().getAttribute("seguranca")).getUsuario());
62 itemEstrtIndResulDao.alterar(itemEstrtIndResulOriginal, listaQtd);
63
64 final ItemEstrtIndResultLocalIettirlDao dao = new ItemEstrtIndResultLocalIettirlDao(request);
65
66
67 dao.deleteBycodIettir( codIettirLong );
68
69 a = request.getParameterNames();
70
71
72
73 while(a.hasMoreElements()){
74 String elemento = (String)a.nextElement();
75
76
77 if ( elemento.startsWith("cmp")){
78
79 StringTokenizer token = new StringTokenizer( elemento, "|", false );
80
81 int cont =0;
82 String[] parts = new String[3];
83 while(token.hasMoreElements()){
84 parts[cont] = (String)token.nextElement();
85 cont++;
86 }
87
88 if ( parts.length==3 && (!parts[2].equalsIgnoreCase("total")) ){
89 String local = parts[1];
90 String exe = parts[2];
91 String vlr = request.getParameter(elemento);
92
93 if ( vlr!=null & (!"".equalsIgnoreCase(vlr))){
94 Long localLong = Long.valueOf(local);
95 Long exeLong = Long.valueOf(exe);
96
97 vlr = Util.formataNumero(vlr);
98
99
100 Double vlrDouble = Double.parseDouble(vlr);
101
102 dao.salvarByLocal( codIettirLong, exeLong, localLong, vlrDouble );
103 }
104 }
105 }
106 }
107
108 conteudo.append("true");
109 responseToHTML(response, conteudo.toString() );
110
111 } catch(Exception e){
112 logger.error(e);
113 e.printStackTrace();
114 StringBuilder responseHTML = new StringBuilder();
115 responseHTML.append("false");
116 responseToHTML(response, responseHTML.toString());
117 }
118 }
119
120 private void responseToHTML ( HttpServletResponse response, String conteudo ) throws IOException {
121 response.setContentType("text/html");
122 PrintWriter writer = response.getWriter();
123 writer.append(conteudo);
124 writer.flush();
125 writer.close();
126 }
127
128
129 }