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: 
RaghuVamseedhar
Active Contributor

Requirement: -

Input Zip file has Order123.txt and Order123.JPG files in it i.e. combination of text(csv, xml) and binary(image, pdf) files. Input Zip file should be unzipped and file names should be preserved i.e., output folder should have Order123.txt (with or without transformation) and Order123.JPN.

Solution: -

Design: -

Create dummy Data Type, Message Type and Outbound/Inbound Service Interfaces.

Parametrized Java Mapping: -


package com.map; 
import com.sap.aii.mapping.api.*; 
public class UnZipParticularFile extends AbstractTransformation { 
    @Override 
    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException { 
        try { 
            java.io.InputStream inputstream = transformationInput.getInputPayload().getInputStream(); 
            java.io.OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream(); 
            String fileNameP = transformationInput.getInputParameters().getString("FileNameP"); // Get Parameter. 
            // A. Unzip and write required file to output. 
            java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(inputstream); 
            java.util.zip.ZipEntry ze; 
            while ((ze = zis.getNextEntry()) != null) {
                //You can use String class methods like endsWith, toLowerCase, contains, matches. Update entry in Interface Determination of ICO accordingly.
                if (ze.getName().matches(fileNameP)) { //ze.getName() is File Name. 
                    int len; 
                    byte b[] = new byte[2048]; 
                    while ((len = zis.read(b, 0, 2048)) != -1) { 
                        outputstream.write(b, 0, len); 
                    } 
                    break; 
                } 
            } 
            // B. Set target File Name and Folder. 
            java.util.Map mapParameters = transformationInput.getInputHeader().getAll(); 
            mapParameters.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/Dynamic", StreamTransformationConstants.DYNAMIC_CONFIGURATION), ""); 
            DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); 
            conf.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName"), ze.getName()); //ze.getName() is File Name. You can add Date prefix or some-other string according to requirement. 
            conf.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory"), "/usr/sap/interfaces/MWS/out");  //You can have different fixed folder or dynamic folder according to requirement.
        } catch (Exception exception) { 
            getTrace().addDebugMessage(exception.getMessage()); 
            throw new StreamTransformationException(exception.toString()); 
        } 
    } 
}

Configuration: -

Remove SWCV as input is binary file (Zip file).

If transformation is required for text file, create new Operational Mapping and add Message Map after Java Map.

Result: -

Input Zip file is unzipped and output file names are same as input file names.

4 Comments
Labels in this area