This is an old revision of the document!


Call Studio Java Examples

  • Set a session variable myInt to be your number, such as the string “12.0” which gets returned from Set value
  • The below Call Studio Action Java Class will retrieve this value and set the session variable “myString” to “12”
import com.audium.server.AudiumException;
import com.audium.server.voiceElement.ActionElementBase;
import com.audium.server.session.ActionElementData;
 
 
/**
 * This class is called when a standard action has been configured to use a 
 * Java class. Since this is a standard action element, it applies to a 
 * specific application and does not have a configuration. As a result, the 
 * only method needed in this class is the doAction method.
 */
public class ConvertNumToString extends ActionElementBase
{
    /**
     * All action classes must implement this method. The data is retrieved 
     * through the ActionElementData class. Unlike decisions, there is no need 
     * to return anything as all actions have a single exit state.
     */
    public void doAction(String name, ActionElementData data) throws AudiumException
    {
 
    	float tempfloat = Float.parseFloat(data.getSessionData("myInt").toString());
    	int tempint = Math.round(tempfloat);
    	String myString = Integer.toString(tempint);
		data.addToLog("myString", myString);
		data.setSessionData("myString", myString);
 
   	}
}
import com.audium.server.AudiumException;
import com.audium.server.voiceElement.DecisionElementBase;
import com.audium.server.session.DecisionElementData;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
 
public class DecideWriteCallback extends DecisionElementBase {
	public String doDecision(String paramString, DecisionElementData data)
			throws AudiumException {
 
		String filePath = data.getSessionData("textConfigPath").toString();
		String filename = data.getSessionData("filename").toString();
		String callbackdata = data.getSessionData("callbackdata").toString();
 
		String fileWriteResponse = doCallbackWrite(filePath + filename ,callbackdata, data);
 
		if (fileWriteResponse.equalsIgnoreCase("FileError")){
			return "Fail";
		} 
		return "Success";
	}
 
	public String doCallbackWrite(String paramString1, String paramString2,
			DecisionElementData data) throws AudiumException {
		try {
			File localFile = new File(paramString1);
			BufferedWriter localBufferedWriter = new BufferedWriter(
 
			new FileWriter(localFile));
			localBufferedWriter.write(paramString2);
			localBufferedWriter.close();
		} catch (IOException localIOException) {
			data.addToLog("Callback-FILE-WRITE-ERROR", localIOException.toString());
			return "FileError";
		}
 
		return "ok";
	}
 
 
}
// Simple Action Element to Simulate a Delay
// Gerard O'Rourke
// date: 25/10/2017
 
import com.audium.server.AudiumException;
import com.audium.server.voiceElement.ActionElementBase;
import com.audium.server.session.ActionElementData;
 
 
/**
 * This class is called when a standard action has been configured to use a 
 * Java class. Since this is a standard action element, it applies to a 
 * specific application and does not have a configuration. As a result, the 
 * only method needed in this class is the doAction method.
 */
public class ActionDelay extends ActionElementBase
{
    /**
     * All action classes must implement this method. The data is retrieved 
     * through the ActionElementData class. Unlike decisions, there is no need 
     * to return anything as all actions have a single exit state.
     */
    public void doAction(String name, ActionElementData data) throws AudiumException
    {
    	int timer = Integer.parseInt((String) data.getSessionData("delay-in-ms"));
    	try {
			Thread.sleep(timer);
		} catch (InterruptedException e) {
			data.addToLog("ERROR InterruptedException", e.toString());
		}
   	}
}
/* 
 * Author: Gerard O'Rourke
 * date: 28 September 2010
 * 
 * DecideADFileupload.java
 * this Java class uploads a file from a local file share to a nework file share.
 * 
 * the following session variables are required to be set in the CVP Studio Application:
 * smbSource
 * smbDestination
 * domain
 * username
 * password
 * 
 */
 
import com.audium.server.AudiumException;
import com.audium.server.session.DecisionElementData;
import com.audium.server.voiceElement.DecisionElementBase;
import jcifs.smb.*;
 
 
 
public class DecideADFileupload extends DecisionElementBase  
{
  public String doDecision(String name, DecisionElementData data)
	throws AudiumException
  {
	String varSMBSource = data.getSessionData("smbSource").toString();
	String varSMBDestination = data.getSessionData("smbDestination").toString();
 
	String varDomain = data.getSessionData("domain").toString();
	String varUser = data.getSessionData("username").toString();
	String varPassword = data.getSessionData("password").toString();
 
	jcifs.Config.setProperty( "jcifs.smb.client.domain", varDomain);
	jcifs.Config.setProperty( "jcifs.smb.client.username", varUser);
	jcifs.Config.setProperty( "jcifs.smb.client.password", varPassword);
 
	try 	{
        SmbFile remote = new SmbFile( varSMBSource );
            if( remote.exists() ) {
                SmbFile local = new SmbFile( varSMBDestination );
                remote.copyTo( local );
            	return "Success";
            }
            else{
            	data.logWarning("FileUploadError: " + varSMBSource + " -> " + varSMBDestination);
            	return "Fail";
            }
        } catch( Exception e ) {
        	data.logWarning("FileUploadError: " + varSMBSource + " -> " + varSMBDestination);
        	data.logWarning("FileUploadError: " + e.toString());
            return "Fail";
        }
    }
 
}
  • vendors/cisco/uc/ucce/cvp/java.1550664088.txt.gz
  • Last modified: 2019/02/20 12:01
  • by gerardorourke