Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182412
Active Contributor

Introduction

The requirement is to archive the files to multiple folders when we pick up the files from multiple folders using sender FILE adapter or SFTP adapter as posted in this discussion Archive multiple files with sFTP (SP 4) adapter

I want to show you step by step how to implement this requirement.

Design

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

Create message type which refer to above data type and create the three service interfaces, one to pick up the file and other one to send the file and other one to archive the file.

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

Create the java mapping to set the dynamic archive directory. I am just reading the directory from adapter specific attribute and adding '/ARCHIVE' to the directory.


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 ArchiveSourceFileJavaMap
  extends AbstractTransformation
{
  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
    throws StreamTransformationException
  {
    try
    {
      IOUtils.copy(transformationInput.getInputPayload().getInputStream(), transformationOutput.getOutputPayload()
        .getOutputStream());
      DynamicConfiguration dynConfig = transformationInput.getDynamicConfiguration();
      DynamicConfigurationKey KEY_DIRECTORY = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File",
        "Directory");
      dynConfig.put(KEY_DIRECTORY, dynConfig.get(KEY_DIRECTORY) + "/ARCHIVE");
    }
    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.

Configuration

Create the below IFLOW in NWDS. Add both interfaces one to send the file to the receiver and one to archive the file. For archive file interface add the java mapping which we created above.

Select the check box maintain order at runtime to maintain order for file interface and archive interface, the  will send only the file delivered successfully.

Configure the sender channel like below, mention one directory in main directory field and other directories you can maintain by selecting Advanced Source File Selection.

Enable FileName and Directory under advanced tab.

Receiver channel configuration:

Enable FileName attribute in ASMA.

Configure below parameters in receiver SFTP adapter to archive the file, basically we can maintain anything in Filename and Filepath when you enable adapter specific message attributes.

Testing

Place files in respective folders in the sender SFTP server. I placed the file in PARTNER_ONE folder

Successfully archived the file to ARCHIVE folder inside PARTNER_ONE folder.

Similarly for second folder, placed the file in PARTNER_TWO folder.

Successfully archived to ARCHIVE directory inside PARTNER_TWO folder.

Message monitor you can see these two messages processed sequentially. One is to send the file to the receiver and the second one is to archive the file.

Conclusion

By adding another interface to archive the file in IFLOW and by using java mapping we can archive the files to multiple folders. i hope this helps to the community.

2 Comments
Labels in this area