Replace DocumentViewerServiceUtility.java

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