// Use of DynamicConfigurationVariable "FileName" in Java-UDF (in Graphical-Map)
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
//1. Read "FileName" variable
String strFileName = "";
strFileName = conf.get(key); //Get the Key-Value
//2. Assign value to "FileName" variable
strFileName = "CustName.asc"; //or get dynamic value from source inputXml-fields
conf.put(key, strFileName); //Set the Key-Value
// Use of DynamicConfigurationVariable "FileName" in Java-Map
DynamicConfiguration conf = (DynamicConfiguration)param.get("DynamicConfiguration");
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
//1. Read "FileName" variable
String strFileName = "";
strFileName = conf.get(key); //Get the Key-Value
//2. Assign value to "FileName" variable
strFileName = "CustName.asc"; //or get dynamic value from source inputXml-fields
conf.put(key, strFileName); //Set the Key-Value
/**
*
*/
package com.sap.adaptermodule;
import java.rmi.RemoteException;
import java.util.ArrayList;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.TimedObject;
import javax.ejb.Timer;
import com.sap.aii.af.lib.mp.module.ModuleContext;
import com.sap.aii.af.lib.mp.module.ModuleData;
import com.sap.aii.af.lib.mp.module.ModuleException;
import com.sap.aii.af.service.auditlog.Audit;
import com.sap.engine.interfaces.messaging.api.Message;
import com.sap.engine.interfaces.messaging.api.MessageKey;
import com.sap.engine.interfaces.messaging.api.MessagePropertyKey;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
/**
* @author
*
*/
public class copyToDynamicFolderBean implements SessionBean, TimedObject {
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbRemove()
*/
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
*/
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.TimedObject#ejbTimeout(javax.ejb.Timer)
*/
public void ejbTimeout(Timer arg0) {
// TODO Auto-generated method stub
}
public void ejbCreate() throws javax.ejb.CreateException {
}
private SessionContext myContext;
MessageKey amk = null;
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException{
Object obj = null;
Message msg = null;
String file_destination_payroll_01 = "";
String file_destination_payroll_02 = "";
String file_destination_payroll_03 = "";
try
{
obj = inputModuleData.getPrincipalData();
msg = (Message) obj;
amk = new MessageKey(msg.getMessageId(),msg.getMessageDirection());
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Start of Custom-JavaAdapterModule JNDI copyToDynamicFolder ................");
//1. Read all MessageProperty (or DynamicConfigurationVariable)
ArrayList<String> dynmPrLst = new ArrayList<String>();
for (MessagePropertyKey key : msg.getMessagePropertyKeys()) {
String propertyName = key.getPropertyName(); //"FileName"
String propertyNamespace = key.getPropertyNamespace(); //"http://sap.com/xi/XI/System/File"
String propertyValue = msg.getMessageProperty(key); //"01.zip"
String propertyVal = "";
propertyVal = propertyName + "_" + propertyNamespace + "_" + propertyValue;
dynmPrLst.add(propertyVal);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, ("MessageProperty " + propertyVal));
}
//2. Read "FileName" MessageProperty(or DynamicConfigurationVariable)
String sourceFileName = "";
for(int i=0;i<dynmPrLst.size();i++){
String dynmParmStr = dynmPrLst.get(i).trim();
if(dynmParmStr.indexOf("FileName_http://sap.com/xi/XI/System/File") > -1){
sourceFileName = dynmParmStr.substring(dynmParmStr.lastIndexOf("_")+1);
break;
}
}
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, ("Source FileName is " + sourceFileName));
/**
* 3. Read value of Module-Input-Parameters (set in channel's Module)
* For example:
* ModuleInputParameter file_destination_payroll_01
* Value <filename>, <destinationFolder>
* Value 01.zip, /Folder1/Folder2/
*/
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Reading module input parameters.....");
file_destination_payroll_01 = (String) moduleContext.getContextData("file_destination_payroll_01");
file_destination_payroll_02 = (String) moduleContext.getContextData("file_destination_payroll_02");
file_destination_payroll_03 = (String) moduleContext.getContextData("file_destination_payroll_03");
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, ("file_destination_payroll_01 " + file_destination_payroll_01));
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, ("file_destination_payroll_02 " + file_destination_payroll_02));
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, ("file_destination_payroll_03 " + file_destination_payroll_03));
/**
* 4. Check if "FileName" matches to any of ModuleInputParameters
* and if found then set respective destination to "Directory" MessageProperty(or DynamicConfigurationVariable)
*/
directoryPropertyValue = "";
getDirectoryVal(sourceFileName, file_destination_payroll_01);
getDirectoryVal(sourceFileName, file_destination_payroll_02);
getDirectoryVal(sourceFileName, file_destination_payroll_03);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, ( "File " + sourceFileName + " to be sent to directory " + directoryPropertyValue));
/**
* 5. Set "Directory" MessageProperty(or DynamicConfigurationVariable)
*/
MessagePropertyKey sKey1 = new MessagePropertyKey("Directory","http://sap.com/xi/XI/System/File");
msg.setMessageProperty(sKey1, directoryPropertyValue);
inputModuleData.setPrincipalData(msg); //set msg property again as principal data
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, ("Setting new MessageProperty as: Namespace=http://sap.com/xi/XI/System/File Name=Directory Value=" + directoryPropertyValue));
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "End of Custom-JavaAdapterModule JNDI copyToDynamicFolder ..................");
return inputModuleData;
}catch (Exception e) {
ModuleException me = new ModuleException(e);
throw me;
}
}
private static String directoryPropertyValue;
private static void getDirectoryVal(String sourceFileName, String file_destination) {
//file_destination = "file1.zip, /abc/dyg/xyz/";
if(file_destination.trim().length() > 0){
String fNm = (file_destination.substring(0, file_destination.indexOf(","))).trim();
if(sourceFileName.equals(fNm)){
String destn = (file_destination.substring(file_destination.indexOf(",") + 1)).trim();
if(destn.length() > 0){
directoryPropertyValue = destn; //if destination found only then set value to global var
}
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |