Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
web-ui
Project
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
WEBGDE-Components
web-ui
Commits
370af334
Commit
370af334
authored
Jul 07, 2023
by
rndeguzman
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-WG-314' into feature-WG-320
parents
c36164ce
1f0bf3b8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
415 additions
and
120 deletions
+415
-120
org.eclipse.m2e.wtp.prefs
WebGde/.settings/org.eclipse.m2e.wtp.prefs
+2
-0
org.eclipse.wst.common.project.facet.core.xml
...e/.settings/org.eclipse.wst.common.project.facet.core.xml
+12
-12
config.ini
WebGde/WebContent/WEB-INF/config/config.ini
+6
-0
DBLookup.js
...ntent/WebGde-Widgets/DataInputWidget/DBLookup/DBLookup.js
+20
-0
config.js
WebGde/WebContent/WebGde-Widgets/DataInputWidget/config.js
+5
-2
displayFieldClass.js
...ntent/WebGde-Widgets/DataInputWidget/displayFieldClass.js
+5
-1
generateFields.js
...bContent/WebGde-Widgets/DataInputWidget/generateFields.js
+0
-0
testdblookup_schema.json
...ent/WebGde-Widgets/sample_schema/testdblookup_schema.json
+179
-0
script.js
WebGde/WebContent/WebGde-Widgets/script.js
+1
-1
pom.xml
WebGde/pom.xml
+2
-1
ApplicationConfig.java
.../com/svi/webgde/restservice/config/ApplicationConfig.java
+6
-1
SecuredFilter.java
...ava/com/svi/webgde/restservice/filters/SecuredFilter.java
+102
-101
GDEWebServices.java
...a/com/svi/webgde/restservice/services/GDEWebServices.java
+15
-1
DBUtil.java
...rc/main/java/com/svi/webgde/restservice/utils/DBUtil.java
+60
-0
No files found.
WebGde/.settings/org.eclipse.m2e.wtp.prefs
0 → 100644
View file @
370af334
eclipse.preferences.version=1
org.eclipse.m2e.wtp.enabledProjectSpecificPrefs=false
WebGde/.settings/org.eclipse.wst.common.project.facet.core.xml
View file @
370af334
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime
name=
"Payara Server 5 (5.202
1.1)"
/>
<fixed
facet=
"jst.web"
/>
<fixed
facet=
"java"
/>
<fixed
facet=
"wst.jsdt.web"
/>
<installed
facet=
"java"
version=
"1.8"
/>
<installed
facet=
"jst.web"
version=
"3.1"
/>
<installed
facet=
"wst.jsdt.web"
version=
"1.0"
/>
<installed
facet=
"jst.jaxrs"
version=
"2.1"
/>
<installed
facet=
"jst.jsf"
version=
"2.2"
/>
</faceted-project>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime
name=
"Payara Server 5 (5.202
2.5)"
/>
<fixed
facet=
"jst.web"
/>
<fixed
facet=
"java"
/>
<fixed
facet=
"wst.jsdt.web"
/>
<installed
facet=
"java"
version=
"1.8"
/>
<installed
facet=
"jst.web"
version=
"3.1"
/>
<installed
facet=
"wst.jsdt.web"
version=
"1.0"
/>
<installed
facet=
"jst.jaxrs"
version=
"2.1"
/>
<installed
facet=
"jst.jsf"
version=
"2.2"
/>
</faceted-project>
WebGde/WebContent/WEB-INF/config/config.ini
View file @
370af334
...
...
@@ -17,3 +17,9 @@ GET_ROLE_RIGHTS_URL=http://localhost:8080/gfs-explorer/svc/gfs-rest/rights/
CHECK_RIGHT_URL
=
http://localhost:8080/gfs-explorer/svc/gfs-rest/check-right/
GET_SUB_URL
=
http://localhost:8080/gfs-explorer/svc/gfs-rest/get-sub/
[MARIADB CONFIG]
JDBC_URL
=
jdbc:mariadb://localhost:3307/
DB_NAME
=
webgde_db
USERNAME
=
root
PASSWORD
=
p455w0rd
WebGde/WebContent/WebGde-Widgets/DataInputWidget/DBLookup/DBLookup.js
0 → 100644
View file @
370af334
import
{
DB_URL
}
from
"../config.js"
;
export
const
fetchOptionsDB
=
async
(
requestBody
)
=>
{
try
{
const
response
=
await
fetch
(
DB_URL
,
{
method
:
'POST'
,
body
:
JSON
.
stringify
(
requestBody
),
headers
:
{
'Content-Type'
:
'application/json'
}
});
const
data
=
await
response
.
json
();
return
data
.
tableData
||
[];
}
catch
(
error
)
{
throw
error
;
}
};
\ No newline at end of file
WebGde/WebContent/WebGde-Widgets/DataInputWidget/config.js
View file @
370af334
//Data Input Field Config
export
var
SCHEMA_FILE_PATH
=
"./WebGde-Widgets/sample_schema/HR Speed Test schema.json"
;
\ No newline at end of file
export
var
SCHEMA_FILE_PATH
=
"./WebGde-Widgets/sample_schema/HR Speed Test schema.json"
;
//DBLookup Webservice URL
export
var
DB_URL
=
"http://localhost:8080/WebGde/svc/gfs-rest/db-lookup"
\ No newline at end of file
WebGde/WebContent/WebGde-Widgets/DataInputWidget/displayFieldClass.js
View file @
370af334
import
{
generateFields
}
from
"./generateFields.js"
;
import
{
clearForm
,
generateFields
}
from
"./generateFields.js"
;
export
class
displayField
{
constructor
(
schema
,
containerId
)
{
...
...
@@ -10,6 +10,10 @@ export class displayField {
generateFields
(
this
.
schema
,
this
.
containerId
);
}
clearForm
(){
clearForm
();
}
updateHeaderText
(
headerIndex
,
newText
)
{
let
headers
=
document
.
getElementsByClassName
(
"field-header"
);
if
(
headerIndex
>=
0
&&
headerIndex
<
headers
.
length
)
{
...
...
WebGde/WebContent/WebGde-Widgets/DataInputWidget/generateFields.js
View file @
370af334
This diff is collapsed.
Click to expand it.
WebGde/WebContent/WebGde-Widgets/sample_schema/testdblookup_schema.json
0 → 100644
View file @
370af334
{
"APPLICATION FORM"
:
{
"SECTION1"
:
{
"Date"
:
{
"fieldLabel"
:
"Date"
,
"aka"
:
"field2"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
20
,
"collection"
:
"alphanumeric"
,
"invalidchar"
:
"`~!@#&$%^*_={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
}
},
"Position Applied For"
:
{
"fieldLabel"
:
"Pos Applied For"
,
"aka"
:
"field3"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
30
,
"collection"
:
"alphanumeric"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
}
},
"Surname"
:
{
"fieldLabel"
:
"Surname"
,
"aka"
:
"field4"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
50
,
"collection"
:
"textarea"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
}
},
"First Name"
:
{
"fieldLabel"
:
"First Name"
,
"aka"
:
"field5"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
50
,
"collection"
:
"textarea"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
}
},
"Middle Name"
:
{
"fieldLabel"
:
"Mid Name"
,
"aka"
:
"field6"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
50
,
"collection"
:
"textarea"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
}
},
"Mother's Maiden Name"
:
{
"fieldLabel"
:
"Mother's Maiden Name"
,
"aka"
:
"field7"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
100
,
"collection"
:
"textarea"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
}
},
"Date of Birth"
:
{
"fieldLabel"
:
"Date of Birth"
,
"aka"
:
"field25"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
30
,
"collection"
:
"datepicker"
,
"mandatory"
:
true
}
},
"Age"
:
{
"fieldLabel"
:
"Age"
,
"aka"
:
"field26"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
3
,
"collection"
:
"numeric"
,
"mandatory"
:
true
}
},
"Gender"
:
{
"fieldLabel"
:
"Gender"
,
"aka"
:
"field27"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
10
,
"collection"
:
"dropdown"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
,
"options"
:
[
"Male"
,
"Female"
]
}
},
"Civil Status"
:
{
"fieldLabel"
:
"Civil Status"
,
"aka"
:
"field28"
,
"source"
:
"s"
,
"validation"
:
{
"fieldLength"
:
10
,
"collection"
:
"alphanumeric"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
,
"validvalues"
:
[
"Single"
,
"Married"
,
"Widowed"
]
}
},
"Spouse Name"
:
{
"fieldLabel"
:
"Spouse Name"
,
"aka"
:
"field29"
,
"source"
:
"s"
,
"validation"
:
{
"fieldLength"
:
100
,
"collection"
:
"textarea"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
},
"childof"
:
"Civil Status"
,
"parentvalue"
:
[
"Married"
,
"Widowed"
]
},
"Date of Marriage"
:
{
"fieldLabel"
:
"Date of Marriage"
,
"aka"
:
"field30"
,
"source"
:
"s"
,
"validation"
:
{
"fieldLength"
:
30
,
"collection"
:
"alphanumeric"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
},
"childof"
:
"Civil Status"
,
"parentvalue"
:
[
"Married"
,
"Widowed"
]
},
"Mother's Name"
:
{
"fieldLabel"
:
"Mother's Name"
,
"aka"
:
"field31"
,
"source"
:
"s"
,
"validation"
:
{
"fieldLength"
:
100
,
"collection"
:
"textarea"
,
"invalidchar"
:
"`~!@#&$%^*={}[]:;/
\"
|
\\
<>"
,
"mandatory"
:
true
},
"childof"
:
"Civil Status"
,
"parentvalue"
:
[
"Single"
]
},
"School"
:
{
"fieldLabel"
:
"School"
,
"aka"
:
"field32"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
100
,
"collection"
:
"dblookup"
,
"mandatory"
:
true
,
"options"
:
"TBLSchool~Name"
}
},
"TOR"
:
{
"fieldLabel"
:
"TOR"
,
"aka"
:
"field33"
,
"source"
:
"p"
,
"validation"
:
{
"fieldLength"
:
100
,
"collection"
:
"alphanumeric"
,
"mandatory"
:
true
},
"hidden"
:
"y"
}
}
}
}
\ No newline at end of file
WebGde/WebContent/WebGde-Widgets/script.js
View file @
370af334
...
...
@@ -111,7 +111,7 @@ async function createInputForm(){
// Instantiate widget and assign it to a container
const
displayFieldClass
=
new
displayField
(
schema
,
containerId
);
// Call Function to generate fields with given schema to provided container
displayFieldClass
.
generateFields
();
await
displayFieldClass
.
generateFields
();
// displayFieldClass.editHeader(element-id)
displayFieldClass
.
updateHeaderText
(
0
,
"User: "
+
sessionStorage
.
getItem
(
"user_id"
));
displayFieldClass
.
updateHeaderText
(
1
,
"Element ID: "
+
sessionStorage
.
getItem
(
"element_id"
));
...
...
WebGde/pom.xml
View file @
370af334
...
...
@@ -42,10 +42,11 @@
<artifactId>
json-simple
</artifactId>
<version>
1.1.1
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>
org.mariadb.jdbc
</groupId>
<artifactId>
mariadb-java-client
</artifactId>
<version>
JDBC 4
.2
</version>
<version>
2.7
.2
</version>
</dependency>
</dependencies>
<build>
...
...
WebGde/src/main/java/com/svi/webgde/restservice/config/ApplicationConfig.java
View file @
370af334
...
...
@@ -22,7 +22,12 @@ public enum ApplicationConfig {
GET_SUBFOLDERS_URL
(
"GET_SUBFOLDERS_URL"
),
GET_SUBFILES_URL
(
"GET_SUBFILES_URL"
),
METRICS_DIR
(
"METRICS_DIR"
);
METRICS_DIR
(
"METRICS_DIR"
),
JDBC_URL
(
"JDBC_URL"
),
DB_NAME
(
"DB_NAME"
),
USERNAME
(
"USERNAME"
),
PASSWORD
(
"PASSWORD"
);
private
String
value
=
""
;
private
static
Properties
prop
;
...
...
WebGde/src/main/java/com/svi/webgde/restservice/filters/SecuredFilter.java
View file @
370af334
package
com
.
svi
.
webgde
.
restservice
.
filters
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
javax.annotation.Priority
;
import
javax.ws.rs.Priorities
;
import
javax.ws.rs.container.ContainerRequestContext
;
import
javax.ws.rs.container.ContainerRequestFilter
;
import
javax.ws.rs.core.Cookie
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.ext.Provider
;
import
org.apache.commons.lang3.StringUtils
;
import
com.svi.sso.jwt.utilities.JWTClaims
;
import
com.svi.sso.jwt.utilities.JWTUtility
;
import
com.svi.template.restservice.globals.AppConfig
;
import
com.svi.template.restservice.globals.GlobalConstants
;
@Secured
@Provider
@Priority
(
Priorities
.
AUTHENTICATION
)
public
class
SecuredFilter
implements
ContainerRequestFilter
{
private
static
final
GlobalConstants
GLOBAL_CONSTANTS
=
GlobalConstants
.
getInstance
();
@Override
public
void
filter
(
ContainerRequestContext
requestContext
)
throws
IOException
{
if
(
AppConfig
.
IS_COOKIE
.
getValue
().
equalsIgnoreCase
(
"Y"
))
{
if
(!
verifyCallerByCookie
(
requestContext
))
{
try
{
redirect
(
requestContext
);
}
catch
(
URISyntaxException
e
)
{
System
.
out
.
println
(
"SSO secured filter: "
+
e
.
getMessage
());
}
}
}
else
{
if
(!
verifyCallerByBearer
(
requestContext
))
{
try
{
redirect
(
requestContext
);
}
catch
(
URISyntaxException
e
)
{
System
.
out
.
println
(
"SSO secured filter: "
+
e
.
getMessage
());
}
}
}
}
private
boolean
verifyCallerByCookie
(
ContainerRequestContext
requestContext
)
{
Cookie
cookie
=
requestContext
.
getCookies
().
get
(
AppConfig
.
ACCESS_TOKEN
.
getValue
());
boolean
callerVerified
=
false
;
URI
uri
=
requestContext
.
getUriInfo
().
getAbsolutePath
();
if
(
cookie
==
null
)
{
callerVerified
=
false
;
}
else
{
try
{
String
token
=
cookie
.
getValue
();
JWTClaims
claims
=
JWTUtility
.
parseTokenSecure
(
token
,
AppConfig
.
ACCESS_SUBJECT
.
getValue
());
if
(
claims
==
null
)
{
callerVerified
=
false
;
}
else
{
requestContext
.
setProperty
(
GLOBAL_CONSTANTS
.
getJwtClaimsText
(),
claims
);
callerVerified
=
true
;
}
}
catch
(
Exception
e
)
{
callerVerified
=
false
;
}
}
return
callerVerified
;
}
private
boolean
verifyCallerByBearer
(
ContainerRequestContext
requestContext
)
{
String
bearer
=
requestContext
.
getHeaderString
(
GLOBAL_CONSTANTS
.
getAuthorizationHeaderText
());
boolean
validRequest
=
false
;
if
(
StringUtils
.
isNoneBlank
(
bearer
))
{
try
{
String
[]
splittedBearer
=
bearer
.
split
(
" "
);
String
token
=
splittedBearer
[
1
];
if
(
StringUtils
.
isNoneBlank
(
token
))
{
JWTClaims
claims
=
JWTUtility
.
parseTokenSecure
(
token
,
AppConfig
.
ACCESS_SUBJECT
.
getValue
());
if
(
claims
!=
null
)
{
requestContext
.
setProperty
(
GLOBAL_CONSTANTS
.
getJwtClaimsText
(),
claims
);
validRequest
=
true
;
}
}
}
catch
(
Exception
e
)
{
}
}
return
validRequest
;
}
private
void
redirect
(
ContainerRequestContext
requestContext
)
throws
URISyntaxException
{
requestContext
.
abortWith
(
Response
.
serverError
().
entity
(
GLOBAL_CONSTANTS
.
getForbiddenText
()).
build
());
}
}
package
com
.
svi
.
webgde
.
restservice
.
filters
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
javax.annotation.Priority
;
import
javax.ws.rs.Priorities
;
import
javax.ws.rs.container.ContainerRequestContext
;
import
javax.ws.rs.container.ContainerRequestFilter
;
import
javax.ws.rs.core.Cookie
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.ext.Provider
;
import
org.apache.commons.lang3.StringUtils
;
import
com.svi.sso.jwt.utilities.JWTClaims
;
import
com.svi.sso.jwt.utilities.JWTUtility
;
import
com.svi.template.restservice.globals.AppConfig
;
import
com.svi.template.restservice.globals.GlobalConstants
;
@Secured
@Provider
@Priority
(
Priorities
.
AUTHENTICATION
)
public
class
SecuredFilter
implements
ContainerRequestFilter
{
private
static
final
GlobalConstants
GLOBAL_CONSTANTS
=
GlobalConstants
.
getInstance
();
@Override
public
void
filter
(
ContainerRequestContext
requestContext
)
throws
IOException
{
if
(
AppConfig
.
IS_COOKIE
.
getValue
().
equalsIgnoreCase
(
"Y"
))
{
if
(!
verifyCallerByCookie
(
requestContext
))
{
try
{
redirect
(
requestContext
);
}
catch
(
URISyntaxException
e
)
{
System
.
out
.
println
(
"SSO secured filter: "
+
e
.
getMessage
());
}
}
}
else
{
if
(!
verifyCallerByBearer
(
requestContext
))
{
try
{
redirect
(
requestContext
);
}
catch
(
URISyntaxException
e
)
{
System
.
out
.
println
(
"SSO secured filter: "
+
e
.
getMessage
());
}
}
}
}
private
boolean
verifyCallerByCookie
(
ContainerRequestContext
requestContext
)
{
Cookie
cookie
=
requestContext
.
getCookies
().
get
(
AppConfig
.
ACCESS_TOKEN
.
getValue
());
boolean
callerVerified
=
false
;
URI
uri
=
requestContext
.
getUriInfo
().
getAbsolutePath
();
if
(
cookie
==
null
)
{
callerVerified
=
false
;
}
else
{
try
{
String
token
=
cookie
.
getValue
();
JWTClaims
claims
=
JWTUtility
.
parseTokenSecure
(
token
,
AppConfig
.
ACCESS_SUBJECT
.
getValue
());
if
(
claims
==
null
)
{
callerVerified
=
false
;
}
else
{
requestContext
.
setProperty
(
GLOBAL_CONSTANTS
.
getJwtClaimsText
(),
claims
);
callerVerified
=
true
;
}
}
catch
(
Exception
e
)
{
callerVerified
=
false
;
}
}
return
callerVerified
;
}
private
boolean
verifyCallerByBearer
(
ContainerRequestContext
requestContext
)
{
String
bearer
=
requestContext
.
getHeaderString
(
GLOBAL_CONSTANTS
.
getAuthorizationHeaderText
());
boolean
validRequest
=
false
;
if
(
StringUtils
.
isNoneBlank
(
bearer
))
{
try
{
String
[]
splittedBearer
=
bearer
.
split
(
" "
);
String
token
=
splittedBearer
[
1
];
if
(
StringUtils
.
isNoneBlank
(
token
))
{
JWTClaims
claims
=
JWTUtility
.
parseTokenSecure
(
token
,
AppConfig
.
ACCESS_SUBJECT
.
getValue
());
if
(
claims
!=
null
)
{
requestContext
.
setProperty
(
GLOBAL_CONSTANTS
.
getJwtClaimsText
(),
claims
);
validRequest
=
true
;
}
}
}
catch
(
Exception
e
)
{
}
}
return
validRequest
;
}
private
void
redirect
(
ContainerRequestContext
requestContext
)
throws
URISyntaxException
{
requestContext
.
abortWith
(
Response
.
serverError
().
entity
(
GLOBAL_CONSTANTS
.
getForbiddenText
()).
build
());
}
}
\ No newline at end of file
WebGde/src/main/java/com/svi/webgde/restservice/services/GDEWebServices.java
View file @
370af334
...
...
@@ -23,12 +23,13 @@ import javax.ws.rs.core.Response;
import
javax.ws.rs.core.Response.ResponseBuilder
;
import
javax.ws.rs.core.StreamingOutput
;
import
org.json.JSONObject
;
import
org.json.
simple.
JSONObject
;
import
com.opencsv.CSVReader
;
import
com.opencsv.CSVWriter
;
import
com.svi.webgde.restservice.object.Request
;
import
com.svi.webgde.restservice.object.XMLContents
;
import
com.svi.webgde.restservice.utils.DBUtil
;
import
com.svi.webgde.restservice.utils.XMLUtil
;
@Path
(
"/gfs-rest"
)
...
...
@@ -39,6 +40,19 @@ public class GDEWebServices {
public
Response
testWebservice
()
{
return
Response
.
ok
(
"test webservice"
).
build
();
}
@POST
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_OCTET_STREAM
)
@Path
(
"/db-lookup"
)
public
Response
dbLookup
(
JsonObject
jsonObject
)
{
JSONObject
json
=
new
JSONObject
();
String
string
=
jsonObject
.
getString
(
"dbLookup"
);
json
=
DBUtil
.
dbLookup
(
string
);
return
Response
.
ok
(
json
.
toString
()).
build
();
}
@POST
@Consumes
(
MediaType
.
APPLICATION_JSON
)
...
...
WebGde/src/main/java/com/svi/webgde/restservice/utils/DBUtil.java
0 → 100644
View file @
370af334
package
com
.
svi
.
webgde
.
restservice
.
utils
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.json.simple.JSONArray
;
import
org.json.simple.JSONObject
;
import
com.svi.webgde.restservice.config.ApplicationConfig
;
public
class
DBUtil
{
public
static
JSONObject
dbLookup
(
String
dbLookup
)
{
try
{
Class
.
forName
(
"org.mariadb.jdbc.Driver"
);
}
catch
(
ClassNotFoundException
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
}
String
jdbcURL
=
ApplicationConfig
.
JDBC_URL
.
value
()
+
ApplicationConfig
.
DB_NAME
.
value
();
String
username
=
ApplicationConfig
.
USERNAME
.
value
();
String
password
=
ApplicationConfig
.
PASSWORD
.
value
();
System
.
out
.
println
(
"url:"
+
jdbcURL
);
String
tableName
=
dbLookup
.
substring
(
0
,
dbLookup
.
indexOf
(
"~"
));
try
(
Connection
connection
=
DriverManager
.
getConnection
(
jdbcURL
,
username
,
password
))
{
String
query
=
"SELECT * FROM "
+
tableName
;
Statement
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
query
);
JSONObject
jsonObject
=
new
JSONObject
();
JSONArray
jsonArray
=
new
JSONArray
();
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
int
columnCount
=
metaData
.
getColumnCount
();
while
(
resultSet
.
next
())
{
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
String
columnName
=
metaData
.
getColumnName
(
i
);
String
columnValue
=
resultSet
.
getString
(
i
);
jsonArray
.
add
(
columnValue
);
}
}
jsonObject
.
put
(
"tableData"
,
jsonArray
);
return
jsonObject
;
}
catch
(
SQLException
e
)
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"error"
,
"500"
);
e
.
printStackTrace
();
return
jsonObject
;
}
}
}
\ No newline at end of file
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