简体   繁体   中英

Conditions monitoring in datapower

I have following request

URI: /IP/{Version}/Account/Payment
HTTP Method: POST

Custom Headers: 

 X-account-number
 X- account-type
 X-user-initials,
 X-dda-number
 X-dda-account-type
 X-number-of-days-gap
 X-send-ch-letter-flag 
 X-payment-date
 X-payment-option

Now what I have to do is I have to get the Payment date from the request and then I have to check the following conditions

if the payment date is not null and is a future date and is within 180 days from today. If so then first do a lookup to make sure there is no future payment scheduled for this date

If no payments for the date scheduled then insert the payment to table

Finally do the first select query again and retrieve the value

I am trying to do it using XSLT and datapower

but I am not getting the logic correct.

Here is what I have tried

    <xsl:stylesheet 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:dp="http://www.datapower.com/extensions"
 xmlns:dpconfig="http://www.datapower.com/param/config"
 xmlns:date="http://exslt.org/dates-and-times"
 extension-element-prefixes="dp date"
 exclude-result-prefixes="dp dpconfig"
 version="1.0" >


<xsl:template match="/">

<AccountNumber><xsl:value-of select="dp:http-request-header('X-account-number')"/></AccountNumber>
<PaymentDate><xsl:value-of select="dp:http-request-header('X-payment-date')"/></PaymentDate>
<PaymentOption><xsl:value-of select="dp:http-request-header('X-payment-option')"/></PaymentOption>
<Amount><xsl:value-of select="dp:http-request-header('X-amount')"/></Amount>
<AccountType><xsl:value-of select="dp:http-request-header('X-dda-account-type')"/></AccountType>

<xsl:variable name="timestamp" select="date:date-time()"/> 

<xsl:variable name="dateDifference" select="date:difference($timestamp,$PaymentDate)"/>

<xsl:if "$dateDifference" < '180' AND "$PaymentDate" != NULL>

<xsl:variable name="LookUp" Select PAYMENT_STATUS_CODE FROM TABLE WHERE WHERE ACCT_NBR ='$ACCOUNTNUMBER' AND AND PMT_DATE = '$PaymentDate'/>
<xsl:variable name ="RunQuery1">
<dp:sql-execute
    source="'XXXXX'"
    statement="$Lookup">
</dp:sql-execute>
<xsl:variable name="test" copy-of select ="$RunQuery1"/>
<xsl:if test = NULL>

<xsl:variable name="InsertQuery" Insert into TABLE(CREATED_DATE,ACCT_NBR,PMT_AMT_OPTION_CODE,AMOUNT,PMT_DATE,ACCOUNT_TYPE_CODE,PAYMENT_STATUS_CODE)
 VALUES('$timestamp','$ACCOUNTNUMBER','$PaymentOption','$Amount','$PaymentDate','$AccountType','P'/>
<xsl:variable name="RunQuery2">
<dp:sql-execute
    source="'XXXXX'"
    statement="$InsertQuery">
</dp:sql-execute>
</xsl:variable>
</xsl:if>
<xsl:variable name="RetrieveQuery" SELECT PAYMENT_STATUS_CODE from TABLE/>
<xsl:variable name="RunQuery3">
<dp:sql-execute
    source="'XXXXX'"
    statement="$RetrieveQuery">
</dp:sql-execute>
</xsl:variable>
<xsl:copy-of select="$RunQuery3"/>

</xsl:if>
</xsl:template>
</xsl:stylesheet>

What I am doing incorrect?

Well, not sure about the entire script, but since the if statement is not correct, here is something that should be a starting point:

<xsl:if test="fn:days-from-duration($dateDifference) &lt; 180 and $PaymentDate != null">

the conversion function used is this .

The SQL variables are not correct. Please check the syntax on both how to define the queries and how to test the result of the SQL operation. There are many good examples on the Datapower info center .

"$dateDifference" < '180'

Two Three things jump out:

  1. You cannot use < as a comparison operator; you need to use &lt; instead.

  2. The result of date:difference() is not a number.

  3. The syntax of the <xsl:if> statement is entirely wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM