Custom Plugins

Custom Plugins can be written in java. Each plugin must extend the abstract 'Plugin' class:

 

package au.com.noojee.answerbar.server.plugin;

import idatam.common.asterisk.AsteriskConnectionProperties;
import idatam.common.asterisk.ChannelVariables;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.apache.commons.configuration.Configuration;

import au.com.noojee.answerbar.server.monitor.ExtensionStatus;

public abstract class Plugin
{
    protected List<String>        requiredChannelVariables;
    protected Map<String, String> channelVariables;

    Vector<String>                didFilters   = new Vector<String>();
    Vector<String>                queueFilters = new Vector<String>();

    @SuppressWarnings("unchecked")
    public Plugin(Configuration aConfig)
    {
    requiredChannelVariables = aConfig.getList("params.channelVariable");

    // load filters
    didFilters.addAll(aConfig.getList("filter.didPattern"));
    queueFilters.addAll(aConfig.getList("filter.queue"));
    }

    /**
     * this method is called by noojee answer bar before calling fetchdata to
     * make required channel variables available to the plugin
     *
     * @param acp
     * @param channel
     * @throws Exception
     */
    public void fetchChannelVars(AsteriskConnectionProperties acp, String channel) throws Exception
    {
    channelVariables = new HashMap<String, String>();
    ChannelVariables cv = new ChannelVariables(acp);
    for (String key : requiredChannelVariables)
    {
        String value = cv.getVar(channel, key);
        if (value != null)
        {
        channelVariables.put(key, value);
        }
    }

    }

    /**
     * called once to allow the plugin to fetch it's data, this data should be
     * used for subsiquent calls to the abstract methods.
     *
     * @param callerIdNum
     * @param exten
     * @param didNumber
     * @throws SQLException
     */
    public abstract void fetchData(String callerIdNum, String exten, String didNumber, String queue)
        throws SQLException;

    public abstract Vector<String> getUrl();

    public abstract String getDisplayData();

    public abstract String getPasteData();

    public abstract String getCallerName();

    public boolean matches(ExtensionStatus status)
    {
    boolean matched = false;
    if (status.getDidNumber() == null && status.getQueueName() == null)
    {
        matched = true;
    }
    else if (didFilters.size() == 0 && queueFilters.size() == 0)
    {
        matched = true;
    }
    else
    {
        matched = didFilters.contains(status.getDidNumber()) || queueFilters.contains(status.getQueueName());
    }

    return matched;
    }
}

The resulting class must then be added to the Noojee Answer class path by placing it into 'classes' directory under the Noojee Answer Webapp on the Java Servlet Container.

If you are using Tomcat 6 the directory is normally:

/var/lib/tomcat6/webapps/noojee-answerbar/WEB-INF/classes