cancel
Showing results for 
Search instead for 
Did you mean: 

SAP PI 7.4: Dynamic Archiving in SFTP

arkesh_sharma
Active Participant
0 Kudos

Hi Experts,

I have pass-through SFTP to SFTP scenario where I have to dynamically archive the PDF files based on the file name and in case the folder does not exist then I have to create one. I have thought of two solutions but I do not have the sandbox to try them out. I am mentioning below the two scenarios and any queries related to it. Kindly provide us with your opinion and feedback -

1. Two Interfaces Solution: In this, I will first create an interface that will pick the PDF file from source directory and place it in a temporary folder in the target. The second interface will pick PDF files from the temporary directory and using ASMA and UDF will create a dynamic target directory to place the files in the actual archive directory. My confusion here is that, since it is a pass-through scenario whether creating a dummy Data Type, Message Type, Service Interface, Message Mapping and Operation Mapping for the second interface will work or not (as I need to write a UDF to define the target directory).

2. Java Program/Script: I will create the pass-through interface and will call the java program/script from "Run OS command after file processing" but my challenge is that I have limited knowledge on scripting and I have never done this before. It will be helpful if someone can outline the steps on how to write the code, where to place the java code and how to call it from the receiver SFTP channel.

Regards,

Arkesh

Accepted Solutions (1)

Accepted Solutions (1)

manoj_khavatkopp
Active Contributor
0 Kudos

Arkesh,

can you please explain how directory name and filename are related ?

Lets say your fileName is :

ABC.pdf then folder would be  /Test/ABC

XYZ.pdf then folder would be   /Test/XYZ

if above is the case then you can create dynamic directory by using DynamicConfiguration module + variable substitution.

And yes as above you have mentioned the pdf will miss for the first approach because before mapping the pdf will be the mainpayload but in mapping as you are using Dynamic UDF so the main payload will be your dummy message type .

alternatively you can use java mapping to assign Dynamic Folder and also make the output as the pdf itself.

Br,

Manoj

arkesh_sharma
Active Participant
0 Kudos

Hi Manoj,

Thank you for replying to my query.

My file name format is "ABC_<DocID>_YYYYMMDD_PQR.pdf"

The Dynamic Folder structure would be /ABC/<DocID>/YYYY/MM

Since, it is a pass-through scenario I do not need to have any ESR Objects.

Regards,

Arkesh

former_member182412
Active Contributor
0 Kudos

Hi Arkesh,

Instead of creating separate interface use one interface and configure two interfaces in interface determination, one for dynamic archive and one for send the file to your receiver.

Use below java mapping as Manoj already suggested.


import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.DynamicConfiguration;

import com.sap.aii.mapping.api.DynamicConfigurationKey;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class SetDynamicDirectoryJavaMap extends AbstractTransformation {

  @Override

  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)

  throws StreamTransformationException {

  try {

  DynamicConfiguration conf = transformationInput.getDynamicConfiguration();

  DynamicConfigurationKey DIRECTORY_KEY = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File",

  "Directory");

  DynamicConfigurationKey FILENAME_KEY = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");

  String fileName = conf.get(FILENAME_KEY);

  String[] fileNameParts = fileName.split("_");

  StringBuilder directory = new StringBuilder();

  directory.append("/").append(fileNameParts[0]).append("/").append(fileNameParts[1]).append("/").append(

  fileNameParts[2].substring(0, 4)).append("/").append(fileNameParts[2].substring(4, 6));

  conf.put(DIRECTORY_KEY, directory.toString());

  InputStream inputStream = transformationInput.getInputPayload().getInputStream();

  byte[] buf = new byte[inputStream.available()];

  inputStream.read(buf);

  transformationOutput.getOutputPayload().getOutputStream().write(buf);

  } catch (Exception e) {

  getTrace().addDebugMessage(e.getMessage());

  throw new StreamTransformationException(e.getMessage());

  }

  }

}

Regards,

Praveen.

arkesh_sharma
Active Participant
0 Kudos

Thank you Praveen for the detailed and comprehensive email.

As I mentioned earlier, I have a pass-through scenario where I need to transport PDF files across SFTP servers. So, no ESR objects are required.

Below is my understanding of the solution you provided. I haven't tried it yet on the PI system as I do not have the access to the sandbox system currently.

Java Mapping will make use of the dummy ESR objects (DT, MT, SI, OM) and will transfer the PDF file as an attachment along with the main payload. In case I modify the code you provided and somehow read the attached PDF file in the main payload I will only get the target directory path but I may not be able to place it as a PDF file in the archiving directory. It will still go as an attachment to the main payload. I need to place the file as a PDF file in the designated path.


Kindly let me know your thoughts on this as I have a limited access to the PI sandbox.

manoj_khavatkopp
Active Contributor
0 Kudos

Akesh ,

Code provided by Praveen will read the pdf(not exactly reading inside pdf) as mainpaylod and sets the output as also the pdf and not as a attachment so in this case your pdf wont miss , so the code will work perfectly.

br,

Manoj

arkesh_sharma
Active Participant
0 Kudos

Hi Manoj,

Thank you for your response. I understand that Praveen's code does a dynamic lookup of the file name.

But once you create a dummy interface for the Java map and pick up a PDF file from the source, it will come as an attachment to the XML main payload created in the DT and MT in PI ( this is my understanding and haven't tried it). If you have access to any sandbox then I request you try this out once without the java map and see if this comes as a attachment to the main payload.

Regards,

Arkesh

manoj_khavatkopp
Active Contributor
0 Kudos

Arkesh,

No the PDF wont come as an attachment(untill and unless you have configured it in additional files or used payloadswap) its comes as a main payload if you pick just by configuring in NFS under filename schema.

Br,

Manoj

former_member182412
Active Contributor
0 Kudos

Hi Arkesh,

  • I am reading the PDF file as main payload
  • I added two interfaces in the interface determination step, one for place the PDF file in receiver SFTP server, one for archive the PDF file to dynamic directory.
  • To send the PDF file to receiver SFTP server there will be no mapping
  • To send the PDF file to dynamic archive directory there will be java mapping to set the dynamic directory.
  • With in the java mapping i am just reading the original PDF file name and using this file name i am setting the dynamic directory for archive the PDF file, i am not touching the content of the payload, i am just sending as it is.
  • There will be no attachments, only main payload which is PDF file.
  • You just need to select the Adapter specific message attributes in the receiver SFTP channels.
  • For normal PDF file select the fileName attribute only, for dynamic directory select fileName and Directory.

Regards,

Praveen.

Answers (1)

Answers (1)

mdejesus
Participant
0 Kudos

Hi Arkesh,

The easiest solution is the first option which is creating two interfaces.

First interface is for the main scenario (Source to Target Folder) and second interface is for your dynamic archiving.  And use a receiver split with different operation mapping so you only have to pick the source file once.

Best regards,

Marc

arkesh_sharma
Active Participant
0 Kudos

Hi Marc,

Thank you for taking time out to reply to my query.

In my scenario, I have to transport PDF files from source SFTP to target SFTP server so it is a pass-through scenario.

One of my friends just called me and said that this scenario is not possible because in the second interface, while creating dummy objects, the PDF file goes missing in the target dynamic directory.

Regards,

Arkesh