Skip to Content

Hi All,

I have a requirement where I need to pick files from multiple source directories and place it to on target file server using one file channel. The interface was passthrough interface so I created dummy structures as I would be needing service interfaces and operation mapping to call JAVA mapping.

To achieve this I prefer to write Adapter Module but sometimes due to BASIS dependency, we have to go for JAVA mapping. Here I am putting up my JAVA code but ADAPTER MODULE code will be shared soon.

Source directories were like

/a/b/c/X

/a/b/c/Y

/a/b/c/Z

and target directories were /X, /Y, /Z

PFB the code:

/*

* Created on May 26, 2015

*

* To change the template for this generated file go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

package global;

/**

* @author ashutosh.a.upadhyay

*

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Map;

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

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

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

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

public class DynamicDirectory extends AbstractTransformation {

  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)throws StreamTransformationException{

  try {

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

      OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

    Map mapParameters = (Map) transformationInput.getInputHeader().getAll();

    // Dynamic Confguration

    mapParameters.put(DynamicConfigurationKey.create(“http://sap.com/xi/XI/Dynamic“, StreamTransformationConstants.DYNAMIC_CONFIGURATION), “”);

    DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

    DynamicConfigurationKey key = DynamicConfigurationKey.create(“http://sap.com/xi/XI/System/File“, “Directory”);

    //Check the input directory and set the output directory

    String inputDir = “”;

    String outputDir = “”;

 

    inputDir = conf.get(key);

    if(inputDir.endsWith(“X”)){

    outputDir = “/X/”;

    }

    else if (inputDir.endsWith(“Y”)){

    outputDir = “/Y/”;

    }

 

    else if(inputDir.endsWith(“Z”)){

    outputDir = “/Z/”;

    }

  //Set the directory parameter

  conf.put(key,outputDir);

    //copy Input file content to Output file content

    byte[] b = new byte[inputstream.available()];

    inputstream.read(b);

    outputstream.write(b);

    }

    catch (Exception exception){

    getTrace().addDebugMessage(exception.getMessage());

    throw new StreamTransformationException(exception.toString());

    }

  }

}

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply