[ADD] SE AGREGO NUEVO ENDPOINT PARA AVANCES DE ENCUESTAS

parent 2200f7ef
nb-configuration.xml
target/
.idea
nb-configuration.xml
target/
.idea
idea
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="formulario-api" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="formulario-api" options="-endorseddirs D:\formulario-api\target/endorsed" />
</option>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="formulario-api" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="formulario-api" options="-endorseddirs $PROJECT_DIR$/target/endorsed" />
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="siia" uuid="60957c5c-de91-49ed-adf8-d0fc940d62b3">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://172.16.2.207:5432/postgres</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="siia" uuid="60957c5c-de91-49ed-adf8-d0fc940d62b3">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://172.16.2.207:5432/postgres</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
......@@ -11,7 +11,7 @@
</inspection_tool>
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="48" name="Java" />
<language minSize="50" name="Java" />
</Languages>
</inspection_tool>
<inspection_tool class="SpellCheckingInspection" enabled="false" level="WARNING" enabled_by_default="false" editorAttributes="WARNING_ATTRIBUTES">
......@@ -19,5 +19,6 @@
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
<inspection_tool class="VulnerableCodeUsages" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="snapshots" />
<option name="name" value="snapshots" />
<option name="url" value="http://161.97.127.173:8081/repository/mvn-poqh-snapshot/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="releases" />
<option name="name" value="releases" />
<option name="url" value="http://161.97.127.173:8081/repository/mvn-poqh-release/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Plugin Repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="snapshots-hosted" />
<option name="name" value="snapshots-hosted" />
<option name="url" value="http://161.97.127.173:8081/repository/mvn-poqh-hosted-snapshot/" />
</remote-repository>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="snapshots" />
<option name="name" value="snapshots" />
<option name="url" value="http://161.97.127.173:8081/repository/mvn-poqh-snapshot/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="releases" />
<option name="name" value="releases" />
<option name="url" value="http://161.97.127.173:8081/repository/mvn-poqh-release/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Plugin Repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="snapshots-hosted" />
<option name="name" value="snapshots-hosted" />
<option name="url" value="http://161.97.127.173:8081/repository/mvn-poqh-hosted-snapshot/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="defaultUnitInitialized" value="true" />
<option name="renamerInitialized" value="true" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="defaultUnitInitialized" value="true" />
<option name="renamerInitialized" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="corretto-11" project-jdk-type="JavaSDK" />
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="corretto-11" project-jdk-type="JavaSDK" />
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SaveActionSettings">
<option name="actions">
<set>
<option value="activateOnShortcut" />
<option value="reload" />
<option value="executeAction" />
</set>
</option>
<option name="configurationPath" value="" />
<option name="quickLists">
<list>
<option value="-1109336397" />
</list>
</option>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SaveActionSettings">
<option name="actions">
<set>
<option value="activateOnShortcut" />
<option value="reload" />
<option value="executeAction" />
</set>
</option>
<option name="configurationPath" value="" />
<option name="quickLists">
<list>
<option value="-1109336397" />
</list>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/main/java/pe/so/api/formulario/postgresdao/PostgreSqlExcel.java" dialect="PostgreSQL" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/main/java/pe/so/api/formulario/postgresdao/PostgreSqlExcel.java" dialect="PostgreSQL" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
# Trismegisto-mongo API
# Trismegisto-mongo API
API Rest especifica para formularios
\ No newline at end of file
package pe.so.api.formulario.api;
import pe.so.api.formulario.filters.CorsFilter;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.*;
@ApplicationPath("api/v1")
public class ApiConfig extends Application {
private final Set<Object> singletons = new HashSet<>();
private final HashSet<Class<?>> classes = new HashSet<>();
public ApiConfig() {
singletons.add(new CorsFilter());
classes.add(ExcelApi.class);
classes.add(TablaApi.class);
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
@Override
public HashSet<Class<?>> getClasses() {
return classes;
}
}
package pe.so.api.formulario.api;
import pe.so.api.formulario.filters.CorsFilter;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.*;
@ApplicationPath("api/v1")
public class ApiConfig extends Application {
private final Set<Object> singletons = new HashSet<>();
private final HashSet<Class<?>> classes = new HashSet<>();
public ApiConfig() {
singletons.add(new CorsFilter());
classes.add(ExcelApi.class);
classes.add(TablaApi.class);
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
@Override
public HashSet<Class<?>> getClasses() {
return classes;
}
}
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();
}
}
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();
}
}
package pe.so.api.formulario.dao;
import org.json.JSONObject;
public interface ExcelDAO{
JSONObject execute_encuesta (JSONObject json) throws Exception;
JSONObject execute_balotario (JSONObject json) throws Exception;
JSONObject ejecutar(JSONObject json) throws Exception;
JSONObject execute_avance (JSONObject json) throws Exception;
JSONObject execute_redes (JSONObject json) throws Exception;
JSONObject execute_VU (JSONObject json) throws Exception;
JSONObject execute_reporte_sedes (JSONObject json) throws Exception;
JSONObject execute_reporte_correos (JSONObject json) throws Exception;
}
package pe.so.api.formulario.dao;
import org.json.JSONObject;
public interface ExcelDAO{
JSONObject execute_encuesta (JSONObject json) throws Exception;
JSONObject execute_balotario (JSONObject json) throws Exception;
JSONObject ejecutar(JSONObject json) throws Exception;
JSONObject execute_avance (JSONObject json) throws Exception;
JSONObject execute_redes (JSONObject json) throws Exception;
JSONObject execute_VU (JSONObject json) throws Exception;
JSONObject execute_reporte_sedes (JSONObject json) throws Exception;
JSONObject execute_reporte_correos (JSONObject json) throws Exception;
JSONObject execute_avance_encuesta (JSONObject json) throws Exception;
}
package pe.so.api.formulario.dao;
import pe.so.api.formulario.mongodbdao.MongoDBFactoryDAO;
import pe.so.api.formulario.postgresdao.PostgreSqlFactoryDAO;
public abstract class FactoryDAO{
public static final int MONGODB = 1;
public static final int POSTGRESQL = 2;
public static FactoryDAO getFactoryDAO(int whichFactory) {
switch (whichFactory) {
case MONGODB:
return new MongoDBFactoryDAO();
case POSTGRESQL:
return new PostgreSqlFactoryDAO();
default:
return null;
}
}
public abstract ExcelDAO getExcelDAO();
public abstract TablasDAO getTablasDAO();
}
package pe.so.api.formulario.dao;
import pe.so.api.formulario.mongodbdao.MongoDBFactoryDAO;
import pe.so.api.formulario.postgresdao.PostgreSqlFactoryDAO;
public abstract class FactoryDAO{
public static final int MONGODB = 1;
public static final int POSTGRESQL = 2;
public static FactoryDAO getFactoryDAO(int whichFactory) {
switch (whichFactory) {
case MONGODB:
return new MongoDBFactoryDAO();
case POSTGRESQL:
return new PostgreSqlFactoryDAO();
default:
return null;
}
}
public abstract ExcelDAO getExcelDAO();
public abstract TablasDAO getTablasDAO();
}
package pe.so.api.formulario.dao;
import org.json.JSONObject;
public interface TablasDAO {
JSONObject tablaIds (JSONObject json) throws Exception;
}
package pe.so.api.formulario.dao;
import org.json.JSONObject;
public interface TablasDAO {
JSONObject tablaIds (JSONObject json) throws Exception;
}
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.sql.SQLException;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;
@Provider
public class CorsFilter implements Filter{
@Override
public void init(FilterConfig filterConfig) throws ServletException{
}
@Override
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");
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")))){
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}");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void destroy(){
}
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");
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();
}
}
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.sql.SQLException;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;
@Provider
public class CorsFilter implements Filter{
@Override
public void init(FilterConfig filterConfig) throws ServletException{
}
@Override
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");
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")))){
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}");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void destroy(){
}
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");
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();
}
}
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{
@Override
public ExcelDAO getExcelDAO(){
return null;
}
@Override
public TablasDAO getTablasDAO(){
return null;
}
}
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{
@Override
public ExcelDAO getExcelDAO(){
return null;
}
@Override
public TablasDAO getTablasDAO(){
return null;
}
}
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;
import java.sql.SQLException;
import java.sql.DriverManager;
import org.json.JSONException;
import static pe.so.api.formulario.utilities.Config.getConfig;
public class PostgreSqlFactoryDAO extends FactoryDAO{
static {
try {
Class.forName(" org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection obtenerConexion(String base) {
Connection conexion = null;
JSONObject dbConfig = new JSONObject();
OsUtils.OSType ostype = OsUtils.getOperatingSystemType();
switch (ostype) {
case Windows:
dbConfig = getConfig("C:/dotenv/formularios-api/config.json", "db_config", base);
break;
case Linux:
case MacOS:
dbConfig = getConfig("/opt/dotenv/formularios-api/config.json", "db_config", base);
break;
case Other:
break;
}
try {
conexion = DriverManager.getConnection(
"jdbc:postgresql://" + dbConfig.getString("host") + ":" + dbConfig.getString("port") + "/" + dbConfig.getString("db_name") + "",
dbConfig.getString("user"),
dbConfig.getString("password"));
} catch (SQLException | JSONException e) {
e.printStackTrace();
}
return conexion;
}
@Override
public ExcelDAO getExcelDAO(){
return new PostgreSqlExcel();
}
public TablasDAO getTablasDAO(){
return new PostgreSqlTabla();
}
}
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;
import java.sql.SQLException;
import java.sql.DriverManager;
import org.json.JSONException;
import static pe.so.api.formulario.utilities.Config.getConfig;
public class PostgreSqlFactoryDAO extends FactoryDAO{
static {
try {
Class.forName(" org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection obtenerConexion(String base) {
Connection conexion = null;
JSONObject dbConfig = new JSONObject();
OsUtils.OSType ostype = OsUtils.getOperatingSystemType();
switch (ostype) {
case Windows:
dbConfig = getConfig("C:/dotenv/formularios-api/config.json", "db_config", base);
break;
case Linux:
case MacOS:
dbConfig = getConfig("/opt/dotenv/formularios-api/config.json", "db_config", base);
break;
case Other:
break;
}
try {
conexion = DriverManager.getConnection(
"jdbc:postgresql://" + dbConfig.getString("host") + ":" + dbConfig.getString("port") + "/" + dbConfig.getString("db_name") + "",
dbConfig.getString("user"),
dbConfig.getString("password"));
} catch (SQLException | JSONException e) {
e.printStackTrace();
}
return conexion;
}
@Override
public ExcelDAO getExcelDAO(){
return new PostgreSqlExcel();
}
public TablasDAO getTablasDAO(){
return new PostgreSqlTabla();
}
}
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.SQLException;
import java.sql.Statement;
public class PostgreSqlTabla implements TablasDAO{
@Override
public JSONObject tablaIds(JSONObject json) throws SQLException{
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_drive_id"};
} 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;
}finally {
if (conexion != null) {
conexion.close();
}
}
return respuesta;
}
}
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.SQLException;
import java.sql.Statement;
public class PostgreSqlTabla implements TablasDAO{
@Override
public JSONObject tablaIds(JSONObject json) throws SQLException{
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_drive_id"};
} 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;
}finally {
if (conexion != null) {
conexion.close();
}
}
return respuesta;
}
}
package pe.so.api.formulario.services;
import org.json.JSONObject;
import pe.so.api.formulario.dao.ExcelDAO;
import pe.so.api.formulario.dao.FactoryDAO;
public class ExcelServices{
ExcelDAO dao = FactoryDAO.getFactoryDAO(FactoryDAO.POSTGRESQL).getExcelDAO();
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);
}
public JSONObject execute_avance(JSONObject json) throws Exception{
return dao.execute_avance(json);
}
public JSONObject execute_redes(JSONObject json) throws Exception{
return dao.execute_redes(json);
}
public JSONObject execute_VU(JSONObject json) throws Exception{
return dao.execute_VU(json);
}
public JSONObject execute_reporte_sedes(JSONObject json) throws Exception{
return dao.execute_reporte_sedes(json);
}
public JSONObject execute_reporte_correos(JSONObject json) throws Exception{
return dao.execute_reporte_correos(json);
}
}
package pe.so.api.formulario.services;
import org.json.JSONObject;
import pe.so.api.formulario.dao.ExcelDAO;
import pe.so.api.formulario.dao.FactoryDAO;
public class ExcelServices{
ExcelDAO dao = FactoryDAO.getFactoryDAO(FactoryDAO.POSTGRESQL).getExcelDAO();
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);
}
public JSONObject execute_avance(JSONObject json) throws Exception{
return dao.execute_avance(json);
}
public JSONObject execute_redes(JSONObject json) throws Exception{
return dao.execute_redes(json);
}
public JSONObject execute_VU(JSONObject json) throws Exception{
return dao.execute_VU(json);
}
public JSONObject execute_reporte_sedes(JSONObject json) throws Exception{
return dao.execute_reporte_sedes(json);
}
public JSONObject execute_reporte_correos(JSONObject json) throws Exception{
return dao.execute_reporte_correos(json);
}
public JSONObject execute_avance_encuesta(JSONObject json) throws Exception{
return dao.execute_avance_encuesta(json);
}
}
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);
}
}
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);
}
}
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();
}
}
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();
}
}
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();
}
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;
}
}
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();
}
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;
}
}
package pe.so.api.formulario.utilities;
import java.io.File;
import java.util.Locale;
public final class OsUtils {
public enum OSType {
Windows, MacOS, Linux, Other
};
// cached result of OS detection
private static String detectedOS;
private static OSType detectedTOS;
/**
* detect the operating system from the os.name System property and cache
* the result
*
* @return - the operating system detected
*/
public static String getOperatingSysstemType() {
if (detectedOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((OS.contains("mac")) || (OS.contains("darwin"))) {
detectedOS = "MacOS";
} else if (OS.contains("win")) {
detectedOS = "Windows";
} else if (OS.contains("nux")) {
detectedOS = "Linux";
} else {
detectedOS = "Other";
}
}
return detectedOS;
}
public static OSType getOperatingSystemType() {
if (detectedTOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((OS.contains("mac")) || (OS.contains("darwin"))) {
detectedTOS = OSType.MacOS;
} else if (OS.contains("win")) {
detectedTOS = OSType.Windows;
} else if (OS.contains("nux")) {
detectedTOS = OSType.Linux;
} else {
detectedTOS = OSType.Other;
}
}
return detectedTOS;
}
public static String getDotEnvPathUtil(String projectName) {
String path = "";
String detectedOs = OsUtils.getOperatingSysstemType();
switch (detectedOs) {
case "MacOS":
case "Linux":
path = "/opt/dotenv/"+projectName;
break;
case "Windows":
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
for (char letter : alphabet) {
path = letter + ":/dotenv/" + projectName;
File directory = new File(path);
if (directory.exists()) {
break;
}
}
break;
}
return path;
}
public static String getFilePath(String projectName) {
String path = "";
String detectedOs = OsUtils.getOperatingSysstemType();
switch (detectedOs) {
case "MacOS":
path = "";
break;
case "Windows":
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
for (char letter : alphabet) {
path = letter + ":/AppServ/www/" + projectName+"/";
File directory = new File(path);
if (directory.exists()) {
break;
}
}
break;
case "Linux":
path = "/var/www/html/"+projectName+"/";
break;
}
return path;
}
}
package pe.so.api.formulario.utilities;
import java.io.File;
import java.util.Locale;
public final class OsUtils {
public enum OSType {
Windows, MacOS, Linux, Other
};
// cached result of OS detection
private static String detectedOS;
private static OSType detectedTOS;
/**
* detect the operating system from the os.name System property and cache
* the result
*
* @return - the operating system detected
*/
public static String getOperatingSysstemType() {
if (detectedOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((OS.contains("mac")) || (OS.contains("darwin"))) {
detectedOS = "MacOS";
} else if (OS.contains("win")) {
detectedOS = "Windows";
} else if (OS.contains("nux")) {
detectedOS = "Linux";
} else {
detectedOS = "Other";
}
}
return detectedOS;
}
public static OSType getOperatingSystemType() {
if (detectedTOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((OS.contains("mac")) || (OS.contains("darwin"))) {
detectedTOS = OSType.MacOS;
} else if (OS.contains("win")) {
detectedTOS = OSType.Windows;
} else if (OS.contains("nux")) {
detectedTOS = OSType.Linux;
} else {
detectedTOS = OSType.Other;
}
}
return detectedTOS;
}
public static String getDotEnvPathUtil(String projectName) {
String path = "";
String detectedOs = OsUtils.getOperatingSysstemType();
switch (detectedOs) {
case "MacOS":
case "Linux":
path = "/opt/dotenv/"+projectName;
break;
case "Windows":
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
for (char letter : alphabet) {
path = letter + ":/dotenv/" + projectName;
File directory = new File(path);
if (directory.exists()) {
break;
}
}
break;
}
return path;
}
public static String getFilePath(String projectName) {
String path = "";
String detectedOs = OsUtils.getOperatingSysstemType();
switch (detectedOs) {
case "MacOS":
path = "";
break;
case "Windows":
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
for (char letter : alphabet) {
path = letter + ":/AppServ/www/" + projectName+"/";
File directory = new File(path);
if (directory.exists()) {
break;
}
}
break;
case "Linux":
path = "/var/www/html/"+projectName+"/";
break;
}
return path;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd">
<context-root>/formulario-api</context-root>
</jboss-web>
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd">
<context-root>/formulario-api</context-root>
</jboss-web>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>pe.so.api.formulario.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/api/v1/*</url-pattern>
</filter-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>pe.so.api.formulario.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/api/v1/*</url-pattern>
</filter-mapping>
</web-app>
<!DOCTYPE html>
<html>
<head>
<title>FORMULARIO-API</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>FORMULARIO-API</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>FORMULARIO-API</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>FORMULARIO-API</h1>
</body>
</html>
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