开发者

Mirth: How to get source file directory from file reader channel

I have a file reader channel p开发者_如何转开发icking up an xml document. By default, a file reader channel populates the 'originalFilename' in the channel map, which ony gives me the name of the file, not the full path. Is there any way to get the full path, withouth having to hard code something?


You can get any of the Source reader properties like this:

var sourceFolder = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance().getDeployedChannelById(channelId).getSourceConnector().getProperties().getProperty('host');

I put it up in the Mirth forums with a list of the other properties you can access http://www.mirthcorp.com/community/forums/showthread.php?t=2210


You could put the directory in a channel deploy script:

globalChannelMap.put("pickupDirectory", "/Mirth/inbox");

then use that map in both your source connector:

${pickupDirectory}

and in another channel script:

function getFileLastModified(fileName) {
   var directory = globalChannelMap.get("pickupDirectory").toString();
   var fullPath = directory + "/" + fileName;
   var file = Packages.java.io.File(fullPath);
   var formatter = new Packages.java.text.SimpleDateFormat("yyyyMMddhhmmss"); 
   formatter.setTimeZone(Packages.java.util.TimeZone.getTimeZone("UTC")); 
   return formatter.format(file.lastModified()); 
};


Unfortunately, there is no variable or method for retrieving the file's full path. Of course, you probably already know the path, since you would have had to provide it in the Directory field. I experimented with using the preprocessor to store the path in a channel variable, but the Directory field is unable to reference variables. Thus, you're stuck having to hard code the full path everywhere you need it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜