Created
March 25, 2016 00:09
-
-
Save fioalpha/2b11f7057f29079ea8a4 to your computer and use it in GitHub Desktop.
Conexao db externo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.gv8.rdias.pesquisa.sincronizacao; | |
import java.io.File; | |
import java.io.FileFilter; | |
import java.io.FileInputStream; | |
import java.io.InputStream; | |
import java.io.PrintWriter; | |
import java.io.StringWriter; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Random; | |
import android.annotation.SuppressLint; | |
import android.content.Context; | |
import android.util.Log; | |
import br.com.gv8.rdias.pesquisa.dao.bd.EntidadeSelecionadaDAO; | |
import br.com.gv8.rdias.pesquisa.dao.bd.RoteiroDAO; | |
import br.com.gv8.rdias.pesquisa.dao.bd.UsuarioDAO; | |
import br.com.gv8.rdias.pesquisa.dao.bd.ValidaSincronizadorDAO; | |
import br.com.gv8.rdias.pesquisa.entity.Entidade; | |
import br.com.gv8.rdias.pesquisa.entity.EntidadeSelecionada; | |
import br.com.gv8.rdias.pesquisa.entity.ItemRespostaCliente; | |
import br.com.gv8.rdias.pesquisa.entity.Pergunta; | |
import br.com.gv8.rdias.pesquisa.entity.PerguntaEntidadePesquisa; | |
import br.com.gv8.rdias.pesquisa.entity.PerguntaProibida; | |
import br.com.gv8.rdias.pesquisa.entity.Pesquisa; | |
import br.com.gv8.rdias.pesquisa.entity.Resposta; | |
import br.com.gv8.rdias.pesquisa.entity.RespostaCliente; | |
import br.com.gv8.rdias.pesquisa.entity.Roteiro; | |
import br.com.gv8.rdias.pesquisa.entity.RoteiroEntidadePesquisa; | |
import br.com.gv8.rdias.pesquisa.entity.Usuario; | |
import br.com.gv8.rdias.pesquisa.exception.RDiasException; | |
import br.com.gv8.rdias.pesquisa.facade.RDiasFacade; | |
import br.com.gv8.rdias.pesquisa.util.DiretorioPesquisaRdias; | |
import br.com.gv8.rdias.pesquisa.util.PesquisaArray; | |
import br.com.gv8.rdias.pesquisa.util.Utilidades; | |
import br.com.gv8.rdias.pesquisa.util.Variaveis; | |
@SuppressLint({ "UseSparseArrays", "DefaultLocale" }) | |
@SuppressWarnings("static-access") | |
public class SincronizadorDAO { | |
private static Variaveis vr = new Variaveis(); | |
static final String JDBC_DRIVER = vr.getJDBC_DRIVER(); | |
static final String DATABASE_URL = vr.getDATABASE_URL(); | |
static final String USER = vr.getUser(); | |
static final String PASSWORD = vr.getPassword(); | |
public static final String nomeLog = vr.getNomeLog(); | |
private static DiretorioPesquisaRdias dir = new DiretorioPesquisaRdias(); | |
private static Connection connection; | |
private List<Roteiro> roteiros; | |
private HashMap<Integer, Entidade> entidades; | |
private HashMap<Integer, Usuario> usuarios; | |
private HashMap<Integer, Resposta> respostas; | |
private HashMap<Integer, Pesquisa> pesquisas; | |
private HashMap<Integer, PerguntaProibida> perguntasProibidas; | |
private HashMap<Integer, Pergunta> perguntas; | |
private HashMap<Integer, RoteiroEntidadePesquisa> roteiroEntidadePesquisas; | |
private HashMap<Integer, PerguntaEntidadePesquisa> perguntasEntidadePesquisa; | |
private HashMap<Integer, RespostaCliente> respostasCliente; | |
private HashMap<Integer, ItemRespostaCliente> itensRespostaCliente; | |
public static ArrayList<RespostaCliente> respostasClientesEnviadas; | |
public static ArrayList<ItemRespostaCliente> itensRespostaClienteEnviadas; | |
public static boolean selecionaLoja = false; | |
private static String usuarioLogin = ""; | |
private static String usuarioSenha = ""; | |
private static String fgRandom = ""; | |
public static Integer statusEnvio = 0; | |
public static Integer idRoteiro = 0; | |
private static Connection conexao; | |
public String getUsuarioLogin() { | |
return usuarioLogin; | |
} | |
public String getUsuarioSenha() { | |
return usuarioSenha; | |
} | |
public static Connection getConection() { | |
try { | |
Class.forName(JDBC_DRIVER); | |
String url = DATABASE_URL; | |
String user = USER; | |
String password = PASSWORD; | |
for (int i = 0; i < 5; i++) { | |
try { | |
connection = DriverManager.getConnection(url, user, password); | |
i = 5; | |
Utilidades.geraLogHomologacao("SincronizadorDAO: Conexão - COM SUCESSO"); | |
} catch (SQLException e) { | |
Utilidades.geraLogHomologacao("SincronizadorDAO: Conexão - SEM SUCESSO SQLException, TENTATIVA: " + i); | |
try { | |
Thread.sleep(15000); | |
} catch (InterruptedException ie) { | |
} | |
} catch (Exception ex) { | |
Utilidades.geraLogHomologacao("SincronizadorDAO: Conexão - SEM SUCESSO Exception, TENTATIVA: " + i); | |
try { | |
Thread.sleep(15000); | |
} catch (InterruptedException ie) { | |
} | |
} | |
} | |
return connection; | |
} catch (ClassNotFoundException e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("SincronizadorDAO: Conexão - CLASS NOT FOUND: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
return null; | |
} | |
} | |
public SincronizadorDAO(List<RespostaCliente> respostasClientes, List<ItemRespostaCliente> itensRespostasClientes, Usuario usuario, Context context) throws RDiasException { | |
ValidaSincronizadorDAO validador = new ValidaSincronizadorDAO(context); | |
selecionaLoja = validador.isSelecionaLoja(); | |
usuarios = new HashMap<Integer, Usuario>(); | |
roteiros = new ArrayList<Roteiro>(); | |
entidades = new HashMap<Integer, Entidade>(); | |
perguntas = new HashMap<Integer, Pergunta>(); | |
pesquisas = new HashMap<Integer, Pesquisa>(); | |
respostas = new HashMap<Integer, Resposta>(); | |
roteiroEntidadePesquisas = new HashMap<Integer, RoteiroEntidadePesquisa>(); | |
respostasCliente = new HashMap<Integer, RespostaCliente>(); | |
itensRespostaCliente = new HashMap<Integer, ItemRespostaCliente>(); | |
perguntasEntidadePesquisa = new HashMap<Integer, PerguntaEntidadePesquisa>(); | |
// pesquisaStatus = new ArrayList<PesquisaUsuarioRoteiroEntidadeStatus>(); | |
perguntasProibidas = new HashMap<Integer, PerguntaProibida>(); | |
Statement statement = null; | |
StringBuilder bd = new StringBuilder(); | |
String inListaRoteiroId = null; | |
String inListaEntidadeId = null; | |
String inListaEntidadeRoteiro = null; | |
PesquisaArray roteiroArray = new PesquisaArray(); | |
roteiroArray.setListaSuja(); | |
PesquisaArray entidadeArray = new PesquisaArray(); | |
Utilidades.geraLogHomologacao("SincronizadorDAO.SincronizadorDAO: sincronizacao foi iniciada"); | |
try { | |
if (respostasClientes.size() > 0 && itensRespostasClientes.size() > 0) { | |
Utilidades.geraLogHomologacao("SincronizadorDAO.SincronizadorDAO: existem pesquisas com o envio pendente"); | |
enviarRespostaCliente(context); | |
} | |
bd.append("insert into sincronizadosme values (SYSDATE,'" + usuarioLogin + "','" + usuarioSenha + "','Iniciou a Sincronização','INICIOU')"); | |
statement = getConection().createStatement(); | |
ResultSet resultSet = statement.executeQuery(bd.toString()); | |
connection.close(); | |
statement.close(); | |
int i = 0; | |
if (selecionaLoja) { | |
bd = new StringBuilder(); | |
bd.append("select c.id_entidade,"); // TABELA ENTIDADE 1 | |
bd.append(" c.no_entidade,"); // TABELA ENTIDADE 2 | |
bd.append(" c.no_endereco,"); // TABELA ENTIDADE 3 | |
bd.append(" c.nr_endereco,"); // TABELA ENTIDADE 4 | |
bd.append(" c.no_bairro,"); // TABELA ENTIDADE 5 | |
bd.append(" c.no_cidade,"); // TABELA ENTIDADE 6 | |
bd.append(" c.no_uf,"); // TABELA ENTIDADE 7 | |
bd.append(" a.id_roteiro,"); // TABELA ROTEIRO 8 | |
bd.append(" b.nr_quota,"); // TABELA ROTEIRO 9 | |
bd.append(" b.no_roteiro,"); // TABELA ROTEIRO 10 | |
bd.append(" b.dt_inicio,"); // TABELA ROTEIRO 11 | |
bd.append(" b.dt_fim,"); // TABELA ROTEIRO 12 | |
bd.append(" replace(replace(b.tx_pesquisa, chr(13), ''), chr(10), '') tx_pesquisa,"); // TABELA ROTEIRO 13 | |
bd.append(" a.id_entidade,"); // TABELA ROTEIRO 14 | |
bd.append(" b.ao_criteriorandom,"); // TABELA ROTEIRO 15 | |
bd.append(" b.ao_lista"); // TABELA ROTEIRO 16 | |
bd.append(" from itroteiro a,"); | |
bd.append(" roteiro b,"); | |
bd.append(" (select a.id_entidade,"); | |
bd.append(" a.ao_ativo,"); | |
bd.append(" max(a.no_entidade) no_entidade,"); | |
bd.append(" max((select max(b.no_endereco)"); | |
bd.append(" from endereco b"); | |
bd.append(" where b.id_entidade = a.id_entidade"); | |
bd.append(" and b.id_tipoendereco = (select id_tipoendereco"); | |
bd.append(" from tipoendereco x"); | |
bd.append(" where x.sg_sistema = 'COMERCIAL'))) no_endereco,"); | |
bd.append(" max((select max(b.nr_endereco)"); | |
bd.append(" from endereco b"); | |
bd.append(" where b.id_entidade = a.id_entidade"); | |
bd.append(" and b.id_tipoendereco = (select id_tipoendereco"); | |
bd.append(" from tipoendereco x"); | |
bd.append(" where x.sg_sistema = 'COMERCIAL'))) nr_endereco,"); | |
bd.append(" max((select max(b.no_bairro)"); | |
bd.append(" from endereco b"); | |
bd.append(" where b.id_entidade = a.id_entidade"); | |
bd.append(" and b.id_tipoendereco = (select id_tipoendereco"); | |
bd.append(" from tipoendereco x"); | |
bd.append(" where x.sg_sistema = 'COMERCIAL'))) no_bairro,"); | |
bd.append(" max((select max(b.no_cidade)"); | |
bd.append(" from endereco b"); | |
bd.append(" where b.id_entidade = a.id_entidade"); | |
bd.append(" and b.id_tipoendereco = (select id_tipoendereco"); | |
bd.append(" from tipoendereco x"); | |
bd.append(" where x.sg_sistema = 'COMERCIAL'))) no_cidade,"); | |
bd.append(" max((select max(b.no_uf)"); | |
bd.append(" from endereco b"); | |
bd.append(" where b.id_entidade = a.id_entidade"); | |
bd.append(" and b.id_tipoendereco = (select id_tipoendereco"); | |
bd.append(" from tipoendereco x"); | |
bd.append(" where x.sg_sistema = 'COMERCIAL'))) no_uf"); | |
bd.append(" from entidade a,"); | |
bd.append(" itroteiro c,"); | |
bd.append(" roteiro d"); | |
bd.append(" where d.id_roteiro = c.id_roteiro"); | |
bd.append(" and a.id_entidade = c.id_entidade"); | |
bd.append(" and sysdate between d.dt_inicio and d.dt_fim"); | |
bd.append(" and d.ao_situacao = 'A'"); | |
bd.append(" and c.id_pesq is not null"); | |
bd.append(" and a.ao_ativo = 'A'"); | |
bd.append(" and c.id_entidadeusu = " + Utilidades.getMyPrefs(context).getValue("idUsuario", null)); | |
bd.append(" group by a.id_entidade,"); | |
bd.append(" a.ao_ativo"); | |
bd.append(" order by id_entidade) c"); | |
bd.append(" where sysdate between b.dt_inicio and b.dt_fim"); | |
bd.append(" and b.ao_situacao = 'A'"); | |
bd.append(" and b.id_roteiro = a.id_roteiro"); | |
bd.append(" and a.id_pesq is not null"); | |
bd.append(" and c.id_entidade = a.id_entidade"); | |
bd.append(" and c.ao_ativo = 'A'"); | |
bd.append(" and a.id_entidadeusu = " + Utilidades.getMyPrefs(context).getValue("idUsuario", null)); | |
bd.append(" group by c.id_entidade, c.no_entidade, c.no_endereco, c.nr_endereco, c.no_bairro, c.no_cidade, c.no_uf, a.id_roteiro, a.id_entidade, b.id_roteiro, b.nr_quota, b.dt_inicio, b.dt_fim, tx_pesquisa, b.no_roteiro, b.ao_criteriorandom, b.ao_lista"); | |
bd.append(" order by a.id_roteiro, a.id_entidade, b.id_roteiro, b.nr_quota, b.dt_inicio, b.dt_fim, tx_pesquisa, b.no_roteiro"); | |
statement = getConection().createStatement(); | |
resultSet = statement.executeQuery(bd.toString()); | |
while (resultSet.next()) { | |
try { | |
Entidade entidade = new Entidade(); | |
entidade.setIdEntidade(resultSet.getInt(1)); | |
entidade.setNome(resultSet.getString(2)); | |
entidade.setEndereco(resultSet.getString(3)); | |
entidade.setNumero(resultSet.getString(4)); | |
entidade.setBairro(resultSet.getString(5)); | |
entidade.setCidade(resultSet.getString(6)); | |
entidade.setUf(resultSet.getString(7)); | |
entidade.setPesquisa(new Pesquisa()); | |
if (!entidades.containsKey(entidade.getIdEntidade())) { | |
entidades.put(entidade.getIdEntidade(), entidade); | |
} | |
i++; | |
Roteiro roteiro = new Roteiro(); | |
roteiro.setId(i); | |
roteiro.setIdRoteiro(resultSet.getInt(8)); | |
roteiro.setQuota(resultSet.getInt(9)); | |
roteiro.setNome(resultSet.getString(10)); | |
roteiro.setDataInicial(resultSet.getDate(11)); | |
roteiro.setDataFinal(resultSet.getDate(12)); | |
roteiro.setTxPesquisa(resultSet.getString(13)); | |
roteiro.setEntidade(entidades.get(resultSet.getInt(14))); | |
SincronizadorDAO.setFgRandom(resultSet.getString(15)); | |
roteiro.setUsuario(usuario); | |
roteiro.setAoLista(resultSet.getString(16)); | |
roteiros.add(roteiro); | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Sincronizar Entidade: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
} | |
} | |
connection.close(); | |
statement.close(); | |
if (i == 0) { | |
Utilidades.getMyPrefs(context).setValue("semroteiro", "SIM"); | |
Utilidades.getMyPrefs(context).save(); | |
throw new RuntimeException("Sem Roteiro"); | |
} | |
} else { | |
RoteiroDAO roteiroDAO = new RoteiroDAO(context); | |
roteiroArray.setListaSuja(); | |
for (Roteiro roteiro : roteiroDAO.consultarTodos()) { | |
idRoteiro = roteiro.getIdRoteiro(); | |
try { | |
roteiroArray.setNovoItem(roteiro.getIdRoteiro()); | |
} catch (Exception e) { | |
roteiroArray.setNovoItem(roteiro.getIdRoteiro()); | |
} | |
} | |
inListaRoteiroId = roteiroArray.arrayToString(); | |
EntidadeSelecionadaDAO selecionadaDAO = new EntidadeSelecionadaDAO(context); | |
entidadeArray.setListaSuja(); | |
for (EntidadeSelecionada selecionada : selecionadaDAO.consultaEntidadeSelecionada(idRoteiro)) { | |
try { | |
entidadeArray.setNovoItem(selecionada.getIdEntidade()); | |
} catch (Exception e) { | |
entidadeArray.setNovoItem(selecionada.getIdEntidade()); | |
} | |
} | |
inListaEntidadeRoteiro = entidadeArray.arrayToString(); | |
if (inListaRoteiroId.length() > 0) { | |
bd = new StringBuilder(); | |
bd.append("select id_pergunta,"); | |
bd.append(" no_pergunta,"); | |
bd.append(" id_pesq,"); | |
bd.append(" id_perguntaprox,"); | |
bd.append(" rownum nr_sequencia,"); | |
bd.append(" ao_tipocampo,"); | |
bd.append(" NR_TAMANHOCAMPO,"); | |
bd.append(" NR_DECIMAISCAMPO,"); | |
bd.append(" AO_PERMITENAOOP,"); | |
bd.append(" tx_comofazer,"); | |
bd.append(" tx_faixaini_ant,"); | |
bd.append(" tx_faixafim_ant,"); | |
bd.append(" nr_tamanhominimo,"); | |
bd.append(" ao_permitefoto,"); | |
bd.append(" id_roteiro,"); | |
bd.append(" id_entidade"); | |
bd.append(" from (select id_pergunta,"); | |
bd.append(" no_pergunta,"); | |
bd.append(" id_pesq,"); | |
bd.append(" id_perguntaprox,"); | |
bd.append(" nr_sequencia,"); | |
bd.append(" ao_tipocampo,"); | |
bd.append(" NR_TAMANHOCAMPO,"); | |
bd.append(" NR_DECIMAISCAMPO,"); | |
bd.append(" AO_PERMITENAOOP,"); | |
bd.append(" tx_comofazer,"); | |
bd.append(" tx_faixaini_ant,"); | |
bd.append(" tx_faixafim_ant,"); | |
bd.append(" nr_tamanhominimo,"); | |
bd.append(" ao_permitefoto,"); | |
bd.append(" id_roteiro,"); | |
bd.append(" id_entidade"); | |
bd.append(" from (select a.id_pergunta,"); | |
bd.append(" replace(replace(a.no_pergunta, chr(13), ''), chr(10), '') no_pergunta,"); | |
bd.append(" a.id_pesq,"); | |
bd.append(" a.id_perguntaprox,"); | |
bd.append(" a.nr_sequencia,"); | |
bd.append(" (case"); | |
bd.append(" when a.ao_tipocampo = 'O' and nvl(a.ao_multiplo, 'N') = 'S' then 1"); // Check | |
bd.append(" when a.ao_tipocampo = 'O' and nvl(a.ao_multiplo, 'N') = 'N' then 2"); // Radio | |
bd.append(" when a.ao_tipocampo = 'A' then 3"); // Texto | |
bd.append(" when a.ao_tipocampo = 'N' and nr_decimaiscampo = 0 then 4"); // Numérico inteiro | |
bd.append(" when a.ao_tipocampo = 'N' and nr_decimaiscampo > 0 then 5"); // Numérico decimal | |
bd.append(" when a.ao_tipocampo = 'D' then 6"); // Data | |
bd.append(" else -1"); | |
bd.append(" end) ao_tipocampo,"); | |
bd.append(" NR_TAMANHOCAMPO,"); | |
bd.append(" NR_DECIMAISCAMPO,"); | |
bd.append(" nvl(AO_PERMITENAOOP, 'N') AO_PERMITENAOOP,"); | |
bd.append(" replace(replace(TX_COMOFAZER, chr(13), ''), chr(10), '') tx_comofazer,"); | |
bd.append(" a.tx_faixaini_ant,"); | |
bd.append(" a.tx_faixafim_ant,"); | |
bd.append(" a.vl_preco,"); | |
bd.append(" a.nr_tamanhominimo nr_tamanhominimo,"); | |
bd.append(" a.ao_permitefoto ao_permitefoto,"); | |
bd.append(" c.id_roteiro,"); | |
bd.append(" e.id_entidade"); | |
bd.append(" from pergunta a,"); | |
bd.append(" roteiro b,"); | |
bd.append(" itroteiro c,"); | |
bd.append(" entidadexpergunta d,"); | |
bd.append(" entidadexpesq c1,"); | |
bd.append(" entidade e"); | |
bd.append(" where a.id_pesq = c.id_pesq"); | |
bd.append(" and sysdate between b.dt_inicio and b.dt_fim"); | |
bd.append(" and b.ao_situacao = 'A'"); | |
bd.append(" and c.id_roteiro = b.id_roteiro"); | |
bd.append(" and c.id_entidadeusu = " + Utilidades.getMyPrefs(context).getValue("idUsuario", null)); | |
bd.append(" and c.id_roteiro in (" + inListaRoteiroId + ")"); | |
bd.append(" and c.id_entidade in (" + inListaEntidadeRoteiro + ")"); | |
bd.append(" and d.id_pergunta = a.id_pergunta"); | |
bd.append(" and d.id_entidade = b.id_genesis"); | |
bd.append(" and c1.id_pesq = c.id_pesq"); | |
bd.append(" and c1.id_entidade = b.id_genesis"); | |
bd.append(" and not exists (select 1"); | |
bd.append(" from entidadexperguntapro x1"); | |
bd.append(" where x1.id_pergunta = a.id_pergunta"); | |
bd.append(" and x1.id_entidade = c.id_entidade)"); | |
bd.append(" AND (B.ID_TIPOPERGUNTA IS NULL OR exists"); | |
bd.append(" (select 1"); | |
bd.append(" from perguntaxtipopergunta pt"); | |
bd.append(" where pt.id_pergunta = a.id_pergunta"); | |
bd.append(" and pt.ID_TIPOPERGUNTA = B.ID_TIPOPERGUNTA))"); | |
bd.append(" and e.id_entidade = c.id_entidade"); | |
bd.append(" and e.ao_ativo = 'A')"); | |
bd.append(" group by id_pergunta, no_pergunta, id_pesq, id_perguntaprox, nr_sequencia, ao_tipocampo, NR_TAMANHOCAMPO, NR_DECIMAISCAMPO, AO_PERMITENAOOP, tx_comofazer, tx_faixaini_ant, tx_faixafim_ant, nr_tamanhominimo, ao_permitefoto, id_roteiro, id_entidade"); | |
bd.append(" order by id_pesq, nr_sequencia, id_pergunta) res1"); | |
statement = getConection().createStatement(); | |
resultSet = statement.executeQuery(bd.toString()); | |
i = 0; | |
while (resultSet.next()) { | |
try { | |
Pergunta pergunta = new Pergunta(); | |
pergunta.setIdPergunta(resultSet.getInt(1)); | |
pergunta.setNome(resultSet.getString(2)); | |
pergunta.setIdPesquisa(resultSet.getInt(3)); | |
pergunta.setIdProxima(resultSet.getInt(4)); | |
pergunta.setSequencia(resultSet.getInt(5)); | |
pergunta.setTipo(resultSet.getString(6)); | |
pergunta.setTamanho(resultSet.getInt(7)); | |
pergunta.setDecimal(resultSet.getDouble(8)); | |
pergunta.setPermiteNaoOpinou(resultSet.getString(9)); | |
pergunta.setComoFazer(resultSet.getString(10)); | |
pergunta.setFaixaInicial(resultSet.getString(11)); | |
pergunta.setFaixaFinal(resultSet.getString(12)); | |
pergunta.setTamanhoMinimo(resultSet.getInt(13)); | |
pergunta.setPermiteFoto(resultSet.getString(14)); | |
pergunta.setIdRoteiro(resultSet.getInt(15)); | |
pergunta.setIdEntidade(resultSet.getInt(16)); | |
perguntas.put(perguntas.size() + 1, pergunta); | |
entidadeArray.setNovoItem(pergunta.getIdEntidade()); | |
i++; | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Sincronizar Pergunta: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
} | |
} | |
inListaEntidadeId = entidadeArray.arrayToString(); | |
connection.close(); | |
statement.close(); | |
bd = new StringBuilder(); | |
bd.append("select res.id_pergunta,"); | |
bd.append(" res.id_resposta,"); | |
bd.append(" res.no_resposta,"); | |
bd.append(" res.id_perguntaprox,"); | |
bd.append(" res.ao_resposta,"); | |
// bd.append(" res.tx_criterio,"); | |
bd.append(" res.ao_foto,"); | |
// bd.append(" res.nr_sequencia,"); | |
// bd.append(" res.id_pesq,"); | |
// bd.append(" res.id_itacionamento,"); | |
bd.append(" (case when '" + SincronizadorDAO.getFgRandom() + "' = 'S' then upper(dbms_random.string('A',10)) else res.ao_resposta end) nr_sequencia"); | |
bd.append(" from (select a1.id_pergunta,"); | |
bd.append(" a1.id_resposta,"); | |
bd.append(" replace(replace(nvl(TX_CRITERIO, a1.no_resposta), chr(13), ''), chr(10), '') no_resposta,"); | |
bd.append(" a1.id_perguntaprox,"); | |
bd.append(" replace(replace(a1.ao_resposta, chr(13), ''), chr(10), '') ao_resposta,"); | |
bd.append(" replace(replace(nvl(TX_CRITERIO, a1.no_resposta), chr(13), ''), chr(10), '') tx_criterio,"); | |
bd.append(" a1.ao_foto,"); | |
bd.append(" nr_sequencia,"); | |
bd.append(" b1.id_pesq,"); | |
bd.append(" (select max(itaci.id_itacionamento)"); | |
bd.append(" from itacionamento itaci,"); | |
bd.append(" acionamento aci"); | |
bd.append(" where itaci.id_resposta = a1.id_resposta"); | |
bd.append(" and aci.id_acionamento = itaci.id_acionamento"); | |
bd.append(" and exists (select 1"); | |
bd.append(" from pergunta perg"); | |
bd.append(" where perg.id_pergunta = a1.id_pergunta"); | |
bd.append(" and perg.ao_permitefoto = 'S')) id_itacionamento"); | |
bd.append(" from resposta a1,"); | |
bd.append(" pergunta b1"); | |
bd.append(" where a1.id_pergunta = b1.id_pergunta"); | |
bd.append(" and b1.id_pergunta in (select a.id_pergunta"); | |
bd.append(" from pergunta a,"); | |
bd.append(" roteiro b,"); | |
bd.append(" itroteiro c,"); | |
bd.append(" entidadexpergunta d,"); | |
bd.append(" entidadexpesq c1,"); | |
bd.append(" entidade e"); | |
bd.append(" where a.id_pesq = c.id_pesq"); | |
bd.append(" and sysdate between b.dt_inicio and b.dt_fim"); | |
bd.append(" and b.ao_situacao = 'A'"); | |
bd.append(" and c.id_roteiro = b.id_roteiro"); | |
bd.append(" and c.id_entidadeusu = " + Utilidades.getMyPrefs(context).getValue("idUsuario", null)); | |
bd.append(" and c.id_roteiro in (" + inListaRoteiroId + ")"); | |
bd.append(" and c.id_entidade in (" + inListaEntidadeRoteiro + ")"); | |
bd.append(" and d.id_pergunta = a.id_pergunta"); | |
bd.append(" and d.id_entidade = b.id_genesis"); | |
bd.append(" and c1.id_pesq = c.id_pesq"); | |
bd.append(" and c1.id_entidade = b.id_genesis"); | |
bd.append(" and not exists (select 1"); | |
bd.append(" from entidadexperguntapro x1"); | |
bd.append(" where x1.id_pergunta = a.id_pergunta"); | |
bd.append(" and x1.id_entidade = c.id_entidade)"); | |
bd.append(" AND (B.ID_TIPOPERGUNTA IS NULL OR exists"); | |
bd.append(" (select 1"); | |
bd.append(" from perguntaxtipopergunta pt"); | |
bd.append(" where pt.id_pergunta = a.id_pergunta"); | |
bd.append(" and pt.ID_TIPOPERGUNTA = B.ID_TIPOPERGUNTA))"); | |
bd.append(" and e.id_entidade = c.id_entidade"); | |
bd.append(" and e.ao_ativo = 'A'"); | |
bd.append(" group by a.id_pergunta)) res"); | |
bd.append(" order by res.id_pergunta, res.nr_sequencia, res.id_resposta, res.id_pesq"); | |
statement = getConection().createStatement(); | |
Log.e("QUery_Consulta", bd.toString()); | |
resultSet = statement.executeQuery(bd.toString()); | |
i = 0; | |
while (resultSet.next()) { | |
try { | |
Resposta resposta = new Resposta(); | |
resposta.setIdPergunta(resultSet.getInt(1)); | |
resposta.setIdResposta(resultSet.getInt(2)); | |
resposta.setNome(resultSet.getString(3)); | |
resposta.setIdProxima(resultSet.getInt(4)); | |
resposta.setAoResposta(resultSet.getString(5)); | |
resposta.setAoFoto(resultSet.getString(6)); | |
resposta.setNrSequencia(resultSet.getString(7)); | |
if (!respostas.containsKey(resposta.getIdResposta())) { | |
respostas.put(resposta.getIdResposta(), resposta); | |
} | |
i++; | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Sincronizar Resposta: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
} | |
} | |
connection.close(); | |
statement.close(); | |
bd = new StringBuilder(); | |
bd.append("select a1.id_pesq,"); | |
bd.append(" replace(replace(a1.no_pesq, chr(13), ''), chr(10), '') no_pesq,"); | |
bd.append(" replace(replace(a1.tx_pergunta, chr(13), ''), chr(10), '') tx_pergunta,"); | |
bd.append(" a1.ao_redundancia"); | |
bd.append(" from itroteiro b,"); | |
bd.append(" roteiro a,"); | |
bd.append(" pesq a1,"); | |
bd.append(" entidadexpesq c"); | |
bd.append(" where sysdate between a.dt_inicio and a.dt_fim"); | |
bd.append(" and a.ao_situacao = 'A'"); | |
bd.append(" and b.id_roteiro in (" + inListaRoteiroId + ")"); | |
bd.append(" and b.id_entidade in (" + inListaEntidadeRoteiro + ")"); | |
bd.append(" and b.id_roteiro = a.id_roteiro"); | |
bd.append(" and a1.id_pesq = b.id_pesq"); | |
bd.append(" and c.id_pesq = b.id_pesq"); | |
bd.append(" and c.id_entidade = a.id_genesis"); | |
bd.append(" and exists (select 1"); | |
bd.append(" from pergunta perg"); | |
bd.append(" where perg.id_pesq = b.id_pesq"); | |
bd.append(" and EXISTS (SELECT 1"); | |
bd.append(" FROM ENTIDADEXPERGUNTA XX"); | |
bd.append(" WHERE XX.ID_ENTIDADE = a.id_genesis"); | |
bd.append(" AND XX.ID_PERGUNTA = perg.ID_PERGUNTA)"); | |
bd.append(" AND (A.ID_TIPOPERGUNTA IS NULL OR exists"); | |
bd.append(" (select 1"); | |
bd.append(" from perguntaxtipopergunta pt"); | |
bd.append(" where pt.id_pergunta = perg.id_pergunta"); | |
bd.append(" and pt.ID_TIPOPERGUNTA = A.ID_TIPOPERGUNTA)))"); | |
bd.append(" order by id_pesq"); | |
statement = getConection().createStatement(); | |
resultSet = statement.executeQuery(bd.toString()); | |
i = 0; | |
while (resultSet.next()) { | |
try { | |
Pesquisa pesquisa = new Pesquisa(); | |
pesquisa.setIdPesquisa(resultSet.getInt(1)); | |
pesquisa.setNome(resultSet.getString(2)); | |
pesquisa.setTxPergunta(resultSet.getString(3)); | |
pesquisa.setRedundancia(resultSet.getString(4)); | |
if (!pesquisas.containsKey(pesquisa.getIdPesquisa())) { | |
pesquisas.put(pesquisa.getIdPesquisa(), pesquisa); | |
} | |
i++; | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Sincronizar Pesquisa: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
} | |
} | |
bd = new StringBuilder(); | |
bd.append("select * "); | |
bd.append(" from entidadexperguntapro e"); | |
bd.append(" where e.id_entidade in (" + inListaEntidadeId + ")"); | |
statement = getConection().createStatement(); | |
resultSet = statement.executeQuery(bd.toString()); | |
i = 0; | |
while (resultSet.next()) { | |
try { | |
PerguntaProibida perguntaProibida = new PerguntaProibida(); | |
perguntaProibida.setIdPerguntaProibida(resultSet.getInt(1)); | |
perguntaProibida.setIdEntidade(resultSet.getInt(2)); | |
perguntaProibida.setIdPergunta(resultSet.getInt(3)); | |
if (!perguntasProibidas.containsKey(perguntaProibida.getIdPerguntaProibida())) { | |
perguntasProibidas.put(perguntaProibida.getIdPerguntaProibida(), perguntaProibida); | |
} | |
i++; | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Sincronizar Pesquisa: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
} | |
} | |
connection.close(); | |
statement.close(); | |
} | |
Utilidades.getMyPrefs(context).setValue("erro", "NAO"); | |
Utilidades.getMyPrefs(context).save(); | |
ValidaSincronizadorDAO validaSincronizador = new ValidaSincronizadorDAO(context); | |
validaSincronizador.alterar("ENTIDADE"); | |
} | |
// TRY PRINCIPAL | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Sincronizar: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
Utilidades.getMyPrefs(context).setValue("erro", "SIM"); | |
Utilidades.getMyPrefs(context).save(); | |
e.printStackTrace(); | |
throw new RDiasException(e); | |
} finally { | |
try { | |
if (connection != null) { | |
connection.close(); | |
} | |
if (statement != null) { | |
statement.close(); | |
} | |
} catch (SQLException e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Sincronização: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
throw new RDiasException(e); | |
} | |
} | |
} | |
public static Usuario logarUsuario(String login, String senha, Context contexto) throws RDiasException { | |
Statement statement = null; | |
UsuarioDAO usuarioDAO = new UsuarioDAO(contexto); | |
Usuario usuario = null; | |
StringBuilder bd = new StringBuilder(); | |
usuarioLogin = login; | |
usuarioSenha = senha; | |
if (usuarioDAO.existeUsuario(login, Utilidades.getSenhaCriptografada(senha))) { | |
Utilidades.geraLogHomologacao("SincronizadorDAO: usuario informado JA existe na base, sera utilizado autenticacao LOCAL: " + usuarioLogin); | |
usuario = usuarioDAO.consultarTodosPorCodigoUsuario(usuarioDAO.getIdUsuario(login, Utilidades.getSenhaCriptografada(senha))); | |
} else { | |
Utilidades.geraLogHomologacao("SincronizadorDAO: usuario informado NAO existe na base, sera utilizado autenticacao EXTERNA: " + usuarioLogin); | |
try { | |
bd.append("select a.id_entidade, "); | |
bd.append(" campo_pck.tx_campo('USUARIO','NO_LOGIN','I',null,a.id_entidade) no_login,"); | |
bd.append(" campo_pck.tx_campo('USUARIO','NO_SENHA','I',null,a.id_entidade) no_senha "); | |
bd.append(" from entidade a "); | |
bd.append(" where a.id_nivel=22 "); | |
bd.append(" and a.ao_ativo='A' "); | |
bd.append(" and campo_pck.tx_campo('USUARIO','NO_LOGIN','I',null,a.id_entidade)= '" + login + "'"); | |
bd.append(" and campo_pck.tx_campo('USUARIO','NO_SENHA','I',null,a.id_entidade)= '" + senha + "'"); | |
bd.append(" order by id_entidade"); | |
statement = getConection().createStatement(); | |
ResultSet resultSet = statement.executeQuery(bd.toString()); | |
while (resultSet.next()) { | |
usuario = new Usuario(); | |
usuario.setIdUsuario(resultSet.getInt(1)); | |
usuario.setLogin(resultSet.getString(2)); | |
// usuario.setPassword(resultSet.getString(3)); // Sem criptografia | |
usuario.setPassword(Utilidades.getSenhaCriptografada(resultSet.getString(3))); // Com criptografia | |
usuarioDAO.inserir(usuario); | |
} | |
if (usuarioDAO.existeUsuario(login, Utilidades.getSenhaCriptografada(senha))) { | |
Utilidades.geraLogHomologacao("SincronizadorDAO: usuario inserido na base local com sucesso: " + usuarioLogin); | |
} else { | |
Utilidades.geraLogHomologacao("SincronizadorDAO: usuario NAO FOI inserido na base local: usuario = " + usuarioLogin + ", senha = " + usuarioSenha); | |
} | |
connection.close(); | |
statement.close(); | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Logar Usuário: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
throw new RDiasException(e); | |
} finally { | |
try { | |
if (connection != null) { | |
connection.close(); | |
} | |
if (statement != null) { | |
statement.close(); | |
} | |
} catch (SQLException e) { | |
throw new RDiasException(e); | |
} | |
} | |
} | |
usuarioDAO.usuarioLogado(login); | |
return usuario; | |
} | |
public static void enviarRespostaCliente(Context context) throws RDiasException, SQLException { | |
RDiasFacade facade = new RDiasFacade(context); | |
Statement statement = null; | |
List<RespostaCliente> respostasClientes = facade.consultarTudoRespostaClienteNaoEnviada(); | |
try { | |
if (!Utilidades.isNullOrEmpty(respostasClientes)) { | |
conexao = getConection(); | |
for (RespostaCliente r : respostasClientes) { | |
StringBuilder bd = new StringBuilder(); | |
bd.append("INSERT INTO RESPCLIMOBILE_TRIAGEM ("); | |
bd.append(" CHAVE_RESPOSTA,"); | |
bd.append(" ID_ENTIDADE,"); | |
bd.append(" ID_ROTEIRO,"); | |
bd.append(" ID_PESQ,"); | |
bd.append(" ID_ENTIDADEUSU,"); | |
bd.append(" DT_GERACAO,"); | |
bd.append(" DT_LOG,"); | |
bd.append(" AO_COMPLETO,"); | |
bd.append(" ID_IMEI,"); | |
bd.append(" NO_LOGIN,"); | |
bd.append(" NO_SENHA) "); | |
bd.append("VALUES ("); | |
bd.append("'" + r.getChaveResposta() + "',"); | |
bd.append(r.getIdEntidade() + ","); | |
bd.append(r.getIdRoteiro() + ","); | |
bd.append(r.getIdPesquisa() + ","); | |
bd.append(r.getIdUsuario() + ","); | |
bd.append("to_timestamp('" + Utilidades.getDataHoraFormatadaSegundos(r.getDtGeracao()) + "', 'DD/MM/YYYY HH24:MI:SS'),"); | |
bd.append("to_date('" + Utilidades.getDataHoraFormatadaSegundos(r.getDtLog()) + "', 'DD/MM/YYYY HH24:MI:SS'),"); | |
bd.append("'N',"); | |
bd.append("'" + r.getIdImei() + "',"); | |
bd.append("'" + r.getUsuarioLogin() + "',"); | |
bd.append("'" + r.getUsuarioSenha() + "')"); | |
statement = conexao.createStatement(); | |
try { | |
statement.executeUpdate(bd.toString()); | |
} catch (Exception e) { | |
statement.close(); | |
Utilidades.getMyPrefs(context).setValue("erro", "SIM"); | |
Utilidades.getMyPrefs(context).save(); | |
} finally { | |
statement.close(); | |
} | |
statement.close(); | |
List<ItemRespostaCliente> itensRespostasClientes = facade.consultarItemRespostaClienteChave(r.getChaveResposta()); | |
if (!Utilidades.isNullOrEmpty(itensRespostasClientes)) { | |
for (ItemRespostaCliente i : itensRespostasClientes) { | |
bd = new StringBuilder(); | |
bd.append("INSERT INTO ITRESPCLIMOBILE_TRIAGEM ("); | |
bd.append(" ID_ITRESPCLI_TRIAGEM,"); | |
bd.append(" CHAVE_RESPOSTA,"); | |
bd.append(" ID_RESPOSTA,"); | |
bd.append(" DT_GERACAO,"); | |
bd.append(" DT_LOG,"); | |
bd.append(" ID_IMEI,"); | |
bd.append(" TX_OBS,"); | |
bd.append(" AO_VINCULADO,"); | |
bd.append(" NR_SEQUENCIAFOTO,"); | |
bd.append(" NO_LOGIN) "); | |
bd.append("VALUES ("); | |
bd.append(i.getIdItemRespostaCliente() + ","); | |
bd.append("'" + i.getChaveResposta() + "',"); | |
bd.append(i.getIdResposta() + ","); | |
bd.append("to_timestamp('" + Utilidades.getDataHoraFormatadaSegundos(i.getDtGeracao()) + "', 'DD/MM/YYYY HH24:MI:SS'),"); | |
bd.append("to_date('" + Utilidades.getDataHoraFormatadaSegundos(i.getDtLog()) + "', 'DD/MM/YYYY HH24:MI:SS'),"); | |
bd.append("'" + i.getIdImei() + "',"); | |
bd.append("'" + i.getTxObservacao() + "',"); | |
bd.append("'" + i.getAoVinculado() + "',"); | |
bd.append(i.getIdSequenciaFotoFinal() + ","); | |
bd.append("'" + i.getTxLogin() + "')"); | |
conexao = getConection(); | |
statement = conexao.createStatement(); | |
try { | |
statement.executeUpdate(bd.toString()); | |
} catch (Exception e) { | |
statement.close(); | |
Utilidades.getMyPrefs(context).setValue("erro", "SIM"); | |
Utilidades.getMyPrefs(context).save(); | |
} finally { | |
statement.close(); | |
} | |
statement.close(); | |
} | |
} | |
try { | |
executeMultipartPostImagem(dir.getTriagemDestinoImagem()); | |
executeMultipartPostVoz(dir.getTriagemDestinoAudio()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
bd = new StringBuilder(); | |
bd.append("UPDATE RESPCLIMOBILE_TRIAGEM SET AO_COMPLETO = 'S' WHERE CHAVE_RESPOSTA = '" + r.getChaveResposta() + "'"); | |
conexao = getConection(); | |
statement = conexao.createStatement(); | |
try { | |
statement.executeUpdate(bd.toString()); | |
} catch (Exception e) { | |
statement.close(); | |
Utilidades.getMyPrefs(context).setValue("erro", "SIM"); | |
Utilidades.getMyPrefs(context).save(); | |
} finally { | |
statement.close(); | |
facade.respostaEnviada(r.getChaveResposta()); | |
} | |
} | |
} | |
} finally { | |
Utilidades.getMyPrefs(context).setValue("erro", "NAO"); | |
Utilidades.getMyPrefs(context).save(); | |
} | |
} | |
public static void executeMultipartPostVoz(String caminhoArquivos) throws Exception { | |
try { | |
File diretorioCartao = new File(caminhoArquivos); | |
if (diretorioCartao.exists()) { | |
File[] files = diretorioCartao.listFiles(new FileFilter() { | |
public boolean accept(File pathname) { | |
return pathname.getName().toLowerCase().endsWith(".mp3"); | |
} | |
}); | |
for (int i = 0; i < files.length; i++) { | |
File arquivoEnviar = new File(dir.getTriagemDestinoAudio() + "/" + files[i].getName()); | |
Utilidades.geraLogHomologacao("SincronizadorDAO.executeMultipartPostVoz: arquivo de audio sera enviado: " + dir.getTriagemDestinoAudio() + "/" + files[i].getName()); | |
String nomeArquivo[] = null; | |
Statement statement = null; | |
try { | |
StringBuilder bd = new StringBuilder(); | |
nomeArquivo = files[i].getName().split("_"); | |
bd.append("INSERT INTO DOCUMENTO_TRIAGEM (CHAVE_RESPOSTA, NO_ARQUIVO, MIME_TYPE, NR_TAMANHO_ARQUIVO, TX_CHARSET, TX_TIPO_ARQUIVO, BLB_ARQUIVO) values (?, ?, ?, ?, ?, ?, ?)"); | |
PreparedStatement ps = getConection().prepareStatement(bd.toString()); | |
InputStream in = new FileInputStream(arquivoEnviar); | |
ps.setString(1, nomeArquivo[6]); // CHAVE_RESPOSTA | |
ps.setString(2, arquivoEnviar.getName()); // NO_ARQUIVO | |
ps.setString(3, "AUDIO"); // MIME_TYPE | |
ps.setLong(4, files[i].length()); // NR_TAMANHO_ARQUIVO | |
ps.setString(5, "WE8ISO8859P1"); // TX_CHARSET | |
ps.setString(6, "BLOB"); // TX_TIPO_ARQUIVO | |
ps.setBinaryStream(7, in, (int) arquivoEnviar.length()); // BLOB_CONTENT | |
ps.executeUpdate(); | |
ps.close(); | |
connection.close(); | |
} catch (Exception e) { | |
throw new RDiasException(e); | |
} finally { | |
try { | |
if (connection != null) { | |
connection.close(); | |
} | |
if (statement != null) { | |
statement.close(); | |
} | |
} catch (SQLException e) { | |
throw new RDiasException(e); | |
} | |
} | |
files[i].delete(); | |
} | |
} | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Envio de Voz: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
} | |
} | |
public static void executeMultipartPostImagem(String caminhoArquivos) throws Exception { | |
try { | |
File diretorioCartao = new File(caminhoArquivos); | |
if (diretorioCartao.exists()) { | |
File[] files = diretorioCartao.listFiles(new FileFilter() { | |
public boolean accept(File pathname) { | |
return pathname.getName().toLowerCase().endsWith(".jpg"); | |
} | |
}); | |
for (int i = 0; i < files.length; i++) { | |
File arquivoEnviar = new File(dir.getTriagemDestinoImagem() + "/" + files[i].getName()); | |
Utilidades.geraLogHomologacao("SincronizadorDAO.executeMultipartPostImagem: arquivo imagem sera enviado: " + dir.getTriagemDestinoImagem() + "/" + files[i].getName()); | |
String nomeArquivo[] = null; | |
Statement statement = null; | |
try { | |
StringBuilder bd = new StringBuilder(); | |
nomeArquivo = files[i].getName().split("_"); | |
bd.append("INSERT INTO DOCUMENTO_TRIAGEM (CHAVE_RESPOSTA, NO_ARQUIVO, MIME_TYPE, NR_TAMANHO_ARQUIVO, TX_CHARSET, TX_TIPO_ARQUIVO, BLB_ARQUIVO) values (?, ?, ?, ?, ?, ?, ?)"); | |
PreparedStatement ps = getConection().prepareStatement(bd.toString()); | |
InputStream in = new FileInputStream(arquivoEnviar); | |
ps.setString(1, nomeArquivo[6]); // CHAVE_RESPOSTA | |
ps.setString(2, arquivoEnviar.getName()); // NO_ARQUIVO | |
ps.setString(3, "IMAGEM"); // MIME_TYPE | |
ps.setLong(4, files[i].length()); // NR_TAMANHO_ARQUIVO | |
ps.setString(5, "WE8ISO8859P1"); // TX_CHARSET | |
ps.setString(6, "BLOB"); // TX_TIPO_ARQUIVO | |
ps.setBinaryStream(7, in, (int) arquivoEnviar.length()); // BLOB_CONTENT | |
ps.executeUpdate(); | |
ps.close(); | |
connection.close(); | |
} catch (Exception e) { | |
Utilidades.geraLogHomologacao("SincronizadorDAO.executeMultipartPostVoz: erro ao enviar a imagem: " + dir.getTriagemDestinoImagem() + "/" + files[i].getName()); | |
Utilidades.geraLogHomologacao("SincronizadorDAO.executeMultipartPostVoz: erro ao enviar a imagem - ERRO: " + e.getMessage()); | |
// throw new RDiasException(e); | |
} finally { | |
try { | |
if (connection != null) { | |
connection.close(); | |
} | |
if (statement != null) { | |
statement.close(); | |
} | |
} catch (SQLException e) { | |
throw new RDiasException(e); | |
} | |
} | |
File arquivoNovo = new File(dir.getBackupImagem() + "/" + files[i].getName()); | |
files[i].renameTo(arquivoNovo); | |
files[i].delete(); | |
} | |
} | |
} catch (Exception e) { | |
try { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
pw.close(); | |
sw.close(); | |
Utilidades.geraLogHomologacao("Envio Imagem: " + sw.getBuffer().toString()); | |
} catch (Exception ex) { | |
} | |
e.printStackTrace(); | |
} | |
} | |
public HashMap<Integer, RespostaCliente> getRespostasCliente() { | |
return respostasCliente; | |
} | |
public void setRespostasCliente(HashMap<Integer, RespostaCliente> respostasCliente) { | |
this.respostasCliente = respostasCliente; | |
} | |
public HashMap<Integer, ItemRespostaCliente> getItensRespostaCliente() { | |
return itensRespostaCliente; | |
} | |
public void setItensRespostaCliente(HashMap<Integer, ItemRespostaCliente> itensRespostaCliente) { | |
this.itensRespostaCliente = itensRespostaCliente; | |
} | |
public HashMap<Integer, Entidade> getEntidades() { | |
return entidades; | |
} | |
public void setEntidades(HashMap<Integer, Entidade> entidades) { | |
this.entidades = entidades; | |
} | |
public List<Roteiro> getRoteiros() { | |
return roteiros; | |
} | |
public void setRoteiros(List<Roteiro> roteiros) { | |
this.roteiros = roteiros; | |
} | |
public HashMap<Integer, Usuario> getUsuarios() { | |
return usuarios; | |
} | |
public void setUsuarios(HashMap<Integer, Usuario> usuarios) { | |
this.usuarios = usuarios; | |
} | |
public HashMap<Integer, RoteiroEntidadePesquisa> getRoteiroEntidadePesquisas() { | |
return roteiroEntidadePesquisas; | |
} | |
public void setRoteiroPesquisas(HashMap<Integer, RoteiroEntidadePesquisa> roteiroEntidadePesquisas) { | |
this.roteiroEntidadePesquisas = roteiroEntidadePesquisas; | |
} | |
public HashMap<Integer, Resposta> getRespostas() { | |
return respostas; | |
} | |
public void setRespostas(HashMap<Integer, Resposta> respostas) { | |
this.respostas = respostas; | |
} | |
public HashMap<Integer, Pesquisa> getPesquisas() { | |
return pesquisas; | |
} | |
public void setPesquisas(HashMap<Integer, Pesquisa> pesquisas) { | |
this.pesquisas = pesquisas; | |
} | |
public HashMap<Integer, Pergunta> getPerguntas() { | |
return perguntas; | |
} | |
public void setPerguntas(HashMap<Integer, Pergunta> perguntas) { | |
this.perguntas = perguntas; | |
} | |
public HashMap<Integer, PerguntaProibida> getPerguntasProibidas() { | |
return perguntasProibidas; | |
} | |
public void setPerguntasProibidas(HashMap<Integer, PerguntaProibida> perguntasProibidas) { | |
this.perguntasProibidas = perguntasProibidas; | |
} | |
public static Integer getProximoNumSequenceArquivo() { | |
Integer proximoNumSequencia = null; | |
Random r = new Random(); | |
int i = r.nextInt(99999999 ^ 45957 * 100); | |
proximoNumSequencia = i; | |
return proximoNumSequencia; | |
} | |
public HashMap<Integer, PerguntaEntidadePesquisa> getPerguntasEntidadePesquisa() { | |
return perguntasEntidadePesquisa; | |
} | |
public void setPerguntasEntidadePesquisa(HashMap<Integer, PerguntaEntidadePesquisa> perguntasEntidadePesquisa) { | |
this.perguntasEntidadePesquisa = perguntasEntidadePesquisa; | |
} | |
public static String getFgRandom() { | |
return fgRandom; | |
} | |
public static void setFgRandom(String fgRandom) { | |
SincronizadorDAO.fgRandom = fgRandom; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment