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
dcb76d0f
Commit
dcb76d0f
authored
May 16, 2023
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] SE AGREGO UN PARAMETRO MAS PARA ENCUESTAS
parent
b6abace7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
53 deletions
+61
-53
ExcelApi.java
src/main/java/pe/so/api/formulario/api/ExcelApi.java
+1
-1
CorsFilter.java
src/main/java/pe/so/api/formulario/filters/CorsFilter.java
+35
-30
PostgreSqlExcel.java
...ava/pe/so/api/formulario/postgresdao/PostgreSqlExcel.java
+3
-1
Config.java
src/main/java/pe/so/api/formulario/utilities/Config.java
+22
-21
No files found.
src/main/java/pe/so/api/formulario/api/ExcelApi.java
View file @
dcb76d0f
...
...
@@ -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
);
...
...
src/main/java/pe/so/api/formulario/filters/CorsFilter.java
View file @
dcb76d0f
...
...
@@ -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
();
}
...
...
src/main/java/pe/so/api/formulario/postgresdao/PostgreSqlExcel.java
View file @
dcb76d0f
...
...
@@ -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
();
...
...
src/main/java/pe/so/api/formulario/utilities/Config.java
View file @
dcb76d0f
...
...
@@ -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
;
}
}
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