Añado los fuentes de java
This commit is contained in:
@@ -0,0 +1,560 @@
|
||||
/**
|
||||
* @(#) GestorAdministracion.java
|
||||
*/
|
||||
|
||||
package com.tarisan.servlets;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.tarisan.control.*;
|
||||
import com.tarisan.data.TanivelActo;
|
||||
import com.tarisan.data.TanivelEspecialidad;
|
||||
import com.tarisan.data.Usuario;
|
||||
import com.tarisan.excepcion.*;
|
||||
import com.tarisan.log.*;
|
||||
import com.tarisan.util.Utilidades;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Vector;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* Servlet direccionador a páginas JSP para el módulo de administración de usuarios.
|
||||
* @author <a href="mailto:sistemas@imqnavarra.com">Dpto. Informática</a>.
|
||||
* @version 1.0, 24/09/2003
|
||||
*/
|
||||
public class GestorAdministracion extends HttpServlet implements Constantes
|
||||
{
|
||||
|
||||
/**
|
||||
* Recepción de la petición de acceso al módulo de administración solicitada por el cliente.
|
||||
* @param request Objeto <code>HttpServletRequest</code> enviado por el cliente.
|
||||
* @param response Objeto <code>HttpServletResponse</code> que recibirá el cliente.
|
||||
*/
|
||||
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.INFO, "GestorAdministracion.service().INI");
|
||||
|
||||
response.setHeader("Expires", "0");
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
HttpSession sesion = request.getSession(true);
|
||||
|
||||
if(sesion.isNew() || (sesion.getAttribute("USUARIO") == null))
|
||||
{
|
||||
String opcion = request.getParameter("OPCION");
|
||||
if (Integer.parseInt(opcion)==OPC_ADM_MOSTRAR_LOG){
|
||||
this.evaluarOpcion(opcion, request, response, sesion);
|
||||
}else{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Sesión no iniciada redirigimos");
|
||||
response.sendRedirect("../html/login.html");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Entrada aceptada al módulo de Administración");
|
||||
|
||||
String opcion = request.getParameter("OPCION");
|
||||
this.evaluarOpcion(opcion, request, response, sesion);
|
||||
}
|
||||
|
||||
LogTarisan.logger.log(NivelLog.INFO, "GestorAdministracion.service().FIN");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Evalúa la opción del módulo de administración solicitada por el usuario.
|
||||
* Redirigiendo a la página JSP correspondiente a la opción de menú requerida.
|
||||
* @param sOpcion El código de la opción de menú solicitada por el usuario.
|
||||
* @param request Objeto <code>HttpServletRequest</code> enviado por el cliente.
|
||||
* @param response Objeto <code>HttpServletResponse</code> que retornará la página al cliente.
|
||||
* @param sesion Objeto <code>HttpSession</code> conla sesión del usuario conectado.
|
||||
*/
|
||||
private void evaluarOpcion(String sOpcion, HttpServletRequest request, HttpServletResponse response, HttpSession sesion) throws IOException
|
||||
{
|
||||
int nOpcion = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nOpcion = Integer.parseInt(sOpcion);
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
}
|
||||
|
||||
switch(nOpcion)
|
||||
{
|
||||
case OPC_ADM_USUARIO_LISTA:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Opción 'Usuarios' seleccionada");
|
||||
response.sendRedirect("../jsp/adm/lista_usuarios.jsp?x=0&pagina=1");
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_PASSWORD:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Opción 'Password' seleccionada");
|
||||
response.sendRedirect("../jsp/med/password.jsp");
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_USUARIO_DETALLE:
|
||||
{
|
||||
try
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Se actualiza la informacion del usuario seleccionado");
|
||||
this.actualizarDatosUsuario(request, response, sesion);
|
||||
//redirigimos a la pagina de detalle de usuario
|
||||
response.sendRedirect("../jsp/adm/detalle_usuario.jsp?x=" + request.getParameter("x") + "&medico=" + request.getParameter("medico"));
|
||||
}
|
||||
catch(ExcepcionTarisan ex)
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.ERROR, "ExcepcionTarisan: " + ex.getMensaje());
|
||||
sesion.setAttribute("ERROR", "Error en la actualizacion de los datos del usuario." + ex.getMensaje());
|
||||
response.sendRedirect("../jsp/error.jsp");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.ERROR, "Exception: " + ex);
|
||||
sesion.setAttribute("ERROR", "Error en la actualizacion de los datos del usuario.");
|
||||
response.sendRedirect("../jsp/error.jsp");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_ACT_AUTORIZACION:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Vamos a actualizar autorizacion");
|
||||
try {
|
||||
if(this.actualizarAutorizacion(request, response, sesion))
|
||||
{
|
||||
sesion.setAttribute("MENSAJE", "Actualizacion realizada correctamente");
|
||||
response.sendRedirect("../jsp/adm/mto_taconaut.jsp?x=" + request.getParameter("x"));
|
||||
}
|
||||
} catch (ExcepcionTarisan e) {
|
||||
LogTarisan.logger.log(NivelLog.ERROR, "Exception: " + e);
|
||||
sesion.setAttribute("ERROR", "Error en la actualizacion de la autorizacion.");
|
||||
response.sendRedirect("../jsp/error.jsp");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_GES_NIVELES_ESPE:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Obtener Niveles y Visibilidad de las especialidades");
|
||||
response.sendRedirect("../jsp/adm/mto_niveles.jsp?x=3&especialidad=" + request.getParameter("hiddenEspecialidad") +"&especialidadSolicitada=" + request.getParameter("hiddenEspecialidadSolicitada"));
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_GES_ACT_VISIBILI:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Actualizar Visibilidad de los niveles");
|
||||
PersistenciaTanivelEspecialidadTanivelActo per = new PersistenciaTanivelEspecialidadTanivelActo();
|
||||
Vector v = new Vector();
|
||||
for (int i = 0; i<3; i++){
|
||||
TanivelEspecialidad TanivEsp = new TanivelEspecialidad();
|
||||
TanivEsp.setEspecialidad(Integer.parseInt(request.getParameter("hiddenEspe")));
|
||||
TanivEsp.setNivel(Integer.parseInt(request.getParameter("hiddenNivel"+(i+1))));
|
||||
TanivEsp.setVisibilidad(Integer.parseInt(request.getParameter("hiddenVisi"+(i+1))));
|
||||
v.addElement(TanivEsp);
|
||||
}
|
||||
if(per.ActualizarVisibilidad(v,Integer.parseInt(request.getParameter("hiddenEspeS"))))
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "OK al actualizar la visibilidad de los niveles");
|
||||
response.sendRedirect("../jsp/adm/mto_niveles.jsp?x=3");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Error al actualizar la visibilidad de los niveles");
|
||||
sesion.setAttribute("ERROR", "Error al actualizar visibilidad de los niveles");
|
||||
response.sendRedirect("../jsp/error.jsp");
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_GES_NIVELES_ACT:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Obtener Actos y niveles de las especialidades");
|
||||
response.sendRedirect("../jsp/adm/mto_actos.jsp?x=3&especialidad=" + request.getParameter("hiddenEspecialidad")+"&pagina="+ request.getParameter("pagina")+"&hiddenActo="+ request.getParameter("hiddenActo"));
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_GES_ACT_NIVEL_ACTO:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Actualizar Nivel de los actos");
|
||||
PersistenciaTanivelEspecialidadTanivelActo per = new PersistenciaTanivelEspecialidadTanivelActo();
|
||||
Vector v = new Vector();
|
||||
for (int i = 0; i<Integer.parseInt(request.getParameter("nElementos")); i++){
|
||||
TanivelActo TanivAct = new TanivelActo();
|
||||
TanivAct.setEspecialidad(Integer.parseInt(request.getParameter("hiddenEspe")));
|
||||
TanivAct.setActo(Integer.parseInt(request.getParameter("hiddenActo"+(i+1))));
|
||||
TanivAct.setNivel(Integer.parseInt(request.getParameter("hiddenNivel"+(i+1))));
|
||||
v.addElement(TanivAct);
|
||||
}
|
||||
|
||||
if(per.ActualizarNivelActo(v))
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "OK al actualizar el nivel de los actos");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Error al actualizar el nivel de los actos");
|
||||
}
|
||||
|
||||
response.sendRedirect("../jsp/adm/mto_actos.jsp?x=3&pagina=1");
|
||||
break;
|
||||
}
|
||||
case OPC_ADM_MOSTRAR_LOG:
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Devuelve el log de Tarisan");
|
||||
String nLineas = request.getParameter("NLINEAS");
|
||||
Integer intSiguiente=0;
|
||||
Integer intAnterior=0;
|
||||
Integer intlini=0;
|
||||
if (request.getParameter("siguiente")!=null){
|
||||
if (request.getParameter("siguiente")!="")
|
||||
intSiguiente=Integer.parseInt(request.getParameter("siguiente"));
|
||||
}
|
||||
if (request.getParameter("anterior")!=null){
|
||||
if (request.getParameter("anterior")!="")
|
||||
intAnterior=Integer.parseInt(request.getParameter("anterior"));
|
||||
}
|
||||
if (request.getParameter("lini")!=null){
|
||||
if (request.getParameter("lini")!="")
|
||||
intlini=Integer.parseInt(request.getParameter("lini"));
|
||||
}
|
||||
String log ="";
|
||||
/*json = this.mostrarLogJson("/root/apache-tomcat-6.0.20/logs/tarisans.log", 1000);
|
||||
response.setContentType("application/json");*/
|
||||
/*log = this.mostrarLogTabla("/root/apache-tomcat-6.0.20/logs/tarisans.log", Integer.parseInt(nLineas), intAnterior, intSiguiente, intlini);*/
|
||||
log = this.mostrarLogTabla("/var/log/tomcat/tarisans.log", Integer.parseInt(nLineas), intAnterior, intSiguiente, intlini);
|
||||
response.setContentType("text/html");
|
||||
PrintWriter out = response.getWriter();
|
||||
out.println(log);
|
||||
out.close();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
response.sendRedirect("../jsp/adm/lista_usuarios.jsp?x=0");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String mostrarLogTabla(String archivo, int maxLinMostradas, Integer intAnterior, Integer intSiguiente, Integer intlini) throws FileNotFoundException, IOException {
|
||||
String tabla = "";
|
||||
FileReader fr= new FileReader(archivo);
|
||||
BufferedReader br= new BufferedReader(fr);
|
||||
String linea=null;
|
||||
int numLin =0; // Número de líneas del fichero
|
||||
int linInicial=0; // Primera línea mostrada
|
||||
int lineaFinal = 0; // Ultima linea mostrada
|
||||
String strFecha="";
|
||||
String strHora="";
|
||||
String strTipo="";
|
||||
String strLog="";
|
||||
String estilo = "";
|
||||
|
||||
while ((linea=br.readLine())!=null){
|
||||
numLin++;
|
||||
}
|
||||
br.close();
|
||||
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Número líneas fichero: "+numLin);
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Número máximo de lines a mostrar: "+maxLinMostradas);
|
||||
|
||||
// Calculamos primera línea mostrada
|
||||
linInicial = numLin-maxLinMostradas;
|
||||
if ((intAnterior == 1) || (intSiguiente == 1)){
|
||||
linInicial = intlini;
|
||||
}
|
||||
lineaFinal = linInicial + maxLinMostradas;
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Linea Inicial: "+linInicial);
|
||||
|
||||
// Volvemos a leer mostrando sólo lo requerido
|
||||
FileReader fr2= new FileReader(archivo);
|
||||
BufferedReader br2 = new BufferedReader(fr2);
|
||||
numLin=0; // Línea actual
|
||||
Collection collection = new ArrayList();
|
||||
|
||||
tabla += "<a class=\"enlace\" href=\"https://192.168.2.192/tarisan/servlet/GestorAdministracion?OPCION=9&NLINEAS="+maxLinMostradas+"&anterior=1&lini=1\">Principio</a>";
|
||||
tabla += "<a class=\"enlace\" href=\"https://192.168.2.192/tarisan/servlet/GestorAdministracion?OPCION=9&NLINEAS="+maxLinMostradas+"&anterior=1&lini="+(linInicial-maxLinMostradas)+"\">Anterior</a>";
|
||||
tabla += "<a class=\"enlace\" href=\"https://192.168.2.192/tarisan/servlet/GestorAdministracion?OPCION=9&NLINEAS="+maxLinMostradas+"&siguiente=1&lini="+(linInicial+maxLinMostradas)+"\">Siguiente</a>";
|
||||
tabla += "<a class=\"enlace\" href=\"https://192.168.2.192/tarisan/servlet/GestorAdministracion?OPCION=9&NLINEAS="+maxLinMostradas+"&siguiente=1&lini="+(numLin-maxLinMostradas)+"\">Final</a>";
|
||||
tabla += "<p> </p>";
|
||||
tabla += "<table style=\"width:100%\">";
|
||||
tabla += "<tr>";
|
||||
tabla += "<td align=\"center\" class=\"cabeceraTabla\">Linea</td>";
|
||||
tabla += "<td align=\"center\" class=\"cabeceraTabla\">Fecha</td>";
|
||||
tabla += "<td align=\"center\" class=\"cabeceraTabla\">Hora</td>";
|
||||
tabla += "<td align=\"center\" class=\"cabeceraTabla\">Tipo</td>";
|
||||
tabla += "<td align=\"center\" class=\"cabeceraTabla\">Log</td>";
|
||||
tabla += "</tr>";
|
||||
|
||||
while ((linea=br2.readLine())!=null){
|
||||
// Si el número de líneas a mostrar es superioral número de líneas mostramos todas
|
||||
if(((numLin>=linInicial) && (numLin<=lineaFinal)) || linInicial<0){
|
||||
if (linea.length()>=10){
|
||||
strFecha = linea.substring(0,10);
|
||||
strHora = linea.substring(11,23);
|
||||
strTipo = linea.substring(24,29);
|
||||
strLog = linea.substring(30);
|
||||
}else{
|
||||
strFecha = "";
|
||||
strHora = "";
|
||||
strTipo = "";
|
||||
strLog = "";
|
||||
}
|
||||
if (numLin % 2 == 0)
|
||||
{
|
||||
estilo = "filaB";
|
||||
}
|
||||
else
|
||||
{
|
||||
estilo = "filaA";
|
||||
}
|
||||
if ((strTipo.trim()).compareTo("ERROR")==0){
|
||||
estilo = "filaError";
|
||||
}
|
||||
tabla += "<tr>";
|
||||
tabla += "<td class=\""+estilo+"\" align=\"center\">"+numLin+"</td>";
|
||||
tabla += "<td class=\""+estilo+"\" align=\"center\">"+strFecha+"</td>";
|
||||
tabla += "<td class=\""+estilo+"\" align=\"center\">"+strHora+"</td>";
|
||||
tabla += "<td class=\""+estilo+"\" align=\"center\">"+strTipo+"</td>";
|
||||
tabla += "<td class=\""+estilo+"\" align=\"left\">"+strLog+"</td>";
|
||||
tabla += "</tr>";
|
||||
}
|
||||
numLin++;
|
||||
}
|
||||
br2.close();
|
||||
|
||||
tabla += "</table>";
|
||||
tabla += "<p> </p>";
|
||||
tabla += "<a class=\"enlace\" href=\"https://192.168.2.192/tarisan/servlet/GestorAdministracion?OPCION=9&NLINEAS="+maxLinMostradas+"&anterior=1&lini="+(linInicial-maxLinMostradas)+"\">Anterior</a>";
|
||||
tabla += "<a class=\"enlace\" href=\"https://192.168.2.192/tarisan/servlet/GestorAdministracion?OPCION=9&NLINEAS="+maxLinMostradas+"&siguiente=1&lini="+(linInicial+maxLinMostradas)+"\">Siguiente</a>";
|
||||
tabla += "<style>";
|
||||
tabla += "body{background-color:rgb(228, 228, 228);}";
|
||||
tabla += ".cabeceraTabla{background-color:grey;color:white;font-weight:bold;}";
|
||||
tabla += ".filaA{background-color:white;}";
|
||||
tabla += ".filaB{background-color:#EBEBEB;}";
|
||||
tabla += ".filaError{background-color:#F07777;}";
|
||||
tabla += ".filaB:hover, .filaA:hover{background-color:#FFE7E7;}";
|
||||
tabla += ".enlace{text-decoration: none;color: white;font-weight: bold;border: 1px solid !important;background-color: rgb(198, 0, 0);padding: 3px;}";
|
||||
tabla += ".enlace:hover {background-color:red;color:white;}";
|
||||
tabla += "</style>";
|
||||
|
||||
return tabla;
|
||||
}
|
||||
|
||||
public String mostrarLogJson(String archivo, int maxLinMostradas) throws FileNotFoundException, IOException {
|
||||
Gson gson = new Gson();
|
||||
FileReader fr= new FileReader(archivo);
|
||||
BufferedReader br= new BufferedReader(fr);
|
||||
String linea=null;
|
||||
int numLin =0; // Número de líneas del fichero
|
||||
int linInicial=0; // Primera línea mostrada
|
||||
|
||||
while ((linea=br.readLine())!=null){
|
||||
numLin++;
|
||||
}
|
||||
br.close();
|
||||
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Número líneas fichero: "+numLin);
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Número máximo de lines a mostrar: "+maxLinMostradas);
|
||||
|
||||
// Calculamos primera línea mostrada
|
||||
linInicial = numLin-maxLinMostradas;
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Linea Inicial: "+linInicial);
|
||||
|
||||
// Volvemos a leer mostrando sólo lo requerido
|
||||
FileReader fr2= new FileReader(archivo);
|
||||
BufferedReader br2 = new BufferedReader(fr2);
|
||||
numLin=0; // Línea actual
|
||||
Collection collection = new ArrayList();
|
||||
|
||||
while ((linea=br2.readLine())!=null){
|
||||
// Si el número de líneas a mostrar es superioral número de líneas mostramos todas
|
||||
if(numLin>=linInicial || linInicial<0){
|
||||
//System.out.println("Tail:"+linea);
|
||||
collection.add(numLin);
|
||||
collection.add(linea);
|
||||
//String jsonString = gson.toJson(linea);
|
||||
}
|
||||
numLin++;
|
||||
}
|
||||
String json = gson.toJson(collection);
|
||||
br2.close();
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
private TanivelEspecialidad MostrarNivelesEspe(HttpServletRequest request, HttpServletResponse response, HttpSession sesion) throws ExcepcionTarisan
|
||||
{
|
||||
TanivelEspecialidad resultado = null;
|
||||
PersistenciaTanivelEspecialidadTanivelActo per = new PersistenciaTanivelEspecialidadTanivelActo();
|
||||
//resultado = per.ObtenerNiveles(Integer.parseInt(request.getParameter("especialidad")));
|
||||
|
||||
|
||||
return resultado;
|
||||
}
|
||||
|
||||
private boolean actualizarAutorizacion(HttpServletRequest request, HttpServletResponse response, HttpSession sesion) throws ExcepcionTarisan
|
||||
{
|
||||
boolean resultado = false;
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "Vamos a actualizar la autorizacion: "+request.getParameter("num_aut")+", con la cantidad "+request.getParameter("cantidad"));
|
||||
PersistenciaTaconaut pertacon = new PersistenciaTaconaut();
|
||||
long autorizacion = Long.parseLong(request.getParameter("num_aut"));
|
||||
int acto = Integer.parseInt(request.getParameter("acto"));
|
||||
int especialidad = Integer.parseInt(request.getParameter("especialidad"));
|
||||
int cantidad = Integer.parseInt(request.getParameter("cantidad"));
|
||||
|
||||
if(pertacon.AutorizacionSinTarjeta(autorizacion))
|
||||
{
|
||||
String tarjeta = pertacon.ObtenerTarjeta(autorizacion);
|
||||
resultado = pertacon.ActualizarCantidadTarjetaAutorizacionADM(autorizacion, acto, especialidad, cantidad, tarjeta);
|
||||
}
|
||||
else
|
||||
resultado = pertacon.ActualizarCantidadAutorizacionADM(autorizacion, acto, especialidad, cantidad);
|
||||
|
||||
return resultado;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza los datos del usuario seleccionado por el administrador.
|
||||
* @param request Objeto <code>HttpServletRequest</code> que contiene los parámetros enviados desde la página Html.
|
||||
* @param response Objeto <code>HttpServletResponse</code> que retornará la página al cliente.
|
||||
* @param sesion Objeto <code>HttpSession</code> con la sesión actual del usuario.
|
||||
* @throws
|
||||
*/
|
||||
private void actualizarDatosUsuario(HttpServletRequest request, HttpServletResponse response, HttpSession sesion) throws ExcepcionTarisan
|
||||
{
|
||||
Object[] aValores = null;
|
||||
Object[] aCondiciones = null;
|
||||
StringBuffer strSql = new StringBuffer();
|
||||
|
||||
Object nMedico = null;
|
||||
Object valor = null;
|
||||
boolean haAccedido = false;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
|
||||
Calendar calCaducidad = Calendar.getInstance();
|
||||
int intMedicoConectado = ((Usuario)sesion.getAttribute("USUARIO")).getMedico();
|
||||
Timestamp tsFechaUltimoAcceso = ((Usuario)sesion.getAttribute("USUARIO")).getFechaUltAcceso();
|
||||
|
||||
try
|
||||
{
|
||||
nMedico = request.getParameter("medico");
|
||||
|
||||
if ((request.getParameter("fecha_ult_acceso") != null) && (request.getParameter("fecha_ult_acceso").trim().compareTo("") != 0))
|
||||
{
|
||||
haAccedido = true;
|
||||
}
|
||||
|
||||
if ((request.getParameter("valor_password") != null) && (request.getParameter("valor_password").trim().compareTo("") != 0))
|
||||
{
|
||||
aValores = new Object[3];
|
||||
if (haAccedido)
|
||||
{
|
||||
aValores[2] = Utilidades.encripta(request.getParameter("valor_password"), (String)nMedico);
|
||||
}
|
||||
else
|
||||
{
|
||||
aValores[2] = request.getParameter("valor_password");
|
||||
}
|
||||
strSql.append(", PASSWORD = ?");
|
||||
}
|
||||
else
|
||||
{
|
||||
aValores = new Object[3];
|
||||
}
|
||||
|
||||
valor = sdf.parse(request.getParameter("valor_fecha_modif_clave"));
|
||||
calCaducidad.setTime((java.util.Date)valor);
|
||||
calCaducidad.add(Calendar.DATE, -ParametrosConfiguracion.diasCaducidad);
|
||||
strSql.insert(0, ", FECHA_MODIF_CLAVE = ?");
|
||||
aValores[2] = new java.sql.Date(calCaducidad.getTime().getTime());
|
||||
|
||||
valor = request.getParameter("valor_bloqueo_clave");
|
||||
/*if ((valor == null) || (((String)valor).toUpperCase().compareTo("S") != 0))
|
||||
{
|
||||
valor = "N";
|
||||
}*/
|
||||
if (valor.equals("N")){
|
||||
strSql.insert(0, " BLOQUEO_CLAVE = ?");
|
||||
strSql.insert(0, "FECHA_ULT_ACCESO = ?,");
|
||||
aValores[0] = "";
|
||||
aValores[1] = valor;
|
||||
} else {
|
||||
aValores = new Object[2];
|
||||
strSql.insert(0, " BLOQUEO_CLAVE = ?");
|
||||
aValores[1] = new java.sql.Date(calCaducidad.getTime().getTime());
|
||||
aValores[0] = valor;
|
||||
}
|
||||
|
||||
|
||||
strSql.insert(0, "UPDATE TAMEDICO SET ");
|
||||
|
||||
//array condiciones
|
||||
strSql.append(" , PASSWORD='123' WHERE MEDICO = ? ");
|
||||
aCondiciones = new Object[1];
|
||||
aCondiciones[0] = nMedico;
|
||||
|
||||
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
||||
ParametrosConfiguracion.dataStore.iniciarTransaccion(conexion);
|
||||
|
||||
try
|
||||
{
|
||||
PersistenciaTamedico perTamedico = new PersistenciaTamedico();
|
||||
LogTarisan.logger.log(NivelLog.DEBUG, "--- La sql es esta: "+strSql.toString()+"<<");
|
||||
perTamedico.modificarMedico(strSql.toString(), aValores, aCondiciones);
|
||||
|
||||
//insertamos un registro en la tabla tareglog para indicar los movimientos realizados por el usuario
|
||||
PersistenciaTareglog perTareglog = new PersistenciaTareglog();
|
||||
//obtenemos el ultimo valor del campo correlativo de la tabla tareglog.
|
||||
//Este campo es un numero correlativo utilizado para diferenciar las claves.
|
||||
int intUltimoValorCorrelativo = perTareglog.obtenerUltimoValorCorrelativo(intMedicoConectado, tsFechaUltimoAcceso);
|
||||
perTareglog.insertarLog(intMedicoConectado, tsFechaUltimoAcceso, Calendar.getInstance(), intUltimoValorCorrelativo + 1, "TAMEDICO", Utilidades.obtenerSentenciaSQL(strSql, aValores, aCondiciones), "", conexion);
|
||||
|
||||
//las actualizaciones han ido bien. Confirmamos la transaccion
|
||||
ParametrosConfiguracion.dataStore.confirmarTransaccion(conexion);
|
||||
}
|
||||
catch (ExcepcionTarisan ex)
|
||||
{
|
||||
ParametrosConfiguracion.dataStore.deshacerTransaccion(conexion);
|
||||
LogTarisan.logger.log(NivelLog.ERROR, "ExcepcionTarisan: " + ex.getMensaje());
|
||||
throw (ExcepcionTarisan)ex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ParametrosConfiguracion.dataStore.deshacerTransaccion(conexion);
|
||||
LogTarisan.logger.log(NivelLog.ERROR, "Exception: " + ex.getMessage());
|
||||
throw new ExcepcionTarisan(ex.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
//liberamos la conexion
|
||||
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
||||
}
|
||||
}
|
||||
catch (ExcepcionTarisan ex)
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.ERROR, "ExcepcionTarisan: " + ex.getMensaje());
|
||||
throw (ExcepcionTarisan)ex;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
LogTarisan.logger.log(NivelLog.ERROR, "Exception: " + ex);
|
||||
throw new ExcepcionTarisan(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user