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
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
387 additions
and
21 deletions
+387
-21
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
+1
-1
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
+4
-0
displayFieldClass.js
...ntent/WebGde-Widgets/DataInputWidget/displayFieldClass.js
+5
-1
generateFields.js
...bContent/WebGde-Widgets/DataInputWidget/generateFields.js
+86
-15
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
+0
-0
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)"
/>
<runtime
name=
"Payara Server 5 (5.202
2.5)"
/>
<fixed
facet=
"jst.web"
/>
<fixed
facet=
"java"
/>
<fixed
facet=
"wst.jsdt.web"
/>
...
...
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"
;
//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
...
...
@@ -5,15 +5,16 @@ import { validateInput, getValidation } from "./validateInput.js";
import
{
showError
}
from
"./showError.js"
;
import
{
submitForm
}
from
"../Submit/submit.js"
;
import
{
BPO_OBJECT
}
from
"../globalVariable.js"
;
import
{
fetchOptionsDB
}
from
"./DBLookup/DBLookup.js"
;
let
newOption
;
export
let
schema
;
export
async
function
generateFields
(
inputSchema
,
containerId
){
export
async
function
generateFields
(
inputSchema
,
containerId
)
{
schema
=
inputSchema
;
let
divContainer
=
document
.
getElementById
(
containerId
);
if
(
!
schema
)
{
if
(
!
schema
)
{
console
.
log
(
'Error Reading Schema File'
);
return
;
}
...
...
@@ -33,7 +34,7 @@ export async function generateFields(inputSchema, containerId){
header2
.
textContent
=
" "
;
header2
.
classList
.
add
(
"field-header"
);
let
header3
=
document
.
createElement
(
"h3"
);
header3
.
setAttribute
(
'id'
,
'counter'
);
header3
.
setAttribute
(
'id'
,
'counter'
);
header3
.
textContent
=
" "
;
header3
.
classList
.
add
(
"field-header"
);
divContainer
.
appendChild
(
header1
);
...
...
@@ -44,7 +45,7 @@ export async function generateFields(inputSchema, containerId){
container
.
id
=
"fields"
;
divContainer
.
appendChild
(
container
);
container
.
addEventListener
(
"submit"
,
(
e
)
=>
submitForm
(
e
));
container
.
addEventListener
(
"submit"
,
(
e
)
=>
submitForm
(
e
));
let
doctype
=
sessionStorage
.
getItem
(
'doctype'
);
let
section
=
sessionStorage
.
getItem
(
'section'
);
...
...
@@ -62,19 +63,24 @@ export async function generateFields(inputSchema, containerId){
container
.
textContent
=
error
container
.
style
.
color
=
'#ff3333'
}
const
sectionPromises
=
[];
for
(
let
sec
in
doctypes
)
{
let
underscoredSec
=
sec
.
replaceAll
(
" "
,
"_"
);
sessionStorage
.
setItem
(
"currentSection"
,
underscoredSec
);
createDocTypeDropdown
(
'DocType'
,
container
,
schema
);
createSection
(
'Section'
,
container
,
doctypes
,
underscoredKey
);
container
=
deconstruct
(
doctypes
[
sec
],
container
,
underscoredSec
)
const
submit
=
document
.
createElement
(
'input'
)
const
promise
=
deconstruct
(
doctypes
[
sec
],
container
,
underscoredSec
);
sectionPromises
.
push
(
promise
);
const
submit
=
document
.
createElement
(
'input'
);
submit
.
setAttribute
(
'id'
,
'submitButton'
);
submit
.
classList
.
add
(
"submitButtons"
);
submit
.
classList
.
add
(
underscoredSec
);
submit
.
type
=
'submit'
container
.
appendChild
(
submit
)
return
false
;
submit
.
type
=
'submit'
;
console
.
log
(
container
);
container
.
appendChild
(
submit
);
return
false
}
});
}
else
{
...
...
@@ -93,7 +99,7 @@ export async function generateFields(inputSchema, containerId){
sessionStorage
.
setItem
(
"currentSection"
,
underscoredSection
);
createDocTypeDropdown
(
'DocType'
,
container
,
schema
,
doctype
);
createSection
(
'Section'
,
container
,
doctypes
,
underscoredDoctype
,
section
);
container
=
deconstruct
(
doctypes
[
section
],
container
,
underscoredSection
)
container
=
await
deconstruct
(
doctypes
[
section
],
container
,
underscoredSection
)
const
submit
=
document
.
createElement
(
'input'
)
submit
.
classList
.
add
(
"submitButtons"
);
submit
.
classList
.
add
(
underscoredSection
);
...
...
@@ -112,7 +118,7 @@ export async function generateFields(inputSchema, containerId){
}
$
(
document
.
body
).
on
(
"change"
,
"#DocType"
,
function
()
{
$
(
document
.
body
).
on
(
"change"
,
"#DocType"
,
async
function
()
{
const
elements
=
document
.
getElementsByClassName
(
sessionStorage
.
getItem
(
"currentSection"
));
while
(
elements
.
length
>
0
)
{
elements
[
0
].
parentNode
.
removeChild
(
elements
[
0
]);
...
...
@@ -138,7 +144,7 @@ export async function generateFields(inputSchema, containerId){
let
underscoredKey
=
key
.
replaceAll
(
" "
,
"_"
);
sessionStorage
.
setItem
(
"currentSection"
,
underscoredKey
);
createSection
(
'Section'
,
container
,
doctypes
,
underscoredValue
);
container
=
deconstruct
(
doctypes
[
key
],
container
,
underscoredKey
)
container
=
await
deconstruct
(
doctypes
[
key
],
container
,
underscoredKey
)
const
submit
=
document
.
createElement
(
'input'
)
submit
.
classList
.
add
(
"submitButtons"
);
...
...
@@ -149,7 +155,7 @@ export async function generateFields(inputSchema, containerId){
}
});
$
(
document
.
body
).
on
(
"change"
,
"#Section"
,
function
()
{
$
(
document
.
body
).
on
(
"change"
,
"#Section"
,
async
function
()
{
const
elements
=
document
.
getElementsByClassName
(
sessionStorage
.
getItem
(
"currentSection"
));
while
(
elements
.
length
>
0
)
{
elements
[
0
].
parentNode
.
removeChild
(
elements
[
0
]);
...
...
@@ -158,7 +164,7 @@ export async function generateFields(inputSchema, containerId){
let
underscoredKey
=
this
.
value
.
replaceAll
(
" "
,
"_"
);
sessionStorage
.
setItem
(
"currentSection"
,
underscoredKey
);
container
=
deconstruct
(
schema
[
sessionStorage
.
getItem
(
"currentDoctype"
).
replaceAll
(
"_"
,
" "
)][
this
.
value
],
container
,
underscoredKey
)
container
=
await
deconstruct
(
schema
[
sessionStorage
.
getItem
(
"currentDoctype"
).
replaceAll
(
"_"
,
" "
)][
this
.
value
],
container
,
underscoredKey
)
const
submit
=
document
.
createElement
(
'input'
)
submit
.
classList
.
add
(
"submitButtons"
);
...
...
@@ -403,6 +409,53 @@ const inputDropdown = (key, validation) => {
}
}
const
inputDbLookup
=
async
(
key
,
validation
)
=>
{
try
{
const
{
mandatory
,
options
}
=
validation
;
const
input
=
document
.
createElement
(
'select'
);
input
.
setAttribute
(
'id'
,
`
${
key
}
`
);
input
.
setAttribute
(
'name'
,
`
${
key
}
`
);
input
.
classList
.
add
(
'dropdown-input'
);
input
.
addEventListener
(
'focusout'
,
handleInput
);
input
.
addEventListener
(
'keydown'
,
function
(
event
)
{
if
(
event
.
keyCode
==
9
)
{
event
.
preventDefault
();
var
elem
=
document
.
getElementsByClassName
(
'select2-search__field'
);
elem
.
focus
();
}
});
const
dbLookupTable
=
await
fetchOptionsDB
({
dbLookup
:
options
});
if
(
dbLookupTable
&&
dbLookupTable
.
length
>
0
)
{
const
newOption
=
document
.
createElement
(
'option'
);
newOption
.
text
=
'Choose an option'
;
newOption
.
value
=
null
;
input
.
add
(
newOption
);
for
(
const
option
of
dbLookupTable
)
{
const
newOption
=
document
.
createElement
(
'option'
);
newOption
.
text
=
option
;
newOption
.
value
=
option
;
input
.
add
(
newOption
);
}
}
else
{
const
newOption
=
document
.
createElement
(
'option'
);
newOption
.
text
=
'No option available'
;
newOption
.
value
=
null
;
input
.
add
(
newOption
);
input
.
setAttribute
(
'disabled'
,
'false'
);
}
return
input
;
}
catch
(
error
)
{
throw
error
;
}
};
/**
*
* @param {*} event
...
...
@@ -471,7 +524,7 @@ const handleDropdown = (event) => {
* @returns
* div with the deconsctructed section
*/
const
deconstruct
=
(
section
,
container
,
classAttribute
)
=>
{
const
deconstruct
=
async
(
section
,
container
,
classAttribute
)
=>
{
try
{
for
(
const
key
in
section
)
{
...
...
@@ -506,6 +559,7 @@ const deconstruct = (section, container, classAttribute) => {
let
input
switch
(
fieldLabel
&&
validation
&&
validation
.
collection
)
{
case
'textarea'
:
case
'alphanumeric'
:
case
'alphabet'
:
input
=
inputString
(
key
,
validation
)
...
...
@@ -521,6 +575,9 @@ const deconstruct = (section, container, classAttribute) => {
case
'datepicker'
:
input
=
inputDate
(
key
,
validation
)
break
case
'dblookup'
:
input
=
await
inputDbLookup
(
key
,
validation
)
break
default
:
input
=
noValidation
()
break
...
...
@@ -567,9 +624,11 @@ const deconstruct = (section, container, classAttribute) => {
// Initial execution of showHideElements to apply the initial state
showHideElements
(
section
);
// Replace "SECTION1" with the desired section key
//logic for show hide
if
(
selectElement
)
{
selectElement
.
addEventListener
(
"change"
,
function
()
{
showHideElements
(
section
);
});
}
return
container
}
catch
(
err
)
{
throw
err
...
...
@@ -802,3 +861,14 @@ export async function populateFields() {
sessionStorage
.
setItem
(
'fields'
,
JSON
.
stringify
(
fields
));
displayFields
(
"fields"
);
}
export
function
clearForm
()
{
// Check if the form element exists
const
formElement
=
document
.
getElementById
(
"fields"
);
if
(
formElement
)
{
// Clear the form by resetting its fields
formElement
.
reset
();
}
else
{
console
.
log
(
"Form element not found"
);
}
}
\ No newline at end of file
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
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"
)
...
...
@@ -43,6 +44,19 @@ public class GDEWebServices {
@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
)
@Produces
(
MediaType
.
APPLICATION_OCTET_STREAM
)
@Path
(
"/get-file"
)
public
Response
getFile
(
JsonObject
jsonObject
)
{
File
file
=
new
File
(
jsonObject
.
getString
(
"filePath"
).
trim
());
...
...
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