Commit 6272171f by Denys Tito Urbano

Merge branch 'mzuniga' of http://version.sacooliveros.edu.pe/dtito/formulario-api into mzuniga

parents 032f2942 0a45daae
...@@ -533,5 +533,27 @@ public class ExcelApi { ...@@ -533,5 +533,27 @@ public class ExcelApi {
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build()); throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
} }
} }
@POST
@Path("/procedure")
public Response procedure(String json){
JSONObject salida = new JSONObject();
try {
JSONObject entrada = new JSONObject(json);
salida = new ExcelServices().procedure(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());
}
}
} }
...@@ -49,5 +49,7 @@ public interface ExcelDAO{ ...@@ -49,5 +49,7 @@ public interface ExcelDAO{
JSONObject actualizar_aniversario (JSONObject entrada) throws Exception; JSONObject actualizar_aniversario (JSONObject entrada) throws Exception;
JSONObject listar_aniversario_reporte (JSONObject entrada) throws Exception; JSONObject listar_aniversario_reporte (JSONObject entrada) throws Exception;
JSONObject procedure (JSONObject entrada) throws Exception;
} }
...@@ -38,20 +38,20 @@ public class CorsFilter implements Filter { ...@@ -38,20 +38,20 @@ public class CorsFilter implements Filter {
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) (Arrays.asList(ExcelIds)
.contains(request.getHeader("Authorization")) || existeId(request.getHeader("Authorization")))) { .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() response.getWriter()
.write("{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}"); .write("{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}");
} }*/
} catch (SQLException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
...@@ -708,5 +708,29 @@ public class PostgreSqlExcel implements ExcelDAO { ...@@ -708,5 +708,29 @@ public class PostgreSqlExcel implements ExcelDAO {
JSONObject salida = PostgreSqlFactoryDAO.queryPSSingle("siiaa", sql, entrada.getJSONArray("params")); JSONObject salida = PostgreSqlFactoryDAO.queryPSSingle("siiaa", sql, entrada.getJSONArray("params"));
return new JSONObject(salida.getString("json")); return new JSONObject(salida.getString("json"));
} }
@Override
public JSONObject procedure(JSONObject entrada) throws Exception {
String sql = entrada.getString("procedure");
JSONArray array = entrada.optJSONArray("array");
JSONArray errores = new JSONArray();
for(int i = 0; i < array.length() ; i++){
JSONObject obj = array.getJSONObject(i);
try{
JSONObject response = PostgreSqlFactoryDAO.queryPSSingle("siiaa", sql, obj.getJSONArray("params"));
JSONObject json = new JSONObject(response.getString("json"));
if(!json.getBoolean("status")){
errores.put(response.put("fila",obj.getInt("fila")));
}
}catch(Exception e){
errores.put(new JSONObject().put("status",false).put("message",e.getMessage()).put("fila",obj.getInt("fila")));
}
}
if(errores.length() > 0){
return new JSONObject().put("status", false).put("message","se encontrarón errores").put("errors", errores);
}else{
return new JSONObject().put("status",true).put("message","ok");
}
}
} }
...@@ -542,5 +542,9 @@ public class ExcelServices { ...@@ -542,5 +542,9 @@ public class ExcelServices {
return dao.listar_aniversario_reporte(entrada); return dao.listar_aniversario_reporte(entrada);
} }
public JSONObject procedure(JSONObject json) throws Exception {
return dao.procedure(json);
}
} }
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