Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
formulario-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Denys Tito Urbano
formulario-api
Commits
ad8aa760
Commit
ad8aa760
authored
Nov 19, 2022
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] ENDPOINTS AGREGADOS Y SEGURIDAD A LOS ENDPOINTS
parent
e052969d
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
463 additions
and
51 deletions
+463
-51
ApiConfig.java
src/main/java/pe/so/api/formulario/api/ApiConfig.java
+2
-0
ExcelApi.java
src/main/java/pe/so/api/formulario/api/ExcelApi.java
+58
-19
TablaApi.java
src/main/java/pe/so/api/formulario/api/TablaApi.java
+29
-0
ExcelDAO.java
src/main/java/pe/so/api/formulario/dao/ExcelDAO.java
+5
-1
FactoryDAO.java
src/main/java/pe/so/api/formulario/dao/FactoryDAO.java
+1
-0
TablasDAO.java
src/main/java/pe/so/api/formulario/dao/TablasDAO.java
+8
-0
CorsFilter.java
src/main/java/pe/so/api/formulario/filters/CorsFilter.java
+53
-19
MongoDBFactoryDAO.java
...va/pe/so/api/formulario/mongodbdao/MongoDBFactoryDAO.java
+6
-0
PostgreSqlExcel.java
...ava/pe/so/api/formulario/postgresdao/PostgreSqlExcel.java
+148
-7
PostgreSqlFactoryDAO.java
...e/so/api/formulario/postgresdao/PostgreSqlFactoryDAO.java
+5
-0
PostgreSqlTabla.java
...ava/pe/so/api/formulario/postgresdao/PostgreSqlTabla.java
+58
-0
ExcelServices.java
...ain/java/pe/so/api/formulario/services/ExcelServices.java
+10
-3
TablasServices.java
...in/java/pe/so/api/formulario/services/TablasServices.java
+15
-0
Commons.java
src/main/java/pe/so/api/formulario/utilities/Commons.java
+63
-0
index.html
src/main/webapp/index.html
+2
-2
No files found.
src/main/java/pe/so/api/formulario/api/ApiConfig.java
View file @
ad8aa760
...
...
@@ -14,9 +14,11 @@ public class ApiConfig extends Application {
public
ApiConfig
()
{
singletons
.
add
(
new
CorsFilter
());
classes
.
add
(
ExcelApi
.
class
);
classes
.
add
(
TablaApi
.
class
);
}
@Override
...
...
src/main/java/pe/so/api/formulario/api/ExcelApi.java
View file @
ad8aa760
...
...
@@ -6,27 +6,30 @@ import pe.so.api.formulario.services.ExcelServices;
import
javax.ws.rs.*
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.ext.Provider
;
import
pe.so.api.formulario.utilities.Commons
;
@Provider
@Path
(
"excel"
)
@Consumes
(
"application/json"
)
@Produces
(
"application/json"
)
public
class
ExcelApi
{
private
final
String
[]
jsonString
=
{
"p_encuesta_id"
,
"p_grupo_encuesta"
,
"p_correo_alumno"
,
"p_unidad_interna_id"
};
public
class
ExcelApi
{
private
JSONObject
MSJ_RESPUESTA
=
new
JSONObject
();
@POST
@Path
(
"/execute"
)
public
Response
ejecutar
(
String
json
)
throws
Exception
{
@Path
(
"/encuesta"
)
public
Response
encuesta
(
String
json
)
throws
Exception
{
String
[]
jsonString
=
{
"p_encuesta_id"
,
"p_grupo_encuesta"
,
"p_correo_alumno"
};
JSONObject
entrada
=
new
JSONObject
(
json
);
JSONObject
formato
=
formatoJSON
(
jsonString
);
JSONObject
formato
=
Commons
.
formatoJSON
(
jsonString
);
if
(
validarFormato
(
jsonString
,
json
)){
if
(
Commons
.
validarFormato
(
jsonString
,
json
)){
ExcelServices
excelServices
=
new
ExcelServices
();
MSJ_RESPUESTA
=
excelServices
.
execute
(
entrada
);
MSJ_RESPUESTA
=
excelServices
.
execute
_encuesta
(
entrada
);
return
Response
.
status
(
200
).
entity
(
MSJ_RESPUESTA
.
toString
()).
build
();
}
else
{
...
...
@@ -38,22 +41,58 @@ public class ExcelApi{
}
}
private
JSONObject
formatoJSON
(
String
[]
formato
){
JSONObject
json
=
new
JSONObject
();
for
(
String
key
:
formato
)
{
json
.
put
(
key
,
"valor"
);
@POST
@Path
(
"/balotario"
)
public
Response
balotario
(
String
json
)
throws
Exception
{
String
[]
jsonString
=
{
"p_drive_respuesta"
,
"p_fila_drive"
,
"p_correo_alumno"
,
"p_nota"
,
"p_apellidos"
,
"p_nombres"
,
"p_sede"
};
JSONObject
entrada
=
new
JSONObject
(
json
);
JSONObject
formato
=
Commons
.
formatoJSON
(
jsonString
);
if
(
Commons
.
validarFormato
(
jsonString
,
json
)){
ExcelServices
excelServices
=
new
ExcelServices
();
MSJ_RESPUESTA
=
excelServices
.
execute_balotario
(
entrada
);
return
Response
.
status
(
200
).
entity
(
MSJ_RESPUESTA
.
toString
()).
build
();
}
else
{
return
Response
.
status
(
500
).
entity
(
MSJ_RESPUESTA
.
put
(
"status"
,
false
)
.
put
(
"mensaje"
,
"Error en el formato de entrada"
)
.
put
(
"formato_esperado"
,
formato
).
toString
()
).
build
();
}
return
json
;
}
private
boolean
validarFormato
(
String
[]
formato
,
String
json
)
{
@POST
@Path
(
"/ejecutar"
)
public
Response
ejecutar
(
String
json
)
throws
Exception
{
String
[]
jsonString
=
{
"p_drive_origen"
,
"p_drive_fila"
,
"p_sede"
,
"p_fecha_hora_registro"
,
"p_medio_atencion"
,
"p_contacto_nombres"
,
"p_contacto_apellidos"
,
"p_numero_documento"
,
"p_contacto_correo"
,
"p_contacto_telefono"
,
"p_distrito"
,
"p_grado"
,
"p_colegio_procedencia"
,
"p_medio_difusion_nombre"
,
"p_atencion_usuario"
,
"p_atencion_fecha"
,
"p_atencion_estado"
,
"p_atencion_medio_atencion"
,
"p_atencion_hora"
,
"p_atencion_observacion"
};
JSONObject
entrada
=
new
JSONObject
(
json
);
for
(
String
key
:
formato
)
{
if
(!
entrada
.
has
(
key
))
{
return
false
;
}
}
JSONObject
formato
=
Commons
.
formatoJSON
(
jsonString
);
if
(
Commons
.
validarFormato
(
jsonString
,
json
)){
return
true
;
ExcelServices
excelServices
=
new
ExcelServices
();
MSJ_RESPUESTA
=
excelServices
.
ejecutar
(
entrada
);
return
Response
.
status
(
200
).
entity
(
MSJ_RESPUESTA
.
toString
()).
build
();
}
else
{
return
Response
.
status
(
500
).
entity
(
MSJ_RESPUESTA
.
put
(
"status"
,
false
)
.
put
(
"mensaje"
,
"Error en el formato de entrada"
)
.
put
(
"formato_esperado"
,
formato
).
toString
()
).
build
();
}
}
}
src/main/java/pe/so/api/formulario/api/TablaApi.java
0 → 100644
View file @
ad8aa760
package
pe
.
so
.
api
.
formulario
.
api
;
import
org.json.JSONObject
;
import
pe.so.api.formulario.services.ExcelServices
;
import
pe.so.api.formulario.services.TablasServices
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.ext.Provider
;
@Provider
@Path
(
"tabla"
)
@Consumes
(
"application/json"
)
@Produces
(
"application/json"
)
public
class
TablaApi
{
@Path
(
"/ids"
)
@POST
public
Response
tablaIds
(
String
json
)
throws
Exception
{
TablasServices
tablasServices
=
new
TablasServices
();
JSONObject
MSJ_RESPUESTA
=
tablasServices
.
tablaIds
(
new
JSONObject
(
json
));
return
Response
.
status
(
200
).
entity
(
MSJ_RESPUESTA
.
toString
()).
build
();
}
}
src/main/java/pe/so/api/formulario/dao/ExcelDAO.java
View file @
ad8aa760
...
...
@@ -4,6 +4,10 @@ import org.json.JSONObject;
public
interface
ExcelDAO
{
public
JSONObject
execute
(
JSONObject
json
)
throws
Exception
;
JSONObject
execute_encuesta
(
JSONObject
json
)
throws
Exception
;
JSONObject
execute_balotario
(
JSONObject
json
)
throws
Exception
;
JSONObject
ejecutar
(
JSONObject
json
)
throws
Exception
;
}
src/main/java/pe/so/api/formulario/dao/FactoryDAO.java
View file @
ad8aa760
...
...
@@ -19,6 +19,7 @@ public abstract class FactoryDAO{
}
public
abstract
ExcelDAO
getExcelDAO
();
public
abstract
TablasDAO
getTablasDAO
();
}
src/main/java/pe/so/api/formulario/dao/TablasDAO.java
0 → 100644
View file @
ad8aa760
package
pe
.
so
.
api
.
formulario
.
dao
;
import
org.json.JSONObject
;
public
interface
TablasDAO
{
JSONObject
tablaIds
(
JSONObject
json
)
throws
Exception
;
}
src/main/java/pe/so/api/formulario/filters/CorsFilter.java
View file @
ad8aa760
package
pe
.
so
.
api
.
formulario
.
filters
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
pe.so.api.formulario.postgresdao.PostgreSqlTabla
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.ws.rs.ext.Provider
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.concurrent.atomic.AtomicReference
;
@Provider
public
class
CorsFilter
implements
Filter
{
...
...
@@ -15,25 +21,31 @@ public class CorsFilter implements Filter{
}
@Override
public
void
doFilter
(
ServletRequest
servletRequest
,
ServletResponse
servletResponse
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
HttpServletResponse
response
=
(
HttpServletResponse
)
servletResponse
;
HttpServletRequest
request
=
(
HttpServletRequest
)
servletRequest
;
response
.
setHeader
(
"Access-Control-Allow-Origin"
,
"*"
);
response
.
setHeader
(
"Access-Control-Allow-Methods"
,
"POST"
);
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"
);
if
(
response
.
getHeader
(
"Access-Control-Allow-Origin"
).
equals
(
"*"
)){
filterChain
.
doFilter
(
servletRequest
,
response
);
}
else
if
(
response
.
getHeader
(
"Access-Control-Allow-Origin"
).
contains
(
request
.
getRemoteHost
()))
{
filterChain
.
doFilter
(
servletRequest
,
response
);
}
else
{
response
.
sendError
(
HttpServletResponse
.
SC_FORBIDDEN
);
}
public
void
doFilter
(
ServletRequest
servletRequest
,
ServletResponse
servletResponse
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
String
[]
ExcelIds
={
"1ItAa2YGBj60AVghmsCfMJZYooDRQGN2gyPWpgtvGHxA"
,
"1puh5xCtsGwwFaqKSgPcRt5II23MtZ2C9u0C_ussVYyc"
};
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"
);
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
);
}
else
{
response
.
setContentType
(
"application/json"
);
response
.
setStatus
(
401
);
response
.
getWriter
().
write
(
"{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}"
);
}
}
...
...
@@ -41,4 +53,26 @@ public class CorsFilter implements Filter{
public
void
destroy
(){
}
private
Boolean
existeId
(
String
id
){
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"
);
data
.
forEach
(
obj
->
{
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
)){
existe
.
set
(
true
);
}
});
return
existe
.
get
();
}
}
src/main/java/pe/so/api/formulario/mongodbdao/MongoDBFactoryDAO.java
View file @
ad8aa760
...
...
@@ -2,6 +2,7 @@ package pe.so.api.formulario.mongodbdao;
import
pe.so.api.formulario.dao.ExcelDAO
;
import
pe.so.api.formulario.dao.FactoryDAO
;
import
pe.so.api.formulario.dao.TablasDAO
;
public
class
MongoDBFactoryDAO
extends
FactoryDAO
{
...
...
@@ -9,4 +10,9 @@ public class MongoDBFactoryDAO extends FactoryDAO{
public
ExcelDAO
getExcelDAO
(){
return
null
;
}
@Override
public
TablasDAO
getTablasDAO
(){
return
null
;
}
}
src/main/java/pe/so/api/formulario/postgresdao/PostgreSqlExcel.java
View file @
ad8aa760
...
...
@@ -6,37 +6,35 @@ import pe.so.api.formulario.dao.ExcelDAO;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.Timestamp
;
import
java.util.Date
;
public
class
PostgreSqlExcel
implements
ExcelDAO
{
@Override
public
JSONObject
execute
(
JSONObject
json
)
throws
Exception
{
public
JSONObject
execute
_encuesta
(
JSONObject
json
)
throws
Exception
{
JSONObject
respuesta
=
new
JSONObject
();
Connection
conexion
=
null
;
try
{
Date
date
=
new
Date
();
java
.
sql
.
Date
sqlDate
=
new
java
.
sql
.
Date
(
date
.
getTime
());
java
.
sql
.
Timestamp
sqlTime
=
new
java
.
sql
.
Timestamp
(
date
.
getTime
());
Date
sqlDate
=
new
Date
(
date
.
getTime
());
Timestamp
sqlTime
=
new
Timestamp
(
date
.
getTime
());
//private final String[] jsonString = {"p_encuesta_id","p_grupo_encuesta","p_correo_alumno"};
int
p_encuensta_id
=
json
.
isNull
(
"p_encuesta_id"
)
?
0
:
json
.
getInt
(
"p_encuesta_id"
);
String
p_grupo_encuesta
=
json
.
isNull
(
"p_grupo_encuesta"
)
?
""
:
json
.
getString
(
"p_grupo_encuesta"
);
String
p_correo_alumno
=
json
.
isNull
(
"p_correo_alumno"
)
?
""
:
json
.
getString
(
"p_correo_alumno"
);
int
p_unidad_interna_id
=
json
.
isNull
(
"p_unidad_interna_id"
)
?
0
:
json
.
getInt
(
"p_unidad_interna_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
.
setInt
(
4
,
p_unidad_interna_id
);
ResultSet
rs
=
ps
.
executeQuery
();
...
...
@@ -59,4 +57,147 @@ public class PostgreSqlExcel implements ExcelDAO{
return
respuesta
;
}
@Override
public
JSONObject
execute_balotario
(
JSONObject
json
)
throws
Exception
{
JSONObject
respuesta
=
new
JSONObject
();
Connection
conexion
=
null
;
try
{
Date
date
=
new
Date
();
java
.
sql
.
Date
sqlDate
=
new
java
.
sql
.
Date
(
date
.
getTime
());
java
.
sql
.
Timestamp
sqlTime
=
new
java
.
sql
.
Timestamp
(
date
.
getTime
());
/*p_drive_respuesta text, p_fila_drive integer, p_correo_alumno character varying, p_nota character varying, p_apellidos character varying, p_nombres character varying, p_sede character varying*/
String
p_drive_respuesta
=
json
.
isNull
(
"p_drive_respuesta"
)
?
""
:
json
.
getString
(
"p_drive_respuesta"
);
int
p_fila_drive
=
json
.
isNull
(
"p_fila_drive"
)
?
0
:
json
.
getInt
(
"p_fila_drive"
);
String
p_correo_alumno
=
json
.
isNull
(
"p_correo_alumno"
)
?
""
:
json
.
getString
(
"p_correo_alumno"
);
String
p_nota
=
json
.
isNull
(
"p_nota"
)
?
""
:
json
.
getString
(
"p_nota"
);
String
p_apellidos
=
json
.
isNull
(
"p_apellidos"
)
?
""
:
json
.
getString
(
"p_apellidos"
);
String
p_nombres
=
json
.
isNull
(
"p_nombres"
)
?
""
:
json
.
getString
(
"p_nombres"
);
String
p_sede
=
json
.
isNull
(
"p_sede"
)
?
""
:
json
.
getString
(
"p_sede"
);
conexion
=
PostgreSqlFactoryDAO
.
obtenerConexion
(
"siiaa"
);
String
sql
=
"select academico.func_balotario_procesar_alumno(?,?,?,?,?,?,?)"
;
PreparedStatement
ps
=
conexion
.
prepareStatement
(
sql
);
ps
.
setString
(
1
,
p_drive_respuesta
);
ps
.
setInt
(
2
,
p_fila_drive
);
ps
.
setString
(
3
,
p_correo_alumno
);
ps
.
setString
(
4
,
p_nota
);
ps
.
setString
(
5
,
p_apellidos
);
ps
.
setString
(
6
,
p_nombres
);
ps
.
setString
(
7
,
p_sede
);
ResultSet
rs
=
ps
.
executeQuery
();
if
(
rs
.
next
())
{
int
columnCount
=
rs
.
getMetaData
().
getColumnCount
();
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
respuesta
.
put
(
"mensaje"
,
rs
.
getObject
(
i
));
}
}
respuesta
.
put
(
"status"
,
true
);
}
catch
(
Exception
e
)
{
respuesta
.
put
(
"status"
,
false
);
respuesta
.
put
(
"mensaje"
,
e
.
getMessage
());
}
finally
{
if
(
conexion
!=
null
)
{
conexion
.
close
();
}
}
return
respuesta
;
}
public
JSONObject
ejecutar
(
JSONObject
json
)
throws
Exception
{
JSONObject
respuesta
=
new
JSONObject
();
Connection
conexion
=
null
;
try
{
Date
date
=
new
Date
();
java
.
sql
.
Date
sqlDate
=
new
java
.
sql
.
Date
(
date
.
getTime
());
java
.
sql
.
Timestamp
sqlTime
=
new
java
.
sql
.
Timestamp
(
date
.
getTime
());
// String[] jsonString = {"p_drive_origen", "p_drive_fila", "p_fecha_hora_registro", "p_sede", "p_medio_atencion", "p_contacto_nombres", "p_contacto_apellidos", "p_numero_documento", "p_contacto_correo", "p_contacto_telefono", "p_distrito", "p_grado", "p_colegio_procedencia","p_medio_difusion_nombre", "p_atencion_usuario", "p_atencion_fecha", "p_atencion_estado", "p_atencion_medio_atencion", "p_atencion_hora", "p_atencion_observacion"};
String
p_drive_origen
=
json
.
getString
(
"p_drive_origen"
);
int
p_drive_fila
=
json
.
getInt
(
"p_drive_fila"
);
String
p_fecha_hora_registro
=
json
.
isNull
(
"p_fecha_hora_registro"
)
?
sqlTime
.
toString
()
:
json
.
getString
(
"p_fecha_hora_registro"
);
String
p_sede
=
json
.
getString
(
"p_sede"
);
String
p_medio_atencion
=
json
.
getString
(
"p_medio_atencion"
);
String
p_contacto_nombres
=
json
.
getString
(
"p_contacto_nombres"
);
String
p_contacto_apellidos
=
json
.
getString
(
"p_contacto_apellidos"
);
String
p_numero_documento
=
json
.
getString
(
"p_numero_documento"
);
String
p_contacto_correo
=
json
.
getString
(
"p_contacto_correo"
);
String
p_atencion_usuario
=
json
.
getString
(
"p_atencion_usuario"
);
String
p_grado
=
json
.
getString
(
"p_grado"
);
String
p_contacto_telefono
=
json
.
getString
(
"p_contacto_telefono"
);
String
p_colegio_procedencia
=
json
.
getString
(
"p_colegio_procedencia"
);
String
p_distrito
=
json
.
getString
(
"p_distrito"
);
String
p_atencion_fecha
=
json
.
getString
(
"p_atencion_fecha"
);
String
p_atencion_estado
=
json
.
getString
(
"p_atencion_estado"
);
String
p_atencion_medio_atencion
=
json
.
getString
(
"p_atencion_medio_atencion"
);
String
p_atencion_hora
=
json
.
getString
(
"p_atencion_hora"
);
String
p_atencion_observacion
=
json
.
getString
(
"p_atencion_observacion"
);
String
p_medio_difusion_nombre
=
json
.
getString
(
"p_medio_difusion_nombre"
);
conexion
=
PostgreSqlFactoryDAO
.
obtenerConexion
(
"siiaa"
);
String
sql
=
"select matricula.func_informe_registrar(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
;
PreparedStatement
ps
=
conexion
.
prepareStatement
(
sql
);
ps
.
setString
(
1
,
p_drive_origen
);
ps
.
setInt
(
2
,
p_drive_fila
);
ps
.
setString
(
3
,
sqlTime
.
toString
());
ps
.
setString
(
4
,
p_sede
);
ps
.
setString
(
5
,
p_medio_atencion
);
ps
.
setString
(
6
,
p_contacto_nombres
);
ps
.
setString
(
7
,
p_contacto_apellidos
);
ps
.
setString
(
8
,
p_numero_documento
);
ps
.
setString
(
9
,
p_contacto_correo
);
ps
.
setString
(
10
,
p_contacto_telefono
);
ps
.
setString
(
11
,
p_distrito
);
ps
.
setString
(
12
,
p_grado
);
ps
.
setString
(
13
,
p_colegio_procedencia
);
ps
.
setString
(
14
,
p_medio_difusion_nombre
);
ps
.
setString
(
15
,
p_atencion_usuario
);
ps
.
setString
(
16
,
p_atencion_fecha
);
ps
.
setString
(
17
,
p_atencion_estado
);
ps
.
setString
(
18
,
p_atencion_medio_atencion
);
ps
.
setString
(
19
,
p_atencion_hora
);
ps
.
setString
(
20
,
p_atencion_observacion
);
ResultSet
rs
=
ps
.
executeQuery
();
if
(
rs
.
next
())
{
int
columnCount
=
rs
.
getMetaData
().
getColumnCount
();
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
respuesta
.
put
(
rs
.
getMetaData
().
getColumnName
(
i
),
rs
.
getObject
(
i
));
}
if
(
respuesta
.
getString
(
"func_informe_registrar"
).
contains
(
"_informe_id"
)){
respuesta
.
put
(
"status"
,
true
);
}
else
{
respuesta
.
put
(
"status"
,
false
);
}
}
}
catch
(
Exception
e
)
{
respuesta
.
put
(
"status"
,
false
);
respuesta
.
put
(
"mensaje"
,
e
.
getMessage
());
}
finally
{
if
(
conexion
!=
null
)
{
conexion
.
close
();
}
}
return
respuesta
;
}
}
src/main/java/pe/so/api/formulario/postgresdao/PostgreSqlFactoryDAO.java
View file @
ad8aa760
...
...
@@ -3,6 +3,7 @@ package pe.so.api.formulario.postgresdao;
import
org.json.JSONObject
;
import
pe.so.api.formulario.dao.ExcelDAO
;
import
pe.so.api.formulario.dao.FactoryDAO
;
import
pe.so.api.formulario.dao.TablasDAO
;
import
pe.so.api.formulario.utilities.OsUtils
;
import
java.sql.Connection
;
...
...
@@ -53,4 +54,8 @@ public class PostgreSqlFactoryDAO extends FactoryDAO{
public
ExcelDAO
getExcelDAO
(){
return
new
PostgreSqlExcel
();
}
public
TablasDAO
getTablasDAO
(){
return
new
PostgreSqlTabla
();
}
}
src/main/java/pe/so/api/formulario/postgresdao/PostgreSqlTabla.java
0 → 100644
View file @
ad8aa760
package
pe
.
so
.
api
.
formulario
.
postgresdao
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
pe.so.api.formulario.dao.TablasDAO
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
public
class
PostgreSqlTabla
implements
TablasDAO
{
@Override
public
JSONObject
tablaIds
(
JSONObject
json
){
JSONArray
data
=
new
JSONArray
();
JSONObject
respuesta
=
new
JSONObject
();
Connection
conexion
=
null
;
String
[]
columnas
=
{};
if
(
json
.
getString
(
"tabla"
).
equals
(
"ac_encuesta_plc"
)){
columnas
=
new
String
[]{
"grupo_encuesta"
,
"respuesta_encuesta"
};
}
else
if
(
json
.
getString
(
"tabla"
).
equals
(
"ac_balotario"
)){
columnas
=
new
String
[]{
"formulario_titulo"
,
"formulario_respuesta_url"
};
}
try
{
conexion
=
PostgreSqlFactoryDAO
.
obtenerConexion
(
"siiaa"
);
String
sql
=
""
;
sql
=
"SELECT * FROM academico."
+
json
.
getString
(
"tabla"
)+
""
;
Statement
st
=
conexion
.
createStatement
();
ResultSet
rs
=
st
.
executeQuery
(
sql
);
while
(
rs
.
next
()){
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"nombre"
,
rs
.
getString
(
columnas
[
0
]));
obj
.
put
(
"id"
,
rs
.
getString
(
columnas
[
1
]));
data
.
put
(
obj
);
}
respuesta
.
put
(
"data"
,
data
);
respuesta
.
put
(
"status"
,
true
);
respuesta
.
put
(
"mensaje"
,
"OK"
);
}
catch
(
Exception
e
){
respuesta
.
put
(
"mensaje"
,
e
.
getMessage
());
return
respuesta
;
}
return
respuesta
;
}
}
src/main/java/pe/so/api/formulario/services/ExcelServices.java
View file @
ad8aa760
...
...
@@ -3,12 +3,19 @@ package pe.so.api.formulario.services;
import
org.json.JSONObject
;
import
pe.so.api.formulario.dao.ExcelDAO
;
import
pe.so.api.formulario.dao.FactoryDAO
;
import
pe.so.api.formulario.postgresdao.PostgreSqlExcel
;
public
class
ExcelServices
{
ExcelDAO
dao
=
FactoryDAO
.
getFactoryDAO
(
FactoryDAO
.
POSTGRESQL
).
getExcelDAO
();
public
JSONObject
execute
(
JSONObject
json
)
throws
Exception
{
return
dao
.
execute
(
json
);
public
JSONObject
execute_encuesta
(
JSONObject
json
)
throws
Exception
{
return
dao
.
execute_encuesta
(
json
);
}
public
JSONObject
execute_balotario
(
JSONObject
json
)
throws
Exception
{
return
dao
.
execute_balotario
(
json
);
}
public
JSONObject
ejecutar
(
JSONObject
json
)
throws
Exception
{
return
dao
.
ejecutar
(
json
);
}
}
src/main/java/pe/so/api/formulario/services/TablasServices.java
0 → 100644
View file @
ad8aa760
package
pe
.
so
.
api
.
formulario
.
services
;
import
org.json.JSONObject
;
import
pe.so.api.formulario.dao.FactoryDAO
;
import
pe.so.api.formulario.dao.TablasDAO
;
public
class
TablasServices
{
TablasDAO
dao
=
FactoryDAO
.
getFactoryDAO
(
FactoryDAO
.
POSTGRESQL
).
getTablasDAO
();
public
JSONObject
tablaIds
(
JSONObject
json
)
throws
Exception
{
return
dao
.
tablaIds
(
json
);
}
}
src/main/java/pe/so/api/formulario/utilities/Commons.java
0 → 100644
View file @
ad8aa760
package
pe
.
so
.
api
.
formulario
.
utilities
;
import
org.json.JSONObject
;
import
java.util.regex.Pattern
;
public
class
Commons
{
public
static
JSONObject
formatoJSON
(
String
[]
formato
){
JSONObject
json
=
new
JSONObject
();
for
(
String
key
:
formato
)
{
json
.
put
(
key
,
"valor"
);
}
return
json
;
}
public
static
boolean
validarFormato
(
String
[]
formato
,
String
json
)
{
JSONObject
entrada
=
new
JSONObject
(
json
);
for
(
String
key
:
formato
)
{
if
(!
entrada
.
has
(
key
))
{
return
false
;
}
}
return
true
;
}
public
static
boolean
like
(
final
String
str
,
final
String
expr
)
{
String
regex
=
quotemeta
(
expr
);
regex
=
regex
.
replace
(
"_"
,
"."
).
replace
(
"%"
,
".*?"
);
Pattern
p
=
Pattern
.
compile
(
regex
,
Pattern
.
CASE_INSENSITIVE
|
Pattern
.
DOTALL
);
return
p
.
matcher
(
str
).
matches
();
}
public
static
String
quotemeta
(
String
s
)
{
if
(
s
==
null
)
{
throw
new
IllegalArgumentException
(
"String cannot be null"
);
}
int
len
=
s
.
length
();
if
(
len
==
0
)
{
return
""
;
}
StringBuilder
sb
=
new
StringBuilder
(
len
*
2
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
c
=
s
.
charAt
(
i
);
if
(
"[](){}.*+?$^|#\\"
.
indexOf
(
c
)
!=
-
1
)
{
sb
.
append
(
"\\"
);
}
sb
.
append
(
c
);
}
return
sb
.
toString
();
}
}
src/main/webapp/index.html
View file @
ad8aa760
<!DOCTYPE html>
<html>
<head>
<title>
Start Page
</title>
<title>
FORMULARIO-API
</title>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
</head>
<body>
<h1>
Hello World!
</h1>
<h1>
FORMULARIO-API
</h1>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment