Skip to Content
Author's profile photo Praveen Gandepalli

Archive File to Multiple Folders When Pickup from Multiple Folders

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.

fileData.png

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.

serviceInter.png

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.

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

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.

importedArchive.png

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. 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.

IFLOW.png

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.

interfaceSplit.png

maintainOrder.png

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.

senderChannel.png

Enable FileName and Directory under advanced tab.

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

Receiver channel configuration:

receiverChannel.png

Enable FileName attribute in ASMA.

fileName_asma.png

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.

archiveChannel.png

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

Testing

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

partnerOneFile.png

Successfully archived the file to ARCHIVE folder inside PARTNER_ONE folder.

partnerOneArchive.png

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

partnerTwoFile.png

Successfully archived to ARCHIVE directory inside PARTNER_TWO folder.

partnerTwoArchive.png

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.

maintainOrderInMM.png

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.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Shahar Hadad
      Shahar Hadad

       

      Many thanks Praveen!

      This blog helped me alot!

      I just want to add that for readers who are not familiar with Java mapping, its not clear enough but I was able to do it with some other blogs about Java mapping.

      Author's profile photo Aamir Khan
      Aamir Khan

      Thank you Praveen for this wonderful blog.