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
a7b591e6
Commit
a7b591e6
authored
Nov 14, 2023
by
Owen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify xml generation, added ordering. fixed general apperance of xml.
parent
574e5618
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
195 additions
and
45 deletions
+195
-45
generateFields.js
...bContent/WebGde-Widgets/DataInputWidget/generateFields.js
+62
-20
validateInput.js
...ebContent/WebGde-Widgets/DataInputWidget/validateInput.js
+17
-2
XML_Saver.js
...e/WebContent/WebGde-Widgets/Submit/XMLWriter/XML_Saver.js
+33
-9
config.js
WebGde/WebContent/WebGde-Widgets/Submit/config.js
+2
-1
Navotas 2.json
...de/WebContent/WebGde-Widgets/sample_schema/Navotas 2.json
+6
-6
Field.java
...rc/main/java/com/svi/webgde/restservice/object/Field.java
+4
-0
Record.java
...c/main/java/com/svi/webgde/restservice/object/Record.java
+4
-0
SubRecord.java
...ain/java/com/svi/webgde/restservice/object/SubRecord.java
+35
-0
XMLContents.java
...n/java/com/svi/webgde/restservice/object/XMLContents.java
+12
-1
XMLUtil.java
...c/main/java/com/svi/webgde/restservice/utils/XMLUtil.java
+20
-6
No files found.
WebGde/WebContent/WebGde-Widgets/DataInputWidget/generateFields.js
View file @
a7b591e6
...
...
@@ -15,6 +15,7 @@ let newOption;
export
let
schema
;
export
async
function
generateFields
(
inputSchema
,
containerId
)
{
window
.
populateFields
=
populateFields
;
schema
=
inputSchema
;
let
divContainer
=
document
.
getElementById
(
containerId
);
...
...
@@ -197,10 +198,8 @@ export async function generateFields(inputSchema, containerId) {
$
(
document
).
ready
(
function
()
{
$
(
'form:first *:input[type!=hidden]:first'
).
focus
();
// Run code
});
}
}
...
...
@@ -242,6 +241,32 @@ const noValidation = (key) => {
* @returns
* created input field element
*/
const
inputHidden
=
(
key
,
validation
)
=>
{
try
{
const
input
=
document
.
createElement
(
'textarea'
);
input
.
setAttribute
(
'rows'
,
5
);
input
.
setAttribute
(
'id'
,
key
);
input
.
setAttribute
(
'name'
,
key
);
input
.
setAttribute
(
'cols'
,
30
);
input
.
setAttribute
(
'autocomplete'
,
'off'
);
input
.
setAttribute
(
'inputMode'
,
validation
.
collection
===
'email'
?
'email'
:
'text'
);
input
.
addEventListener
(
'focusout'
,
handleInput
);
return
input
;
}
catch
(
err
)
{
throw
err
;
}
}
/**
*
* @param {*} key
* will serve as id of input field
* @param {*} validation
* validation of field from schema
* @returns
* created input field element
*/
const
inputString
=
(
key
,
validation
)
=>
{
try
{
const
{
...
...
@@ -1829,21 +1854,37 @@ const deconstruct = async (section, container, classAttribute) => {
fieldLabel, hidden
} = section[key]
// Create hidden input for fields with hidden="y"
// if (hidden && hidden.toLowerCase() === "y") {
// const hiddenInput = document.createElement('
input
');
// hiddenInput.setAttribute('
type
', '
hidden
');
// hiddenInput.setAttribute('
name
', key);
// hiddenInput.setAttribute('
value
', ''); // Set the value as needed
const validation = getValidation(key, schema)
// // Append the hidden input to the container
// container.appendChild(hiddenInput);
if (hidden) {
const hiddenField = document.createElement('
div
') // will contain input field and label
hiddenField.setAttribute('
class
', '
fieldContainer
' + classAttribute)
container.appendChild(hiddenField)
// // Skip creating other visible input elements for hidden fields
// continue;
// }
const labelContainer = document.createElement('
div
') // name beside input field
labelContainer.setAttribute('
class
', '
labelContainer
' + classAttribute)
hiddenField.appendChild(labelContainer)
const validation = getValidation(key, schema)
const label = document.createElement('
label
')
label.textContent = fieldLabel ? fieldLabel : `Missing label`
label.style.color = fieldLabel ? '
#
000000
' : '
#
ff3333
'
labelContainer.appendChild(label)
const inputContainer = document.createElement('
div
') // input field
inputContainer.setAttribute('
class
', '
inputContainer
' + classAttribute)
hiddenField.appendChild(inputContainer)
// default hiddeninputs to String
const hiddenInput = inputHidden(key, schema);
hiddenInput.setAttribute('
class
', classAttribute)
inputContainer.appendChild(hiddenInput);
hiddenField.style.display = '
none
'; // Hide the input
hiddenField.classList.add('
hidden
'); // Add '
hidden
' class
continue;
}
const newField = document.createElement('
div
') // will contain input field and label
newField.setAttribute('
class
', '
fieldContainer
' + classAttribute)
...
...
@@ -1924,10 +1965,6 @@ const deconstruct = async (section, container, classAttribute) => {
}
input.setAttribute('
class
', classAttribute)
inputContainer.appendChild(input)
if (hidden && hidden !== undefined) {
newField.style.display = '
none
'; // Hide the input
newField.classList.add('
hidden
'); // Add '
hidden
' class
}
}
//keys na drop down
...
...
@@ -2226,10 +2263,15 @@ export async function populateFields() {
for (let key of Object.keys(schema[doctype][section])) {
if (schema[doctype][section][key].aka == "field" + k) {
//console.log("key = " + key
);
console.log("key = " + key + +", value ="+v
);
//console.log("validation: " + schema[doctype][section][key].validation.collection);
fields["field" + k] = v;
if (schema[doctype][section][key].hidden){
document.getElementById(key).value = v;
continue;
}
if(schema[doctype][section][key].validation.collection === '
radiolist
'){
//retrieve the radio button value from the XML
...
...
WebGde/WebContent/WebGde-Widgets/DataInputWidget/validateInput.js
View file @
a7b591e6
...
...
@@ -22,6 +22,10 @@ export const validateInput = (fieldID, value) => {
if
(
!
validation
)
return
{
valid
:
false
,
error
:
[
`FieldName: '
${
fieldID
}
' not in schema`
]
}
// Skip validation for hidden fields
if
(
isFieldHidden
(
fieldID
)){
return
{
valid
:
true
};
}
switch
(
validation
.
collection
)
{
case
'email'
:
return
validateEmail
(
validation
,
value
)
...
...
@@ -429,4 +433,15 @@ export const checkValidValues = (fieldID, value) => {
}
catch
(
err
)
{
return
{
isValidValue
:
false
,
errMsg
:
[
err
]}
}
}
\ No newline at end of file
}
function
isFieldHidden
(
key
)
{
for
(
const
docType
in
schema
)
{
for
(
const
section
in
schema
[
docType
])
{
if
(
schema
[
docType
][
section
][
key
]
&&
schema
[
docType
][
section
][
key
].
hidden
)
{
return
true
;
}
}
}
return
false
;
}
\ No newline at end of file
WebGde/WebContent/WebGde-Widgets/Submit/XMLWriter/XML_Saver.js
View file @
a7b591e6
...
...
@@ -15,7 +15,7 @@ export async function WriteForm(e,metrics,doctype,section) {
// localStorage.setItem("submit", "1");
let
fields
=
{};
for
(
var
i
=
0
;
i
<
Nodes
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
Nodes
.
length
;
i
++
)
{
if
(
Nodes
[
i
].
style
.
display
===
'none'
&&
!
Nodes
[
i
].
classList
.
contains
(
'hidden'
))
continue
let
fid
=
Nodes
[
i
].
id
;
if
(
fid
==
'DocType'
||
fid
==
'Section'
||
fid
==
''
||
fid
==
"submitButton"
)
continue
...
...
@@ -73,8 +73,11 @@ export async function WriteForm(e,metrics,doctype,section) {
}
fields
[
Object
.
keys
(
lookup
[
fid
]).
includes
(
'aka'
)
?
lookup
[
fid
].
aka
.
replace
(
"field"
,
""
)
:
fid
]
=
Nodes
[
i
].
value
;
}
let
fieldOrder
=
extractAkaValues
(
schema
,
doctype
,
section
);
console
.
log
(
fieldOrder
);
let
response
=
await
createOutputXml
(
fields
,
myArray
,
doctype
,
section
);
let
response
=
await
createOutputXml
(
fields
,
myArray
,
doctype
,
section
,
fieldOrder
);
return
response
;
}
catch
(
Err
)
{
...
...
@@ -83,17 +86,36 @@ export async function WriteForm(e,metrics,doctype,section) {
return
false
;
}
async
function
createOutputXml
(
fields
,
metrics
,
doctype
,
section
)
{
function
extractAkaValues
(
json
,
doctype
,
section
)
{
const
akaValues
=
[];
function
recursiveExtract
(
obj
)
{
for
(
const
key
in
obj
)
{
if
(
typeof
obj
[
key
]
===
'object'
)
{
recursiveExtract
(
obj
[
key
]);
}
else
if
(
key
===
'aka'
)
{
akaValues
.
push
(
obj
[
key
].
replace
(
'field'
,
''
));
}
}
}
recursiveExtract
(
json
[
doctype
][
section
]);
return
akaValues
.
join
(
'|'
);
}
async
function
createOutputXml
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
)
{
let
response
=
null
;
if
(
IS_RETRIEVE_FROM_BPO
==
"Y"
)
{
response
=
await
createBPOXML
(
fields
,
metrics
,
doctype
,
section
);
response
=
await
createBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
);
}
else
{
response
=
await
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
);
response
=
await
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
);
}
return
response
;
}
async
function
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
){
async
function
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
){
console
.
log
(
fields
);
let
fileExt
=
""
;
switch
(
ENCODING_PASS
){
case
"PASS1"
:
...
...
@@ -137,7 +159,8 @@ async function createNonBPOXML(fields, metrics, doctype, section){
"fields"
:
fields
,
"outputDir"
:
TEMPORARY_FOLDER
+
"/"
+
fileNameOnly
+
"/"
+
fileName
,
"doctype"
:
doctype
,
"section"
:
section
"section"
:
section
,
"fieldOrder"
:
fieldOrder
}
let
response
=
await
fetch
(
urlWriteXml
,
{
...
...
@@ -151,7 +174,7 @@ async function createNonBPOXML(fields, metrics, doctype, section){
return
response
;
}
async
function
createBPOXML
(
fields
,
metrics
,
doctype
,
section
){
async
function
createBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
){
let
elementId
=
sessionStorage
.
getItem
(
"element_id"
);
let
filePaths
=
JSON
.
parse
(
sessionStorage
.
getItem
(
"dir_files"
));
...
...
@@ -176,7 +199,8 @@ async function createBPOXML(fields, metrics, doctype, section){
"fields"
:
fields
,
"outputDir"
:
sessionStorage
.
getItem
(
"element_file_loc"
)
+
"/"
+
(
ENCODING_PASS
==
"PASS1"
?
elementId
+
".DTA"
:
elementId
+
".DTB"
),
"doctype"
:
doctype
,
"section"
:
section
"section"
:
section
,
"fieldOrder"
:
fieldOrder
}
let
response
=
await
fetch
(
urlWriteXml
,
{
...
...
WebGde/WebContent/WebGde-Widgets/Submit/config.js
View file @
a7b591e6
...
...
@@ -2,5 +2,5 @@ export const PROJECT_CODE = "PROJCODE01";
export
const
ENCODING_PASS
=
"PASS1"
;
export
const
GFS_URL
=
"http://107.20.193.188/gfs-explorer-ws/svc/gfs-rest/"
;
export
const
TEMPORARY_FOLDER
=
"
C:/Users/oang/Desktop/Mobile GDE/
Elements"
;
export
const
TEMPORARY_FOLDER
=
"
E:/Coding/Mobile GDE
Elements"
;
export
const
GFS_ROOT_FOLDER
=
"/Users"
;
\ No newline at end of file
WebGde/WebContent/WebGde-Widgets/sample_schema/Navotas 2.json
View file @
a7b591e6
...
...
@@ -2001,9 +2001,9 @@
"mandatory"
:
true
}
},
"ver_question
3
"
:
{
"fieldLabel"
:
"Verification Question
3
"
,
"aka"
:
"field17
2
"
,
"ver_question
4
"
:
{
"fieldLabel"
:
"Verification Question
4
"
,
"aka"
:
"field17
3
"
,
"validation"
:
{
"fieldLength"
:
3.0
,
"collection"
:
"radiolist"
,
...
...
@@ -2011,9 +2011,9 @@
"mandatory"
:
true
}
},
"ver_question
4
"
:
{
"fieldLabel"
:
"Verification Question
4
"
,
"aka"
:
"field17
3
"
,
"ver_question
3
"
:
{
"fieldLabel"
:
"Verification Question
3
"
,
"aka"
:
"field17
2
"
,
"validation"
:
{
"fieldLength"
:
3.0
,
"collection"
:
"radiolist"
,
...
...
WebGde/src/main/java/com/svi/webgde/restservice/object/Field.java
View file @
a7b591e6
...
...
@@ -24,4 +24,8 @@ public class Field {
this
.
no
=
no
;
this
.
value
=
value
;
}
public
String
getNo
()
{
return
this
.
no
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/object/Record.java
View file @
a7b591e6
...
...
@@ -36,4 +36,8 @@ public class Record {
this
.
section
=
xml
.
getSection
();
this
.
subRecord
=
new
SubRecord
(
xml
);
}
public
SubRecord
getSubRecord
()
{
return
this
.
subRecord
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/object/SubRecord.java
View file @
a7b591e6
package
com
.
svi
.
webgde
.
restservice
.
object
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
com.svi.webgde.restservice.utils.XMLUtil
;
import
com.thoughtworks.xstream.annotations.XStreamAlias
;
...
...
@@ -31,4 +33,37 @@ public class SubRecord {
this
.
eor
=
xml
.
getEor
();
this
.
fields
=
XMLUtil
.
generateFields
(
xml
);
}
/**
* Arrange the contents of the fields list based on the order specified in the pipe-delimited string.
*
* @param orderPipeDelimited Pipe-delimited string specifying the order.
*/
public
void
arrangeFields
(
String
orderPipeDelimited
)
{
List
<
Field
>
sortedFields
=
fields
.
stream
()
.
sorted
(
Comparator
.
comparingInt
(
f
->
getOrder
(
f
.
getNo
(),
orderPipeDelimited
)))
.
collect
(
Collectors
.
toList
());
// Update the fields list with the sorted order
fields
.
clear
();
fields
.
addAll
(
sortedFields
);
}
/**
* Helper method to get the order of a field based on the pipe-delimited string.
*
* @param fieldNo The field number to get the order for.
* @param orderPipeDelimited The pipe-delimited string specifying the order.
* @return The order of the field.
*/
private
int
getOrder
(
String
fieldNo
,
String
orderPipeDelimited
)
{
String
[]
orderArray
=
orderPipeDelimited
.
split
(
"\\|"
);
for
(
int
i
=
0
;
i
<
orderArray
.
length
;
i
++)
{
if
(
orderArray
[
i
].
equals
(
fieldNo
))
{
return
i
;
}
}
// Default to a high value if not found (end of the list)
return
orderArray
.
length
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/object/XMLContents.java
View file @
a7b591e6
package
com
.
svi
.
webgde
.
restservice
.
object
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
class
XMLContents
{
...
...
@@ -21,10 +22,19 @@ public class XMLContents {
private
String
imageName
;
private
int
subRecordNo
;
private
String
eor
;
private
Map
<
String
,
String
>
fields
;
private
Map
<
String
,
String
>
fields
=
new
LinkedHashMap
<>();
;
private
String
outputDir
;
private
String
doctype
;
private
String
section
;
private
String
fieldOrder
;
public
String
getFieldOrder
()
{
return
fieldOrder
;
}
public
void
setFieldOrder
(
String
fieldOrder
)
{
this
.
fieldOrder
=
fieldOrder
;
}
public
String
getProjCode
()
{
return
projCode
;
...
...
@@ -193,4 +203,5 @@ public class XMLContents {
public
void
setSection
(
String
section
)
{
this
.
section
=
section
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/utils/XMLUtil.java
View file @
a7b591e6
...
...
@@ -20,7 +20,10 @@ import javax.xml.transform.TransformerException;
import
javax.xml.transform.TransformerFactory
;
import
javax.xml.transform.dom.DOMSource
;
import
javax.xml.transform.stream.StreamResult
;
import
javax.xml.xpath.XPath
;
import
javax.xml.xpath.XPathConstants
;
import
javax.xml.xpath.XPathExpressionException
;
import
javax.xml.xpath.XPathFactory
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
...
...
@@ -67,29 +70,40 @@ public class XMLUtil {
*/
public
static
String
generateXML
(
XMLContents
xml
)
throws
TransformerException
,
ParserConfigurationException
,
SAXException
,
IOException
,
XPathExpressionException
{
XStream
xs
=
new
XStream
(
new
DomDriver
(
"
ISO-8859-1
"
,
new
XmlFriendlyNameCoder
(
"_-"
,
"_"
)));
XStream
xs
=
new
XStream
(
new
DomDriver
(
"
UTF-8
"
,
new
XmlFriendlyNameCoder
(
"_-"
,
"_"
)));
xs
.
alias
(
xml
.
getProjCode
(),
OutputXML
.
class
);
xs
.
processAnnotations
(
Record
.
class
);
Header
header
=
new
Header
(
xml
);
Record
record
=
new
Record
(
xml
);
record
.
getSubRecord
().
arrangeFields
(
xml
.
getFieldOrder
());
OutputXML
output
=
new
OutputXML
(
header
,
record
);
//
SAXParserFactory spf = SAXParserFactory.newInstance();
//
SAXParser sp = spf.newSAXParser();
//
Source source = new SAXSource(sp.getXMLReader(),
//
new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[ ](?![^\\W_])", " "))));
//
SAXParserFactory spf = SAXParserFactory.newInstance();
//
SAXParser sp = spf.newSAXParser();
//
Source source = new SAXSource(sp.getXMLReader(),
//
new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[ ](?![^\\W_])", " "))));
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
Document
document
=
builder
.
parse
(
new
InputSource
(
new
StringReader
(
xs
.
toXML
(
output
).
replaceAll
(
"(?<![^\\W_])[ ](?![^\\W_])"
,
" "
))));
// Generate list of all empty Nodes, them remove them
XPath
xp
=
XPathFactory
.
newInstance
().
newXPath
();
NodeList
nl
=
(
NodeList
)
xp
.
evaluate
(
"//text()[normalize-space(.)='']"
,
document
,
XPathConstants
.
NODESET
);
for
(
int
i
=
0
;
i
<
nl
.
getLength
();
++
i
)
{
// note the position of the '++'
Node
node
=
nl
.
item
(
i
);
node
.
getParentNode
().
removeChild
(
node
);
}
DOMSource
source
=
new
DOMSource
(
document
);
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
Transformer
transformer
=
transformerFactory
.
newTransformer
();
transformer
.
setOutputProperty
(
OutputKeys
.
ENCODING
,
"
ISO-8859-1
"
);
transformer
.
setOutputProperty
(
OutputKeys
.
ENCODING
,
"
UTF-8
"
);
transformer
.
setOutputProperty
(
OutputKeys
.
INDENT
,
"yes"
);
transformer
.
setOutputProperty
(
OutputKeys
.
STANDALONE
,
"no"
);
transformer
.
setOutputProperty
(
"{http://xml.apache.org/xslt}indent-amount"
,
"4"
);
...
...
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