Commit b6abace7 by Denys Tito Urbano

[ADD] ENDPOINT LISTAR EXAMEN Y ACTUALIZAR EXAMEN

parent 69fd7cb4
......@@ -11,6 +11,7 @@ import pe.so.api.formulario.utilities.Commons;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.json.JSONException;
@Provider
@Path("excel")
......@@ -225,4 +226,80 @@ public class ExcelApi {
return Response.status(200).entity(MSJ_RESPUESTA.toString()).build();
}
@POST
@Path("/examen")
public Response actualizar_examen_alumno(String json) throws Exception {
JSONObject salida = new JSONObject();
try {
JSONObject entrada = new JSONObject(json);
salida = new ExcelServices().actualizar_examen_alumno(entrada);
return Response.status(200).entity(salida.toString()).build();
} catch (JSONException ex) {
salida.put("status", false);
salida.put("message", ex.getMessage());
throw new WebApplicationException(Response.status(400).entity(salida.toString()).build());
} catch (BadRequestException ex) {
salida = new JSONObject(ex.getMessage());
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
} catch (Exception ex) {
salida.put("status", false);
salida.put("message", ex.getMessage());
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
}
}
@POST
@Path("/listar_examen")
public Response listar_examen(String json) {
JSONObject salida = new JSONObject();
try {
JSONObject entrada = new JSONObject(json);
salida = new ExcelServices().listar_examen(entrada);
return Response.status(200).entity(salida.toString()).build();
} catch (JSONException ex) {
salida.put("status", false);
salida.put("message", ex.getMessage());
throw new WebApplicationException(Response.status(400).entity(salida.toString()).build());
} catch (BadRequestException ex) {
salida = new JSONObject(ex.getMessage());
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
} catch (Exception ex) {
salida.put("status", false);
salida.put("message", ex.getMessage());
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
}
}
@POST
@Path("/actualizar_examen")
public Response actualizar_examen(String json) throws Exception {
JSONObject salida = new JSONObject();
try {
JSONObject entrada = new JSONObject(json);
salida = new ExcelServices().actualizar_examen(entrada);
return Response.status(200).entity(salida.toString()).build();
} catch (JSONException ex) {
salida.put("status", false);
salida.put("message", ex.getMessage());
throw new WebApplicationException(Response.status(400).entity(salida.toString()).build());
} catch (BadRequestException ex) {
salida = new JSONObject(ex.getMessage());
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
} catch (Exception ex) {
salida.put("status", false);
salida.put("message", ex.getMessage());
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
}
}
}
......@@ -27,4 +27,11 @@ public interface ExcelDAO{
JSONObject execute_matricula_online2 (JSONObject json) throws Exception;
JSONObject execute_reporte_pagos(JSONObject entrada) throws Exception;
JSONObject actualizar_examen_alumno (JSONObject json) throws Exception;
JSONObject listar_examen (JSONObject entrada) throws Exception;
JSONObject actualizar_examen (JSONObject entrada) throws Exception;
}
......@@ -3,7 +3,7 @@ package pe.so.api.formulario.dao;
import pe.so.api.formulario.mongodbdao.MongoDBFactoryDAO;
import pe.so.api.formulario.postgresdao.PostgreSqlFactoryDAO;
public abstract class FactoryDAO{
public abstract class FactoryDAO extends DAO {
public static final int MONGODB = 1;
public static final int POSTGRESQL = 2;
......
......@@ -25,7 +25,8 @@ public class CorsFilter implements Filter{
public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException{
String[] ExcelIds={"1ItAa2YGBj60AVghmsCfMJZYooDRQGN2gyPWpgtvGHxA",
"1puh5xCtsGwwFaqKSgPcRt5II23MtZ2C9u0C_ussVYyc"};
"1puh5xCtsGwwFaqKSgPcRt5II23MtZ2C9u0C_ussVYyc",
"1ft51jmdtqqMpj51y2EisvwUFlNc8b3IZhOKff2DUScA"};
HttpServletResponse response=(HttpServletResponse)servletResponse;
HttpServletRequest request=(HttpServletRequest)servletRequest;
......@@ -63,6 +64,7 @@ public class CorsFilter implements Filter{
AtomicReference<Boolean> existe=new AtomicReference<>(false);
JSONArray data=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_encuesta_plc")).getJSONArray("data");
JSONArray data2=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_balotario")).getJSONArray("data");
JSONArray data3=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_examen")).getJSONArray("data");
data.forEach(obj -> {
JSONObject o=(JSONObject)obj;
......@@ -76,7 +78,13 @@ public class CorsFilter implements Filter{
existe.set(true);
}
});
data3.forEach(obj -> {
JSONObject o=(JSONObject)obj;
if(o.getString("id").equals(id)){
existe.set(true);
}
});
return existe.get();
}
......
......@@ -653,4 +653,25 @@ public class PostgreSqlExcel implements ExcelDAO {
return respuesta;
}
@Override
public JSONObject actualizar_examen_alumno(JSONObject entrada) throws Exception {
String sql = "SELECT * FROM academico.func_examen_procesar_alumno( ?, ?, ?, ?, ?, ?, ?, ? );";
JSONObject data = PostgreSqlFactoryDAO.queryPSSingle("siiaa", sql, entrada.getJSONArray("params"));
return new JSONObject(data.getString("json"));
}
@Override
public JSONObject listar_examen(JSONObject entrada) throws Exception {
String sql = "SELECT * FROM academico.func_examen_listar ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );";
JSONObject salida = PostgreSqlFactoryDAO.queryPSSingle("siiaa", sql, entrada.getJSONArray("params"));
return new JSONObject(salida.getString("json"));
}
@Override
public JSONObject actualizar_examen(JSONObject entrada) throws Exception {
String sql = "SELECT * FROM academico.func_examen_actualizar ( ?, ?, ?, ?, ?, ?, ?, ? :: JSON );";
JSONObject data = PostgreSqlFactoryDAO.queryPSSingle("siiaa", sql, entrada.getJSONArray("params"));
return new JSONObject(data.getString("json"));
}
}
......@@ -9,6 +9,7 @@ import pe.so.api.formulario.utilities.OsUtils;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -49,6 +50,19 @@ public class PostgreSqlFactoryDAO extends FactoryDAO{
}
return conexion;
}
//Store procedure
public static JSONArray queryProcedure(String base, String sql, JSONArray... parametros) throws Exception {
return queryProcedure(obtenerConexion(base), sql, false, parametros);
}
public static JSONObject queryPSSingle(String base, String sql, JSONArray... parametros) throws Exception {
return queryPSSingle(obtenerConexion(base), sql, false, parametros);
}
public static JSONObject queryJSONObject(String base, String sql, JSONObject data) throws Exception {
return queryJSONObject(obtenerConexion(base), sql, data);
}
@Override
public ExcelDAO getExcelDAO(){
......
......@@ -24,6 +24,9 @@ public class PostgreSqlTabla implements TablasDAO{
} else if(json.getString("tabla").equals("ac_balotario")){
columnas = new String[]{"formulario_titulo","formulario_respuesta_url"};
} else if(json.getString("tabla").equals("ac_examen")){
columnas = new String[]{"formulario_titulo","formulario_url_respuesta"};
}
try{
......
......@@ -5,6 +5,7 @@ import pe.so.api.formulario.dao.ExcelDAO;
import pe.so.api.formulario.dao.FactoryDAO;
import java.util.Objects;
import org.json.JSONArray;
public class ExcelServices{
......@@ -56,4 +57,113 @@ public class ExcelServices{
public JSONObject execute_reporte_pagos(JSONObject entrada) throws Exception{
return dao.execute_reporte_pagos(entrada);
}
public JSONObject actualizar_examen_alumno(JSONObject entrada) throws Exception{
JSONArray params = new JSONArray();
params.put(0, entrada.getString("drive_respuesta"));
params.put(1, entrada.getString("fecha_registro"));
params.put(2, entrada.getInt("fila_drive"));
params.put(3, entrada.getString("correo_alumno"));
params.put(4, entrada.getString("nota"));
params.put(5, entrada.getString("apellidos"));
params.put(6, entrada.getString("nombres"));
params.put(7, entrada.getString("sede"));
entrada.put("params", params);
return dao.actualizar_examen_alumno(entrada);
}
public JSONObject listar_examen(JSONObject entrada) throws Exception{
JSONArray params = new JSONArray();
if (!entrada.isNull("usuario_perfil_id")) {
params.put(0, entrada.getInt("usuario_perfil_id"));
}
params.put(1, entrada.getString("tipo_operacion"));
if (!entrada.isNull("capitulo_id")) {
params.put(2, entrada.getInt("capitulo_id"));
}
if (!entrada.isNull("grado_turno_id")) {
params.put(3, entrada.getString("grado_turno_id"));
}
if (!entrada.isNull("curso_id")) {
params.put(4, entrada.getInt("curso_id"));
}
if (!entrada.isNull("dia")) {
params.put(5, entrada.getInt("dia"));
}
if (!entrada.isNull("estado_id")) {
params.put(6, entrada.getInt("estado_id"));
}
if (!entrada.isNull("enlazado")) {
params.put(7, entrada.getBoolean("enlazado"));
}
if (!entrada.isNull("sede_id")) {
params.put(8, entrada.getInt("sede_id"));
}
if (!entrada.isNull("aula_id")) {
params.put(9, entrada.getInt("aula_id"));
}
entrada.put("params", params);
return dao.listar_examen(entrada);
}
public JSONObject actualizar_examen(JSONObject entrada) throws Exception{
JSONArray params = new JSONArray();
if (!entrada.isNull("usuario_perfil_id")) {
params.put(0, entrada.getInt("usuario_perfil_id"));
}
params.put(1, entrada.getString("tipo_operacion"));
if (!entrada.isNull("examen_id")) {
params.put(2, entrada.getInt("examen_id"));
}
if (!entrada.isNull("capitulo_id")) {
params.put(3, entrada.getInt("capitulo_id"));
}
if (!entrada.isNull("url_publicado")) {
params.put(4, entrada.getString("url_publicado"));
}
if (!entrada.isNull("url_edicion")) {
params.put(5, entrada.getString("url_edicion"));
}
if (!entrada.isNull("url_respuesta")) {
params.put(6, entrada.getString("url_respuesta"));
}
if (!entrada.isNull("lista_examen")) {
params.put(7, entrada.getJSONArray("lista_examen"));
}
entrada.put("params", params);
return dao.actualizar_examen(entrada);
}
}
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