Commit 275b82d2 by Jorem Magcawas

change code of getting the encoded fields from the xml to form fields

parent 57713be7
...@@ -26,23 +26,7 @@ ...@@ -26,23 +26,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
......
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="WebGde-0.0.1-SNAPSHOT"> <wb-module deploy-name="WebGde-0.0.1-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/annotations"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<property name="java-output-path" value="/WebGde/build/classes"/> <property name="java-output-path" value="/WebGde/build/classes"/>
<property name="context-root" value="WebGde"/> <property name="context-root" value="WebGde"/>
</wb-module> </wb-module>
</project-modules> </project-modules>
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
// schema with 5 fields and all possible collections // schema with 5 fields and all possible collections
//const SCHEMA_FILE = "./src/sample_schema/5_field_schema.json" //const SCHEMA_FILE = "./src/sample_schema/5_field_schema.json"
var SCHEMA_FILE = "./src/sample_schema/HR Speed Test schema.json" /*var SCHEMA_FILE = "./src/sample_schema/SC Schema.json"*/
// const SCHEMA_FILE = "./src/sample_schema/Sample_Schema.json" var SCHEMA_FILE = "./src/sample_schema/HR Speed Test schema.json"
//const INPUT_FILES = ["./input/Ong, Mae Janica - Application Form.TIFF","./input/Magalona, Rowell James - Application Form.TIFF","./input/Felizardo, Brylle Theodure - Application Form.TIFF","./input/Laxamana, Conrad John - Application Form.TIFF"] // list of URLs //const INPUT_FILES = ["./input/Ong, Mae Janica - Application Form.TIFF","./input/Magalona, Rowell James - Application Form.TIFF","./input/Felizardo, Brylle Theodure - Application Form.TIFF","./input/Laxamana, Conrad John - Application Form.TIFF"] // list of URLs
......
...@@ -18,7 +18,7 @@ async function initGetElement() { ...@@ -18,7 +18,7 @@ async function initGetElement() {
let dir = await lst.data; let dir = await lst.data;
dir = [...dir]; dir = [...dir];
Dirfiles = dir.slice(dir.indexOf(lastImage) + 1); Dirfiles = dir;
sessionStorage.setItem("dir_files", JSON.stringify(Dirfiles)); sessionStorage.setItem("dir_files", JSON.stringify(Dirfiles));
sessionStorage.setItem("element_id", retElement.element.elementId); sessionStorage.setItem("element_id", retElement.element.elementId);
...@@ -183,8 +183,29 @@ async function getWaitingElement() { ...@@ -183,8 +183,29 @@ async function getWaitingElement() {
return json; return json;
} }
async function getFieldData(){
let elementId = sessionStorage.getItem("element_id");
let xmlData = {
"imageName": File_Path,
"outputDir": sessionStorage.getItem("element_file_loc") + "/" + (ENCODING_PASS == "PASS1" ? elementId + ".DTA" : elementId + ".DTB")
}
let response = await fetch(urlGetFields, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(xmlData)
});
let json = await response.json();
return json;
}
async function createOutputXml(fields, metrics, doctype, section) { async function createOutputXml(fields, metrics, doctype, section) {
let elementId = sessionStorage.getItem("element_id"); let elementId = sessionStorage.getItem("element_id");
let xmlData = { let xmlData = {
"projCode": PROJECT_CODE, "projCode": PROJECT_CODE,
"userId": sessionStorage.getItem("user_id"), "userId": sessionStorage.getItem("user_id"),
......
...@@ -3,4 +3,5 @@ let urlGetXml = GFS_URL + "/" + "get-xml"; ...@@ -3,4 +3,5 @@ let urlGetXml = GFS_URL + "/" + "get-xml";
let urlWriteXml = GFS_URL + "/" + "write-xml"; let urlWriteXml = GFS_URL + "/" + "write-xml";
let urlUpdateEob = GFS_URL + "/" + "update-eob"; let urlUpdateEob = GFS_URL + "/" + "update-eob";
let urlUpdateException = GFS_URL + "/" + "update-exception"; let urlUpdateException = GFS_URL + "/" + "update-exception";
let urlWriteMetrics = GFS_URL + "/" + "write-metrics"; let urlWriteMetrics = GFS_URL + "/" + "write-metrics";
\ No newline at end of file let urlGetFields = GFS_URL + "/" + "get-fields";
\ No newline at end of file
...@@ -3,20 +3,20 @@ let closerWindow; ...@@ -3,20 +3,20 @@ let closerWindow;
let endButton = document.getElementById("endBtn"); let endButton = document.getElementById("endBtn");
function checkForm(form){ function checkForm(form) {
var inputs = form.getElementsByTagName("input"); var inputs = form.getElementsByTagName("input");
var selects = form.getElementsByTagName("select"); var selects = form.getElementsByTagName("select");
inputsBlankCount = inputs.length; inputsBlankCount = inputs.length;
selectsBlankCount = selects.length - 2; selectsBlankCount = selects.length - 2;
for(var i=0; i<inputs.length; i++){ for (var i = 0; i < inputs.length; i++) {
if(inputs[i].value == "") inputsBlankCount--; if (inputs[i].value == "") inputsBlankCount--;
} }
for(var i=0; i<selects.length; i++){ for (var i = 0; i < selects.length; i++) {
if(selects[i].options[selects[i].selectedIndex].value === "null") selectsBlankCount--; if (selects[i].options[selects[i].selectedIndex].value === "null") selectsBlankCount--;
} }
if(inputsBlankCount==0 && selectsBlankCount==0) return true; if (inputsBlankCount == 0 && selectsBlankCount == 0) return true;
} }
/*endButton.addEventListener("click", function(){ /*endButton.addEventListener("click", function(){
...@@ -26,87 +26,86 @@ function checkForm(form){ ...@@ -26,87 +26,86 @@ function checkForm(form){
*/ */
function createEndSessionWindow(){ function createEndSessionWindow() {
let overlay = document.createElement("div"); let overlay = document.createElement("div");
overlay.classList.add("genericPopup"); overlay.classList.add("genericPopup");
let endWindow = document.createElement('div'); let endWindow = document.createElement('div');
endWindow.id = 'end_window'; endWindow.id = 'end_window';
endWindow.classList.add("parent_Window") endWindow.classList.add("parent_Window")
let endBodyDiv = document.createElement('div'); let endBodyDiv = document.createElement('div');
endBodyDiv.id = 'endBodyDiv'; endBodyDiv.id = 'endBodyDiv';
let endLabel = document.createElement('p'); let endLabel = document.createElement('p');
endLabel.innerText = "Session will end. Current Element will be Returned."; endLabel.innerText = "Session will end. Current Element will be Returned.";
let endContinue = document.createElement('p'); let endContinue = document.createElement('p');
endContinue.innerText = "Continue Y/N?"; endContinue.innerText = "Continue Y/N?";
let endOkCnclDiv = document.createElement('div'); let endOkCnclDiv = document.createElement('div');
endOkCnclDiv.id = 'endOkCnclCont'; endOkCnclDiv.id = 'endOkCnclCont';
let okEnd = document.createElement('button'); let okEnd = document.createElement('button');
okEnd.classList.add("emphasizeButton"); okEnd.classList.add("emphasizeButton");
okEnd.innerHTML = 'ok'; okEnd.innerHTML = 'ok';
okEnd.id = 'okEndButtn'; okEnd.id = 'okEndButtn';
okEnd.onclick = async function () { okEnd.onclick = async function() {
if(checkForm(form)){ if (checkForm(form)) {
var DBdeleteRequest = window.indexedDB.deleteDatabase("ImageDatabase"); var DBdeleteRequest = window.indexedDB.deleteDatabase("ImageDatabase");
DBdeleteRequest.addEventListener('blocked', function(e){ DBdeleteRequest.addEventListener('blocked', function(e) {
console.log("Database cleared."); console.log("Database cleared.");
}); });
DBdeleteRequest.addEventListener('upgradeneeded', function(e){ DBdeleteRequest.addEventListener('upgradeneeded', function(e) {
console.log("Upgrade needed in deleting database"); console.log("Upgrade needed in deleting database");
}); });
DBdeleteRequest.addEventListener('error', function(e){ DBdeleteRequest.addEventListener('error', function(e) {
console.log("Error in deleting database"); console.log("Error in deleting database");
}); });
DBdeleteRequest.addEventListener('success', function(e){ DBdeleteRequest.addEventListener('success', function(e) {
console.log("Database cleared."); console.log("Database cleared.");
}); });
let returnElem = await returnElementLogout(sessionStorage.getItem("element_id")); let returnElem = await returnElementLogout(sessionStorage.getItem("element_id"));
if( returnElem == 200){ if (returnElem == 200) {
returnSaveXML(); returnSaveXML();
endWindow.style.display = 'none'; endWindow.style.display = 'none';
localStorage.clear(); localStorage.clear();
sessionStorage.clear(); sessionStorage.clear();
logoutKeycloak(); logoutKeycloak();
submitted = false; submitted = false;
} }
} } else {
else{ alert("Fields are not empty. Submit or clear fields first.");
alert("Fields are not empty. Submit or clear fields first."); overlay.remove();
overlay.remove(); }
} endWindow.style.display = 'none';
endWindow.style.display = 'none'; }
}
let cancelEnd = document.createElement('button'); let cancelEnd = document.createElement('button');
cancelEnd.classList.add("normalButton"); cancelEnd.classList.add("normalButton");
cancelEnd.innerHTML = 'cancel'; cancelEnd.innerHTML = 'cancel';
cancelEnd.id = 'cnclEndButton'; cancelEnd.id = 'cnclEndButton';
endOkCnclDiv.appendChild(okEnd); endOkCnclDiv.appendChild(okEnd);
endOkCnclDiv.appendChild(cancelEnd); endOkCnclDiv.appendChild(cancelEnd);
endBodyDiv.appendChild(endLabel); endBodyDiv.appendChild(endLabel);
endBodyDiv.appendChild(endContinue); endBodyDiv.appendChild(endContinue);
endBodyDiv.appendChild(endOkCnclDiv); endBodyDiv.appendChild(endOkCnclDiv);
endWindow.appendChild(endBodyDiv); endWindow.appendChild(endBodyDiv);
cancelEnd.addEventListener("click", function () { cancelEnd.addEventListener("click", function() {
overlay.remove(); overlay.remove();
}); });
overlay.append(endWindow); overlay.append(endWindow);
document.body.append(overlay); document.body.append(overlay);
} }
\ No newline at end of file
...@@ -53,7 +53,8 @@ const displayFields = async (parentID) => { ...@@ -53,7 +53,8 @@ const displayFields = async (parentID) => {
if (doctype == null && section == null) { if (doctype == null && section == null) {
Object.keys(schema).every(function(key) { Object.keys(schema).every(function(key) {
let doctypes = schema[key]; let doctypes = schema[key];
sessionStorage.setItem("currentDoctype", key); let underscoredKey = key.replaceAll(" ", "_");
sessionStorage.setItem("currentDoctype", underscoredKey);
const { const {
valid, valid,
error error
...@@ -62,17 +63,24 @@ const displayFields = async (parentID) => { ...@@ -62,17 +63,24 @@ const displayFields = async (parentID) => {
div.textContent = error div.textContent = error
div.style.color = '#ff3333' div.style.color = '#ff3333'
} }
for (let key in doctypes) { for (let sec in doctypes) {
sessionStorage.setItem("currentSection", key); let underscoredSec = sec.replaceAll(" ", "_");
sessionStorage.setItem("currentSection", underscoredSec);
createDocTypeDropdown('DocType', div, schema); createDocTypeDropdown('DocType', div, schema);
createSection('Section', div, doctypes, key); createSection('Section', div, doctypes, underscoredKey);
div = deconstruct(doctypes[key], div, key) div = deconstruct(doctypes[sec], div, underscoredSec)
const submit = document.createElement('input')
submit.classList.add("submitButtons");
submit.classList.add(underscoredSec);
submit.type = 'submit'
div.appendChild(submit)
return false; return false;
} }
}); });
} else { } else {
let doctypes = schema[doctype]; let doctypes = schema[doctype];
sessionStorage.setItem("currentDoctype", doctype); let underscoredDoctype = doctype.replaceAll(" ", "_");
sessionStorage.setItem("currentDoctype", underscoredDoctype);
const { const {
valid, valid,
error error
...@@ -81,12 +89,72 @@ const displayFields = async (parentID) => { ...@@ -81,12 +89,72 @@ const displayFields = async (parentID) => {
div.textContent = error div.textContent = error
div.style.color = '#ff3333' div.style.color = '#ff3333'
} }
sessionStorage.setItem("currentSection", section); let underscoredSection = section.replaceAll(" ", "_");
sessionStorage.setItem("currentSection", underscoredSection);
createDocTypeDropdown('DocType', div, schema); createDocTypeDropdown('DocType', div, schema);
createSection('Section', div, doctypes, section); createSection('Section', div, doctypes, underscoredDoctype);
div = deconstruct(doctypes[section], div, section) div = deconstruct(doctypes[section], div, underscoredSection)
const submit = document.createElement('input')
submit.classList.add("submitButtons");
submit.classList.add(underscoredSection);
submit.type = 'submit'
div.appendChild(submit)
} }
$(document.body).on("change","#DocType",function(){
const elements = document.getElementsByClassName(sessionStorage.getItem("currentSection"));
while(elements.length > 0){
elements[0].parentNode.removeChild(elements[0]);
}
const secElements = document.getElementsByClassName(sessionStorage.getItem("currentDoctype"));
while(secElements.length > 0){
secElements[0].parentNode.removeChild(secElements[0]);
}
let doctypes = schema[this.value];
let underscoredValue = this.value.replaceAll(" ","_");
sessionStorage.setItem("currentDoctype", underscoredValue);
const { valid, error } = validateSchema()
if(!valid){
div.textContent = error
div.style.color = '#ff3333'
}
for (let key in doctypes) {
let underscoredKey = key.replaceAll(" ", "_");
sessionStorage.setItem("currentSection", underscoredKey);
createSection('Section', div, doctypes, underscoredValue);
div = deconstruct(doctypes[key], div, underscoredKey)
const submit = document.createElement('input')
submit.classList.add("submitButtons");
submit.classList.add(underscoredKey);
submit.type = 'submit'
div.appendChild(submit)
break;
}
});
$(document.body).on("change","#Section",function(){
const elements = document.getElementsByClassName(sessionStorage.getItem("currentSection"));
while(elements.length > 0){
elements[0].parentNode.removeChild(elements[0]);
}
let underscoredKey = this.value.replaceAll(" ", "_");
sessionStorage.setItem("currentSection", underscoredKey);
div = deconstruct(schema[sessionStorage.getItem("currentDoctype").replaceAll("_", " ")][this.value], div, underscoredKey)
const submit = document.createElement('input')
submit.classList.add("submitButtons");
submit.classList.add(underscoredKey);
submit.type = 'submit'
div.appendChild(submit)
});
/* const { ACCOUNTING_DOCUMENTS } = schema /* const { ACCOUNTING_DOCUMENTS } = schema
//getDocType = DOC_TYPE1 ; //getDocType = DOC_TYPE1 ;
...@@ -104,13 +172,13 @@ const displayFields = async (parentID) => { ...@@ -104,13 +172,13 @@ const displayFields = async (parentID) => {
const { HR_FILES } = schema const { HR_FILES } = schema
const { SECTION3 } = HR_FILES const { SECTION3 } = HR_FILES
div = deconstruct(SECTION3, div, 'SECTION3')*/ div = deconstruct(SECTION3, div, 'SECTION3')
const submit = document.createElement('input') const submit = document.createElement('input')
submit.classList.add("submitButtons"); submit.classList.add("submitButtons");
submit.type = 'submit' submit.type = 'submit'
div.appendChild(submit) div.appendChild(submit)*/
// add handler event handler for dropdown // add handler event handler for dropdown
// separate handler is used to fit with the library used 'select2' // separate handler is used to fit with the library used 'select2'
...@@ -679,7 +747,7 @@ function saveForm(index){ ...@@ -679,7 +747,7 @@ function saveForm(index){
}); });
index--; index--;
var formArray = JSON.parse(sessionStorage.getItem('formArray')); /* var formArray = JSON.parse(sessionStorage.getItem('formArray'));
//formArray.push(formValues); //formArray.push(formValues);
if(typeof formArray[index] !== 'undefined') { if(typeof formArray[index] !== 'undefined') {
formArray.splice(index, 1, values) formArray.splice(index, 1, values)
...@@ -687,7 +755,7 @@ function saveForm(index){ ...@@ -687,7 +755,7 @@ function saveForm(index){
formArray.splice(index, 0, values) formArray.splice(index, 0, values)
} }
sessionStorage.setItem('formArray', JSON.stringify(formArray)); sessionStorage.setItem('formArray', JSON.stringify(formArray));*/
} }
function populateForm(index){ function populateForm(index){
...@@ -705,7 +773,45 @@ function populateForm(index){ ...@@ -705,7 +773,45 @@ function populateForm(index){
document.getElementById(field).value = currForm[field]; document.getElementById(field).value = currForm[field];
} }
} }
}
async function populateFields(){
var data = [];
data.push(await getFieldData());
sessionStorage.setItem('formArray', JSON.stringify(data));
var formArray = JSON.parse(sessionStorage.getItem('formArray'));
var doctype = formArray[0].DocType;
var section = formArray[0].Section;
if (formArray[0] != null) {
} var currForm = formArray[0];
\ No newline at end of file
for (let field in currForm) {
//document.getElementById(field).value = currForm[field];
if(field == "DocType"){
const mySelect = document.getElementById(field);
const selectedOption = mySelect.options[mySelect.selectedIndex];
selectedOption.value = doctype;
}
if(field == "Section"){
const mySelect = document.getElementById(field);
const selectedOption = mySelect.options[mySelect.selectedIndex];
selectedOption.value = section;
}
if(field == "fields"){
let fieldsobj = currForm[field];
for (let [k,v] of Object.entries(fieldsobj)) {
for(let key of Object.keys(schema[doctype][section])) {
if(schema[doctype][section][key].aka == "field"+k) {
var fieldId = schema[doctype][section][key].fieldLabel;
var currId = fieldId.replace(" ", "_")
document.getElementById(currId).value = v;
}
}
}
}
}
}
}
...@@ -3,7 +3,6 @@ const init = () => { ...@@ -3,7 +3,6 @@ const init = () => {
displayFields("fields"); displayFields("fields");
accessFile(); accessFile();
window.onkeydown = (key) => { window.onkeydown = (key) => {
if (!started_flag) { if (!started_flag) {
if (searchStringInArray(`${key.key}`, keyArray) == true || key.ctrlKey && key.key) { if (searchStringInArray(`${key.key}`, keyArray) == true || key.ctrlKey && key.key) {
...@@ -23,7 +22,7 @@ const refresh = () => { ...@@ -23,7 +22,7 @@ const refresh = () => {
let started_flag = false; let started_flag = false;
displayFields("fields"); displayFields("fields");
refreshImage(); refreshImage();
window.onkeydown = (key) => { window.onkeydown = (key) => {
if (!started_flag) { if (!started_flag) {
......
{ {
"ACCOUNTING_DOCUMENTS": "ACCOUNTING DOCUMENTS":
{ {
"SECTION1": "SECTION1":
{ {
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
} }
}, },
"BANK_APPLICATION_FORMS": "BANK APPLICATION FORMS":
{ {
"SECTION2": "SECTION2":
{ {
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
} }
}, },
"HR_FILES": "HR FILES":
{ {
"SECTION3": "SECTION3":
{ {
......
...@@ -78,8 +78,8 @@ const submitForm = (e) => { ...@@ -78,8 +78,8 @@ const submitForm = (e) => {
}); });
document.getElementById("counter").innerHTML = ""; document.getElementById("counter").innerHTML = "";
clearTimeout(interval); clearTimeout(interval);
sessionStorage.removeItem("section"); /* sessionStorage.removeItem("section");
sessionStorage.removeItem("doctype"); sessionStorage.removeItem("doctype");*/
isCanvasNotCreated = true; isCanvasNotCreated = true;
if(IS_RETRIEVE_FROM_GFS != "Y"){ if(IS_RETRIEVE_FROM_GFS != "Y"){
......
...@@ -66,7 +66,7 @@ const validateInput = (fieldID, value) => { ...@@ -66,7 +66,7 @@ const validateInput = (fieldID, value) => {
const getValidation = (fieldID) => { const getValidation = (fieldID) => {
// const { SECTION } = schema // const { SECTION } = schema
let section = schema[sessionStorage.getItem("currentDoctype")][sessionStorage.getItem("currentSection")]; let section = schema[sessionStorage.getItem("currentDoctype").replaceAll("_"," ")][sessionStorage.getItem("currentSection").replaceAll("_"," ")];
try{ try{
if (Object.keys(section).includes(fieldID)) return section[fieldID].validation; if (Object.keys(section).includes(fieldID)) return section[fieldID].validation;
......
const validateSchema = () => { const validateSchema = () => {
const validate = schema[sessionStorage.getItem("currentDoctype")] const validate = schema[sessionStorage.getItem("currentDoctype").replaceAll("_"," ")]
if(!validate) return { valid: false, error: 'SECTION is missing!' } if(!validate) return { valid: false, error: 'SECTION is missing!' }
return { valid: true } return { valid: true }
......
...@@ -14,15 +14,16 @@ html { ...@@ -14,15 +14,16 @@ html {
} }
#prompt{ #prompt{
background-color:white; background-color: white;
height: 10%; height: 10%;
position: absolute; position: absolute;
display: block; display: block;
margin: auto; margin: auto;
width: 42%; width: 42%;
top: 47%; top: 47%;
left: 31%; left: 31%;
text-align: center; text-align: center;
padding: 30px;
} }
/* The actual popup */ /* The actual popup */
...@@ -919,6 +920,8 @@ input[type=text] { ...@@ -919,6 +920,8 @@ input[type=text] {
select { select {
width: 100%; width: 100%;
height: 28px;
color: #444;
} }
#fields *:not([type=submit]):focus { #fields *:not([type=submit]):focus {
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<artifactId>json-simple</artifactId> <artifactId>json-simple</artifactId>
<version>1.1.1</version> <version>1.1.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
......
...@@ -228,6 +228,19 @@ public class GDEWebServices { ...@@ -228,6 +228,19 @@ public class GDEWebServices {
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/get-fields")
public Response getFields(XMLContents xml) {
try {
return Response.ok(XMLUtil.getFields(xml)).build();
} catch (Exception e) {
return Response.status(500).entity("Fail").build();
}
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/update-exception") @Path("/update-exception")
public Response updateException(XMLContents xml) { public Response updateException(XMLContents xml) {
......
...@@ -33,6 +33,7 @@ import com.svi.webgde.restservice.object.Field; ...@@ -33,6 +33,7 @@ import com.svi.webgde.restservice.object.Field;
import com.svi.webgde.restservice.object.Header; import com.svi.webgde.restservice.object.Header;
import com.svi.webgde.restservice.object.OutputXML; import com.svi.webgde.restservice.object.OutputXML;
import com.svi.webgde.restservice.object.Record; import com.svi.webgde.restservice.object.Record;
import com.svi.webgde.restservice.object.SubRecord;
import com.svi.webgde.restservice.object.XMLContents; import com.svi.webgde.restservice.object.XMLContents;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.io.xml.DomDriver;
...@@ -282,4 +283,47 @@ public class XMLUtil { ...@@ -282,4 +283,47 @@ public class XMLUtil {
} }
public static Map<String, Object> getFields(XMLContents xml)
throws ParserConfigurationException, SAXException, IOException {
Map<String, Object> records = new HashMap<>();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xml.getOutputDir());
Map<String, Integer> imagenames = new HashMap<>();
for (int i = 0; i < document.getElementsByTagName("imagename").getLength(); i++) {
imagenames.put(document.getElementsByTagName("imagename").item(i).getTextContent(), i);
}
if (imagenames.containsKey(xml.getImageName())) {
Node imagename = document.getElementsByTagName("imagename").item(imagenames.get(xml.getImageName()));
Node xmlSubRecord = imagename.getParentNode().getLastChild().getPreviousSibling();
Map<String, String> fields = new HashMap<>();
records.put("DocType", imagename.getParentNode().getFirstChild().getNextSibling().getNextSibling()
.getNextSibling().getTextContent());
records.put("Section", imagename.getParentNode().getFirstChild().getNextSibling().getNextSibling()
.getNextSibling().getNextSibling().getNextSibling().getTextContent());
records.put("fields", fields);
for (int i = 0; i < xmlSubRecord.getChildNodes().getLength(); i++) {
if (xmlSubRecord.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE) {
for (int j = 0; j < xmlSubRecord.getChildNodes().item(i).getChildNodes().getLength(); j++) {
if (xmlSubRecord.getChildNodes().item(i).getChildNodes().item(j)
.getNodeType() == Node.ELEMENT_NODE) {
fields.put(
xmlSubRecord.getChildNodes().item(i).getAttributes().getNamedItem("no")
.getNodeValue(),
xmlSubRecord.getChildNodes().item(i).getChildNodes().item(j).getTextContent());
records.put("fields", fields);
}
}
}
}
}
return records;
}
} }
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