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:
- Create a sftp and rest connections.
- Create an appdriven integration and configure rest to read the latest file and contents as response.
- List the files using sftp adapter.
- Read the latest file using sftp adapter. The tweaking, we have to do in the mapping file itself.
- For each file, we have to sort as descending order based on lastModifiedTine
- and if position =1 map the file name and ditectory
- 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:
No comments:
Post a Comment