[ADD] SE AGREGO UN PARAMETRO MAS PARA ENCUESTAS

parent b6abace7
...@@ -26,7 +26,7 @@ public class ExcelApi { ...@@ -26,7 +26,7 @@ public class ExcelApi {
@Path("/encuesta") @Path("/encuesta")
public Response encuesta(String json) throws Exception { public Response encuesta(String json) throws Exception {
String[] jsonString = {"p_encuesta_id","p_grupo_encuesta","p_correo_alumno","p_documento","p_nombres"}; String[] jsonString = {"p_encuesta_id","p_grupo_encuesta","p_correo_alumno","p_documento","p_nombres","p_drive_id"};
JSONObject entrada = new JSONObject(json); JSONObject entrada = new JSONObject(json);
JSONObject formato = Commons.formatoJSON(jsonString); JSONObject formato = Commons.formatoJSON(jsonString);
......
...@@ -14,40 +14,42 @@ import java.util.Arrays; ...@@ -14,40 +14,42 @@ import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@Provider @Provider
public class CorsFilter implements Filter{ public class CorsFilter implements Filter {
@Override @Override
public void init(FilterConfig filterConfig) throws ServletException{ public void init(FilterConfig filterConfig) throws ServletException {
} }
@Override @Override
public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException{ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String[] ExcelIds={"1ItAa2YGBj60AVghmsCfMJZYooDRQGN2gyPWpgtvGHxA", String[] ExcelIds = {"1ItAa2YGBj60AVghmsCfMJZYooDRQGN2gyPWpgtvGHxA",
"1puh5xCtsGwwFaqKSgPcRt5II23MtZ2C9u0C_ussVYyc", "1puh5xCtsGwwFaqKSgPcRt5II23MtZ2C9u0C_ussVYyc",
"1ft51jmdtqqMpj51y2EisvwUFlNc8b3IZhOKff2DUScA"}; "1ft51jmdtqqMpj51y2EisvwUFlNc8b3IZhOKff2DUScA"};
HttpServletResponse response=(HttpServletResponse)servletResponse; HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request=(HttpServletRequest)servletRequest; HttpServletRequest request = (HttpServletRequest) servletRequest;
response.setHeader("Access-Control-Allow-Origin","*"); response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS,HEAD"); response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS,HEAD");
response.setHeader("Access-Control-Max-Age","3600"); response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers","x-requested-with, Content-Type, Authorization"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Authorization");
response.setHeader("Access-Control-Allow-Credentials","true"); response.setHeader("Access-Control-Allow-Credentials", "true");
try { try {
if((response.getHeader("Access-Control-Allow-Origin").equals("*") || if ((response.getHeader("Access-Control-Allow-Origin").equals("*") ||
response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) && response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) &&
(Arrays.asList(ExcelIds).contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))){ (Arrays.asList(ExcelIds)
.contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))) {
filterChain.doFilter(servletRequest,response); filterChain.doFilter(servletRequest, response);
} else { } else {
response.setContentType("application/json"); response.setContentType("application/json");
response.setStatus(401); response.setStatus(401);
response.getWriter().write("{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}"); response.getWriter()
.write("{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}");
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -56,31 +58,34 @@ public class CorsFilter implements Filter{ ...@@ -56,31 +58,34 @@ public class CorsFilter implements Filter{
} }
@Override @Override
public void destroy(){ public void destroy() {
} }
private Boolean existeId(String id) throws SQLException{ private Boolean existeId(String id) throws SQLException {
AtomicReference<Boolean> existe=new AtomicReference<>(false); AtomicReference<Boolean> existe = new AtomicReference<>(false);
JSONArray data=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_encuesta_plc")).getJSONArray("data"); JSONArray data = new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla", "ac_encuesta_plc"))
JSONArray data2=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_balotario")).getJSONArray("data"); .getJSONArray("data");
JSONArray data3=new PostgreSqlTabla().tablaIds(new JSONObject().put("tabla","ac_examen")).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 -> { data.forEach(obj -> {
JSONObject o=(JSONObject)obj; JSONObject o = (JSONObject) obj;
if(o.getString("id").equals(id)){ if (o.getString("id").equals(id)) {
existe.set(true); existe.set(true);
} }
}); });
data2.forEach(obj -> { data2.forEach(obj -> {
JSONObject o=(JSONObject)obj; JSONObject o = (JSONObject) obj;
if(o.getString("id").equals(id)){ if (o.getString("id").equals(id)) {
existe.set(true); existe.set(true);
} }
}); });
data3.forEach(obj -> { data3.forEach(obj -> {
JSONObject o=(JSONObject)obj; JSONObject o = (JSONObject) obj;
if(o.getString("id").equals(id)){ if (o.getString("id").equals(id)) {
existe.set(true); existe.set(true);
} }
}); });
......
...@@ -21,16 +21,18 @@ public class PostgreSqlExcel implements ExcelDAO { ...@@ -21,16 +21,18 @@ public class PostgreSqlExcel implements ExcelDAO {
String p_correo_alumno = json.isNull("p_correo_alumno") ? "" : json.getString("p_correo_alumno"); String p_correo_alumno = json.isNull("p_correo_alumno") ? "" : json.getString("p_correo_alumno");
String p_documento = json.isNull("p_documento") ? "" : json.getString("p_documento"); String p_documento = json.isNull("p_documento") ? "" : json.getString("p_documento");
String p_nombres = json.isNull("p_nombres") ? "" : json.getString("p_nombres"); String p_nombres = json.isNull("p_nombres") ? "" : json.getString("p_nombres");
String p_drive_id = json.isNull("p_drive_id") ? "" : json.getString("p_drive_id");
conexion = PostgreSqlFactoryDAO.obtenerConexion("siiaa"); conexion = PostgreSqlFactoryDAO.obtenerConexion("siiaa");
String sql = "select horario.func_encuesta_procesar_alumno(?,?,?,?,?)"; String sql = "select horario.func_encuesta_procesar_alumno(?,?,?,?,?,?)";
PreparedStatement ps = conexion.prepareStatement(sql); PreparedStatement ps = conexion.prepareStatement(sql);
ps.setInt(1, p_encuensta_id); ps.setInt(1, p_encuensta_id);
ps.setString(2, p_grupo_encuesta); ps.setString(2, p_grupo_encuesta);
ps.setString(3, p_correo_alumno); ps.setString(3, p_correo_alumno);
ps.setString(4, p_documento); ps.setString(4, p_documento);
ps.setString(5, p_nombres); ps.setString(5, p_nombres);
ps.setString(6, p_drive_id);
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
......
...@@ -3,13 +3,14 @@ package pe.so.api.formulario.utilities; ...@@ -3,13 +3,14 @@ package pe.so.api.formulario.utilities;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Scanner; import java.util.Scanner;
import org.json.JSONObject; import org.json.JSONObject;
public class Config { public class Config {
private static JSONObject getJsonFromFile(String path) { private static JSONObject getJsonFromFile(String path) {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
StringBuilder stringJson =new StringBuilder(); StringBuilder stringJson = new StringBuilder();
File file = new File(path); File file = new File(path);
try { try {
Scanner scanner = new Scanner(file); Scanner scanner = new Scanner(file);
......
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