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
0
Merge Requests
0
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
Rishikesh Santosh Kumar
Component Sharing
Commits
26f8685e
Commit
26f8685e
authored
Dec 11, 2023
by
Sonawane Amol Madhjuar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
24d720da
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
328 additions
and
0 deletions
+328
-0
Amol/Bank/GenerateXml.java
Amol/Bank/GenerateXml.java
+328
-0
No files found.
Amol/Bank/GenerateXml.java
0 → 100644
View file @
26f8685e
package
ibase
.
utility
.
training
;
import
java.io.File
;
import
java.rmi.RemoteException
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Random
;
import
javax.naming.InitialContext
;
import
javax.naming.NamingException
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
org.w3c.dom.NodeList
;
import
ibase.bi.common.system.config.DBInfo
;
import
ibase.ejb.CommonDBAccessEJB
;
import
ibase.system.config.AppConnectParm
;
import
ibase.system.config.ConnDriver
;
import
ibase.utility.BaseException
;
import
ibase.utility.BaseLogger
;
import
ibase.utility.E12GenericUtility
;
import
ibase.utility.UserInfoBean
;
import
ibase.webitm.ejb.ActionHandlerEJB
;
import
ibase.webitm.ejb.DBAccessEJB
;
import
ibase.webitm.ejb.MasterStatefulLocal
;
import
ibase.webitm.utility.ITMException
;
public
class
GenerateXml
extends
ActionHandlerEJB
{
/*
* */
public
String
actionHandler
(
String
tranID
,
String
xtraParam
,
String
forceFlag
)
throws
RemoteException
,
ITMException
{
String
retVal
=
""
;
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Inside actionHandler.. "
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Inside actionHandler.. tranID[ "
+
tranID
+
"]"
);
// P2BPH0125
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Inside actionHandler.. xtraParam"
+
xtraParam
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Inside actionHandler.. forceFlag"
+
forceFlag
);
// 11
//String filePath = "/wildfly/BankIntegration/From HSBC/ACK1PSRV3.PC000019210.SS210026.20210823070047001.XML";
String
filePath2
=
"/wildfly/BankIntegration/From HSBC/ACK2PSRV3.PC000019210.SS210026.20210823070120002.XML"
;
BaseLogger
.
log
(
"3"
,
null
,
null
,
"VALUE OF filePath..["
+
filePath2
+
"]"
);
try
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Inside try..gsb "
);
// Parse the XML file
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// DocumentBuilder builder = factory.newDocumentBuilder();
// Document document = builder.parse(new File(filePath));
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
Document
document
=
builder
.
parse
(
new
File
(
filePath2
));
Element
rootElement
=
document
.
getDocumentElement
();
System
.
out
.
println
(
"Root Element gsb: "
+
document
.
getDocumentElement
().
getTagName
());
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Acknowledgement document:["
+
E12GenericUtility
.
documentToString
(
document
)
+
"]"
);
// Document document = parseXmlFile(filePath);
// Extract the value of <Id>ABC31378001</Id>
String
idValue
=
getElementValue
(
rootElement
,
"Othr"
,
"Id"
);
//String GrpSts = getElementValueByTagName(document, "GrpSts"); TxSts
String
OrgnlMsgId
=
getElementValueByTagName
(
document
,
"OrgnlMsgId"
);
String
TxSts
=
getElementValueByTagName
(
document
,
"TxSts"
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"VALUE OF OrgnlMsgId.. ["
+
OrgnlMsgId
+
"]"
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"VALUE OF TxSts.. ["
+
TxSts
+
"]"
);
}
catch
(
Exception
f
)
{
f
.
printStackTrace
();
}
//
try
{
// updatePaymentStatus(tranID, xtraParam);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
retVal
;
}
// Method to update Payment Status, this method will get called from Confirm
// Action of misc_pay.
// Thr is a need to be called from other places as well as while receiving the
// staus update from Bank, So need to ensure this accomodates that as well
// Mostly may get called from Scheduler - thr user may be the generic here,
// but while calling from action user will be the person who called the
// confirmation
private
void
updatePaymentStatus
(
String
tranID
,
String
xtraParam
)
throws
Exception
{
Connection
connection
=
null
;
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Inside updatePaymentStatus.. "
);
try
{
E12GenericUtility
e12GenericUtility
=
new
E12GenericUtility
();
CommonDBAccessEJB
commonDBAccessEJB
=
new
CommonDBAccessEJB
();
AppConnectParm
appConnect
=
new
AppConnectParm
();
InitialContext
initialContext
=
new
InitialContext
(
appConnect
.
getProperty
());
String
userCode
=
e12GenericUtility
.
getValueFromXTRA_PARAMS
(
xtraParam
,
"loginCode"
);
UserInfoBean
userInfo
=
commonDBAccessEJB
.
createUserInfo
(
userCode
);
ConnDriver
connDriver
=
new
ConnDriver
();
connection
=
connDriver
.
getConnectDB
(
userInfo
.
getTransDB
());
StringBuffer
processDynXmlString
=
new
StringBuffer
();
processDynXmlString
.
append
(
"<DocumentRoot><description>Datawindow Root</description><group0>"
);
processDynXmlString
.
append
(
"<description>Group0 description</description><Header0><description>Header0 members</description>"
);
processDynXmlString
.
append
(
"<objName><![CDATA[payintstatus]]></objName>"
);
processDynXmlString
.
append
(
"<pageContext><![CDATA[1]]></pageContext>"
);
processDynXmlString
.
append
(
"<objContext><![CDATA[1]]></objContext>"
);
processDynXmlString
.
append
(
"<editFlag><![CDATA[A]]></editFlag>"
);
processDynXmlString
.
append
(
"<focusedColumn><![CDATA[]]></focusedColumn>"
);
processDynXmlString
.
append
(
"<action><![CDATA[SAVE]]></action>"
);
processDynXmlString
.
append
(
"<elementName><![CDATA[]]></elementName>"
);
processDynXmlString
.
append
(
"<keyValue><![CDATA[1]]></keyValue>"
);
// processDynXmlString.append("<taxKeyValue><![CDATA[]]></taxKeyValue>");
processDynXmlString
.
append
(
"<saveLevel><![CDATA[1]]></saveLevel>"
);
processDynXmlString
.
append
(
"<forcedSave><![CDATA[false]]></forcedSave>"
);
processDynXmlString
.
append
(
"<Detail1 dbID='' domID='1' objContext='1' objName='payintstatus'>"
);
processDynXmlString
.
append
(
"<attribute IS_CHANGE='Y' pkNames='TRAN_ID' selected='N' status='N' updateFlag='A'/>"
);
// processDynXmlString.append("<taxInFocus><![CDATA[false]]></taxInFocus>");
// TO GET REFSER
String
refser
=
""
;
DBAccessEJB
dbAccessEJB
=
new
DBAccessEJB
();
try
{
refser
=
dbAccessEJB
.
getDBColumnValue
(
"TRANSETUP"
,
"REF_SER"
,
"TRAN_WINDOW = 'w_misc_pay'"
,
userInfo
.
getTransDB
());
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Value of refser... ["
+
refser
+
"]"
);
}
catch
(
RemoteException
|
ITMException
e
)
{
e
.
printStackTrace
();
}
processDynXmlString
.
append
(
getTransXML
(
tranID
,
refser
,
"Payment Initiated"
,
""
,
""
));
processDynXmlString
.
append
(
"</Detail1>"
);
processDynXmlString
.
append
(
"</Header0></group0></DocumentRoot>"
);
String
XmlString
=
processDynXmlString
.
toString
();
BaseLogger
.
log
(
"3"
,
null
,
null
,
" Xml String... "
+
XmlString
);
// call the process request here
MasterStatefulLocal
masterStateful
=
(
MasterStatefulLocal
)
initialContext
.
lookup
(
"ibase/MasterStatefulEJB/local"
);
String
reString
=
masterStateful
.
processRequest
(
getUserInfo
(),
XmlString
,
false
,
connection
);
// userInfo
// --pass
BaseLogger
.
log
(
"3"
,
null
,
null
,
"reString.. "
+
reString
);
}
catch
(
Exception
e
)
{
throw
e
;
}
finally
{
try
{
// if(rs != null)
// {
// rs.close();
// rs = null;
// }
// if(pstmt != null)
// {
// pstmt.close();
// pstmt = null;
// }
if
(
connection
!=
null
)
{
connection
.
close
();
connection
=
null
;
}
}
catch
(
Exception
e
)
{
e
.
getMessage
();
}
}
}
/*
*
* */
private
String
getTransXML
(
String
paymentTranID
,
String
refSer
,
String
descr
,
String
remarks
,
String
errorDet
)
{
// Need to generate XML for payIntStatus
StringBuffer
transXML
=
new
StringBuffer
();
// transXML.append("<tran_id><![CDATA[]]></tran_id>");
// transXML.append("<TRAN_ID><![CDATA[gsb]]></TRAN_ID>");
transXML
.
append
(
"<ref_ser><![CDATA["
+
refSer
+
"]]></ref_ser>"
);
transXML
.
append
(
"<ref_id><![CDATA["
+
paymentTranID
+
"]]></ref_id>"
);
transXML
.
append
(
"<status_date><![CDATA["
+
getCurrentDate
()
+
"]]></status_date>"
);
transXML
.
append
(
"<stage_descr><![CDATA["
+
descr
+
"]]></stage_descr>"
);
transXML
.
append
(
"<remarks><![CDATA["
+
remarks
+
"]]></remarks>"
);
transXML
.
append
(
"<error_det><![CDATA["
+
errorDet
+
"]]></error_det>"
);
return
transXML
.
toString
();
}
private
InitialContext
getInitialContext
()
throws
ITMException
{
InitialContext
ctx
=
null
;
try
{
AppConnectParm
appConnect
=
new
AppConnectParm
();
ctx
=
new
InitialContext
(
appConnect
.
getProperty
());
}
catch
(
ITMException
itme
)
{
BaseLogger
.
log
(
"0"
,
null
,
null
,
"ITMException : getInitialContext : "
+
itme
.
getMessage
());
throw
itme
;
}
catch
(
Exception
e
)
{
BaseLogger
.
log
(
"0"
,
null
,
null
,
"Exception : getInitialContext : "
+
e
.
getMessage
());
throw
new
ITMException
(
e
);
}
return
ctx
;
}
public
static
String
getCurrentDate
()
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"inside getCurrentDate .. "
);
// LocalDate currentDate = LocalDate.now();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yy");
// BaseLogger.log("3", null, null, "currentDate is .. [" + currentDate.format(formatter) + "]");
// return currentDate.format(formatter);
LocalDateTime
currentDateTime
=
LocalDateTime
.
now
();
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"dd/MM/yy HH:mm:ss"
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"currentDateTime is .. ["
+
currentDateTime
.
format
(
formatter
)
+
"]"
);
return
currentDateTime
.
format
(
formatter
);
}
//11 dec
private
static
String
getElementValueByTagName
(
Document
document
,
String
tagName
)
{
NodeList
nodeList
=
document
.
getElementsByTagName
(
tagName
);
if
(
nodeList
.
getLength
()
>
0
)
{
Element
element
=
(
Element
)
nodeList
.
item
(
0
);
return
element
.
getTextContent
();
}
else
{
return
null
;
// Tag not found
}
}
// private static String getElementValueByIdWithParent(Document document, String parentTagName, String childTagName) {
// BaseLogger.log("3", null, null, "Inside method getElementValueByIdWithParent");
// NodeList parentList = document.getElementsByTagName(parentTagName);
// for (int i = 0; i < parentList.getLength(); i++) {
// Element parentElement = (Element) parentList.item(i);
// NodeList idList = parentElement.getElementsByTagName(childTagName);
// if (idList.getLength() > 0) {
// Element idElement = (Element) idList.item(0);
// return idElement.getTextContent();
// }
// }
// return null; // Id tag not found under the specified parent tag
// }
private
static
Document
parseXmlFile
(
String
filePath
)
throws
Exception
{
// Create a DocumentBuilderFactory
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
// Create a DocumentBuilder
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
// Parse the XML file and create a Document object
return
builder
.
parse
(
new
File
(
filePath
));
}
private
static
String
getIdValue
(
Document
document
)
{
// Find the <Id> element using XPath
NodeList
idNodeList
=
document
.
getElementsByTagName
(
"Id"
);
// Assuming there's only one <Id> element in the XML
if
(
idNodeList
.
getLength
()
>
0
)
{
Element
idElement
=
(
Element
)
idNodeList
.
item
(
0
);
// Get the text content of the <Id> element
return
idElement
.
getTextContent
();
}
// Return null if <Id> element is not found
return
null
;
}
private
static
String
getElementValue
(
Element
parentElement
,
String
parentTagName
,
String
tagName
)
{
// Find the specified element using XPath under the specified parent element
NodeList
parentNodes
=
parentElement
.
getElementsByTagName
(
parentTagName
);
for
(
int
i
=
0
;
i
<
parentNodes
.
getLength
();
i
++)
{
Element
parent
=
(
Element
)
parentNodes
.
item
(
i
);
// Find the specified element under the parent
NodeList
nodeList
=
parent
.
getElementsByTagName
(
tagName
);
// Iterate through the elements to find the one under the specified parent
for
(
int
j
=
0
;
j
<
nodeList
.
getLength
();
j
++)
{
Element
element
=
(
Element
)
nodeList
.
item
(
j
);
// Get the text content of the element
return
element
.
getTextContent
();
}
}
// Return null if the element is not found
return
null
;
}
//
}
\ No newline at end of file
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