Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SalidasAutomaticas
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
Billy Larru
SalidasAutomaticas
Commits
bdc4c081
Commit
bdc4c081
authored
Sep 22, 2018
by
Billy Larru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD implementando DotEnv en el proyecto]
parent
495cefd1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
5 deletions
+117
-5
MysqlDAOFactory.java
...ain/java/salidasautomaticas/mysqldao/MysqlDAOFactory.java
+11
-5
OsUtils.java
src/main/java/salidasautomaticas/util/OsUtils.java
+106
-0
No files found.
src/main/java/salidasautomaticas/mysqldao/MysqlDAOFactory.java
View file @
bdc4c081
...
...
@@ -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
();
...
...
src/main/java/salidasautomaticas/util/OsUtils.java
0 → 100644
View file @
bdc4c081
/*
* 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
;
}
}
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