on 12-28-2011 1:28 PM
Hi team,
Please check the below java mapping. Its existing code.The output is as follows.
source file : ABC.123
Target file : CAM_ABC.123
Now I have changed the code (in RED color).I want target file name as : CAM_ABC.123_yyyyMMdd_hhmmss . (date and time format)
Please check and suggest , why its not working.
Thanks.
Drumi
Code :
//Package Name
package com.xiproject;
//App specific imports
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
//Java specific imports
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;
public class MM_INF00011_Middleware_to_XIData implements StreamTransformation
{
private Map objMap = null;
static String[] strCAM = null;
static int intNDFlag = 0;
static int intNFlag = 0;
static int intFlag = 0;
static int intINCTPTFlag = 0;
static int intCount = 0;
static int intLength = 0;
/**
This function is called at runtime after executing the default constructor
and before calling execute(InputStream, OutputStream). A java.util.Map is
passed that contains an AbstractTrace, values of the message header. The
constants in StreamTransformationConstants can be used as a key for reading
values from the java.util.Map param.
@param objMapParam parameter object containing an AbstractTrace which has
values of the MessageHeader
*/
public void setParameter(Map objMapParam)
{
this.objMap = objMapParam;
}
/**
This function Is called from the runtime after executing setParameter()
This method contains an java.io.InputStream for the source document and an
java.io.OutputStream for the target document as parameters. These streams
are usually XML documents. The target document must be written in the
passed java.io.OutputStream out. While converting bytes to java.lang.String
or java.lang.String to bytes take care about the encoding.
@param isInStream InputStream object
@param osOutStream OutputStream object
@exception StreamTransformationException, IOException
*/
public void execute(InputStream isInStream, OutputStream osOutStream)
throws StreamTransformationException
{
String strFilePath = "http://sap.com/xi/XI/System/File";
String strProperty = "FileName";
String strFileName = null;
String strFile = null;
String strOutFile = null;
String strLine = null;
String[] strSalesOrder = null;
String[] strTemp = null;
StringBuffer sbfOutFile = null;
DynamicConfiguration objDynConf = null;
BufferedReader brBufferRead = null;
BufferedWriter bwBufferWrite = null;
ArrayList arlSalesOrder = new ArrayList();
String strCurrDate = null;
StringBuffer sbfFile = null;
Date dteDate = null;
SimpleDateFormat sdfFormat = null;
int intCAM = 0;
int intSize = 0;
try
{
sbfOutFile = new StringBuffer();
brBufferRead = new BufferedReader(new InputStreamReader(isInStream));
bwBufferWrite = new BufferedWriter(new OutputStreamWriter(osOutStream));
while( null != (strLine = brBufferRead.readLine()) )
{
arlSalesOrder.add(strLine);
}
strSalesOrder = new String[arlSalesOrder.size()];
intLength = arlSalesOrder.size();
for ( int j = 0; j < intLength; j++ )
{
strSalesOrder[j] = (String) arlSalesOrder.get(j);
}
strCAM = new String [intLength];
strTemp = new String [intLength];
separateCAM(strSalesOrder);
final DynamicConfigurationKey KEY_FILENAME =
DynamicConfigurationKey.create(strFilePath, strProperty);
objDynConf = (DynamicConfiguration) objMap.get(
StreamTransformationConstants.DYNAMIC_CONFIGURATION);
// read the source file name
strFileName = objDynConf.get(KEY_FILENAME);
dteDate = new Date();
+ sdfFormat = new SimpleDateFormat("yyyyMMdd_hhmmss");+
+ sbfFile = new StringBuffer();+
+ strCurrDate = sdfFormat.format(dteDate);+
+ ((MappingTrace)objMap.get(StreamTransformationConstants.MAPPING_TRACE))+
+ .addWarning("<-strCurrDate->"strCurrDate);
+ sbfFile.append(strFileName + strCurrDate);+
+ strFileName = sbfFile.toString();+
+ ((MappingTrace)objMap.get(StreamTransformationConstants.MAPPING_TRACE))+
+ .addWarning("<-strFileName->"strFileName);
if( null != strCAM )
{
strFile = "CAM_" + strFileName;
objDynConf.put(KEY_FILENAME,strFile);
intSize = strCAM.length;
for (intCAM = 0; intCAM < intSize; intCAM++)
{
if( null != strCAM[intCAM])
{
sbfOutFile.append(strCAM[intCAM].trim() + "\n");
}
}
strOutFile = sbfOutFile.toString();
byte[] bytData = strOutFile.getBytes();
osOutStream.write(bytData);
}
}
catch(Exception objIOException)
{
((MappingTrace)objMap.get(StreamTransformationConstants.MAPPING_TRACE))
.addWarning(":::Map Failed::" + objIOException.getMessage());
throw new StreamTransformationException(objIOException.getMessage());
}
finally
{
// clearing and closing buffers and streams
try
{
bwBufferWrite.flush();
bwBufferWrite.close();
brBufferRead.close();
isInStream.close();
osOutStream.close();
}
catch(IOException objIOException)
{
throw new StreamTransformationException(objIOException.getMessage());
}
}
}
/**
This function finds each CAM data and append to the temporary CAM Array
@param strSalesOrder String Array
*/
private static void separateCAM(String[] strSalesOrder)
{
// MOD01- Start of Change
int intInpStrLen = 0;
//MOD01- End of Change
int intCAMF = 0;
int intNonCAMF = 0;
//MOD01- Start of Change
String [] strTemp = new String [intLength];
//MOD01- End of Change
intInpStrLen = strSalesOrder.length;
for ( int j = 0, k = 0; j < intInpStrLen; j+, k+ )
{
if ( null != strSalesOrder[j] )
{
strSalesOrder[j] = strSalesOrder[j].trim();
strTemp[k] = strSalesOrder[j];
if ( ("ZCZC").equals(strSalesOrder[j]))
{
intFlag = 0;
}
if ( ("/NODISPOSAL/").equals(strSalesOrder[j]) )
{
intNDFlag = 1;
}
if ( ("/INTCPT/").equals(strSalesOrder[j]) )
{
intINCTPTFlag = 1;
}
if( ("CAM").equals(strSalesOrder[j]) )
{
intFlag = 1;
}
if( ("NNNN").equals(strSalesOrder[j]) )
{
intNFlag = 1;
}
if ( (1 == intFlag) && (1 == intNFlag) )
{
if ( (0 == intINCTPTFlag) && (0 == intNDFlag) )
{
intCAMF = 1;
// copy the temporary string to the CAM String
appendToString(strTemp);
intFlag = 0;
intNFlag = 0;
strTemp = new String[intInpStrLen];
}
else
{
intNonCAMF = 1;
intNFlag = 0;
// clearing the temp string array
strTemp = new String[intInpStrLen];
}
}
if ( (0 == intFlag) && (1 == intNFlag) )
{
intNonCAMF = 1;
intNFlag = 0;
// clearing the temp string array
strTemp = new String[intInpStrLen];
}
}//end of if
}// end of for loop
}
/**
This function appends the Intermediate CAM String Array to the global
CAM Array
@param strArrIntr String Array
*/
private static void appendToString (String[] strArrIntr)
{
int intLengthI = 0;
int intCAM = 0;
int intICAM = 0;
int intCount = 0;
intLengthI = strArrIntr.length;
while( null != strCAM[intCAM] )
{
intCAM++;
}
while( null == strArrIntr[intICAM] )
{
intICAM++;
}
intCount = intLengthI - intICAM ;
for( int j = 0; j < intCount; j+, intICAM+ )
{
if ( null != strArrIntr[intICAM] )
{
strCAM[intCAM] = strArrIntr[intICAM];
intCAM++;
}
}
}
}
Its resolved.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>>Hi team, Please check the below java mapping.
It seems that you have copied the mail as it is. Reformat it so that it become more readable.
Regards,
Prateek Raj Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.