Forum Discussion

radhika1's avatar
radhika1
Contributor
6 years ago

Query to compare the latest number by transaction time

Hi team,

 

I have two entries for a reference number . i need to compare if the display order is correct based on the transaction time,

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Header/>
<soapenv:Body>
<ac:getConsumerProfileTransactionHistoryResponse xmlns:ac="http://www.moneygram.com/AgentConnect1705">
<ac:payload>
<ac:doCheckIn>true</ac:doCheckIn>
<ac:timeStamp>2018-07-18T16:37:24.679-05:00</ac:timeStamp>
<ac:flags>18</ac:flags>
<ac:mgiSessionID>443077301E15319498444757393417</ac:mgiSessionID>
<ac:GAFVersionNumber>1.1.20180612</ac:GAFVersionNumber>
<ac:numberOfRowsFound>1</ac:numberOfRowsFound>
<ac:transactions>
<ac:transaction>
<ac:currentValues>
<ac:currentValue>
<ac:infoKey>sender_FirstName</ac:infoKey>
<ac:value>ASCFV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sender_LastName</ac:infoKey>
<ac:value>CVVV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiver_FirstName</ac:infoKey>
<ac:value>SDCV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiver_LastName</ac:infoKey>
<ac:value>TESGBVBV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sendAmount</ac:infoKey>
<ac:value>12</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sendCurrency</ac:infoKey>
<ac:value>USD</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiveCurrency</ac:infoKey>
<ac:value>EUR</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receive_Country</ac:infoKey>
<ac:value>CYP</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>deliveryOption</ac:infoKey>
<ac:value>0</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>referenceNumber</ac:infoKey>
<ac:value>26191807</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>productId</ac:infoKey>
<ac:value>1</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>transaction_Event_SequenceNumber</ac:infoKey>
<ac:value>1</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>transactionStatus</ac:infoKey>
<ac:value>SEN</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>transactionStatusUpdateDate</ac:infoKey>
<ac:value>2018-07-18T14:19:30-05:00</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>send_Date</ac:infoKey>
<ac:value>2018-07-18T14:19:30-05:00</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sender_PrimaryPhone</ac:infoKey>
<ac:value>15224747193</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiveAmount</ac:infoKey>
<ac:value>9.98</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>poeTranId</ac:infoKey>
<ac:value>2496480377</ac:value>
</ac:currentValue>
</ac:currentValues>
</ac:transaction>
<ac:transaction>
<ac:currentValues>
<ac:currentValue>
<ac:infoKey>sender_FirstName</ac:infoKey>
<ac:value>ASCFV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sender_LastName</ac:infoKey>
<ac:value>CVVV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiver_FirstName</ac:infoKey>
<ac:value>SDCV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiver_LastName</ac:infoKey>
<ac:value>TESGBVBV</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sendAmount</ac:infoKey>
<ac:value>12</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sendCurrency</ac:infoKey>
<ac:value>USD</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiveCurrency</ac:infoKey>
<ac:value>EUR</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receive_Country</ac:infoKey>
<ac:value>CYP</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>deliveryOption</ac:infoKey>
<ac:value>0</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>referenceNumber</ac:infoKey>
<ac:value>98038080</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>productId</ac:infoKey>
<ac:value>1</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>transaction_Event_SequenceNumber</ac:infoKey>
<ac:value>1</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>transactionStatus</ac:infoKey>
<ac:value>SEN</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>transactionStatusUpdateDate</ac:infoKey>
<ac:value>2018-07-18T14:19:02-05:00</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>send_Date</ac:infoKey>
<ac:value>2018-07-18T14:19:02-05:00</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>sender_PrimaryPhone</ac:infoKey>
<ac:value>15224747193</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>receiveAmount</ac:infoKey>
<ac:value>9.98</ac:value>
</ac:currentValue>
<ac:currentValue>
<ac:infoKey>poeTranId</ac:infoKey>
<ac:value>2496480376</ac:value>
</ac:currentValue>
</ac:currentValues>
</ac:transaction>
</ac:transactions>
<ac:infos>
<ac:info xsi:type="ac:CategoryInfo">
<ac:infoKey>profileTransactionHistoryInfoSet</ac:infoKey>
<ac:label>Consumer Profile Transaction History</ac:label>
<ac:labelStandAlone>Consumer Profile Transaction History</ac:labelStandAlone>
<ac:displayOrder>1</ac:displayOrder>
<ac:infos>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>sendAmount</ac:infoKey>
<ac:label>Send Amount</ac:label>
<ac:labelStandAlone>Send Amount</ac:labelStandAlone>
<ac:displayOrder>15</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>decimal</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>sendCurrency</ac:infoKey>
<ac:label>Send Currency</ac:label>
<ac:labelStandAlone>Send Currency</ac:labelStandAlone>
<ac:displayOrder>16</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>direction1</ac:infoKey>
<ac:label>Home Delivery Direction 1</ac:label>
<ac:labelStandAlone>Home Delivery Direction 1</ac:labelStandAlone>
<ac:displayOrder>17</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>direction2</ac:infoKey>
<ac:label>Home Delivery Direction 2</ac:label>
<ac:labelStandAlone>Home Delivery Direction 2</ac:labelStandAlone>
<ac:displayOrder>18</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>direction3</ac:infoKey>
<ac:label>Home Delivery Direction 3</ac:label>
<ac:labelStandAlone>Home Delivery Direction 3</ac:labelStandAlone>
<ac:displayOrder>19</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>customerReceiveNumber</ac:infoKey>
<ac:label>Receiver Registration Number (RRN)</ac:label>
<ac:labelStandAlone>Receiver Registration Number (RRN)</ac:labelStandAlone>
<ac:displayOrder>22</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>displayAccountID</ac:infoKey>
<ac:label>Account ID</ac:label>
<ac:labelStandAlone>displayAccountID</ac:labelStandAlone>
<ac:displayOrder>23</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>receiveAgentID</ac:infoKey>
<ac:label>Receive Agent ID</ac:label>
<ac:labelStandAlone>Receive Agent ID</ac:labelStandAlone>
<ac:displayOrder>24</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>receiveCurrency</ac:infoKey>
<ac:label>Receive Currency</ac:label>
<ac:labelStandAlone>Receive Currency</ac:labelStandAlone>
<ac:displayOrder>27</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>receiveCode</ac:infoKey>
<ac:label>Biller Receive Code</ac:label>
<ac:labelStandAlone>Biller Receive Code</ac:labelStandAlone>
<ac:displayOrder>29</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>productVariant</ac:infoKey>
<ac:label>Product Variant</ac:label>
<ac:labelStandAlone>Product Variant</ac:labelStandAlone>
<ac:displayOrder>30</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>accountNickName</ac:infoKey>
<ac:label>Account Nick Name</ac:label>
<ac:labelStandAlone>Account Nick Name</ac:labelStandAlone>
<ac:displayOrder>43</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>receiveAmount</ac:infoKey>
<ac:label>Receive Amount</ac:label>
<ac:labelStandAlone>Receive Amount</ac:labelStandAlone>
<ac:displayOrder>46</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>decimal</ac:dataType>
</ac:info>
<ac:info xsi:type="ac:FieldInfo">
<ac:infoKey>transactionStatus</ac:infoKey>
<ac:label>Transaction Status</ac:label>
<ac:labelStandAlone>Transaction Status</ac:labelStandAlone>
<ac:displayOrder>56</ac:displayOrder>
<ac:display>true</ac:display>
<ac:dataType>string</ac:dataType>
</ac:info>
</ac:infos>
</ac:info>
</ac:infos>
</ac:payload>
</ac:getConsumerProfileTransactionHistoryResponse>
</soapenv:Body>
</soapenv:Envelope>

1 Reply

  • Hi, I shortened the xml and added a third transaction, so that we can test the negative case also:

     

     

    import javax.xml.xpath.*
    
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    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;
    
    def xml = """
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<soapenv:Header/>
    	<soapenv:Body>
    		<ac:getConsumerProfileTransactionHistoryResponse xmlns:ac="http://www.moneygram.com/AgentConnect1705">
    			<ac:payload>
    				<ac:doCheckIn>true</ac:doCheckIn>
    				<ac:timeStamp>2018-07-18T16:37:24.679-05:00</ac:timeStamp>
    				<ac:flags>18</ac:flags>
    				<ac:mgiSessionID>443077301E15319498444757393417</ac:mgiSessionID>
    				<ac:GAFVersionNumber>1.1.20180612</ac:GAFVersionNumber>
    				<ac:numberOfRowsFound>1</ac:numberOfRowsFound>
    				<ac:transactions>
    					<ac:transaction>
    						<ac:currentValues>
    							<ac:currentValue>
    								<ac:infoKey>transactionStatusUpdateDate</ac:infoKey>
    								<ac:value>2018-07-18T14:19:30-05:00</ac:value>
    							</ac:currentValue>
    						</ac:currentValues>
    					</ac:transaction>
    					<ac:transaction>
    						<ac:currentValues>
    							<ac:currentValue>
    								<ac:infoKey>transactionStatusUpdateDate</ac:infoKey>
    								<ac:value>2018-07-18T14:19:02-05:00</ac:value>
    							</ac:currentValue>
    						</ac:currentValues>
    					</ac:transaction>
    					<ac:transaction>
    						<ac:currentValues>
    							<ac:currentValue>
    								<ac:infoKey>transactionStatusUpdateDate</ac:infoKey>
    								<ac:value>2018-07-18T22:19:02-05:00</ac:value>
    							</ac:currentValue>
    						</ac:currentValues>
    					</ac:transaction>
    				</ac:transactions>
    				<ac:infos/>
    			</ac:payload>
    		</ac:getConsumerProfileTransactionHistoryResponse>
    	</soapenv:Body>
    </soapenv:Envelope>"""
    
    
    def date1 = null
    def date2 = null
    def rootNode = new XmlSlurper().parseText(xml)
    
    rootNode.'**'.findAll { node->
    	node.text() == 'transactionStatusUpdateDate'
    }.each { node->
    	if(date1 == null) {
    		date1 = new Date().parse("yyyy-MM-dd'T'HH:mm:ss", node.parent().value.toString().substring(0,19))
    	} else {
    		date2 = new Date().parse("yyyy-MM-dd'T'HH:mm:ss", node.parent().value.toString().substring(0,19))
    		log.info("${date1.format('yyyy-MM-dd HH:mm:ss')} newer than ${date2.format('yyyy-MM-dd HH:mm:ss')} = ${checkDates(date1, date2)}")
    		date1 = date2
    	}
    }
    
    log.info "done"
    
    def checkDates(date1, date2) {
    	try {
    		assert date1 > date2
    		return true
    	} catch (AssertionError e) {
    		return false
    	}
    }
    

     

     

    The result looks like this:

    Thu Nov 01 14:12:09 CET 2018:INFO:2018-07-18 14:19:30 newer than 2018-07-18 14:19:02 = true
    Thu Nov 01 14:12:09 CET 2018:INFO:2018-07-18 14:19:02 newer than 2018-07-18 22:19:02 = false
    Thu Nov 01 14:12:09 CET 2018:INFO:done