Wednesday, August 29, 2012

Google Voice (SMS) with TDI

Recently I've been working on an Assemblyline line which needed to send sms notification.  As most know, TDI already provides a sendMail() method in its UserFunction class to send email.  Using this method allows messages to be sent to phone numbers which have a service provider email address (e.g. 5552224444@txt.att.net).

However some providers like Google Voice(GV), do not provide this number@email option.
So with this limitation it took a little searching to find another option.

I found by using the google-voice-java API (api docs) we can send sms messages via TDI directly to a phone number, instead of relying on a phonenumber@email address.

JARs are available at:
http://code.google.com/p/google-voice-java/downloads/list

At the time of this posting, there were 5 jars (google-voice-java-1.14-java6.jar, dom4j-1.6.1.jar,
jaxen-1.1.3.jar, json.jar, jtidy.jar).
Simply add the jars to the <TDI>\jars\3rdparty\others\GoogleVoice directory

You can then use the following function from your Resource/Script library to to send sms from TDI by the way of Google Voice.



/*
 * sendGVsms uses the api made available at
 * http://code.google.com/p/google-voice-java/w/list
 */
function sendGVsms(dst,txt){
    try{
        destinationNumber = dst;
        txt = txt;
        username = system.getTDIProperty("gvuserName")
        pass = system.getTDIProperty("gvpass")
        var gvoice = Packages.com.techventus.server.voice.Voice(username,pass);
        gvoice.sendSMS(destinationNumber,txt);
        } catch (e) {
            task.logmsg(">>sms error " +e);
    }
}


NOTE:  You will need to add Google's  public certificate to the TDI truststore, otherwise you'll receive a 'java.lang.reflect.InvocationTargetException' when calling the class.

I used the following information to obtain and add the certificate to the TDI truststore.

1. Obtaining the Google certificate
a. 


b. 


c.

d.  Choose a 'Save as type' of DER when exporting the certificate.

2. Adding the certificate into the default TDI truststore.
By default, a TDI 7.x installation uses the serverapi/truststore.jks as its truststore.
This file location may vary depending on if you have a specific Solution Directory, or if the TDI Install directory is the Solution directory.  You can refer to the contents of the <TDI_Install>/bin/defaultSolDir.bat to determine the default Solution directory.

The TDI Component as a Client section in the TDI Infocenter discusses the importation of a certificate.
Here's an example of the command to import the google certificate into the testadmin.jks file.

<TDI>/jvm/jre/bin/keytool -import -trustcacerts -file google.der -keystore testadmin.jks -storepass administrator -alias googleCert





Thursday, November 17, 2011

Passing Initialization Parameters via tdisrvctl


I found the following process to work if you want to pass initialization parameters to a connector, via the command line.

For further details on parameters used for the 'tdisrvctl' command, refer to the docs.
Due to an APAR with the 'tdisrvctl' utiltity, you will need to be at TDIv7.1 FP0006 for the '-alop' parameter to parse correctly.


1.  Use the 'op-entry' object in the connector's configuration to access the passed in value.
All initialization attributes are to be prefixed with $init





























2.  When calling the 'tdisrvclt' utility,  use the '-alop' parameter to pass the value pairs to the server.
You can refer to the documentation link above for further details about this parameter.

Syntax:
bin\tdisrvctl -p 1099 -K serverapi\testadmin.jks
-P administrator -T testserver.jks -W server -op start -c config.xml -r SampleAL -alop $initialize {parameter:value;parameter:value}

Windows Exmaple:
\bin\tdisrvctl -p 1099 -K serverapi\testadmin.jks -P administrator -T testserver.jks -W server -op start -c config.xml -r SampleAL-alop $initialize {$init.oraId:oradmin;$init.oraPwd:abc123}

Linux Example:
./bin/tdisrvctl -p 1099 -K serverapi/testadmin.jks -P administrator -T testserver.jks -W server -op start -c config.xml -r SampleAL -alop \$initialize '{$init.oraId:oradmin;$init.oraPwd:abc123}'


------
Passing Initialization Parameters to the startAL() method via the tdisrvctl utility:
Here's a simple AL with the following in the AL Prolog.

//------------------------------------------------//
var stats;
var error;
var num;
var adds;
var result;

var OpEntry = task.getOpEntry();
var tcb = system.newTCB();

tcb.setConnectorParameter ( "JDBCconnector", "jdbcLogin", OpEntry.getString("$init.oraId"));
tcb.setConnectorParameter ( "JDBCconnector", "jdbcPassword", OpEntry.getString("$init.oraPwd"));

task.logmsg("**** Check Emp Status ******");
var check = main.startAL("AL1",tcb);
check.join();
result = check.getResult();
stats = task.getStats();
error=stats.getError();
num=stats.numErrors();

if (num == 0 ){
    task.logmsg("**** Running Emp Update ******");
    var empUpdate = main.startAL("AL2",tcb);
    empUpdate.join();
    result = empUpdate.getResult();
    stats = task.getStats();
    error=stats.getError();
    num=stats.numErrors();
    adds=stats.numAdd();

    task.logmsg("stats are: "+stats);
    task.logmsg("error is "+error);
    task.logmsg("numerrors is "+num);  
    task.logmsg("**** Run complete ******");
}else{
task.logmsg("**** Run ended ******");
        task.exit
}
//------------------------------------------------//


Commandline Command:

bin\tdisrvctl -p 1099 -K serverapi\testadmin.jks
-P administrator -T testserver.jks -W server -op start -c config.xml -r SampleAL -alop $initialize {parameter:value;parameter:value}



Monday, September 19, 2011

Solution Portability


Here's an additional option of making a solution easily portable/testable between QA, Dev, and Production environments.

When developing within the TDI Config Editor we want to make the most of the flexibility provided in Eclipse.  In this example we want to create a Property store for each environment which you'll be testing your Assemblyline against.

Here's an example of my Property Stores:



















-- Script References:
When referencing an property from a Property Store...reference the Property Name only.
Not the Property Store Name. With out declaring the Property Store Name, the TDI Server will pull the value from the Default Property Store.  Use setParam(string), not setParam(String,String) when referencing the property.
















-- 'Use Property' Reference:
When setting the value of a Connector's Field, there's many different ways to do this.
I believe the easiest approach is the 'Use Property' option.

When using the 'Use Property' option of a Field definition you'll see it automatically adds the Property Store Name to the Property Name.  This occurs when you select the property from your available properties.


By removing the Property Store Name (in the above example it would be 'Customer_Test:') the server will pull the Property Name from the Default Property Store.



-- Setting the Default Property Store
Now that we've set the solution to read the values from the Default Property Store, and not a particular Property Store we can easily and quickly redirect the direction of an AL just by selecting which Property Store we indicate as the Default Property Store.

To set the Default Property Store, just right click any of your Property Stores and select 'Default Property Store'.


On your next AL execution, the AL will read all it's property values from this particular Property Store.


-- Required Environment: