Friday, September 29, 2023

OIC - Read latest file from SFTP server | Poll the file last time modified from a SFTP server

Usecase: Client has given a requirement that the file polling folder may have multiple files and we only need to read or poll latest file or the file last time modified.


Logic flow:

  1. Create a sftp and rest connections.
  2. Create an appdriven integration and configure rest to read the latest file and contents as response.
  3. List the files using sftp adapter.
  4. Read the latest file using sftp adapter. The tweaking, we have to do in the mapping file itself. 
    1. For each file, we have to sort as descending order based on lastModifiedTine
    2.  and if position =1 map the file name and ditectory
  5. Then map the read file contents  and file name to rest response.


Used json:

{

"FileName":"",

"Employees":{

"Employee":[

{"Empid":1,"Fname":"","Lname":"","Dept":"","Age":"","Country":"","Skill":""},

"Empid":1,"Fname":"","Lname":"","Dept":"","Age":"","Country":"","Skill":""}

]

}

}

Map part for reading latest file:

<nstrgmpr:SyncReadFile>

<ns27:FileReadRequest>

<xsl:for-each select="$listFiles/nsmpr2:ListFileResponse/ns24:ListResponse/ns24:FileList/ns24:File">

<xsl:sort select="ns24:lastModifiedTime" order="descending"/>

<xsl:if test="position()=1">

<ns27:filename>

<xsl:value-of select="ns24:filename"/>

</ns27:filename>

<ns27:directory>

<xsl:value-of select="ns24:directory"/>

</ns27:directory>

</xsl:if>

</xsl:for-each>

</ns27:FileReadRequest>

</nstrgmpr:SyncReadFile>


Detailed screenshots:

Integration flow:


Configure rest trigger to read the latest file name and contents as response.





List the files:




Read the latest file:







Add tracking, save, activate and test




No comments:

Post a Comment

Featured Post

OIC - how can I use XSLT functions to remove leading zeros from numeric and alphanumeric fields?

To remove leading zeros from an numeric field in Oracle Integration Cloud (OIC) using XSLT, you can Use number() Function The number() funct...