Introduction

The requirement is to pick the files from dynamic directory using sender file adapter as mentioned in below question
Move Folders containing multiple file with File adapter

I want to show how we can implement this in PI/PRO.


Design

Create the data type like below, it can be any data type because the file is non XML.

/wp-content/uploads/2016/09/filedata_1035253.png

Create a message type and refer the above data type and create the below service interfaces. One is sender side receive the file, one is to send the file to the receiver.

Since file is non XML so select the interface pattern to Stateless (XI30-Compatible) forSenderData_Out service interface then we no need to remove the software component in ICO.

/wp-content/uploads/2016/09/xi30_1035348.png

Create below java mapping to set the file name and directory using dynamic configuration.

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.InputPayload;
import com.sap.aii.mapping.api.OutputPayload;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import org.apache.commons.io.IOUtils;

public class SetFileNameDirectoryJavaMap
  extends AbstractTransformation
{
  private static final String NAMESPACE = "http://sap.com/xi/XI/System/File";
  
  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
    throws StreamTransformationException
  {
    try
    {
      DynamicConfiguration dynConfig = transformationInput.getDynamicConfiguration();
      DynamicConfigurationKey FILE_NAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
      String fileName = dynConfig.get(FILE_NAME);
      String[] parts = fileName.split("/");
      dynConfig.put(FILE_NAME, parts[1]);
      dynConfig.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory"), "/usr/sap/intf/test/FileData/In/" + parts[0]);
      IOUtils.copy(transformationInput.getInputPayload().getInputStream(), transformationOutput.getOutputPayload()
        .getOutputStream());
    }
    catch (Exception e)
    {
      throw new StreamTransformationException(e.getMessage());
    }
  }
}

Create imported archive and import the above java mapping.

I am using IOUtils class from commons IO, so you need to import this jar in common software component then create the dependency for your original software component then this jar will be available.

commonSoft.png

/wp-content/uploads/2016/09/dependency_1036229.png


Configuration

Create the below IFLOW in NWDS.

 

Configure the sender channel like below,

Enable FileName under adapter specific message attributes.

Maintain below values in FileName and Directory in receiver file channel.

Enable FileName and Directory under adapter specific message attributes.


Testing

Files are placed in the source directory.

The file name comes with folder and the file name, The file successfully written to the dynamic target directory with source file name.

The folder and files are placed in the target FTP server.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply