web stats
Transformer Error on create PDF attachment code - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2019, 11:46 AM
aby1098 aby1098 is offline
What's HL7?
 
Join Date: Jun 2019
Posts: 4
aby1098 is on a distinguished road
Default Transformer Error on create PDF attachment code

Hi,
I am migrating channel from Mirth 1.8 to 3.5.1 .
I have a channel that creates pdf attachments and it started giving errors .
I replaced messageObject with connectorMessage . still i am getting the following error.
Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: TDH_AP_REMIT_ADVICE_EMAILER_824
CONNECTOR: sourceConnector
SCRIPT SOURCE: TRANSFORMER
SOURCE CODE:
783: var fisTargetFile = new Packages.java.io.FileInputStream(new Packages.java.io.File(templateFilePath));
784:
785: var styleSheet = Packages.org.apache.commons.io.IOUtils.toString(fi sTargetFile);
786:
787: var replacer = new com.mirth.connect.server.util.TemplateValueReplace r;
788: var template = replacer.replaceValues(styleSheet, connectorMessage);
789:
790: // create w3 document and import stylesheet
791: var builder = new DocumentBuilderFactory.newInstance().newDocumentBu ilder();
792: var buf = new StringBufferInputStream(template.toString());
LINE NUMBER: 788
DETAILS: Can't find method com.mirth.connect.server.util.TemplateValueReplace r.replaceValues(java.lang.String,com.mirth.connect .userutil.ImmutableConnectorMessage).
at ae2dc56b-4c14-40ec-aa55-05b424d9b742:788 (doTransform)
at ae2dc56b-4c14-40ec-aa55-05b424d9b742:830 (doScript)
at ae2dc56b-4c14-40ec-aa55-05b424d9b742:832
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:154)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
----------------------------------------------------------------

Here is the code i am using in transformer.
...

importPackage(Packages.javax.xml.parsers);
importPackage(Packages.org.w3c.dom);
importPackage(Packages.java.io);

var templateFilePath = 'E:\\Program Files\\velocity\\remit_advice_slip.html';
var fisTargetFile = new Packages.java.io.FileInputStream(new Packages.java.io.File(templateFilePath));

var styleSheet = Packages.org.apache.commons.io.IOUtils.toString(fi sTargetFile);

var replacer = new com.mirth.connect.server.util.TemplateValueReplace r;
var template = replacer.replaceValues(styleSheet, connectorMessage);

// create w3 document and import stylesheet
var builder = new DocumentBuilderFactory.newInstance().newDocumentBu ilder();
var buf = new StringBufferInputStream(template.toString());
//var buf = new ByteArrayInputStream(template.toString().getBytes( ));
var document = builder.parse(buf);

// create pdf from html
var renderer = new Packages.org.xhtmlrenderer.pdf.ITextRenderer;
renderer.setDocument(document,null);
renderer.layout();

var PDF = new ByteArrayOutputStream();

renderer.createPDF(PDF,true);

var encDocument = FileUtil.encode(PDF.toByteArray());

channelMap.put('PDFencoded',encDocument);
// encDocument has the base64 encoded PDF file, ready to store in SQL database



Thanks.
AJ
Reply With Quote
  #2  
Old 11-22-2019, 11:55 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,348
cory_cole is on a distinguished road
Default

replacer.replaceValues(styleSheet, connectorMessage);

This is causing your error. I am not aware of this function. So, it may be a user defined function that has not been moved over. Or, with going from 1.8 to 3.5, there is a good possibility that it has become deprecated.
Reply With Quote
  #3  
Old 11-22-2019, 12:04 PM
aby1098 aby1098 is offline
What's HL7?
 
Join Date: Jun 2019
Posts: 4
aby1098 is on a distinguished road
Default

This is the working code in 1.8
...............
importPackage(Packages.javax.xml.parsers);
importPackage(Packages.org.w3c.dom);
importPackage(Packages.java.io);


var templateFilePath = 'c:\\Program Files\\Mirth\\lib\\extensions\\velocity\\remit_adv ice_slip.html';
var fisTargetFile = new Packages.java.io.FileInputStream(new Packages.java.io.File(templateFilePath));

var styleSheet = Packages.org.apache.commons.io.IOUtils.toString(fi sTargetFile);

var replacer = new Packages.org.mule.providers.TemplateValueReplacer;
var template = replacer.replaceValues(styleSheet, messageObject);

// create w3 document and import stylesheet
var builder = new DocumentBuilderFactory.newInstance().newDocumentBu ilder();
var buf = new StringBufferInputStream(template.toString());
//var buf = new ByteArrayInputStream(template.toString().getBytes( ));
var document = builder.parse(buf);

// create pdf from html
var renderer = new Packages.org.xhtmlrenderer.pdf.ITextRenderer;
renderer.setDocument(document,null);
renderer.layout();

var PDF = new ByteArrayOutputStream();

renderer.createPDF(PDF,true);

var encDocument = FileUtil.encode(PDF.toByteArray());

channelMap.put('PDFencoded',encDocument);
// encDocument has the base64 encoded PDF file, ready to store in SQL database
Reply With Quote
  #4  
Old 11-22-2019, 12:36 PM
aby1098 aby1098 is offline
What's HL7?
 
Join Date: Jun 2019
Posts: 4
aby1098 is on a distinguished road
Default

When I remove 'connectorMessage' from line 788 . The Pdf is getting generated without error but without the content .
Reply With Quote
  #5  
Old 11-22-2019, 12:41 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,348
cory_cole is on a distinguished road
Default

I think that mule as been removed. Take a look at this page...

https://github.com/nextgenhealthcare...eValueReplacer
Reply With Quote
  #6  
Old 11-22-2019, 01:45 PM
agermano agermano is online now
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,110
agermano is on a distinguished road
Default

You actually don't need to create replacer yourself. Mirth already has a variable named replacer in the default context that is an instance of TemplateValueReplacer.

The issue is that it wants a ConnectorMessage, but you are passing in an ImmutableConnectorMessage, which is actually not a subclass, but a wrapper instead.

You could instead use the replaceValues(template, channelId, map) method and pass the relevant map (channel?) like
Code:
var template = replacer.replaceValues(styleSheet, channelId, channelMap);
If you need values from multiple maps, you can build a new one with the ones you need. Make sure you add them in the correct order. The configurationMap, globalMap, and globalChannelMap should already be included for you from passing the channelId.
Code:
var replacerMap = new java.util.HashMap();
replacerMap.putAll(sourceMap);
replacerMap.putAll(connectorMap);
replacerMap.putAll(channelMap);
Reply With Quote
  #7  
Old 12-02-2019, 06:14 AM
aby1098 aby1098 is offline
What's HL7?
 
Join Date: Jun 2019
Posts: 4
aby1098 is on a distinguished road
Default

Thank you so much . This resolved my issue .
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:08 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation