Commit d6bd16cc by Jorem Magcawas

Merge branch 'feature-merge-branch' into 'feature-UI_construction'

# Conflicts: # WebGde/WebContent/src/tiffViewer/tiffViewer.js # WebGde/WebContent/style.css
parents 3af64547 8f42e223
...@@ -26,7 +26,23 @@ ...@@ -26,7 +26,23 @@
<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"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> </attributes>
</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"/>
......
...@@ -34,4 +34,15 @@ ...@@ -34,4 +34,15 @@
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures> </natures>
<filteredResources>
<filter>
<id>1675315043043</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription> </projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
...@@ -7,5 +7,6 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled ...@@ -7,5 +7,6 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8
<?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="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/annotations"/>
<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>
...@@ -10,7 +10,45 @@ async function rejectElement() { ...@@ -10,7 +10,45 @@ async function rejectElement() {
}, },
body: JSON.stringify(load) body: JSON.stringify(load)
}); });
if (response.status == 200) { if (response.status == 200) {
const indexedDB =
window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB ||
window.shimIndexedDB;
const request = indexedDB.open("ImageDatabase", 1);
request.onsuccess = function () {
const db = request.result;
const delRequest = db.transaction("image", 'readwrite')
.objectStore("image")
.clear();
};
[...document.getElementsByClassName("TiffModalContent")].forEach(el => {
while (el.children[1].hasChildNodes()) {
el.children[1].removeChild(el.children[1].firstChild);
}
while (el.children[2].hasChildNodes()) {
el.children[2].removeChild(el.children[2].firstChild);
}
while (el.children[3].hasChildNodes()) {
el.children[3].removeChild(el.children[3].firstChild);
}
});
[...document.getElementsByClassName("bar")].forEach(el => {
el.style.removeProperty('display');
});
document.getElementById("counter").innerHTML = "";
clearTimeout(interval);
sessionStorage.removeItem("section");
sessionStorage.removeItem("doctype");
isCanvasNotCreated = true;
localStorage.clear();
Current_page = 0;
await initGetElement(); await initGetElement();
init(); init();
alert("Element Rejected"); alert("Element Rejected");
...@@ -206,6 +244,27 @@ function createButtonElem(className, buttonName, icon) { ...@@ -206,6 +244,27 @@ function createButtonElem(className, buttonName, icon) {
function saveExceptionToXml(){ function saveExceptionToXml(){
var selected = document.querySelector('input[name="rejectRadio"]:checked').value; var selected = document.querySelector('input[name="rejectRadio"]:checked').value;
var elementId = sessionStorage.getItem("element_id"); var elementId = sessionStorage.getItem("element_id");
let doctype;
let section;
// Validate all elements again
for(let element of document.getElementById("fields").elements) {
if (element.style.display === 'none') continue
const { id, value,type } = element
const { valid } = validateInput(id, value)
// Skip submit button
if(type==='submit') continue
if(id==='DocType') {
doctype = element.options[element.selectedIndex].text;
continue;
}
if(id==='Section') {
section = element.options[element.selectedIndex].text;
continue;
}
}
let xmlData = { let xmlData = {
"projCode": PROJECT_CODE, "projCode": PROJECT_CODE,
...@@ -227,8 +286,8 @@ function saveExceptionToXml(){ ...@@ -227,8 +286,8 @@ function saveExceptionToXml(){
"eor": "", "eor": "",
"fields": {}, "fields": {},
"outputDir": sessionStorage.getItem("element_file_loc") + "/" + (ENCODING_PASS == "PASS1" ? elementId + ".DTA" : elementId + ".DTB"), "outputDir": sessionStorage.getItem("element_file_loc") + "/" + (ENCODING_PASS == "PASS1" ? elementId + ".DTA" : elementId + ".DTB"),
"doctype": "", "doctype": doctype,
"section": "" "section": section
} }
updateXMLException(xmlData); updateXMLException(xmlData);
...@@ -280,7 +339,7 @@ async function updateXMLException(xmlData){ ...@@ -280,7 +339,7 @@ async function updateXMLException(xmlData){
body: JSON.stringify(xmlData) body: JSON.stringify(xmlData)
}); });
if (response.status == 200) { if (response.status == 200) {
alert("Exception Updated"); console.log("Exception Updated");
} }
else{ else{
alert(`Error ${response.status}: Xml Update`); alert(`Error ${response.status}: Xml Update`);
......
...@@ -3,6 +3,44 @@ async function returnElementBPO(elementId) { ...@@ -3,6 +3,44 @@ async function returnElementBPO(elementId) {
if (response.status == 200) { if (response.status == 200) {
saveExceptionToXml(); saveExceptionToXml();
const indexedDB =
window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB ||
window.shimIndexedDB;
const request = indexedDB.open("ImageDatabase", 1);
request.onsuccess = function () {
const db = request.result;
const delRequest = db.transaction("image", 'readwrite')
.objectStore("image")
.clear();
};
[...document.getElementsByClassName("TiffModalContent")].forEach(el => {
while (el.children[1].hasChildNodes()) {
el.children[1].removeChild(el.children[1].firstChild);
}
while (el.children[2].hasChildNodes()) {
el.children[2].removeChild(el.children[2].firstChild);
}
while (el.children[3].hasChildNodes()) {
el.children[3].removeChild(el.children[3].firstChild);
}
});
[...document.getElementsByClassName("bar")].forEach(el => {
el.style.removeProperty('display');
});
document.getElementById("counter").innerHTML = "";
clearTimeout(interval);
sessionStorage.removeItem("section");
sessionStorage.removeItem("doctype");
isCanvasNotCreated = true;
localStorage.clear();
Current_page = 0;
await loadWaitingElement(); await loadWaitingElement();
init(); init();
alert('Element Returned'); alert('Element Returned');
......
...@@ -3,23 +3,16 @@ var File_Path; ...@@ -3,23 +3,16 @@ var File_Path;
var gfsFileName; var gfsFileName;
async function accessFile() { async function accessFile() {
var button = 0;
var size = 0; var size = 0;
let file_url = [];
const elStatus = document.getElementById('status'); const elStatus = document.getElementById('status');
function status(text) { function status(text) {
elStatus.innerHTML = text; elStatus.innerHTML = text;
} }
const progressBar = document.getElementById('progressBar'); const progressBar = document.getElementById('progressBar');
const elProgress = document.getElementById('progress');
function progress({ loaded, total }) { function progress({ loaded, total }) {
// elProgress.innerHTML = Math.round(loaded * .000001) + " mb of " + Math.round(total * .000001); // elProgress.innerHTML = Math.round(loaded * .000001) + " mb of " + Math.round(total * .000001);
progressBar.value = Math.round(loaded / total * 100); progressBar.value = Math.round(loaded / total * 100);
} }
const indexedDB = const indexedDB =
window.indexedDB || window.indexedDB ||
window.mozIndexedDB || window.mozIndexedDB ||
...@@ -43,14 +36,6 @@ async function accessFile() { ...@@ -43,14 +36,6 @@ async function accessFile() {
const store = db.createObjectStore("image", { keyPath: "id" }); const store = db.createObjectStore("image", { keyPath: "id" });
store.createIndex("image_address", ["address"], { unique: false }); store.createIndex("image_address", ["address"], { unique: false });
}; };
request.onsuccess = function () {
const db = request.result;
const delRequest = db.transaction("image", 'readwrite')
.objectStore("image")
.clear();
}
async function main(img) { async function main(img) {
const request = indexedDB.open("ImageDatabase", 1); const request = indexedDB.open("ImageDatabase", 1);
......
...@@ -27,12 +27,32 @@ const displayFields = async (parentID) => { ...@@ -27,12 +27,32 @@ const displayFields = async (parentID) => {
clearFields(parentID) // make sure input fields are clear clearFields(parentID) // make sure input fields are clear
await fetchSchema() await fetchSchema();
console.log(schema);
createDocTypeDropdown('DocType', div, schema)
createDocTypeDropdown('DocType', div, schema)
createSection('Section', div) createSection('Section', div)
const { ACCOUNTING_DOCUMENTS } = schema
/* Object.keys(schema).forEach(function(key) {
let doctypes = schema[key];
const { valid, error } = validateSchema(key)
if(!valid){
div.textContent = error
div.style.color = '#ff3333'
}
for (let key in doctypes) {
if (doctypes.hasOwnProperty(key)) {
console.log(key + ": " + doctypes[key]); //sections on doctypes
let section = doctypes[key];
console.log(section);
div = deconstruct(section, div, key)
}
}
});*/
const { ACCOUNTING_DOCUMENTS } = schema
//getDocType = DOC_TYPE1 ; //getDocType = DOC_TYPE1 ;
...@@ -51,10 +71,6 @@ const displayFields = async (parentID) => { ...@@ -51,10 +71,6 @@ const displayFields = async (parentID) => {
const { SECTION3 } = HR_FILES const { SECTION3 } = HR_FILES
div = deconstruct(SECTION3, div, 'SECTION3') div = deconstruct(SECTION3, div, 'SECTION3')
if(!valid){
div.textContent = error
div.style.color = '#ff3333'
}
const submit = document.createElement('input') const submit = document.createElement('input')
submit.classList.add("submitButtons"); submit.classList.add("submitButtons");
...@@ -221,6 +237,7 @@ const inputString = (key, validation) => { ...@@ -221,6 +237,7 @@ const inputString = (key, validation) => {
let input = document.createElement('input') let input = document.createElement('input')
input.setAttribute('id', `${key}`) input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.setAttribute('type', 'text') input.setAttribute('type', 'text')
input.setAttribute('autocomplete', 'off') input.setAttribute('autocomplete', 'off')
input.addEventListener('focusout', handleInput) input.addEventListener('focusout', handleInput)
...@@ -283,6 +300,7 @@ const inputNumeric = (key, validation) => { ...@@ -283,6 +300,7 @@ const inputNumeric = (key, validation) => {
const input = document.createElement('input') const input = document.createElement('input')
input.setAttribute('id', `${key}`) input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.setAttribute('type', 'text') input.setAttribute('type', 'text')
input.setAttribute('autocomplete', 'off') input.setAttribute('autocomplete', 'off')
input.setAttribute('pattern', '[0-9/-]+') input.setAttribute('pattern', '[0-9/-]+')
...@@ -313,6 +331,7 @@ const inputDate = (key, validation) => { ...@@ -313,6 +331,7 @@ const inputDate = (key, validation) => {
const input = document.createElement('input') const input = document.createElement('input')
input.setAttribute('id', `${key}`) input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.setAttribute('type', 'date') input.setAttribute('type', 'date')
input.addEventListener('focusout', handleInput) input.addEventListener('focusout', handleInput)
...@@ -339,6 +358,7 @@ const inputDropdown = (key, validation) => { ...@@ -339,6 +358,7 @@ const inputDropdown = (key, validation) => {
const { mandatory, options } = validation const { mandatory, options } = validation
const input = document.createElement('select') const input = document.createElement('select')
input.setAttribute('id', `${key}`) input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.classList.add('dropdown-input') input.classList.add('dropdown-input')
input.addEventListener('focusout', handleInput) input.addEventListener('focusout', handleInput)
...@@ -607,22 +627,23 @@ const createSection = (fieldLabel, div) => { ...@@ -607,22 +627,23 @@ const createSection = (fieldLabel, div) => {
} }
function saveForm(index){ function saveForm(index){
const form = document.querySelector("#fields");
const inputs = form.querySelectorAll("input,textarea");
const values = {};
inputs.forEach(input => {
if(input.value != ''){
values[input.name] = input.value;
}
});
let formValues = {
name : document.getElementById("Name").value,
subject : document.getElementById("Subject").value,
docNo : document.getElementById("Document_No").value,
date : document.getElementById("Date").value,
accountNo : document.getElementById("Account_No").value,
empNo : document.getElementById("Employee_No").value,
}
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, formValues) formArray.splice(index, 1, values)
} else { } else {
formArray.splice(index, 0, formValues) formArray.splice(index, 0, values)
} }
sessionStorage.setItem('formArray', JSON.stringify(formArray)); sessionStorage.setItem('formArray', JSON.stringify(formArray));
...@@ -637,36 +658,13 @@ function populateForm(index){ ...@@ -637,36 +658,13 @@ function populateForm(index){
var formArray = JSON.parse(sessionStorage.getItem('formArray')); var formArray = JSON.parse(sessionStorage.getItem('formArray'));
var name = document.getElementById("Name"); if (formArray[index] != null) {
var subject = document.getElementById("Subject"); var currForm = formArray[index];
var docNo = document.getElementById("Document_No"); for (let field in currForm) {
var date = document.getElementById("Date"); document.getElementById(field).value = currForm[field];
var accountNo = document.getElementById("Account_No"); }
var empNo = document.getElementById("Employee_No");
if (formArray[index].name != null) {
name.value = formArray[index].name;
}
if (formArray[index].subject != null) {
subject.value = formArray[index].subject;
}
if (formArray[index].docNo != null) {
docNo.value = formArray[index].docNo;
}
if (formArray[index].date != null) {
date.value = formArray[index].date;
}
if (formArray[index].accountNo != null) {
accountNo.value = formArray[index].accountNo;
}
if (formArray[index].empNo != null) {
empNo.value = formArray[index].empNo;
} }
} }
\ No newline at end of file
...@@ -182,8 +182,6 @@ function initHighlight() { ...@@ -182,8 +182,6 @@ function initHighlight() {
//waits until TIFF image is loaded, since its size is based on the displayed TIFF image //waits until TIFF image is loaded, since its size is based on the displayed TIFF image
const observer = new MutationObserver(function (mutations, mutationInstance) { const observer = new MutationObserver(function (mutations, mutationInstance) {
console.log(sessionStorage.getItem("TiffViewer_current"));
var TIFFimg = document.getElementById(sessionStorage.getItem("TiffViewer_current")); var TIFFimg = document.getElementById(sessionStorage.getItem("TiffViewer_current"));
if (TIFFimg != null) { if (TIFFimg != null) {
//waits until width and height has been assigned //waits until width and height has been assigned
......
...@@ -316,29 +316,30 @@ function TIFFViewer(xhr, TiffViewerImageName) { ...@@ -316,29 +316,30 @@ function TIFFViewer(xhr, TiffViewerImageName) {
document.getElementById('TestTIFFDisplay').src = tiff.toCanvas().toDataURL(); document.getElementById('TestTIFFDisplay').src = tiff.toCanvas().toDataURL();
//creating blank image containers for each page and setting TIFF data as image source //creating blank image containers for each page and setting TIFF data as image source
for (var i = 0; i < TiffViewer_pages; ++i) { for (var i = 1; i <= TiffViewer_pages; i++) {
var img = document.createElement('img'); var img = document.createElement('img');
img.id = `IMG${i + 1}`; img.id = `IMG${i}`;
if (i != 0) { if (i != 1) {
img.style.display = "none"; img.style.display = "none";
wzoom[TiffViewer_current - 1] = changedwidth; /*ADDED: to fit large TIFF files*/ wzoom[TiffViewer_current - 1] = changedwidth; /*ADDED: to fit large TIFF files*/
hzoom[TiffViewer_current - 1] = changedheight; hzoom[TiffViewer_current - 1] = changedheight;
Edited(); Edited();
} }
img.classList.add("TiffViewer_imgclass");
document.getElementById('TiffViewer_ImageContainer').append(img); document.getElementById('TiffViewer_ImageContainer').append(img);
tiff.setDirectory(i); img.classList.add("TiffViewer_imgclass");
tiff.setDirectory(i - 1);
var canvas = tiff.toCanvas().toDataURL(); var canvas = tiff.toCanvas().toDataURL();
document.getElementById(`IMG${i + 1}`).src = canvas; document.getElementById(`IMG${i}`).src = canvas;
} }
//setting the style per page //setting the style per page
for (var j = 1; j <= TiffViewer_pages; ++j) { for (var j = 1; j <= TiffViewer_pages; j++) {
var img = document.getElementById("IMG" + j); var img = document.getElementById("IMG" + j);
getMeta(canvas, function (width, height) { getMeta(canvas, function (width, height) {
wzoom[TiffViewer_current - 1] = changedwidth; /*ADDED: to fit large TIFF files*/ wzoom[TiffViewer_current - 1] = changedwidth; /*ADDED: to fit large TIFF files*/
hzoom[TiffViewer_current - 1] = changedheight; hzoom[TiffViewer_current - 1] = changedheight;
Edited(); origheight = height; Edited();
origheight = height;
origwidth = width; origwidth = width;
setwidth = width; setwidth = width;
setheight = height; setheight = height;
...@@ -360,18 +361,23 @@ function TIFFViewer(xhr, TiffViewerImageName) { ...@@ -360,18 +361,23 @@ function TIFFViewer(xhr, TiffViewerImageName) {
} else if (setheight > 800 && setwidth <= 1000) { } else if (setheight > 800 && setwidth <= 1000) {
img.style = "width: 800;"; img.style = "width: 800;";
changed = true; changed = true;
} } else{
img.style = `width: {setwidth}; height: {setheight}`;
if(setheight < 800 && setwidth < 1000){ changed = true;
}
changed = true;
}
if (changed) { if (changed) {
setwidth = parseInt(img.style.width, 10); if(TiffViewer_pages > 1){
setheight = parseInt(img.style.height, 10); hpercent = (parseInt(setheight, 10) * (10 / 100));
wpercent = (parseInt(setwidth, 10) * (10 / 100));
}
setwidth = parseInt(img.style.width, 10);
setheight = parseInt(img.style.height, 10);
document.getElementById("TiffViewer_FitButton").style.display = "inherit"; document.getElementById("TiffViewer_FitButton").style.display = "inherit";
} }
changedheight = setheight; changedheight = setheight;
changedwidth = setwidth; changedwidth = setwidth;
hpercent = (parseInt(setheight, 10) * (10 / 100)); hpercent = (parseInt(setheight, 10) * (10 / 100));
...@@ -392,7 +398,13 @@ function TIFFViewer(xhr, TiffViewerImageName) { ...@@ -392,7 +398,13 @@ function TIFFViewer(xhr, TiffViewerImageName) {
} }
} }
if(TiffViewer_pages > 1){
for (var j = 1; j <= TiffViewer_pages; j++) {
var img = document.getElementById("IMG" + j).style.display = "none";
}
}
//getting the metadata of each TIFF page //getting the metadata of each TIFF page
function getMeta(url, callback) { function getMeta(url, callback) {
...@@ -791,7 +803,4 @@ function TIFFViewer(xhr, TiffViewerImageName) { ...@@ -791,7 +803,4 @@ function TIFFViewer(xhr, TiffViewerImageName) {
}); });
initHighlight(); initHighlight();
} }
...@@ -3,4 +3,4 @@ const validateSchema = () => { ...@@ -3,4 +3,4 @@ const validateSchema = () => {
if(!ACCOUNTING_DOCUMENTS) return { valid: false, error: 'SECTION is missing!' } if(!ACCOUNTING_DOCUMENTS) return { valid: false, error: 'SECTION is missing!' }
return { valid: true } return { valid: true }
} }
\ No newline at end of file
...@@ -85,8 +85,7 @@ button:hover{ ...@@ -85,8 +85,7 @@ button:hover{
padding: 0; padding: 0;
left: 0; left: 0;
top: 0; top: 0;
position: relative; /* position: relative; */
overflow-y: hidden;
overflow-x: hidden; overflow-x: hidden;
} }
...@@ -161,7 +160,7 @@ button:hover{ ...@@ -161,7 +160,7 @@ button:hover{
flex: 1; flex: 1;
max-height: 100vh; max-height: 100vh;
display: inline-block; display: inline-block;
overflow-y: scroll; overflow-y: auto;
} }
#fields>div { #fields>div {
......
...@@ -141,7 +141,7 @@ public class GDEWebServices { ...@@ -141,7 +141,7 @@ public class GDEWebServices {
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/write-mertrics") @Path("/write-metrics")
public Response writeCSVMetrics(JsonObject jsonObject) { public Response writeCSVMetrics(JsonObject jsonObject) {
SimpleDateFormat isoFormat = new SimpleDateFormat("MM-dd-yyyy"); SimpleDateFormat isoFormat = new SimpleDateFormat("MM-dd-yyyy");
......
...@@ -2,12 +2,12 @@ package com.svi.webgde.restservice.utils; ...@@ -2,12 +2,12 @@ package com.svi.webgde.restservice.utils;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
...@@ -95,7 +95,7 @@ public class XMLUtil { ...@@ -95,7 +95,7 @@ public class XMLUtil {
Result result = new StreamResult(xml.getOutputDir()); Result result = new StreamResult(xml.getOutputDir());
transformer.transform(source, result); transformer.transform(source, result);
return new String(Files.readAllBytes(Paths.get(xml.getOutputDir()))); return new String(Files.readAllBytes(Paths.get(xml.getOutputDir())));
} }
...@@ -133,42 +133,74 @@ public class XMLUtil { ...@@ -133,42 +133,74 @@ public class XMLUtil {
document.getElementsByTagName("proc_duration").item(0).setTextContent( document.getElementsByTagName("proc_duration").item(0).setTextContent(
String.valueOf(Double.valueOf(xmlLastProcDuration) + Double.valueOf(xml.getProcDuration()))); String.valueOf(Double.valueOf(xmlLastProcDuration) + Double.valueOf(xml.getProcDuration())));
NodeList xmlRecords = document.getElementsByTagName("record"); Map<String, Integer> imagenames = new HashMap<>();
Node xmlLastRecord = xmlRecords.item(xmlRecords.getLength() - 1);
String lastRecordNo = xmlLastRecord.getAttributes().getNamedItem("no").getNodeValue(); for (int i = 0; i < document.getElementsByTagName("imagename").getLength(); i++) {
imagenames.put(document.getElementsByTagName("imagename").item(i).getTextContent(), i);
Element xmlRecord = document.createElement("record"); }
xmlRecord.setAttribute("no", String.valueOf(Integer.valueOf(lastRecordNo) + 1));
xmlRecord.setAttribute("total_subrec", String.valueOf(xml.getTotalSubRec()));
xmlRecord.setAttribute("max_subrec", String.valueOf(xml.getMaxSubRec()));
Element imagename = document.createElement("imagename");
imagename.appendChild(document.createTextNode(xml.getImageName()));
Element doctype = document.createElement("doctype");
doctype.appendChild(document.createTextNode(xml.getDoctype()));
Element section = document.createElement("section");
section.appendChild(document.createTextNode(xml.getSection()));
xmlRecord.appendChild(imagename);
xmlRecord.appendChild(doctype);
xmlRecord.appendChild(section);
Element xmlSubRecord = document.createElement("sub-record");
xmlSubRecord.setAttribute("no", String.valueOf(Integer.valueOf(xml.getSubRecordNo())));
xmlSubRecord.setAttribute("eor", String.valueOf(xml.getEor()));
xml.getFields().forEach((key, value) -> {
Element xmlField = document.createElement("field");
Element valueField = document.createElement("value");
valueField.appendChild(document.createTextNode(value));
xmlField.setAttribute("no", key);
xmlField.appendChild(valueField);
xmlSubRecord.appendChild(xmlField);
});
xmlRecord.appendChild(xmlSubRecord); if (imagenames.containsKey(xml.getImageName())) {
root.appendChild(xmlRecord); Node imagename = document.getElementsByTagName("imagename").item(imagenames.get(xml.getImageName()));
Node xmlSubRecord = imagename.getParentNode().getLastChild().getPreviousSibling();
// xml.getFields().forEach((key, value) -> {
for (Map.Entry<String, String> entry : xml.getFields().entrySet()) {
for (int i = 0; i < xmlSubRecord.getChildNodes().getLength(); i++) {
String key = entry.getKey();
String value = entry.getValue();
if (xmlSubRecord.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE) {
if (xmlSubRecord.getChildNodes().item(i).getAttributes().getNamedItem("no").getNodeValue()
.equals(key)) {
for (int j = 0; j < xmlSubRecord.getChildNodes().item(i).getChildNodes().getLength(); j++) {
if (xmlSubRecord.getChildNodes().item(i).getChildNodes().item(j)
.getNodeType() == Node.ELEMENT_NODE) {
xmlSubRecord.getChildNodes().item(i).getChildNodes().item(j).setTextContent(value);
}
}
}
}
}
}
// });
} else {
NodeList xmlRecords = document.getElementsByTagName("record");
Node xmlLastRecord = xmlRecords.item(xmlRecords.getLength() - 1);
String lastRecordNo = xmlLastRecord.getAttributes().getNamedItem("no").getNodeValue();
Element xmlRecord = document.createElement("record");
xmlRecord.setAttribute("no", String.valueOf(Integer.valueOf(lastRecordNo) + 1));
xmlRecord.setAttribute("total_subrec", String.valueOf(xml.getTotalSubRec()));
xmlRecord.setAttribute("max_subrec", String.valueOf(xml.getMaxSubRec()));
Element imagename = document.createElement("imagename");
imagename.appendChild(document.createTextNode(xml.getImageName()));
Element doctype = document.createElement("doctype");
doctype.appendChild(document.createTextNode(xml.getDoctype()));
Element section = document.createElement("section");
section.appendChild(document.createTextNode(xml.getSection()));
xmlRecord.appendChild(imagename);
xmlRecord.appendChild(doctype);
xmlRecord.appendChild(section);
Element xmlSubRecord = document.createElement("sub-record");
xmlSubRecord.setAttribute("no", String.valueOf(Integer.valueOf(xml.getSubRecordNo())));
xmlSubRecord.setAttribute("eor", String.valueOf(xml.getEor()));
xml.getFields().forEach((key, value) -> {
Element xmlField = document.createElement("field");
Element valueField = document.createElement("value");
valueField.appendChild(document.createTextNode(value));
xmlField.setAttribute("no", key);
xmlField.appendChild(valueField);
xmlSubRecord.appendChild(xmlField);
});
xmlRecord.appendChild(xmlSubRecord);
root.appendChild(xmlRecord);
}
TransformerFactory transformerFactory = TransformerFactory.newInstance(); TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(); Transformer transformer = transformerFactory.newTransformer();
...@@ -226,10 +258,10 @@ public class XMLUtil { ...@@ -226,10 +258,10 @@ public class XMLUtil {
StreamResult result = new StreamResult(xml.getOutputDir()); StreamResult result = new StreamResult(xml.getOutputDir());
transformer.transform(source, result); transformer.transform(source, result);
} }
public static void updateExceptionRmrk(XMLContents xml) public static void updateExceptionRmrk(XMLContents xml)
throws ParserConfigurationException,SAXException, IOException, TransformerException { throws ParserConfigurationException, SAXException, IOException, TransformerException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder(); DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xml.getOutputDir()); Document document = builder.parse(xml.getOutputDir());
...@@ -247,8 +279,7 @@ public class XMLUtil { ...@@ -247,8 +279,7 @@ public class XMLUtil {
DOMSource source = new DOMSource(document); DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(xml.getOutputDir()); StreamResult result = new StreamResult(xml.getOutputDir());
transformer.transform(source, result); transformer.transform(source, result);
} }
} }
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