279 lines
10 KiB
Java
279 lines
10 KiB
Java
package com.tarisan.chipcard.tpvvs.ws;
|
|
|
|
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.ClienteServicioWeb;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.ControladorRespuestas;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.ActoMedico;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.CompaniaSanitaria;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.EspecialidadSanitaria;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.ListaActos;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.Paciente;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.ProfesionalSanitario;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.TerminalSanitario;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.accesodatos.UsuarioTVS;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.AutReq;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.Msg;
|
|
import com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.SoloTarjeta;
|
|
import com.tarisan.control.ParametrosConfiguracion;
|
|
import com.tarisan.excepcion.ExcepcionTarisan;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
import java.util.Calendar;
|
|
|
|
public class Tarisan {
|
|
public static String mensaje = "";
|
|
public static int contador = 0;
|
|
public static void check_card(String login, String pass, int terminal, int company, String url, String pista, String nif, int especialidad, int codlista, int codact, int secuencial){
|
|
mensaje = "";
|
|
UsuarioTVS user = new UsuarioTVS();
|
|
user.setLogin(login);
|
|
user.setPassword(pass);
|
|
TerminalSanitario aTS = new TerminalSanitario();
|
|
aTS.setNumeroTerminal(terminal);
|
|
user.setTerminal(aTS);
|
|
Paciente paciente = new Paciente();
|
|
paciente.setPista(pista);
|
|
CompaniaSanitaria comp = new CompaniaSanitaria();
|
|
comp.setCodigoCompania(company);
|
|
ProfesionalSanitario prof = new ProfesionalSanitario();
|
|
prof.setCodProfesional(nif);
|
|
EspecialidadSanitaria espe = new EspecialidadSanitaria();
|
|
espe.setCodigoEspecialidad(especialidad);
|
|
|
|
ListaActos listaActos = new ListaActos();
|
|
listaActos.setCodigoListaActos(codlista);
|
|
ActoMedico arrActos[] = new ActoMedico[1];
|
|
ActoMedico acto = new ActoMedico();
|
|
acto.setCodigoActo(codact);
|
|
arrActos[0] = acto;
|
|
|
|
try {
|
|
AutReq autRequest =
|
|
autRequest =
|
|
new SoloTarjeta(
|
|
user,
|
|
paciente,
|
|
comp,
|
|
espe,
|
|
prof,
|
|
listaActos,
|
|
arrActos);
|
|
|
|
ResponseController aResponseController = new ResponseController();
|
|
|
|
java.net.URL endPointURL = null;
|
|
|
|
try {
|
|
endPointURL = new java.net.URL(url);
|
|
} catch (Exception err) {
|
|
err.printStackTrace();
|
|
}
|
|
/*if(contador == 0)
|
|
{
|
|
Thread.sleep(1000);
|
|
contador = 1;
|
|
}
|
|
else if(contador == 1)
|
|
{
|
|
try {
|
|
System.out.println("Contador = 1, esperando.");
|
|
Thread.sleep(5100);
|
|
contador = 0;
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}*/
|
|
ClienteServicioWeb objClienteServicioWeb =
|
|
new ClienteServicioWeb(
|
|
autRequest,
|
|
aResponseController,
|
|
endPointURL, secuencial);
|
|
|
|
// mensaje = aResponseController.devolverAutorización(aResponseController.toString());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// System.out.println("Mensaje vale: "+mensaje);
|
|
//Para asegurarnos de que no devuelve el mensaje vacío...
|
|
/*while(mensaje.isEmpty())
|
|
{
|
|
try {
|
|
Thread.sleep(510);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}*/
|
|
|
|
}
|
|
|
|
static class ResponseController implements ControladorRespuestas {
|
|
/*****
|
|
* Recibe la respuesta del Servicio Web
|
|
*/
|
|
|
|
|
|
|
|
public String recibeRespuesta(String sResponse) {
|
|
String respuesta="";
|
|
mensaje = "";
|
|
System.out.println("Entra en devuelveRespuesta. Mensaje tiene valor: "+mensaje);
|
|
Msg objResponse = null;
|
|
if (sResponse != null) {
|
|
|
|
try {
|
|
// System.out.println("ResponseController.recibeRespuesta:"+sResponse+"\n");
|
|
objResponse = Msg.createMsgFromString(sResponse);
|
|
if(objResponse.getTypeOfMessage()==Msg.TYPE_OF_MESSAGE_ERROR){
|
|
com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.Error errorMes=(com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.Error)objResponse;
|
|
//Es un Error en la peticion
|
|
System.out.println("Se ha producido el error con código "+errorMes.getErrorCode()+".\nDescripción:"+errorMes.getErrorDescription());
|
|
respuesta=objResponse.toString();
|
|
}else {
|
|
com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.AutRes autResMes=(com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.AutRes)objResponse;
|
|
respuesta=objResponse.toString();
|
|
mensaje=objResponse.toString();
|
|
System.out.println("Respuesta chipcard tarjeta: "+autResMes.getNumeroTarjeta()+", respuesta: "+respuesta);
|
|
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println("Excepcion en recibeRespuesta");
|
|
}
|
|
}
|
|
else{
|
|
System.out.println("Sin respuesta");
|
|
respuesta = "ERROR";
|
|
}
|
|
return respuesta;
|
|
}
|
|
|
|
|
|
/**
|
|
* 15/03/2013 - Inutilizada, devolvemos el mensaje entero en la propia llamada del ControladorRespuestas...
|
|
*
|
|
* "Parsea" la respuesta del webservice y devuelve el número de la autorización o 0 si no está autorizado
|
|
* @param sResponse la respuesta del webservice
|
|
* @return El número de autorización
|
|
*/
|
|
public String devolverAutorizacion(String sResponse)
|
|
{
|
|
String resul = "";
|
|
// System.out.println("Mensaje previo: "+mensaje);
|
|
if(sResponse != null)
|
|
{
|
|
Msg objResponse = null;
|
|
try
|
|
{
|
|
//System.out.println("Llega 125 "+sResponse);
|
|
objResponse = Msg.createMsgFromString(sResponse);
|
|
//System.out.println("Llega 127 "+objResponse.toString());
|
|
if(objResponse.getTypeOfMessage() == Msg.TYPE_OF_MESSAGE_ERROR)
|
|
{
|
|
// System.out.println("Llega 130 Error");
|
|
com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.Error errorMes=(com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.Error)objResponse;
|
|
//System.out.println("Llega 132 Error: " + errorMes.toString());
|
|
}
|
|
else
|
|
{
|
|
//System.out.println("Llega 136 Bien");
|
|
com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.AutRes autResMes=(com.tarisan.chipcard.tpvvs.webservicetrayicon.messages.AutRes)objResponse;
|
|
//System.out.println("Llega 138 Bien: " + autResMes.toString());
|
|
resul = objResponse.toString();
|
|
//System.out.println("Resultado: "+resul);
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
// System.out.println("Llega 145 Excepcion");
|
|
return resul;
|
|
}
|
|
}
|
|
return resul;
|
|
}
|
|
|
|
}
|
|
|
|
public static boolean inserta_respuesta_oracle(String sResponse, int secuencial){
|
|
boolean resul = false;
|
|
|
|
//insert en la bbdd alberto
|
|
|
|
StringBuffer strSql = new StringBuffer();
|
|
int espe = 0;
|
|
int acto = 0;
|
|
String tarjeta = "";
|
|
String fecha = "";
|
|
String respuesta = "";
|
|
String mensaje = "";
|
|
Integer autorizacion = 0;
|
|
int terminal = 0;
|
|
//String cadena_conexion = "jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.75)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.76)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=realrac)))";
|
|
//Properties info = new Properties( );
|
|
//info.put( "user", "ALBERTO" );
|
|
//info.put( "password", "ALBERTO" );
|
|
|
|
tarjeta = sResponse.substring(sResponse.indexOf("<Tarjeta><num>")+14, sResponse.indexOf("</num><ver>"));
|
|
respuesta = sResponse.substring(sResponse.indexOf("<Aut><response>")+15, sResponse.indexOf("</response><desc>"));
|
|
mensaje = sResponse.substring(sResponse.indexOf("</response><desc>")+17, sResponse.indexOf("</desc><AutID>"));
|
|
autorizacion = Integer.parseInt(sResponse.substring(sResponse.indexOf("<numref>")+8, sResponse.indexOf("</numref>")));
|
|
terminal = Integer.parseInt(sResponse.substring(sResponse.indexOf("<term>")+6, sResponse.indexOf("</term>")));
|
|
acto = Integer.parseInt(sResponse.substring(sResponse.indexOf("<acto>")+6, sResponse.indexOf("</acto>")));
|
|
espe = Integer.parseInt(sResponse.substring(sResponse.indexOf("<Espec>")+7, sResponse.indexOf("</Espec>")));
|
|
|
|
strSql.append("INSERT INTO CHIPCARD_MOVIMIENTOS (TARJETA, RESPUESTA, MENSAJE, AUTORIZACION, TERMINAL, ESPECIALIDAD, ACTO, FECHA_HORA, XMLCOMPLETO, SECUENCIA) VALUES (");
|
|
strSql.append("'"+tarjeta+"', ");
|
|
strSql.append("'"+respuesta+"', ");
|
|
strSql.append("'"+mensaje+"', ");
|
|
strSql.append(autorizacion+", ");
|
|
strSql.append(terminal+", ");
|
|
strSql.append(espe+", ");
|
|
strSql.append(acto+", ");//?, '?', TO_DATE('?', 'dd/mm/yyyy hh24:mi:ss'), ?)");
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
String segundos = "";
|
|
if(cal.get(Calendar.SECOND)<10)
|
|
segundos = "0"+cal.get(Calendar.SECOND);
|
|
else
|
|
segundos = Integer.toString(cal.get(Calendar.SECOND));
|
|
|
|
fecha = new String(cal.get(Calendar.DAY_OF_MONTH)+"/"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.YEAR)+" "+cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+":"+segundos);
|
|
strSql.append("TO_DATE('"+fecha+"', 'dd/mm/yyyy hh24:mi:ss'), '"+sResponse+"', ");
|
|
strSql.append(secuencial + ")");
|
|
|
|
|
|
try {
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
|
|
/*
|
|
* sqlInsert.append("Insert into control_medicos (id, medico, fecha, tarjeta) values (?, ?, sysdate, ?)");
|
|
aValores[0]=siguiente_id();
|
|
aValores[1]=Integer.valueOf(medico);
|
|
aValores[2]=new String(tarjeta);
|
|
|
|
resul = ParametrosConfiguracion.dataStore.insertar(sqlInsert.toString(), aValores, conexion);
|
|
*/
|
|
|
|
conexion.setAutoCommit(false);
|
|
PreparedStatement ps = conexion.prepareStatement(strSql.toString());
|
|
int a = ps.executeUpdate();
|
|
ps.close();
|
|
|
|
conexion.commit();
|
|
conexion.setAutoCommit(true);
|
|
conexion.close();
|
|
if(a>0)
|
|
resul = true;
|
|
} catch (SQLException | ExcepcionTarisan e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
|
|
|
|
return resul;
|
|
}
|
|
}
|