cancel
Showing results for 
Search instead for 
Did you mean: 

how to handle Directory in File receiver adapter

Former Member
0 Kudos

Hi

I have a Mail (attachment) to File scenario in PI 7.11, where I need to send the message to one directory, if a certain condition is meet and an other direktory if that condition i not meet.

More specifically, then my initial java mapping picks up 2 files and if the files cover the same period, then they should be merged and then sent to the following message mapping in the Operation mapping and after that sent to "Folder1". I have specified this Folder one in the receiver file communication channel.

If the two files are not covering the same period, then the message should be sent to "Folder2" (which works as a trash folder). This Folder2 is specified in the javamapping by using dynamic configuration.

In the receiver file communication channel I have ticked the "Directory" under Adapter-Specific Message Attributes.

However, it all works fine, when the two files are NOT covering the same period, cause then the "Directory" variable is set under dynamic configuration by the java mapping, but when the two files DO cover the same period, then the file adapter errors cause I have ticked the "Directory" under ASMA but not assigned the variable under dynamic configuration.

Of cause, one solution would be to assign the value for Folder1" in the java mapping, e.g. via a value mapping lookup, but I would like to avoid this.

Is there a smart way to solve this challenge?

Some code extracts:

if (samePeriod(sb6157,sb6158))

{

StringBuffer sboutput = mergeFiles(sb6157, sb6158);

os.write(sboutput.toString().getBytes());

}

else

{

updateDynamicConfiguration("http://sap.com/xi/XI/System/File","Directory","

*********
test$
MILUN
trash");

copyStream(is,os);

}

private boolean samePeriod(StringBuffer sb6157, StringBuffer sb6158)

{

int startText6157 = sb6157.indexOf("<PROCESSING_PERIOD_START>");

int endText6157 = sb6157.indexOf("</PROCESSING_PERIOD_START>");

String date6157 = (sb6157.substring(startText6157 +25, endText6157));

int startText6158 = sb6158.indexOf("<PROCESSING_PERIOD_START>");

int endText6158 = sb6158.indexOf("</PROCESSING_PERIOD_START>");

String date6158 = (sb6158.substring(startText6158 +25, endText6158));

return (date6157.equalsIgnoreCase(date6158));

}

Mikael

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I'm not sure to have understand everything on your topic (you merge file inside your java mapping?)... but I suggest you to see this blog: /people/jochen.damzog/blog/2010/10/07/pi-adapter-module-filename-from-payload

I presume you can do the same with the directory, instead of filename.

Regards.

Mickael

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Why dont you use dynamic configuration for both Directory 1 & Directory 2???

I had a similar scenario where we have to define a directory name based on source file names. The sample code is as follows. You can modify this as per your requirement. Let me know if you have any issues.


DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
and
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory");
 
conf.put(key, arg)
String fileName = conf.get(key);
 
if(filename.equals("file1.txt")){
	conf.put(key1, Directory1)
else
	conf.put(key1, Directory2)
 
return "";

Warm Regards,

Gouri

Former Member
0 Kudos

Hi

I solved it by using extended receiver determination.