[ADD] sqlserver to mysql

parent a8559080
...@@ -15,7 +15,7 @@ public class AreaCargoMysqlDAO implements AreaCargoDAO { ...@@ -15,7 +15,7 @@ public class AreaCargoMysqlDAO implements AreaCargoDAO {
@Override @Override
public JSONObject obtenerAreaCargo(AreaBean a, CargoBean c) { public JSONObject obtenerAreaCargo(AreaBean a, CargoBean c) {
System.out.println("AreaCargo MysqlDAO: obtenerAreaCargo"); System.out.println("AreaCargoMysqlDAO: obtenerAreaCargo");
JSONObject JOObtenerAreaCargo = null; JSONObject JOObtenerAreaCargo = null;
ResponseHelper response = new ResponseHelper(); ResponseHelper response = new ResponseHelper();
...@@ -75,7 +75,7 @@ public class AreaCargoMysqlDAO implements AreaCargoDAO { ...@@ -75,7 +75,7 @@ public class AreaCargoMysqlDAO implements AreaCargoDAO {
@Override @Override
public JSONObject asignarAreaCargo(JSONObject datos) { public JSONObject asignarAreaCargo(JSONObject datos) {
System.out.println("AreaCargo MysqlDAO: asignarAreaCargo"); System.out.println("AreaCargoMysqlDAO: asignarAreaCargo");
JSONObject jObject = null; JSONObject jObject = null;
ResponseHelper response = new ResponseHelper(); ResponseHelper response = new ResponseHelper();
Connection cnx = null; Connection cnx = null;
......
...@@ -28,11 +28,14 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -28,11 +28,14 @@ public class PersonaMysqlDAO implements PersonaDAO {
ResponseHelper response = new ResponseHelper(); ResponseHelper response = new ResponseHelper();
int existeNumeroDocumento = 0; int existeNumeroDocumento = 0;
String sql = "" String sql = "SELECT "
+ "select " + " count(1) existeNumeroDocumento "
+ "count(1) existeNumeroDocumento " + "FROM "
+ "from persona " + " personal "
+ "where estado_registro = 1 and codigo_tipo_documento = ? and numero_documento = ?"; + "WHERE "
+ " retirado = 1 "
+ "AND codigo_tipo_documento = ? "
+ "AND dni = ?";
Connection conexion = null; Connection conexion = null;
PreparedStatement ps = null; PreparedStatement ps = null;
...@@ -55,7 +58,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -55,7 +58,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]"); response.setMessage("Error: " + e.getMessage() + " Error Code: [" + e.getErrorCode() + "]");
} finally { } finally {
try { try {
if (rs != null) { if (rs != null) {
...@@ -71,6 +74,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -71,6 +74,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
e.printStackTrace(); e.printStackTrace();
} }
} }
jsonObjValidarExistenciaNumeroDocumento = new JSONObject(response); jsonObjValidarExistenciaNumeroDocumento = new JSONObject(response);
return jsonObjValidarExistenciaNumeroDocumento; return jsonObjValidarExistenciaNumeroDocumento;
} }
...@@ -82,15 +86,18 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -82,15 +86,18 @@ public class PersonaMysqlDAO implements PersonaDAO {
ResponseHelper response = new ResponseHelper(); ResponseHelper response = new ResponseHelper();
int existeCorreoElectronico = 0; int existeCorreoElectronico = 0;
String sql = "" String sql = "SELECT "
+ "select " + " count(1) existeCorreoElectronico "
+ "count(1) existeCorreoElectronico " + "FROM "
+ "from persona " + " personal "
+ "where estado_registro = 1 and correo = ?"; + "WHERE "
+ " retirado = 0 "
+ "AND email = ?";
Connection conexion = null; Connection conexion = null;
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
conexion = MysqlDAOFactory.obtenerConexion(Variables.MYSQL_NUEVO_BD_NAME); conexion = MysqlDAOFactory.obtenerConexion(Variables.MYSQL_NUEVO_BD_NAME);
ps = conexion.prepareStatement(sql); ps = conexion.prepareStatement(sql);
...@@ -108,7 +115,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -108,7 +115,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]"); response.setMessage("Error: " + e.getMessage() + " Error Code: [" + e.getErrorCode() + "]");
} finally { } finally {
try { try {
if (rs != null) { if (rs != null) {
...@@ -124,6 +131,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -124,6 +131,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
e.printStackTrace(); e.printStackTrace();
} }
} }
jsonObjValidarExistenciaCorreoElectronico = new JSONObject(response); jsonObjValidarExistenciaCorreoElectronico = new JSONObject(response);
return jsonObjValidarExistenciaCorreoElectronico; return jsonObjValidarExistenciaCorreoElectronico;
} }
...@@ -134,31 +142,32 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -134,31 +142,32 @@ public class PersonaMysqlDAO implements PersonaDAO {
JSONObject jsonObjRegistrarPersona = null; JSONObject jsonObjRegistrarPersona = null;
ResponseHelper response = new ResponseHelper(); ResponseHelper response = new ResponseHelper();
String sqlPersona = "" String sqlPersona = "INSERT INTO personal ( "
+ "insert into persona " + " apellidoPaterno, " // apellido_paterno
+ "(apellido_paterno, " + " apellidoMaterno, " // apellido_materno
+ "apellido_materno, " + " nombre, "
+ "nombre, " + " codigo_tipo_documento, "
+ "codigo_tipo_documento, " + " dni, " // numero_documento
+ "numero_documento, " + " email, " // correo
+ "correo, " + " is_default_mail, "
+ "is_default_mail, " + " retirado " // estado_registro
+ "estado_registro) " + ") "
+ "values " + "VALUES "
+ "(" + " ( "
+ "upper(rtrim(ltrim(?))), " + " upper(rtrim(ltrim(?))), "
+ "upper(rtrim(ltrim(?))), " + " upper(rtrim(ltrim(?))), "
+ "upper(rtrim(ltrim(?))), " + " upper(rtrim(ltrim(?))), "
+ "upper(rtrim(ltrim(?))), " + " upper(rtrim(ltrim(?))), "
+ "upper(rtrim(ltrim(?))), " + " upper(rtrim(ltrim(?))), "
+ "upper(rtrim(ltrim(?))), " + " upper(rtrim(ltrim(?))), "
+ "upper(rtrim(ltrim(?))), " + " upper(rtrim(ltrim(?))), "
+ "1)"; + " 0 "
+ " )";
Connection conexion = null; Connection conexion = null;
PreparedStatement psPersona = null, psFicha = null, psEstadoFicha = null, psTokenFicha = null, psObtenerToken = null, psObtenerCodigoFicha = null; PreparedStatement psPersona = null, psFicha = null, psEstadoFicha = null, psTokenFicha = null, psObtenerToken = null, psObtenerCodigoFicha = null;
ResultSet rsPersona = null, rsFicha = null, rsEstadoFicha = null, rsTokenFicha = null, rsObtenerToken = null, rsObtenerCodigoFicha = null; ResultSet rsPersona = null, rsFicha = null, rsEstadoFicha = null, rsTokenFicha = null, rsObtenerToken = null, rsObtenerCodigoFicha = null;
try { try {
conexion = MysqlDAOFactory.obtenerConexion(Variables.MYSQL_NUEVO_BD_NAME); conexion = MysqlDAOFactory.obtenerConexion(Variables.MYSQL_NUEVO_BD_NAME);
conexion.setAutoCommit(false); conexion.setAutoCommit(false);
...@@ -178,15 +187,12 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -178,15 +187,12 @@ public class PersonaMysqlDAO implements PersonaDAO {
int codigoPersona = rsPersona.getInt(1); int codigoPersona = rsPersona.getInt(1);
/*-************ REGISTRAR FICHA **************-*/ /*-************ REGISTRAR FICHA **************-*/
String sqlFicha = "" String sqlFicha = "INSERT INTO ficha ( "
+ "insert into ficha ( " + " codigo_persona, "
+ "codigo_persona " + " estado_registro "
+ ",estado_registro "
+ ") " + ") "
+ "values ( " + "VALUES "
+ "? " + " (?, 1)";
+ ",1 "
+ ")";
conexion.setAutoCommit(false); conexion.setAutoCommit(false);
psFicha = conexion.prepareStatement(sqlFicha, Statement.RETURN_GENERATED_KEYS); psFicha = conexion.prepareStatement(sqlFicha, Statement.RETURN_GENERATED_KEYS);
...@@ -199,20 +205,15 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -199,20 +205,15 @@ public class PersonaMysqlDAO implements PersonaDAO {
int codigoFicha = rsFicha.getInt(1); int codigoFicha = rsFicha.getInt(1);
/*-************ REGISTRAR ESTADO DE FICHA **************-*/ /*-************ REGISTRAR ESTADO DE FICHA **************-*/
String sqlEstadoFicha = "" String sqlEstadoFicha = "INSERT INTO estado_ficha ( "
+ "insert into estado_ficha ( " + " codigo_ficha, "
+ "codigo_ficha " + " codigo_tipo_estado_ficha, "
+ ",codigo_tipo_estado_ficha " + " fecha_registro, "
+ ",fecha_registro " + " codigo_usuario, "
+ ",codigo_usuario " + " estado_registro "
+ ",estado_registro " + ") "
+ ") VALUES ( " + "VALUES "
+ "?, " + " (?, 1, NOW(), ?, 1)";
+ "1, "
+ "getdate(), "
+ "?, "
+ "1 "
+ ")";
conexion.setAutoCommit(false); conexion.setAutoCommit(false);
psEstadoFicha = conexion.prepareStatement(sqlEstadoFicha); psEstadoFicha = conexion.prepareStatement(sqlEstadoFicha);
...@@ -222,28 +223,24 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -222,28 +223,24 @@ public class PersonaMysqlDAO implements PersonaDAO {
if (resultRegistrarEstadoFicha > 0) { if (resultRegistrarEstadoFicha > 0) {
/*-************ REGISTRAR TOKEN DE FICHA **************-*/ /*-************ REGISTRAR TOKEN DE FICHA **************-*/
String sqlTokenFicha = "" String sqlTokenFicha = "INSERT INTO token_ficha ( "
+ "insert into token_ficha " + " codigo_ficha, "
+ " ( " + " codigo_verificacion, "
+ "codigo_ficha " + " fecha_creacion, "
+ ",codigo_verificacion " + " fecha_expiracion, "
+ ",fecha_creacion " + " token, "
+ ",fecha_expiracion " + " codigo_sede_area, "
+ ",token " + " codigo_area_cargo, "
+ ",codigo_sede_area" + " estado_registro "
+ ",codigo_area_cargo"
+ ",estado_registro "
+ ") " + ") "
+ "values ( " + "VALUES "
+ "? " + " ( "
+ ",? " + " ? ,?, "
+ ",getdate() " + " now(), "
+ ",dateadd(dd, 1, getdate()) " + " timestampadd (DAY, 1, now()), "
+ ",lower(newid()) " + " lower(uuid()) ,? ,?, "
+ ",?" + " 1 "
+ ",?" + " )";
+ ",1 "
+ ")";
String CodeVerification = GenerateCodeVerification.randomString(6); // almacenar el codigo de verificacion a enviar String CodeVerification = GenerateCodeVerification.randomString(6); // almacenar el codigo de verificacion a enviar
conexion.setAutoCommit(false); conexion.setAutoCommit(false);
...@@ -260,11 +257,13 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -260,11 +257,13 @@ public class PersonaMysqlDAO implements PersonaDAO {
int codigoTokenFicha = rsTokenFicha.getInt(1); int codigoTokenFicha = rsTokenFicha.getInt(1);
/*-************ OBTENER TOKEN FICHA **************-*/ /*-************ OBTENER TOKEN FICHA **************-*/
String sqlGetToken = "" String sqlGetToken = "SELECT "
+ "select " + " token "
+ "token " + "FROM "
+ "from token_ficha " + " token_ficha "
+ "where codigo_token_ficha = ? and estado_registro = 1"; + "WHERE "
+ " codigo_token_ficha = ? "
+ "AND estado_registro = 1";
conexion.setAutoCommit(false); conexion.setAutoCommit(false);
psObtenerToken = conexion.prepareStatement(sqlGetToken); psObtenerToken = conexion.prepareStatement(sqlGetToken);
...@@ -310,7 +309,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -310,7 +309,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]"); response.setMessage("Error: " + e.getMessage() + " Error Code: [" + e.getErrorCode() + "]");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
...@@ -406,7 +405,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -406,7 +405,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]"); response.setMessage("Error: " + e.getMessage() + " Error Code: [" + e.getErrorCode() + "]");
} finally { } finally {
try { try {
if (rs != null) { if (rs != null) {
...@@ -460,7 +459,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -460,7 +459,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]"); response.setMessage("Error: " + e.getMessage() + " Error Code: [" + e.getErrorCode() + "]");
} finally { } finally {
try { try {
if (rsUpdatePersona != null) { if (rsUpdatePersona != null) {
...@@ -521,7 +520,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -521,7 +520,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]"); response.setMessage("Error: " + e.getMessage() + " Error Code: [" + e.getErrorCode() + "]");
} finally { } finally {
try { try {
if (rs != null) { if (rs != null) {
...@@ -596,7 +595,7 @@ public class PersonaMysqlDAO implements PersonaDAO { ...@@ -596,7 +595,7 @@ public class PersonaMysqlDAO implements PersonaDAO {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
response.setStatus(false); response.setStatus(false);
response.setMessage("Error: " + e.getMessage() + " \n Error Code: [" + e.getErrorCode() + "]"); response.setMessage("Error: " + e.getMessage() + " Error Code: [" + e.getErrorCode() + "]");
} finally { } finally {
try { try {
if (rs != null) { if (rs != null) {
......
...@@ -332,7 +332,7 @@ public class VacanteMysqlDAO implements VacanteDAO { ...@@ -332,7 +332,7 @@ public class VacanteMysqlDAO implements VacanteDAO {
+ " vacante.cantidad - ( " + " vacante.cantidad - ( "
+ " ( " + " ( "
+ " SELECT " + " SELECT "
+ " COUNT (1) " + " COUNT(1) "
+ " FROM " + " FROM "
+ " ficha_laboral fl " + " ficha_laboral fl "
+ " WHERE " + " WHERE "
...@@ -341,7 +341,7 @@ public class VacanteMysqlDAO implements VacanteDAO { ...@@ -341,7 +341,7 @@ public class VacanteMysqlDAO implements VacanteDAO {
+ " AND fl.codigo_area_cargo = vacante.codigo_area_cargo " + " AND fl.codigo_area_cargo = vacante.codigo_area_cargo "
+ " ) + ( " + " ) + ( "
+ " SELECT " + " SELECT "
+ " COUNT (1) " + " COUNT(1) "
+ " FROM " + " FROM "
+ " token_ficha tf " + " token_ficha tf "
+ " WHERE " + " WHERE "
......
...@@ -6,17 +6,17 @@ import trismegistoplanilla.dao.DAOFactory; ...@@ -6,17 +6,17 @@ import trismegistoplanilla.dao.DAOFactory;
public class ConfiguracionFichaService { public class ConfiguracionFichaService {
DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.SQL_SERVER); DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
ConfiguracionFichaDAO objConfiguracionFichaDAO = factory.getConfiguracionFichaDAO(); ConfiguracionFichaDAO objConfiguracionFichaDAO = factory.getConfiguracionFichaDAO();
public JSONObject getDefaultMail() { public JSONObject getDefaultMail() {
JSONObject JOmail = null; JSONObject JOmail = null;
try { try {
JOmail = objConfiguracionFichaDAO.getDefaultMail(); JOmail = objConfiguracionFichaDAO.getDefaultMail();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return JOmail; return JOmail;
} }
} }
...@@ -9,67 +9,67 @@ import trismegistoplanilla.dao.PersonaDAO; ...@@ -9,67 +9,67 @@ import trismegistoplanilla.dao.PersonaDAO;
public class PersonaService { public class PersonaService {
DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.SQL_SERVER); DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
PersonaDAO objPersonaDAO = factory.getPersonaDAO(); PersonaDAO objPersonaDAO = factory.getPersonaDAO();
public JSONObject validarExistenciaNumeroDocumento(PersonaBean p) { public JSONObject validarExistenciaNumeroDocumento(PersonaBean p) {
JSONObject jsonObjValidarExistenciaNumeroDocumento = null; JSONObject jsonObjValidarExistenciaNumeroDocumento = null;
try { try {
jsonObjValidarExistenciaNumeroDocumento = objPersonaDAO.validarExistenciaNumeroDocumento(p); jsonObjValidarExistenciaNumeroDocumento = objPersonaDAO.validarExistenciaNumeroDocumento(p);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjValidarExistenciaNumeroDocumento; return jsonObjValidarExistenciaNumeroDocumento;
} }
public JSONObject validarExistenciaCorreoElectronico(PersonaBean p) { public JSONObject validarExistenciaCorreoElectronico(PersonaBean p) {
JSONObject jsonObjValidarExistenciaCorreoElectronico = null; JSONObject jsonObjValidarExistenciaCorreoElectronico = null;
try { try {
jsonObjValidarExistenciaCorreoElectronico = objPersonaDAO.validarExistenciaCorreoElectronico(p); jsonObjValidarExistenciaCorreoElectronico = objPersonaDAO.validarExistenciaCorreoElectronico(p);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjValidarExistenciaCorreoElectronico; return jsonObjValidarExistenciaCorreoElectronico;
} }
public JSONObject registrarPersona(PersonaBean p, EstadoFichaBean ef, TokenFichaBean tf) { public JSONObject registrarPersona(PersonaBean p, EstadoFichaBean ef, TokenFichaBean tf) {
JSONObject jsonObjRegistrarPersona = null; JSONObject jsonObjRegistrarPersona = null;
try { try {
jsonObjRegistrarPersona = objPersonaDAO.registrarPersona(p, ef, tf); jsonObjRegistrarPersona = objPersonaDAO.registrarPersona(p, ef, tf);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjRegistrarPersona; return jsonObjRegistrarPersona;
} }
public JSONObject verificarPersona(TokenFichaBean tf, PersonaBean p) { public JSONObject verificarPersona(TokenFichaBean tf, PersonaBean p) {
JSONObject jsonObjVerificarPersona = null; JSONObject jsonObjVerificarPersona = null;
try { try {
jsonObjVerificarPersona = objPersonaDAO.verificarPersona(tf, p); jsonObjVerificarPersona = objPersonaDAO.verificarPersona(tf, p);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjVerificarPersona; return jsonObjVerificarPersona;
} }
public JSONObject obtenerCodigoPersona(TokenFichaBean tf) { public JSONObject obtenerCodigoPersona(TokenFichaBean tf) {
JSONObject jsonObjObtenerCodigoPersona = null; JSONObject jsonObjObtenerCodigoPersona = null;
try { try {
jsonObjObtenerCodigoPersona = objPersonaDAO.obtenerCodigoPersona(tf); jsonObjObtenerCodigoPersona = objPersonaDAO.obtenerCodigoPersona(tf);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjObtenerCodigoPersona; return jsonObjObtenerCodigoPersona;
} }
public JSONObject obtenerPersonaSession(PersonaBean p) { public JSONObject obtenerPersonaSession(PersonaBean p) {
JSONObject jsonObjObtenerPersonaSession = null; JSONObject jsonObjObtenerPersonaSession = null;
try { try {
jsonObjObtenerPersonaSession = objPersonaDAO.obtenerPersonaSession(p); jsonObjObtenerPersonaSession = objPersonaDAO.obtenerPersonaSession(p);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjObtenerPersonaSession; return jsonObjObtenerPersonaSession;
} }
} }
...@@ -7,7 +7,7 @@ import trismegistoplanilla.dao.SedeDAO; ...@@ -7,7 +7,7 @@ import trismegistoplanilla.dao.SedeDAO;
public class SedeService { public class SedeService {
DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.SQL_SERVER); DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
SedeDAO objSedeDAO = factory.getSedeDAO(); SedeDAO objSedeDAO = factory.getSedeDAO();
public JSONObject listarSede() { public JSONObject listarSede() {
......
...@@ -8,47 +8,47 @@ import trismegistoplanilla.dao.TipoDocumentoDAO; ...@@ -8,47 +8,47 @@ import trismegistoplanilla.dao.TipoDocumentoDAO;
public class TipoDocumentoService { public class TipoDocumentoService {
DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.SQL_SERVER); DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
TipoDocumentoDAO objTipoDocumentoDAO = factory.getTipoDocumentoDAO(); TipoDocumentoDAO objTipoDocumentoDAO = factory.getTipoDocumentoDAO();
public JSONObject listarTipoDocumento() { public JSONObject listarTipoDocumento() {
JSONObject jsonObjListarTipoDocumento = null; JSONObject jsonObjListarTipoDocumento = null;
try { try {
jsonObjListarTipoDocumento = objTipoDocumentoDAO.listarTipoDocumento(); jsonObjListarTipoDocumento = objTipoDocumentoDAO.listarTipoDocumento();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjListarTipoDocumento; return jsonObjListarTipoDocumento;
} }
public JSONObject validarExistenciaTipoDocumento(TipoDocumentoBean tipoDocumento) { public JSONObject validarExistenciaTipoDocumento(TipoDocumentoBean tipoDocumento) {
JSONObject jsonObjValidarExistenciaTipoDocumento = null; JSONObject jsonObjValidarExistenciaTipoDocumento = null;
try { try {
jsonObjValidarExistenciaTipoDocumento = objTipoDocumentoDAO.validarExistenciaTipoDocumento(tipoDocumento); jsonObjValidarExistenciaTipoDocumento = objTipoDocumentoDAO.validarExistenciaTipoDocumento(tipoDocumento);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjValidarExistenciaTipoDocumento; return jsonObjValidarExistenciaTipoDocumento;
} }
public JSONObject obtenerLongitudTipoEntrdadaTipoDocumento(TipoDocumentoBean tipoDocumento) { public JSONObject obtenerLongitudTipoEntrdadaTipoDocumento(TipoDocumentoBean tipoDocumento) {
JSONObject jsonObjObtenerLongitudTipoEntrdadaTipoDocumento = null; JSONObject jsonObjObtenerLongitudTipoEntrdadaTipoDocumento = null;
try { try {
jsonObjObtenerLongitudTipoEntrdadaTipoDocumento = objTipoDocumentoDAO.obtenerLongitudTipoEntrdadaTipoDocumento(tipoDocumento); jsonObjObtenerLongitudTipoEntrdadaTipoDocumento = objTipoDocumentoDAO.obtenerLongitudTipoEntrdadaTipoDocumento(tipoDocumento);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjObtenerLongitudTipoEntrdadaTipoDocumento; return jsonObjObtenerLongitudTipoEntrdadaTipoDocumento;
} }
public JSONObject obtenerCodigoTipoDocumento(TokenFichaBean tf) { public JSONObject obtenerCodigoTipoDocumento(TokenFichaBean tf) {
JSONObject jsonObjObtenerCodigoTipoDocumento = null; JSONObject jsonObjObtenerCodigoTipoDocumento = null;
try { try {
jsonObjObtenerCodigoTipoDocumento = objTipoDocumentoDAO.obtenerCodigoTipoDocumento(tf); jsonObjObtenerCodigoTipoDocumento = objTipoDocumentoDAO.obtenerCodigoTipoDocumento(tf);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return jsonObjObtenerCodigoTipoDocumento; return jsonObjObtenerCodigoTipoDocumento;
} }
} }
...@@ -20,7 +20,6 @@ public class ConfiguracionFichaServlet extends HttpServlet { ...@@ -20,7 +20,6 @@ public class ConfiguracionFichaServlet extends HttpServlet {
if (accion.equals("getDefaultMail")) { if (accion.equals("getDefaultMail")) {
getDefaultMail(request, response); getDefaultMail(request, response);
} }
} }
private void getDefaultMail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { private void getDefaultMail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
......
...@@ -13,288 +13,288 @@ import pe.siso.webservicesseguridad.webservices.UsuarioBean; ...@@ -13,288 +13,288 @@ import pe.siso.webservicesseguridad.webservices.UsuarioBean;
import trismegistoplanilla.beans.EstadoFichaBean; import trismegistoplanilla.beans.EstadoFichaBean;
import trismegistoplanilla.beans.PersonaBean; import trismegistoplanilla.beans.PersonaBean;
import trismegistoplanilla.beans.TokenFichaBean; import trismegistoplanilla.beans.TokenFichaBean;
import trismegistoplanilla.services.PersonaService; import trismegistoplanilla.servicesMysql.PersonaService;
import trismegistoplanilla.services.TipoDocumentoService; import trismegistoplanilla.services.TipoDocumentoService;
import trismegistoplanilla.utilities.ParamsValidation; import trismegistoplanilla.utilities.ParamsValidation;
public class PersonaServlet extends HttpServlet { public class PersonaServlet extends HttpServlet {
private static final long serialVersionUID = 767323838778604646L; private static final long serialVersionUID = 767323838778604646L;
HttpSession session = null; HttpSession session = null;
String mensaje = ""; String mensaje = "";
@Override @Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
session = request.getSession(); session = request.getSession();
String accion = request.getParameter("accion"); String accion = request.getParameter("accion");
if (accion == null) { if (accion == null) {
} else { } else {
switch (accion) { switch (accion) {
case "validarExistenciaNumeroDocumento": case "validarExistenciaNumeroDocumento":
validarExistenciaNumeroDocumento(request, response); validarExistenciaNumeroDocumento(request, response);
break; break;
case "validarExistenciaCorreoElectronico": case "validarExistenciaCorreoElectronico":
validarExistenciaCorreoElectronico(request, response); validarExistenciaCorreoElectronico(request, response);
break; break;
case "registrarNuevaFicha": case "registrarNuevaFicha":
registrarNuevaFicha(request, response); registrarNuevaFicha(request, response);
break; break;
case "verificarPersona": case "verificarPersona":
verificarPersona(request, response); verificarPersona(request, response);
break; break;
default: default:
break; break;
} }
} }
} }
private void validarExistenciaNumeroDocumento(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { private void validarExistenciaNumeroDocumento(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json"); response.setContentType("application/json");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
JSONObject JOPersona = new JSONObject(); JSONObject JOPersona = new JSONObject();
if (request.getParameter("json") == null) { if (request.getParameter("json") == null) {
JOPersona.put("status", false); JOPersona.put("status", false);
JOPersona.put("message", "El parámetro llegó nulo"); JOPersona.put("message", "El parámetro llegó nulo");
} else { } else {
String data = request.getParameter("json"); String data = request.getParameter("json");
JSONObject json = new JSONObject(data); JSONObject json = new JSONObject(data);
// validar numero de documento // validar numero de documento
if (!ParamsValidation.validaTipoEntrada(json.getString("tipoEntrada"), json.getString("numeroDocumento"))) { if (!ParamsValidation.validaTipoEntrada(json.getString("tipoEntrada"), json.getString("numeroDocumento"))) {
JOPersona.put("status", false); JOPersona.put("status", false);
JOPersona.put("message", "El parámetro llegó nulo"); JOPersona.put("message", "El parámetro llegó nulo");
} }
if (!ParamsValidation.validaLongitudNumeroDocumento(json.getInt("longitud"), json.getString("numeroDocumento"))) { if (!ParamsValidation.validaLongitudNumeroDocumento(json.getInt("longitud"), json.getString("numeroDocumento"))) {
JOPersona.put("status", false); JOPersona.put("status", false);
JOPersona.put("message", "El parámetro llegó nulo"); JOPersona.put("message", "El parámetro llegó nulo");
} }
PersonaService service = new PersonaService(); PersonaService service = new PersonaService();
PersonaBean p = new PersonaBean(); PersonaBean p = new PersonaBean();
p.setCodigoTipoDocumento(json.getInt("codigoTipoDocumento")); p.setCodigoTipoDocumento(json.getInt("codigoTipoDocumento"));
p.setNumeroDocumento(json.getString("numeroDocumento")); p.setNumeroDocumento(json.getString("numeroDocumento"));
JOPersona = service.validarExistenciaNumeroDocumento(p); JOPersona = service.validarExistenciaNumeroDocumento(p);
} }
out.print(JOPersona); out.print(JOPersona);
} }
private void validarExistenciaCorreoElectronico(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { private void validarExistenciaCorreoElectronico(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json"); response.setContentType("application/json");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
JSONObject jsonObjValidarExistenciaCorreoElectronico = null; JSONObject jsonObjValidarExistenciaCorreoElectronico = null;
if (request.getParameter("correoElectronico") != null) { if (request.getParameter("correoElectronico") != null) {
String correoElectronico = request.getParameter("correoElectronico"); String correoElectronico = request.getParameter("correoElectronico");
boolean validarCorreoElectronico = ParamsValidation.validaCorreo(correoElectronico); boolean validarCorreoElectronico = ParamsValidation.validaCorreo(correoElectronico);
if (validarCorreoElectronico) { if (validarCorreoElectronico) {
PersonaService service = new PersonaService(); PersonaService service = new PersonaService();
PersonaBean p = new PersonaBean(); PersonaBean p = new PersonaBean();
p.setCorreo(correoElectronico); p.setCorreo(correoElectronico);
jsonObjValidarExistenciaCorreoElectronico = service.validarExistenciaCorreoElectronico(p); jsonObjValidarExistenciaCorreoElectronico = service.validarExistenciaCorreoElectronico(p);
out.print(jsonObjValidarExistenciaCorreoElectronico); out.print(jsonObjValidarExistenciaCorreoElectronico);
} else { } else {
jsonObjValidarExistenciaCorreoElectronico = new JSONObject(); jsonObjValidarExistenciaCorreoElectronico = new JSONObject();
jsonObjValidarExistenciaCorreoElectronico.put("status", false); jsonObjValidarExistenciaCorreoElectronico.put("status", false);
jsonObjValidarExistenciaCorreoElectronico.put("message", "Ha sucedido un error, el dato ingresado no es un correo electrónico"); jsonObjValidarExistenciaCorreoElectronico.put("message", "Ha sucedido un error, el dato ingresado no es un correo electrónico");
out.print(jsonObjValidarExistenciaCorreoElectronico); out.print(jsonObjValidarExistenciaCorreoElectronico);
} }
} else { } else {
jsonObjValidarExistenciaCorreoElectronico = new JSONObject(); jsonObjValidarExistenciaCorreoElectronico = new JSONObject();
jsonObjValidarExistenciaCorreoElectronico.put("status", false); jsonObjValidarExistenciaCorreoElectronico.put("status", false);
jsonObjValidarExistenciaCorreoElectronico.put("message", "Ha sucedido un error, el dato llegó nulo"); jsonObjValidarExistenciaCorreoElectronico.put("message", "Ha sucedido un error, el dato llegó nulo");
out.print(jsonObjValidarExistenciaCorreoElectronico); out.print(jsonObjValidarExistenciaCorreoElectronico);
} }
} }
private void registrarNuevaFicha(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { private void registrarNuevaFicha(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json"); response.setContentType("application/json");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
JSONObject JOFicha = new JSONObject(); JSONObject JOFicha = new JSONObject();
if (request.getParameter("json") == null) { if (request.getParameter("json") == null) {
JOFicha.put("status", false); JOFicha.put("status", false);
JOFicha.put("message", "El parámetro llegó nulo"); JOFicha.put("message", "El parámetro llegó nulo");
} else { } else {
String data = request.getParameter("json"); String data = request.getParameter("json");
JSONObject json = new JSONObject(data); JSONObject json = new JSONObject(data);
HttpSession sessionUser = request.getSession(); HttpSession sessionUser = request.getSession();
UsuarioBean usuario = (UsuarioBean) sessionUser.getAttribute("usuario"); UsuarioBean usuario = (UsuarioBean) sessionUser.getAttribute("usuario");
// -------------------------------------------------------- // // -------------------------------------------------------- //
int codigoUsuario = usuario.getCodigoUsuario(); int codigoUsuario = usuario.getCodigoUsuario();
EstadoFichaBean ef = new EstadoFichaBean(); EstadoFichaBean ef = new EstadoFichaBean();
ef.setCodigoUsuario(codigoUsuario); ef.setCodigoUsuario(codigoUsuario);
// -------------------------------------------------------- // // -------------------------------------------------------- //
int codigoSedeArea = json.getInt("codigoSedeArea"); int codigoSedeArea = json.getInt("codigoSedeArea");
int codigoAreaCargo = json.getInt("codigoAreaCargo"); int codigoAreaCargo = json.getInt("codigoAreaCargo");
TokenFichaBean tf = new TokenFichaBean(); TokenFichaBean tf = new TokenFichaBean();
tf.setCodigoSedeArea(codigoSedeArea); tf.setCodigoSedeArea(codigoSedeArea);
tf.setCodigoAreaCargo(codigoAreaCargo); tf.setCodigoAreaCargo(codigoAreaCargo);
// -------------------------------------------------------- // // -------------------------------------------------------- //
int codigoTipoDocumento = json.getJSONObject("tipoDocumento").getInt("codigoTipoDocumento"); int codigoTipoDocumento = json.getJSONObject("tipoDocumento").getInt("codigoTipoDocumento");
String numeroDocumento = json.getJSONObject("tipoDocumento").getString("numeroDocumento"); String numeroDocumento = json.getJSONObject("tipoDocumento").getString("numeroDocumento");
int tieneCorreo = 0; int tieneCorreo = 0;
String correo = ""; String correo = "";
if (json.getBoolean("tieneCorreo")) { if (json.getBoolean("tieneCorreo")) {
tieneCorreo = 0; tieneCorreo = 0;
correo = json.getString("correo"); correo = json.getString("correo");
} else { } else {
tieneCorreo = 1; tieneCorreo = 1;
correo = json.getString("correoPorDefecto"); correo = json.getString("correoPorDefecto");
} }
PersonaBean p = new PersonaBean(); PersonaBean p = new PersonaBean();
p.setCodigoTipoDocumento(codigoTipoDocumento); p.setCodigoTipoDocumento(codigoTipoDocumento);
p.setNumeroDocumento(numeroDocumento); p.setNumeroDocumento(numeroDocumento);
p.setCorreo(correo); p.setCorreo(correo);
p.setIsDefaultMail(tieneCorreo); p.setIsDefaultMail(tieneCorreo);
p.setApellidoPaterno(null); p.setApellidoPaterno(null);
p.setApellidoMaterno(null); p.setApellidoMaterno(null);
p.setNombre(null); p.setNombre(null);
// tipo de ducumento = dni // tipo de ducumento = dni
if (json.getJSONObject("tipoDocumento").getInt("codigoTipoDocumento") == 1 && json.getBoolean("validadoPoReniec") && !json.getBoolean("errorReniec")) { if (json.getJSONObject("tipoDocumento").getInt("codigoTipoDocumento") == 1 && json.getBoolean("validadoPoReniec") && !json.getBoolean("errorReniec")) {
JSONObject persona = json.getJSONObject("persona"); JSONObject persona = json.getJSONObject("persona");
String apellidoPaterno = persona.getString("apellidoPaterno"); String apellidoPaterno = persona.getString("apellidoPaterno");
String apellidoMaterno = persona.getString("apellidoMaterno"); String apellidoMaterno = persona.getString("apellidoMaterno");
String nombres = persona.getString("nombres"); String nombres = persona.getString("nombres");
String dni = persona.getString("dni"); String dni = persona.getString("dni");
p.setApellidoPaterno(apellidoPaterno); p.setApellidoPaterno(apellidoPaterno);
p.setApellidoMaterno(apellidoMaterno); p.setApellidoMaterno(apellidoMaterno);
p.setNombre(nombres); p.setNombre(nombres);
p.setNumeroDocumento(dni); p.setNumeroDocumento(dni);
} else if (json.getJSONObject("tipoDocumento").getInt("codigoTipoDocumento") == 1 && !json.getBoolean("validadoPoReniec") && json.getBoolean("errorReniec")) { } else if (json.getJSONObject("tipoDocumento").getInt("codigoTipoDocumento") == 1 && !json.getBoolean("validadoPoReniec") && json.getBoolean("errorReniec")) {
JSONObject persona = json.getJSONObject("serviceFailure"); JSONObject persona = json.getJSONObject("serviceFailure");
String apellidoPaterno = persona.getString("apellidoPaterno"); String apellidoPaterno = persona.getString("apellidoPaterno");
String apellidoMaterno = persona.getString("apellidoMaterno"); String apellidoMaterno = persona.getString("apellidoMaterno");
String nombres = persona.getString("nombres"); String nombres = persona.getString("nombres");
String dni = persona.getString("dni"); String dni = persona.getString("dni");
p.setApellidoPaterno(apellidoPaterno); p.setApellidoPaterno(apellidoPaterno);
p.setApellidoMaterno(apellidoMaterno); p.setApellidoMaterno(apellidoMaterno);
p.setNombre(nombres); p.setNombre(nombres);
p.setNumeroDocumento(dni); p.setNumeroDocumento(dni);
} }
PersonaService service = new PersonaService(); PersonaService service = new PersonaService();
JOFicha = service.registrarPersona(p, ef, tf); JOFicha = service.registrarPersona(p, ef, tf);
} }
out.print(JOFicha); out.print(JOFicha);
} }
private void verificarPersona(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { private void verificarPersona(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String codigoVerificacion = request.getParameter("codigoVerificacion"); String codigoVerificacion = request.getParameter("codigoVerificacion");
String numeroDocumento = request.getParameter("numeroDocumento"); String numeroDocumento = request.getParameter("numeroDocumento");
// verificamos que los parametros enviados desde el jsp no sean nulos // verificamos que los parametros enviados desde el jsp no sean nulos
if (codigoVerificacion != null && numeroDocumento != null) { if (codigoVerificacion != null && numeroDocumento != null) {
// validar que los parametros sean solo alfanumericos // validar que los parametros sean solo alfanumericos
if (ParamsValidation.validaSoloAlfanumerico(codigoVerificacion) && ParamsValidation.validaSoloAlfanumerico(numeroDocumento)) { if (ParamsValidation.validaSoloAlfanumerico(codigoVerificacion) && ParamsValidation.validaSoloAlfanumerico(numeroDocumento)) {
// obtenemos los valores de session // obtenemos los valores de session
TokenFichaBean tf = (TokenFichaBean) session.getAttribute("tokenFicha"); TokenFichaBean tf = (TokenFichaBean) session.getAttribute("tokenFicha");
tf.setCodigoVerificacion(codigoVerificacion); tf.setCodigoVerificacion(codigoVerificacion);
// instanciar objeto persona y setear valores // instanciar objeto persona y setear valores
PersonaBean p = new PersonaBean(); PersonaBean p = new PersonaBean();
p.setNumeroDocumento(numeroDocumento); p.setNumeroDocumento(numeroDocumento);
// instanciar servicio persona // instanciar servicio persona
PersonaService service = new PersonaService(); PersonaService service = new PersonaService();
// invocar al metodo de verificacion de persona // invocar al metodo de verificacion de persona
JSONObject jsonObjVerificarPersona = service.verificarPersona(tf, p); JSONObject jsonObjVerificarPersona = service.verificarPersona(tf, p);
// validar repuesta del metodo verificar persona // validar repuesta del metodo verificar persona
if (jsonObjVerificarPersona.getBoolean("status")) { if (jsonObjVerificarPersona.getBoolean("status")) {
// obtener codigo tipo de documento // obtener codigo tipo de documento
TipoDocumentoService serviceTipoDocumento = new TipoDocumentoService(); TipoDocumentoService serviceTipoDocumento = new TipoDocumentoService();
JSONObject jsonObjObtenerCodigoTipoDocumento = serviceTipoDocumento.obtenerCodigoTipoDocumento(tf); JSONObject jsonObjObtenerCodigoTipoDocumento = serviceTipoDocumento.obtenerCodigoTipoDocumento(tf);
// validar respuesta del metodo obtener codigo tipo documento // validar respuesta del metodo obtener codigo tipo documento
if (jsonObjObtenerCodigoTipoDocumento.getBoolean("status")) { if (jsonObjObtenerCodigoTipoDocumento.getBoolean("status")) {
int codigoTipoDocumento = jsonObjObtenerCodigoTipoDocumento.getJSONObject("data").getInt("getResultedKey"); int codigoTipoDocumento = jsonObjObtenerCodigoTipoDocumento.getJSONObject("data").getInt("getResultedKey");
JSONObject jsonObjObtenerCodigoPersona = service.obtenerCodigoPersona(tf); JSONObject jsonObjObtenerCodigoPersona = service.obtenerCodigoPersona(tf);
// validar respuesta del metodo obtener codigo persona // validar respuesta del metodo obtener codigo persona
if (jsonObjObtenerCodigoPersona.getBoolean("status")) { if (jsonObjObtenerCodigoPersona.getBoolean("status")) {
int codigoPersona = jsonObjObtenerCodigoPersona.getJSONObject("data").getInt("getResultedKey"); int codigoPersona = jsonObjObtenerCodigoPersona.getJSONObject("data").getInt("getResultedKey");
// instacia de la clase persona // instacia de la clase persona
p.setCodigoPersona(codigoPersona); p.setCodigoPersona(codigoPersona);
p.setCodigoTipoDocumento(codigoTipoDocumento); p.setCodigoTipoDocumento(codigoTipoDocumento);
JSONObject jsonObjObtenerPersonaSession = service.obtenerPersonaSession(p); JSONObject jsonObjObtenerPersonaSession = service.obtenerPersonaSession(p);
// validar respuesta del metodo obtener persona session // validar respuesta del metodo obtener persona session
if (jsonObjObtenerPersonaSession.getBoolean("status")) { if (jsonObjObtenerPersonaSession.getBoolean("status")) {
JSONObject jsonObjPersona = jsonObjObtenerPersonaSession.getJSONObject("data"); JSONObject jsonObjPersona = jsonObjObtenerPersonaSession.getJSONObject("data");
JSONArray jsonArrPersona = jsonObjPersona.getJSONArray("personas"); JSONArray jsonArrPersona = jsonObjPersona.getJSONArray("personas");
if (jsonArrPersona.getJSONObject(0).isNull("apellidoPaterno")) { if (jsonArrPersona.getJSONObject(0).isNull("apellidoPaterno")) {
p.setApellidoPaterno(null); p.setApellidoPaterno(null);
} else { } else {
p.setApellidoPaterno(jsonArrPersona.getJSONObject(0).getString("apellidoPaterno")); p.setApellidoPaterno(jsonArrPersona.getJSONObject(0).getString("apellidoPaterno"));
} }
if (jsonArrPersona.getJSONObject(0).isNull("apellidoMaterno")) { if (jsonArrPersona.getJSONObject(0).isNull("apellidoMaterno")) {
p.setApellidoMaterno(null); p.setApellidoMaterno(null);
} else { } else {
p.setApellidoMaterno(jsonArrPersona.getJSONObject(0).getString("apellidoMaterno")); p.setApellidoMaterno(jsonArrPersona.getJSONObject(0).getString("apellidoMaterno"));
} }
if (jsonArrPersona.getJSONObject(0).isNull("nombre")) { if (jsonArrPersona.getJSONObject(0).isNull("nombre")) {
p.setNombre(null); p.setNombre(null);
} else { } else {
p.setNombre(jsonArrPersona.getJSONObject(0).getString("nombre")); p.setNombre(jsonArrPersona.getJSONObject(0).getString("nombre"));
} }
p.setCorreo(jsonArrPersona.getJSONObject(0).getString("correo")); p.setCorreo(jsonArrPersona.getJSONObject(0).getString("correo"));
p.setNombreTipoDocumento(jsonArrPersona.getJSONObject(0).getString("nombreTipoDocumento")); p.setNombreTipoDocumento(jsonArrPersona.getJSONObject(0).getString("nombreTipoDocumento"));
if (codigoTipoDocumento == 3) { if (codigoTipoDocumento == 3) {
p.setRuc(numeroDocumento); p.setRuc(numeroDocumento);
} }
session.setAttribute("persona", p); session.setAttribute("persona", p);
response.sendRedirect("vistas/ficha.jsp"); response.sendRedirect("vistas/ficha.jsp");
} else { } else {
mensaje = jsonObjObtenerPersonaSession.getString("message"); mensaje = jsonObjObtenerPersonaSession.getString("message");
session.setAttribute("errorTokenFicha", mensaje); session.setAttribute("errorTokenFicha", mensaje);
response.sendRedirect("vistas/response/ErrorToken.jsp"); response.sendRedirect("vistas/response/ErrorToken.jsp");
session.removeAttribute("tokenFicha"); session.removeAttribute("tokenFicha");
} }
} else { } else {
mensaje = jsonObjObtenerCodigoPersona.getString("message"); mensaje = jsonObjObtenerCodigoPersona.getString("message");
session.setAttribute("errorTokenFicha", mensaje); session.setAttribute("errorTokenFicha", mensaje);
response.sendRedirect("vistas/response/ErrorToken.jsp"); response.sendRedirect("vistas/response/ErrorToken.jsp");
session.removeAttribute("tokenFicha"); session.removeAttribute("tokenFicha");
} }
} else { } else {
mensaje = jsonObjObtenerCodigoTipoDocumento.getString("message"); mensaje = jsonObjObtenerCodigoTipoDocumento.getString("message");
session.setAttribute("errorTokenFicha", mensaje); session.setAttribute("errorTokenFicha", mensaje);
response.sendRedirect("vistas/response/ErrorToken.jsp"); response.sendRedirect("vistas/response/ErrorToken.jsp");
session.removeAttribute("tokenFicha"); session.removeAttribute("tokenFicha");
} }
} else { } else {
mensaje = jsonObjVerificarPersona.getString("message"); mensaje = jsonObjVerificarPersona.getString("message");
session.setAttribute("errorTokenFicha", mensaje); session.setAttribute("errorTokenFicha", mensaje);
response.sendRedirect("vistas/response/ErrorToken.jsp"); response.sendRedirect("vistas/response/ErrorToken.jsp");
session.removeAttribute("tokenFicha"); session.removeAttribute("tokenFicha");
} }
} else { } else {
mensaje = "Los valores enviados no son alfanuméricos"; mensaje = "Los valores enviados no son alfanuméricos";
session.setAttribute("errorTokenFicha", mensaje); session.setAttribute("errorTokenFicha", mensaje);
response.sendRedirect("vistas/response/ErrorToken.jsp"); response.sendRedirect("vistas/response/ErrorToken.jsp");
session.removeAttribute("tokenFicha"); session.removeAttribute("tokenFicha");
} }
} else { } else {
mensaje = "Los valores son nulos"; mensaje = "Los valores son nulos";
session.setAttribute("errorTokenFicha", mensaje); session.setAttribute("errorTokenFicha", mensaje);
response.sendRedirect("vistas/response/ErrorToken.jsp"); response.sendRedirect("vistas/response/ErrorToken.jsp");
session.removeAttribute("tokenFicha"); session.removeAttribute("tokenFicha");
} }
} }
} }
...@@ -13,49 +13,49 @@ import trismegistoplanilla.utilities.ParamsValidation; ...@@ -13,49 +13,49 @@ import trismegistoplanilla.utilities.ParamsValidation;
public class SedeServlet extends HttpServlet { public class SedeServlet extends HttpServlet {
private static final long serialVersionUID = -339375847638215388L; private static final long serialVersionUID = -339375847638215388L;
@Override @Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String accion = request.getParameter("accion"); String accion = request.getParameter("accion");
if (accion.equals("listarSede")) { if (accion.equals("listarSede")) {
listarSede(request, response); listarSede(request, response);
} else if (accion.equals("validarExistenciaSede")) { } else if (accion.equals("validarExistenciaSede")) {
validarExistenciaSede(request, response); validarExistenciaSede(request, response);
} }
} }
private void listarSede(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { private void listarSede(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json"); response.setContentType("application/json");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
SedeService service = new SedeService(); SedeService service = new SedeService();
JSONObject JObjectSede = service.listarSede(); JSONObject JObjectSede = service.listarSede();
out.print(JObjectSede); out.print(JObjectSede);
} }
private void validarExistenciaSede(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { private void validarExistenciaSede(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json"); response.setContentType("application/json");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
JSONObject JObjectValidarExistenciaSede = new JSONObject(); JSONObject JObjectValidarExistenciaSede = new JSONObject();
if (request.getParameter("codigoSede") == null) { if (request.getParameter("codigoSede") == null) {
JObjectValidarExistenciaSede.put("message", "Los datos llegaron nulos"); JObjectValidarExistenciaSede.put("message", "Los datos llegaron nulos");
JObjectValidarExistenciaSede.put("status", false); JObjectValidarExistenciaSede.put("status", false);
out.print(JObjectValidarExistenciaSede); out.print(JObjectValidarExistenciaSede);
} else { } else {
if (ParamsValidation.validaSoloNumeros(Integer.parseInt(request.getParameter("codigoSede")))) { if (ParamsValidation.validaSoloNumeros(Integer.parseInt(request.getParameter("codigoSede")))) {
int codigoSede = Integer.parseInt(request.getParameter("codigoSede")); int codigoSede = Integer.parseInt(request.getParameter("codigoSede"));
SedeBean s = new SedeBean(); SedeBean s = new SedeBean();
s.setCodigoSede(codigoSede); s.setCodigoSede(codigoSede);
SedeService service = new SedeService(); SedeService service = new SedeService();
JObjectValidarExistenciaSede = service.validarExistenciaSede(s); JObjectValidarExistenciaSede = service.validarExistenciaSede(s);
out.print(JObjectValidarExistenciaSede); out.print(JObjectValidarExistenciaSede);
} else { } else {
JObjectValidarExistenciaSede.put("message", "El codigoSede solo aceptar numeros"); JObjectValidarExistenciaSede.put("message", "El codigoSede solo aceptar numeros");
JObjectValidarExistenciaSede.put("status", false); JObjectValidarExistenciaSede.put("status", false);
out.print(JObjectValidarExistenciaSede); out.print(JObjectValidarExistenciaSede);
} }
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment