Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Component Sharing
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gagandeep Singh Bhatia
Component Sharing
Commits
e5b74fd4
Commit
e5b74fd4
authored
May 15, 2024
by
Sonawane Amol Madhjuar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
a579c10a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
175 additions
and
0 deletions
+175
-0
Amol/Proteus_Lib_Jar/Frmwrk18/DocumentViewerServiceUtility.java
...roteus_Lib_Jar/Frmwrk18/DocumentViewerServiceUtility.java
+175
-0
No files found.
Amol/Proteus_Lib_Jar/Frmwrk18/DocumentViewerServiceUtility.java
0 → 100644
View file @
e5b74fd4
package
ibase
.
webitm
.
utility
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
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
;
import
ibase.system.config.ConnDriver
;
import
ibase.utility.BaseLogger
;
import
ibase.utility.UserInfoBean
;
import
org.json.JSONObject
;
import
java.io.StringReader
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.ParserConfigurationException
;
import
org.xml.sax.SAXException
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
org.w3c.dom.Node
;
import
org.w3c.dom.NodeList
;
import
org.xml.sax.InputSource
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
public
class
DocumentViewerServiceUtility
extends
RestAPIServiceUtility
{
/*
* Params: objName refID This will contain logic to first get doc ID's against
* the objName and refID via getDocumentData's method
*
*/
public
JSONObject
getPreviewImage
(
String
objName
,
String
refId
,
String
tokenIDfromHeader
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
" getPreviewImage method call: "
);
JSONObject
jsonObject
=
new
JSONObject
();
UserInfoBean
userInfo
=
null
;
if
(
userInfo
==
null
)
{
APIUtility
apiUtility
=
new
APIUtility
();
userInfo
=
apiUtility
.
createUserInfoFromJWTToken
(
tokenIDfromHeader
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"USER_INFO created from TOKEN: ["
+
userInfo
+
"]"
);
}
DocumentHandlerServiceUtility
documentHandlerServiceUtility
=
new
DocumentHandlerServiceUtility
();
String
responseData
=
null
;
String
refCol
=
""
;
byte
[]
byteArray
=
null
;
try
{
responseData
=
documentHandlerServiceUtility
.
getDocumentData
(
objName
,
refId
,
tokenIDfromHeader
,
refCol
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"responseData ==> "
+
responseData
);
List
<
String
>
docIds
=
new
ArrayList
<>();
try
{
JSONArray
jsonArray
=
new
JSONArray
(
responseData
);
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
jsonObject
=
jsonArray
.
getJSONObject
(
i
);
String
docId
=
jsonObject
.
getString
(
"Document_Id"
);
if
(!
docId
.
isEmpty
())
{
docIds
.
add
(
docId
);
}
}
}
catch
(
Exception
e
)
{
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
();
}
}
}
catch
(
Exception
e
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Exception :: "
+
e
);
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
jsonObject
;
}
private
byte
[]
getPreviewImageAgainstDocId
(
String
docId
,
UserInfoBean
userInfo
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"getPreviewImageAgainstDocId Service Called"
);
byte
[]
byteArray
=
null
;
try
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"DocumentViewerServlet :: handleDocument() : GET_VIDEO_FRAME : docID ["
+
docId
+
"]"
);
if
(
docId
==
null
||
""
.
equals
(
docId
.
trim
()))
byteArray
=
new
byte
[]
{
0
};
else
{
byteArray
=
getVideoFrame
(
docId
,
userInfo
);
byteArray
=
(
byteArray
==
null
)
?
new
byte
[]
{
0
}
:
byteArray
;
}
}
catch
(
Exception
ex
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Exception in DocumentViewerServlet :: handleDocument() : "
+
ex
);
ex
.
printStackTrace
();
}
BaseLogger
.
log
(
"3"
,
null
,
null
,
" getPreviewImageAgainstDocId byteArray:: "
+
byteArray
);
return
byteArray
;
}
// getPreviewImageAgainstDocId(List docId's)
private
byte
[]
getVideoFrame
(
String
docId
,
UserInfoBean
userInfo
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"getVideoFrame() Called"
);
Connection
conn
=
null
;
Statement
st
=
null
;
ResultSet
rs
=
null
;
InputStream
inputStream
=
null
;
byte
[]
iconByteArray
=
{
0
};
BaseLogger
.
log
(
"3"
,
null
,
null
,
" getVideoFrame method call: "
);
try
{
String
sql
=
"SELECT ICON FROM DOC_CONTENTS WHERE DOC_ID = "
+
docId
;
BaseLogger
.
log
(
"3"
,
userInfo
,
null
,
"DocumentViewerServlet :: getVideoFrame() : sql ["
+
sql
+
"]"
);
String
transDB
=
userInfo
.
getTransDB
();
conn
=
new
ConnDriver
().
getConnectDB
(
transDB
);
st
=
conn
.
createStatement
();
rs
=
st
.
executeQuery
(
sql
);
if
(
rs
.
next
())
{
inputStream
=
rs
.
getBinaryStream
(
1
);
if
(
inputStream
!=
null
)
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
int
i
=
0
;
while
((
i
=
inputStream
.
read
())
!=
-
1
)
byteArrayOutputStream
.
write
(
i
);
iconByteArray
=
byteArrayOutputStream
.
toByteArray
();
}
}
}
catch
(
Exception
ex
)
{
BaseLogger
.
log
(
"3"
,
userInfo
,
null
,
"Exception in DocumentViewerServlet :: getVideoFrame() : "
+
ex
);
}
finally
{
try
{
if
(
conn
!=
null
)
conn
.
close
();
if
(
st
!=
null
)
st
.
close
();
if
(
rs
!=
null
)
rs
.
close
();
}
catch
(
Exception
ex
)
{
}
}
BaseLogger
.
log
(
"3"
,
userInfo
,
null
,
"getVideoFrame iconByteArray : "
+
iconByteArray
);
return
iconByteArray
;
}
}
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