Commit eae407e0 by Billy Larru

primer commit

parents
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="SalidasAutomaticas" default="default" basedir=".">
<description>Builds, tests, and runs the project SalidasAutomaticas.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="SalidasAutomaticas-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
build.xml.data.CRC32=825f2b90
build.xml.script.CRC32=c1b89b07
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=825f2b90
nbproject/build-impl.xml.script.CRC32=fced78cc
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/SalidasAutomaticas.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
file.reference.c3p0-0.9.1.1.jar=D:\\LIBRERIAS\\quartz\\c3p0-0.9.1.1.jar
file.reference.commons-dbcp-1.4.jar=D:\\LIBRERIAS\\pool\\commons-dbcp-1.4.jar
file.reference.commons-pool-1.6.jar=D:\\LIBRERIAS\\pool\\commons-pool-1.6.jar
file.reference.json-20151123.jar=D:\\LIBRERIAS\\json-20151123.jar
file.reference.log4j-1.2.16.jar=D:\\LIBRERIAS\\quartz\\log4j-1.2.16.jar
file.reference.mysql-connector-java-3.1.14-bin.jar=D:\\LIBRERIAS\\mysql-connector-java-3.1.14-bin.jar
file.reference.quartz-2.2.3.jar=D:\\LIBRERIAS\\quartz\\quartz-2.2.3.jar
file.reference.quartz-jobs-2.2.3.jar=D:\\LIBRERIAS\\quartz\\quartz-jobs-2.2.3.jar
file.reference.slf4j-api-1.7.7.jar=D:\\LIBRERIAS\\quartz\\slf4j-api-1.7.7.jar
file.reference.slf4j-log4j12-1.7.7.jar=D:\\LIBRERIAS\\quartz\\slf4j-log4j12-1.7.7.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.c3p0-0.9.1.1.jar}:\
${file.reference.log4j-1.2.16.jar}:\
${file.reference.quartz-2.2.3.jar}:\
${file.reference.quartz-jobs-2.2.3.jar}:\
${file.reference.slf4j-api-1.7.7.jar}:\
${file.reference.slf4j-log4j12-1.7.7.jar}:\
${file.reference.json-20151123.jar}:\
${file.reference.commons-dbcp-1.4.jar}:\
${file.reference.commons-pool-1.6.jar}:\
${file.reference.mysql-connector-java-3.1.14-bin.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=salidasautomaticas.main.Main
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>SalidasAutomaticas</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.dao;
import salidasautomaticas.mysqldao.MysqlDAOFactory;
/**
*
* @author sistem08user
*/
public abstract class DAOFactory{
public static final int MYSQL = 1;
public static final int ORACLE = 2;
public static final int DB2 = 3;
public static final int SQLSERVER = 4;
public static final int XML = 5;
public static DAOFactory getFactory(int BD) {
switch (BD) {
case MYSQL:
return new MysqlDAOFactory();
/*
case SQLSERVER:
return new SqlserverDAOFactory();
case ORACLE:
return new OracleDAOFactory();
case DB2:
return new Db2DAOFactory();
case SQLSERVER:
return new SqlServerDAOFactory();
case XML:
return new XmlDAOFactory();
*/
default:
return null;
}
}
// CREAR NUESTRO ABSTRACTO PARA LA CONEXION AL SERVICE
public abstract SalidasDAO getSalidasDAO();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.dao;
import org.json.JSONArray;
import org.json.JSONObject;
/**
*
* @author sistem19user
*/
public interface SalidasDAO {
public JSONArray obtenerHorariosSalida() throws Exception;
public JSONObject actualizarSalida() throws Exception;
}
package salidasautomaticas.main;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.quartz.CronScheduleBuilder.cronSchedule;
import org.quartz.CronTrigger;
import static org.quartz.JobBuilder.newJob;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import static org.quartz.TriggerBuilder.newTrigger;
import org.quartz.impl.StdSchedulerFactory;
import salidasautomaticas.schedule.Planificador;
import salidasautomaticas.schedule.ProgramarSalidasJob;
public class Main {
public static void main(String[] args) {
SchedulerFactory sf = Planificador.getInstance().getSchedulerFactory();
Scheduler scheduler;
try {
scheduler = sf.getScheduler();
JobDetail job = newJob(ProgramarSalidasJob.class).withIdentity("job1", "group1").build();
CronTrigger trigger = newTrigger().withIdentity("trigger1", "group1").withSchedule(cronSchedule("30 15 * * * ?"))
.build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
} catch (SchedulerException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.mysqldao;
import java.sql.Connection;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import salidasautomaticas.dao.DAOFactory;
import salidasautomaticas.dao.SalidasDAO;
/**
*
* @author sistem08user
*/
public class MysqlDAOFactory extends DAOFactory {
private static DataSource dataSourceMySQL;
static {
try {
createPoolConnectionsMySQL();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void createPoolConnectionsMySQL() {
if (dataSourceMySQL == null) {
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
basicDataSource.setUsername("billy");
basicDataSource.setPassword("billy");
basicDataSource.setUrl("jdbc:mysql://172.16.2.39:3306/nuevo");
basicDataSource.setMaxActive(30);
basicDataSource.setMaxIdle(30);
basicDataSource.setRemoveAbandoned(true);
basicDataSource.setRemoveAbandonedTimeout(5000);
basicDataSource.setMaxWait(6000);
dataSourceMySQL = basicDataSource;
}
}
public static Connection getConneccion(String bd) {
Connection connection = null;
if (bd.equals("nuevo")) {
try {
connection = dataSourceMySQL.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
return connection;
}
@Override
public SalidasDAO getSalidasDAO() {
return new SalidasMysqlDAO();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.mysqldao;
import java.sql.Connection;
import java.time.LocalDate;
import org.json.JSONArray;
import org.json.JSONObject;
import salidasautomaticas.dao.SalidasDAO;
import salidasautomaticas.util.EstandarDAO;
/**
*
* @author sistem19user
*/
public class SalidasMysqlDAO implements SalidasDAO {
@Override
public JSONArray obtenerHorariosSalida() throws Exception {
Connection cn = MysqlDAOFactory.getConneccion("nuevo");
int diaSemana = obtenerDiaSemana();
String query = "select ? as salida from personal inner join "
+ "cargo on (personal.codcargo=cargo.codcargo) where NULLIF(? , '') is NOT null and retirado=0 GROUP BY ?";
if (diaSemana >= 1 && diaSemana <= 5) {
query = query.replaceAll("\\?", "salidaLV");
} else if (diaSemana == 6) {
query = query.replaceAll("\\?", "salidaS");
}
JSONArray jsonArray = EstandarDAO.getInstance().consultar(cn, query);
return jsonArray;
}
private int obtenerDiaSemana() {
int diaSemana;
LocalDate date = LocalDate.now();
diaSemana = date.getDayOfWeek().getValue();
return diaSemana;
}
@Override
public JSONObject actualizarSalida() throws Exception {
JSONObject resultado = null;
Connection cn = MysqlDAOFactory.getConneccion("nuevo");
String queryPersonal = "select codper from personal where salidaLV='10:00' and retirado=0";
JSONArray jsonArray = EstandarDAO.getInstance().consultar(cn, queryPersonal);
for(int i=0; i<jsonArray.length(); i++){
JSONObject objJSON = (JSONObject) jsonArray.get(i);
String codper = objJSON.getString("codper");
String query = "update asistencia set horasal=2, minsal=0 where codper=?";
JSONArray parametros = new JSONArray();
parametros.put(codper);
resultado = EstandarDAO.getInstance().ejecutar(cn, query);
}
return resultado;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.schedule;
import java.time.LocalDate;
import java.time.LocalDateTime;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
*
* @author sistem19user
*/
public class GenerarSalidasJob implements Job{
@Override
public void execute(JobExecutionContext jec) throws JobExecutionException {
System.out.println("Salida "+LocalDateTime.now());
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.schedule;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
/**
*
* @author sistem19user
*/
public class Planificador {
private static Planificador instance;
private StdSchedulerFactory sf;
private Planificador(){
sf = new StdSchedulerFactory();
}
public static Planificador getInstance(){
if(instance==null) instance = new Planificador();
return instance;
}
public SchedulerFactory getSchedulerFactory(){
return sf;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.schedule;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import static org.quartz.CronScheduleBuilder.cronSchedule;
import org.quartz.CronTrigger;
import org.quartz.Job;
import static org.quartz.JobBuilder.newJob;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import static org.quartz.TriggerBuilder.newTrigger;
import org.quartz.impl.StdSchedulerFactory;
import salidasautomaticas.main.Main;
import salidasautomaticas.services.SalidasServices;
/**
*
* @author sistem19user
*/
public class ProgramarSalidasJob implements Job{
@Override
public void execute(JobExecutionContext jec) throws JobExecutionException {
SalidasServices services = new SalidasServices();
try {
JSONArray listaHorarios = services.obtenerHorariosSalida();
Iterator it = listaHorarios.iterator();
int i =0;
while(it.hasNext()){
JSONObject objJSON = (JSONObject) it.next();
String horaSalida = objJSON.getString("salida");
System.out.println(horaSalida);
programar(horaSalida, Integer.toString(i));
i++;
}
} catch (Exception ex) {
Logger.getLogger(ProgramarSalidasJob.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void programar(String horaSalida, String jobName){
SchedulerFactory sf = Planificador.getInstance().getSchedulerFactory();
Scheduler scheduler;
String[] splitHora = horaSalida.split(":");
try {
scheduler = sf.getScheduler();
JobDetail job = newJob(GenerarSalidasJob.class).withIdentity(jobName, "groupSalida1").build();
String cronExpression = "%s %s * * * ?";
cronExpression = String.format(cronExpression, splitHora[1], splitHora[0]);
CronTrigger trigger = newTrigger().withIdentity("triggerSalida"+jobName, "groupSalida1").withSchedule(cronSchedule(cronExpression))
.build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
} catch (SchedulerException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
package salidasautomaticas.services;
import org.json.JSONArray;
import org.json.JSONObject;
import salidasautomaticas.dao.DAOFactory;
import salidasautomaticas.dao.SalidasDAO;
/**
*
* @author sistem19user
*/
public class SalidasServices {
DAOFactory daofactory = DAOFactory.getFactory(DAOFactory.MYSQL);
SalidasDAO salidadao = daofactory.getSalidasDAO();
public JSONArray obtenerHorariosSalida() throws Exception {
JSONArray listaHorarios = null;
try {
listaHorarios = salidadao.obtenerHorariosSalida();
} catch (Exception e) {
e.printStackTrace();
}
return listaHorarios;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import org.json.JSONArray;
import org.json.JSONObject;
/**
*
* @author sistem19user
*/
public class EstandarDAO {
private static EstandarDAO instance;
private EstandarDAO() {
}
public static EstandarDAO getInstance() {
if (instance == null) {
instance = new EstandarDAO();
}
return instance;
}
public JSONObject listar(Connection cn, String query, JSONArray... parametros) throws Exception {
JSONObject obj = new JSONObject();
JSONArray jsonArray = consultar(cn, query, parametros);
int length = jsonArray.length();
obj.put("data", jsonArray);
obj.put("recordsFiltered", length);
obj.put("recordsTotal", length);
obj.put("draw", "1");
return obj;
}
/**
* Este metodo ejecuta una sentencia sql de consulta(solamente selects) en la base de datos y
* devuelve como resultado en un JSONArray los registros obtenidos
*
*
* @param cn objeto que representa la conexion a la base de datos
* @param query sentencia sql que se desea ejecutar en la base de datos
* @param parametros parametros que vamos a pasar al query, *es opcional
* @return Devuelve como resultado los registros obtenidos por el query en un objeto JSONArray
* @throws Exception
*/
public JSONArray consultar(Connection cn, String query, JSONArray... parametros) throws Exception {
//objeto que almacena todos las filas obtenidas por el query
JSONArray jsonArray = new JSONArray();
try {
if (cn == null) {
jsonArray = null;
} else {
PreparedStatement ps = cn.prepareStatement(query);
//validamos si existen parametros
if (parametros != null && parametros.length > 0) {
JSONArray params = parametros[0];
int cont = 1;
//Recorremos la lista de parametros y lo seteamos en el preparedstatement
for (Object parametro : params) {
castingPS(ps, cont, parametro);
cont++;
}
}
ResultSet rs = ps.executeQuery();
ResultSetMetaData rm = rs.getMetaData();
int numCols = rm.getColumnCount();
while (rs.next()) {
JSONObject obj = new JSONObject();
for (int i = 1; i <= numCols; i++) {
castColumn(rs, rm, i, obj);
}
jsonArray.put(obj);
}
rs.close();
cn.close();
}
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
return jsonArray;
}
/**
* Este metodo nos permite ejecutar una sentencia sql en la base de datos y
* devuelve como resultado en un JSONObject las filas afectadas por el
* query.
*
* @param cn objeto que representa la conexion a la base de datos
* @param query sentencia sql que se desea ejecutar en la base de datos
* @param parametros parametros que vamos a pasar al query, *es opcional
* @return Devuelve la cantidad de filas afectadas por el query en un
* JSONObject.
* @throws Exception
*/
public JSONObject ejecutar(Connection cn, String query, JSONArray... parametros) throws Exception {
JSONObject obj = new JSONObject();
try {
if (cn == null) {
obj.put("msg", 0);
} else {
PreparedStatement ps = cn.prepareStatement(query);
if (parametros != null && parametros.length > 0) {
JSONArray params = parametros[0];
int cont = 1;
for (Object parametro : params) {
castingPS(ps, cont, parametro);
cont++;
}
}
int filas = ps.executeUpdate();
if (filas > 0) {
obj.put("msg", filas);
} else {
obj.put("msg", 0);
}
cn.close();
}
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
return obj;
}
/**
*Setea en el prepared statement el valor del parametro segun su tipo de dato.
*
* @param ps representa el objeto PreparedStatement
* @param index indica la posicion del parametro en la consulta sql
* @param p parametro de la consulta sql
* @throws SQLException
*/
private void castingPS(PreparedStatement ps, int index, Object p) throws SQLException {
if (p instanceof Integer) {
ps.setInt(index, (int) p);
} else if (p instanceof String) {
ps.setString(index, p.toString());
} else if (p instanceof Double) {
ps.setDouble(index, (double) p);
} else if (p instanceof Boolean) {
ps.setBoolean(index, (boolean) p);
}
}
/**
* Obtiene el valor de una columna de una tabla y lo guarda en el objeto JSONObject
* con el tipo de dato que le corresponde.
*
* @param rs Objeto ResultSet para obtener el valor de una columna de una tabla
* @param rsmd Objeto ResultSetMetaData nos permite obtener el nombre y tipo de columna
* @param columnIndex Posicion de la columna en la sentencia sql
* @param obj Representa a un registro de la base de datos
* @throws SQLException
*/
private void castColumn(ResultSet rs, ResultSetMetaData rsmd, int columnIndex, JSONObject obj) throws SQLException {
//obtenemos el tipo de dato de la columna de la tabla
int type = rsmd.getColumnType(columnIndex);
//evaluamos el tipo
switch (type) {
case Types.VARCHAR:
case Types.CHAR:
obj.put(rsmd.getColumnName(columnIndex), rs.getString(columnIndex));
break;
case Types.INTEGER:
obj.put(rsmd.getColumnName(columnIndex), rs.getInt(columnIndex));
break;
case Types.BIT:
obj.put(rsmd.getColumnName(columnIndex), rs.getBoolean(columnIndex));
break;
default:
obj.put(rsmd.getColumnName(columnIndex), rs.getString(columnIndex));
}
}
// public static void main(String[] args) throws Exception {
// String query = "select * from ubigeo";
//
// Connection cn = MysqlDAOFactory.getConneccion("capacitacion");
// JSONArray obj = EstandarDAO.getInstance().consultar(cn, query);
//
// System.out.println(obj);
// }
}
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