on 08-22-2016 7:18 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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
Hi Arkesh,
Regards,
Praveen.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.