Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Using Correct Java Sytax in Mirth via Javascript (http://www.mirthcorp.com/community/forums/showthread.php?t=14173)

dre4967 05-05-2015 10:34 PM

Using Correct Java Sytax in Mirth via Javascript
 
I'm using a custom library called aspose.words and I running into some trouble making sure I user the correct java classes and javascript syntax in Mirth to properly using Library via Mirth.

I need to know how to translate byte[] buffer and ByteArrayInputStream in Mirth, see snippet of code in Java below.

Mirth Version 3.2


Code:

// The document is stored in byte form in the FileContent column.
    // Retrieve these bytes of the first matching record to a new buffer.
    byte[] buffer = resultSet.getBytes("FileContent");

    // Wrap the bytes from the buffer into a new ByteArrayInputStream object.
    ByteArrayInputStream newStream = new ByteArrayInputStream(buffer);


arpitgoel 05-06-2015 02:57 AM

Please follow the below link for using java code in mirth
http://www.mirthcorp.com/community/w...ode+from+Mirth

You need to copy your custom library jar file in mirthconnect/custom-lib folder and then you can create an object of a class :

Code:

var object = new Packages.org.example.Class1();
var object2 = new Packages.org.example.Class1(<param>);


dre4967 05-06-2015 05:29 AM

Thanks, I do know how to add the jar in the custom lib and access the java package but I wanted to know for these particular java methods below does anyone know how these would look using them in Mirth. These below are part of the default java library.

// The document is stored in byte form in the FileContent column.
// Retrieve these bytes of the first matching record to a new buffer.
byte[] buffer = resultSet.getBytes("FileContent");

// Wrap the bytes from the buffer into a new ByteArrayInputStream object.
ByteArrayInputStream newStream = new ByteArrayInputStream(buffer);

narupley 05-06-2015 08:30 AM

The code is almost the same in JavaScript. Except, you should be using "var", because it's JavaScript. Also you need to invoke Java classes using fully-qualified class names, or import the package first.

Code:

    // The document is stored in byte form in the FileContent column.
    // Retrieve these bytes of the first matching record to a new buffer.
    var buffer = resultSet.getBytes("FileContent");

    // Wrap the bytes from the buffer into a new ByteArrayInputStream object.
    var newStream = new java.io.ByteArrayInputStream(buffer);


dre4967 05-06-2015 09:58 AM

Thanks narupley, here is my code, I just got this error because I'm working with a Blob data type in SQL. I'm using aspose words library to convert word document from database to a readable format. Looks like when I call getBytes on a blob datatype it is not liking it. I have more code to write but I'm just testing query column that has the binary version of the word document and then using the aspose words library to convert it to readable text.

LINE NUMBER: 162
DETAILS: Can't find method javax.sql.rowset.serial.SerialBlob.getBytes().

importPackage(Packages.com.aspose.words);
importPackage(java.io);


Code:

        var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://10.5.18.87:1433/train','sa','amicas2');
        dbSQL =        "SELECT DOC_TEXT from W_PATIENT_DOC_TEXT "
       
        logger.debug ("SQL: " + dbSQL);
       
        var dbResult = dbConn.executeCachedQuery(dbSQL);
       

        while (dbResult.next())
        {
                var buffer = dbResult.getBlob("DOC_TEXT").getBytes();
                var newStream = new java.io.ByteArrayInputStream(buffer);
                var doc = new Document(newStream);
                logger.debug(doc.toString(SaveFormat.TEXT));
        }
       
        dbResult.close();
        dbConn.close();


dre4967 05-11-2015 12:37 PM

I don't have this error anymore, after using the primary database source here is the final code. If using Blob type see commented code.


while (dbResult.next())
{
bFound = 1;
mrisReportFound = 1;
//var blob = dbResult.getBlob(4);
//var buffer = blob.getBytes(1,blob.length());
var buffer = dbResult.getBytes(4);
var newStream = new java.io.ByteArrayInputStream(buffer);
var doc = new Document(newStream);
var wordConverted = doc.toString(SaveFormat.TEXT);
//var wordConverted = doc.toString(SaveFormat.HTML);

//BUILD REPORT
fullReport += wordConverted;
}


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

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