web stats
Run Javascript in Channel Context Outside of Mirth - Page 3 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #21  
Old 06-25-2019, 03:29 AM
Jeff Drumm Jeff Drumm is offline
Mirth Newb
 
Join Date: Jun 2019
Posts: 23
Jeff Drumm is on a distinguished road
Default

Quote:
Originally Posted by agermano View Post
Real logger support:
Code:
org.apache.log4j.BasicConfigurator.configure();
var logger = org.apache.log4j.LogManager.getRootLogger();
First line adds a ConsoleAppender to the root logger.

Nice! Thanks
Reply With Quote
  #22  
Old 06-26-2019, 01:43 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 795
agermano is on a distinguished road
Default

Adding this to my init script now. Technically, the sourceMap and configurationMap are supposed to be read-only, but that would make it really hard to stage data in them.

Code:
connectorMap = new java.util.HashMap();
channelMap = new java.util.HashMap();
sourceMap = new java.util.HashMap();
configurationMap = new java.util.HashMap();
responseMap = new java.util.HashMap();
globalMap = com.mirth.connect.server.util.GlobalVariableStore.getInstance();
globalChannelMap = new com.mirth.connect.server.util.GlobalChannelVariableStore();

function $co(key, value) { if (arguments.length == 1) { return connectorMap.get(key); } else { return connectorMap.put(key, value); } }
function $c(key, value) { if (arguments.length == 1) { return channelMap.get(key); } else { return channelMap.put(key, value); } }
function $s(key, value) { if (arguments.length == 1) { return sourceMap.get(key); } else { return sourceMap.put(key, value); } }
function $gc(key, value) { if (arguments.length == 1) { return globalChannelMap.get(key); } else { return globalChannelMap.put(key, value); } }
function $g(key, value) { if (arguments.length == 1) { return globalMap.get(key); } else { return globalMap.put(key, value); } }
function $cfg(key, value) { if (arguments.length == 1) { return configurationMap.get(key); } else { return configurationMap.put(key, value); } }
function $r(key, value) { if (arguments.length == 1) { return responseMap.get(key); } else { return responseMap.put(key, value); } }

function $(string) {
    try { if(responseMap.containsKey(string)) { return $r(string); } } catch(e){}
    try { if(connectorMap.containsKey(string)) { return $co(string); } } catch(e){}
    try { if(channelMap.containsKey(string)) { return $c(string); } } catch(e){}
    try { if(sourceMap.containsKey(string)) { return $s(string); } } catch(e){}
    try { if(globalChannelMap.containsKey(string)) { return $gc(string); } } catch(e){}
    try { if(globalMap.containsKey(string)) { return $g(string); } } catch(e){}
    try { if(configurationMap.containsKey(string)) { return $cfg(string); } } catch(e){}
    return '';
}
Reply With Quote
  #23  
Old 06-26-2019, 06:31 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 795
agermano is on a distinguished road
Default

These functions as well as the map functions in previous post taken from
https://github.com/nextgenhealthcare...ptBuilder.java

Code:
function validate(mapping, defaultValue, replacement) {
    var result = mapping;
    if ((result == undefined) || (result.toString().length == 0)) {
        if (defaultValue == undefined) {
            defaultValue = '';
        }
        result = defaultValue;
    }
    if ('string' === typeof result || result instanceof java.lang.String || 'xml' === typeof result) {
        result = new java.lang.String(result.toString());
        if (replacement != undefined) {
            for (var i = 0; i < replacement.length; i++) { 
                var entry = replacement[i];
                result = result.replaceAll(entry[0], entry[1]);
            }
        }
    }
    return result;
}

// Helper function to create segments
function createSegment(name, msgObj, index) {
    if (arguments.length == 1) { return new XML('<' + name + '></' + name + '>'); };
    if (arguments.length == 2) { index = 0; };
    msgObj[name][index] = new XML('<' + name + '></' + name + '>');
    return msgObj[name][index];
}

// Helper function to create segments after specified field
function createSegmentAfter(name, segment) {
    var msgObj = segment;
    while (msgObj.parent() != undefined) { msgObj = msgObj.parent(); }
    msgObj.insertChildAfter(segment[0], new XML('<' + name + '></' + name + '>'));
    return msgObj.child(segment[0].childIndex() + 1);
}

// Helper function to get the length of an XMLList or array
function getArrayOrXmlLength(obj) {
    if (typeof obj == 'xml' || obj instanceof java.lang.String) {
        return obj.length();
    } else if (typeof obj != 'undefined' && obj != null) {
        return obj.length || 0;
    }
    return 0;
}
Reply With Quote
  #24  
Old 06-27-2019, 02:46 AM
Jeff Drumm Jeff Drumm is offline
Mirth Newb
 
Join Date: Jun 2019
Posts: 23
Jeff Drumm is on a distinguished road
Default

Tony, are you putting all of this into a single initialization file, or creating different versions for specific testing scenarios?
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 05:39 PM.


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