[ADD] SE AGREGO UN PARAMETRO MAS PARA ENCUESTAS

parent b6abace7
......@@ -26,7 +26,7 @@ public class ExcelApi {
@Path("/encuesta")
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 formato = Commons.formatoJSON(jsonString);
......
......@@ -14,40 +14,42 @@ import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;
@Provider
public class CorsFilter implements Filter{
public class CorsFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException{
public void init(FilterConfig filterConfig) throws ServletException {
}
@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",
"1puh5xCtsGwwFaqKSgPcRt5II23MtZ2C9u0C_ussVYyc",
String[] ExcelIds = {"1ItAa2YGBj60AVghmsCfMJZYooDRQGN2gyPWpgtvGHxA",
"1puh5xCtsGwwFaqKSgPcRt5II23MtZ2C9u0C_ussVYyc",
"1ft51jmdtqqMpj51y2EisvwUFlNc8b3IZhOKff2DUScA"};
HttpServletResponse response=(HttpServletResponse)servletResponse;
HttpServletRequest request=(HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request = (HttpServletRequest) servletRequest;
response.setHeader("Access-Control-Allow-Origin","*");
response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS,HEAD");
response.setHeader("Access-Control-Max-Age","3600");
response.setHeader("Access-Control-Allow-Headers","x-requested-with, Content-Type, Authorization");
response.setHeader("Access-Control-Allow-Credentials","true");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS,HEAD");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Authorization");
response.setHeader("Access-Control-Allow-Credentials", "true");
try {
if((response.getHeader("Access-Control-Allow-Origin").equals("*") ||
response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) &&
(Arrays.asList(ExcelIds).contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))){
if ((response.getHeader("Access-Control-Allow-Origin").equals("*") ||
response.getHeader("Access-Control-Allow-Origin").contains(request.getRemoteHost())) &&
(Arrays.asList(ExcelIds)
.contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))) {
filterChain.doFilter(servletRequest,response);
filterChain.doFilter(servletRequest, response);
} else {
response.setContentType("application/json");
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) {
throw new RuntimeException(e);
......@@ -56,35 +58,38 @@ public class CorsFilter implements Filter{
}
@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);
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");
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;
if(o.getString("id").equals(id)){
JSONObject o = (JSONObject) obj;
if (o.getString("id").equals(id)) {
existe.set(true);
}
});
data2.forEach(obj -> {
JSONObject o=(JSONObject)obj;
if(o.getString("id").equals(id)){
JSONObject o = (JSONObject) obj;
if (o.getString("id").equals(id)) {
existe.set(true);
}
});
data3.forEach(obj -> {
JSONObject o=(JSONObject)obj;
if(o.getString("id").equals(id)){
JSONObject o = (JSONObject) obj;
if (o.getString("id").equals(id)) {
existe.set(true);
}
});
return existe.get();
}
......
......@@ -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_documento = json.isNull("p_documento") ? "" : json.getString("p_documento");
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");
String sql = "select horario.func_encuesta_procesar_alumno(?,?,?,?,?)";
String sql = "select horario.func_encuesta_procesar_alumno(?,?,?,?,?,?)";
PreparedStatement ps = conexion.prepareStatement(sql);
ps.setInt(1, p_encuensta_id);
ps.setString(2, p_grupo_encuesta);
ps.setString(3, p_correo_alumno);
ps.setString(4, p_documento);
ps.setString(5, p_nombres);
ps.setString(6, p_drive_id);
ResultSet rs = ps.executeQuery();
......
......@@ -3,31 +3,32 @@ package pe.so.api.formulario.utilities;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import org.json.JSONObject;
public class Config {
private static JSONObject getJsonFromFile(String path) {
JSONObject response = new JSONObject();
StringBuilder stringJson =new StringBuilder();
File file = new File(path);
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
stringJson.append(scanner.nextLine());
}
scanner.close();
response = new JSONObject(stringJson.toString());
} catch (IOException e) {
e.printStackTrace();
private static JSONObject getJsonFromFile(String path) {
JSONObject response = new JSONObject();
StringBuilder stringJson = new StringBuilder();
File file = new File(path);
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
stringJson.append(scanner.nextLine());
}
scanner.close();
response = new JSONObject(stringJson.toString());
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
return response;
}
public static JSONObject getConfig(String configPath, String config, String configName) {
JSONObject response;
JSONObject configJson = getJsonFromFile(configPath);
response = configJson.getJSONObject(config).getJSONObject(configName);
return response;
}
public static JSONObject getConfig(String configPath, String config, String configName) {
JSONObject response;
JSONObject configJson = getJsonFromFile(configPath);
response = configJson.getJSONObject(config).getJSONObject(configName);
return response;
}
}
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