Replace DocumentViewerServiceUtility.java

parent 71e46dd1
......@@ -8,6 +8,7 @@ import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
......@@ -40,8 +41,9 @@ public class DocumentViewerServiceUtility extends RestAPIServiceUtility {
* the objName and refID via getDocumentData's method
*
*/
public byte[] getPreviewImage(String objName, String refId, String tokenIDfromHeader) {
public JSONObject getPreviewImage(String objName, String refId, String tokenIDfromHeader) {
BaseLogger.log("3", null, null, " getPreviewImage method call: ");
JSONObject jsonObject = new JSONObject();
UserInfoBean userInfo = null;
......@@ -59,7 +61,7 @@ public class DocumentViewerServiceUtility extends RestAPIServiceUtility {
byte[] byteArray = null;
try {
responseData = new String(documentHandlerServiceUtility.getDocumentData(objName, refId, refCol, dataFormat, tokenIDfromHeader));
responseData = new String(documentHandlerServiceUtility.getDocumentData(objName, refId, tokenIDfromHeader, refCol, dataFormat));
BaseLogger.log("3", null, null, "responseData ==> " + responseData);
List<String> docIds = new ArrayList<>();
......@@ -69,29 +71,36 @@ public class DocumentViewerServiceUtility extends RestAPIServiceUtility {
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(responseData));
Document doc = builder.parse(is);
NodeList docIdNodes = doc.getElementsByTagName("Document_Id");
// Extract Document_Id values
for (int i = 0; i < docIdNodes.getLength(); i++)
{
Node docIdNode = docIdNodes.item(i);
if (docIdNode.getNodeType() == Node.ELEMENT_NODE) {
Element docIdElement = (Element) docIdNode;
String docId = docIdElement.getTextContent();
NodeList idNodes = doc.getElementsByTagName("ID");
// Extract Document_Id attribute values
for (int i = 0; i < idNodes.getLength(); i++) {
Node idNode = idNodes.item(i);
if (idNode.getNodeType() == Node.ELEMENT_NODE) {
Element idElement = (Element) idNode;
String docId = idElement.getAttribute("Document_Id").trim();
if (!docId.isEmpty()) {
docIds.add(docId);
BaseLogger.log("3", null, null, "DocumentViewerServlet docIDs : [" + docIds + "]");
}
}
}
catch (ParserConfigurationException | SAXException | IOException e)
{
BaseLogger.log("3", null, null, " docID's List : " + docIds);
}
catch (ParserConfigurationException | SAXException | IOException e) {
BaseLogger.log("3", null, null, "Error parsing XML response: " + e.getMessage());
e.printStackTrace();
}
for (String docId : docIds) {
try {
BaseLogger.log("3", null, null, "DocumentViewerServlet :: docID [" + docId + "]");
byteArray = getPreviewImageAgainstDocId(docId, userInfo);
String encodedByteArray = Base64.getEncoder().encodeToString(byteArray);
jsonObject.put(docId, encodedByteArray);
} catch (Exception ex) {
BaseLogger.log("3", null, null, "Exception in DocumentViewerServlet :: handleDocument() : " + ex);
ex.printStackTrace();
......@@ -102,8 +111,10 @@ public class DocumentViewerServiceUtility extends RestAPIServiceUtility {
e.printStackTrace();
}
BaseLogger.log("3", null, null, "jsonObject with docID and encoded byte array0:: [" + jsonObject + "]");
BaseLogger.log("3", null, null, "byteArray of:: [" + byteArray.toString() + "]");
return byteArray;
return jsonObject;
}
private byte[] getPreviewImageAgainstDocId(String docId, UserInfoBean userInfo) {
......@@ -125,7 +136,7 @@ public class DocumentViewerServiceUtility extends RestAPIServiceUtility {
BaseLogger.log("3", null, null, "Exception in DocumentViewerServlet :: handleDocument() : " + ex);
ex.printStackTrace();
}
BaseLogger.log("3", null, null, "byteArray:: " + byteArray);
BaseLogger.log("3", null, null, " getPreviewImageAgainstDocId byteArray:: " + byteArray);
return byteArray;
}
......@@ -176,6 +187,7 @@ public class DocumentViewerServiceUtility extends RestAPIServiceUtility {
} catch (Exception ex) {
}
}
BaseLogger.log("3", userInfo, null, "getVideoFrame iconByteArray : " + iconByteArray);
return iconByteArray;
}
......
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