Commit bdc4c081 by Billy Larru

[ADD implementando DotEnv en el proyecto]

parent 495cefd1
......@@ -5,10 +5,12 @@
*/
package salidasautomaticas.mysqldao;
import io.github.cdimascio.dotenv.Dotenv;
import java.sql.Connection;
import java.sql.DriverManager;
import salidasautomaticas.dao.DAOFactory;
import salidasautomaticas.dao.SalidasDAO;
import salidasautomaticas.util.OsUtils;
/**
*
......@@ -29,11 +31,15 @@ public class MysqlDAOFactory extends DAOFactory {
Connection conexion = null;
if (base.equals("nuevo")) {
try {
String url = "jdbc:mysql://172.16.0.15:3306/nuevo";
String username = "eduardo";
String password = "mysql";
conexion = DriverManager.getConnection(url, username, password);
Dotenv dotenv = Dotenv.configure().directory(OsUtils.getDotEnvPath("salidasautomaticas")).load();
final String DB_HOST = dotenv.get("MYSQL_SALIDASAUTOMATICAS_DB_HOST");
final String DB_PORT = dotenv.get("MYSQL_SALIDASAUTOMATICAS_DB_PORT");
final String DB_USER = dotenv.get("MYSQL_SALIDASAUTOMATICAS_DB_USER");
final String DB_PASSWORD = dotenv.get("MYSQL_SALIDASAUTOMATICAS_DB_PASSWORD");
final String DB_NAME = dotenv.get("MYSQL_SALIDASAUTOMATICAS_DB_NAME");
final String URL = "jdbc:mysql://" + DB_HOST + ":" + DB_PORT + "/" + DB_NAME;
conexion = DriverManager.getConnection(URL, DB_USER, DB_PASSWORD);
} catch (Exception e) {
e.printStackTrace();
......
/*
* 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.io.File;
import java.util.Locale;
/**
*
* @author sistem08user
*/
public final class OsUtils {
/**
* types of Operating Systems
*/
public enum OSType {
Windows, MacOS, Linux, Other
};
// cached result of OS detection
protected static String detectedOS;
/**
* 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 String getPathOfVouchersDependingOS() {
String path = "";
String detectedOs = OsUtils.getOperatingSysstemType();
switch (detectedOs) {
case "MacOS":
path = "";
break;
case "Windows":
path = "C:/AppServ/www/comprobantes";
break;
case "Linux":
path = "/var/www/html/comprobantes";
break;
}
return path;
}
public static String getJSONDependingOS() {
String path = "";
String detectedOs = OsUtils.getOperatingSysstemType();
switch (detectedOs) {
case "MacOS":
path = "";
break;
case "Windows":
path = "C:/AppServ/www/comprobantes-log";
break;
case "Linux":
path = "/var/www/html/comprobantes-log";
break;
}
return path;
}
public static String getDotEnvPath(String nameProject) {
String path = "";
String detectedOs = OsUtils.getOperatingSysstemType();
switch (detectedOs) {
case "MacOS":
path = "";
break;
case "Windows":
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
for (char letter : alphabet) {
path = letter + ":/dotenv/" + nameProject;
File directory = new File(path);
if (directory.exists()) {
break;
}
}
break;
case "Linux":
path = "/opt/dotenv/" + nameProject;
break;
}
return path;
}
}
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