Search in sources :

Example 26 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class Serializer method toCall.

/**
 * Deserializes a byte array stream into an call object.
 *
 * @param call call as a byte array representation.
 * @param runtime runtime to used
 * @return call object
 * @throws SerializerException
 */
public static ICall toCall(byte[] call, IRuntime runtime) throws SerializerException {
    if (runtime == null)
        throw new SerializerException("Runtime object is not set but required.");
    String callString = new String(call);
    if (callString.indexOf(m_ctoken) < 0)
        throw new SerializerException("Call format is invalid. Call is set <" + callString + ">");
    // tokenize the whole input
    StringTokenizer st = new StringTokenizer(callString, m_ctoken);
    if (st.countTokens() != 2)
        throw new SerializerException("Call format is invalid. Found " + st.countTokens() + " tokens, but required are exactly 2.");
    ICaller caller = toCaller(st.nextToken().getBytes(), runtime);
    if (!st.hasMoreTokens())
        throw new SerializerException("Call format is invalid. Second token is empty.");
    // tokenize to call data
    callString = st.nextToken();
    st = new StringTokenizer(callString, m_token);
    if (st.countTokens() < 7)
        throw new SerializerException("Call format is invalid. Token count < 7.");
    // build MSN
    IMsn msn = runtime.getCallFactory().createMsn(// token 1
    decode(st.nextToken().trim()), // token 2
    decode(st.nextToken().trim()));
    if (msn.getMSN().equalsIgnoreCase("*")) {
        msn.setMSN("0");
    }
    // build CIP
    ICip cip = runtime.getCallFactory().createCip(// token 3
    decode(st.nextToken().trim()), // token 4
    decode(st.nextToken().trim()));
    // token 5
    String uuid = decode(st.nextToken().trim());
    // token 6
    Date date = new Date(Long.parseLong(decode(st.nextToken().trim())));
    // build attributes
    String attString = decode(st.nextToken().trim());
    IAttributeMap attList = runtime.getCallFactory().createAttributeMap();
    if (attString.length() > 0) {
        StringTokenizer ast = new StringTokenizer(attString, m_atoken);
        String attrib = null;
        while (ast.hasMoreTokens()) {
            attrib = ast.nextToken().trim();
            if (attrib.indexOf(EQUAL) > -1) {
                IAttribute att = runtime.getCallFactory().createAttribute(decode(attrib.substring(0, attrib.indexOf(EQUAL))), decodeAttributeValue(attrib.substring(attrib.indexOf(EQUAL) + EQUAL.length())));
                attList.add(att);
            }
        }
    }
    return runtime.getCallFactory().createCall(uuid, caller, msn, cip, date, attList);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) ICip(de.janrufmonitor.framework.ICip) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date)

Example 27 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class Identifier method identify.

/**
 * Identifies a caller with all active caller managers specified in the configuration.
 *
 * @param r the current runtime
 * @param pn a valid number, should not be a clired number or null
 * @param activeCallerManagers a list of active caller managers
 * @return an identified ICaller object or null, if not identified by any caller manager
 */
public static ICaller identify(IRuntime r, IPhonenumber pn, List activeCallerManagers) {
    if (activeCallerManagers == null || activeCallerManagers.size() == 0)
        return null;
    long start = System.currentTimeMillis();
    Identifier.logger.info("<---- Begin caller identification ---->");
    Identifier.logger.info("Order of identification: " + activeCallerManagers.toString());
    ICaller identifiedCaller = null;
    int i = 0;
    Object obj = null;
    ICallerManager cm = null;
    while (identifiedCaller == null && i < activeCallerManagers.size()) {
        obj = activeCallerManagers.get(i);
        i++;
        if (obj != null && obj instanceof ICallerManager) {
            cm = (ICallerManager) obj;
            try {
                if (cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
                    identifiedCaller = ((IIdentifyCallerRepository) cm).getCaller(pn);
                    Identifier.logger.info("Caller identified by [" + cm.getManagerID() + "]: " + identifiedCaller);
                }
            } catch (CallerNotFoundException e) {
                Identifier.logger.info("Caller was not identified by [" + cm.getManagerID() + "]: " + e.getMessage());
            }
        } else {
            Identifier.logger.severe("Invalid caller manager object: " + obj);
        }
    }
    Identifier.logger.info("<---- Finished caller identification (" + (System.currentTimeMillis() - start) + " msec.) ---->");
    return identifiedCaller;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 28 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class PhonenumberAnalyzer method toIdentifiedPhonenumber.

/**
 * Creates a valid IPhonenumber object out of a number string. This methods
 * ignores MSN specific settings. The IPhonenumber object is also being
 * identified and phone number is split up into 3 parts: international are
 * code e.g. 49, area code 7261 and phone number 123456789
 *
 * @param number
 *            a raw phone number starting with leading 0
 * @param cleanNumber
 *            if set to true truncate and prefix trim option is executed
 * @return a valid IPhonenumber object which is split up into international
 *         area code, area code and number
 */
public IPhonenumber toIdentifiedPhonenumber(String number, boolean cleanNumber) {
    String normalized_number = this.normalize(number, (!this.isClired(number) && !this.isInternal(number)));
    if (!this.isClired(normalized_number) && !this.isInternal(normalized_number))
        normalized_number = "0" + normalized_number;
    long start = System.currentTimeMillis();
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("<---- Begin number identification ---->");
    ICaller c = Identifier.identifyDefault(getRuntime(), this.toPhonenumber(normalized_number, null, cleanNumber));
    if (c != null) {
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("PhonenumberAnalyzer formats number to: [" + c.getPhoneNumber().toString() + "]");
            this.m_logger.info("<---- Finished number identification (" + (System.currentTimeMillis() - start) + " msec.) ---->");
        }
        return c.getPhoneNumber();
    }
    if (this.m_logger.isLoggable(Level.INFO)) {
        this.m_logger.info("PhonenumberAnalyzer did NOT identify number: [" + number + "], normalized: [" + normalized_number + "]");
        this.m_logger.info("<---- Finished number identification (" + (System.currentTimeMillis() - start) + " msec.) ---->");
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller)

Example 29 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class OpenTellows method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            if (o instanceof ICall) {
                o = ((ICall) o).getCaller();
            }
            if (o instanceof ICaller) {
                if (!((ICaller) o).getPhoneNumber().isClired() && !PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(((ICaller) o).getPhoneNumber()) && (((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase("49") || ((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase("41") || ((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase("43"))) {
                    StringBuffer url = new StringBuffer();
                    url.append("http://www.tellows.");
                    if (((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase("49"))
                        url.append("de");
                    if (((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase("43"))
                        url.append("at");
                    if (((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase("41"))
                        url.append("ch");
                    url.append("/num/0");
                    url.append(((ICaller) o).getPhoneNumber().getTelephoneNumber());
                    if (this.m_logger.isLoggable(Level.INFO))
                        this.m_logger.info("Found valid web url to execute: " + url.toString());
                    Program.launch(url.toString());
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 30 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class ThunderbirdTransformer method parseMap.

private ICallerList parseMap(Map mx) {
    this.m_current++;
    Map m = new HashMap();
    m.putAll(mx);
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList(2);
    ICaller c = null;
    if (this.checkWork(m)) {
        c = buildWorkContact(m);
        if (c != null)
            cl.add(c);
    }
    if (this.checkHome(m)) {
        c = buildHomeContact(m);
        if (c != null)
            cl.add(c);
    }
    return cl;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Aggregations

ICaller (de.janrufmonitor.framework.ICaller)144 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)62 ICallerList (de.janrufmonitor.framework.ICallerList)49 List (java.util.List)46 IAttribute (de.janrufmonitor.framework.IAttribute)42 ICall (de.janrufmonitor.framework.ICall)41 ArrayList (java.util.ArrayList)40 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)32 SQLException (java.sql.SQLException)26 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)25 IOException (java.io.IOException)25 Viewer (org.eclipse.jface.viewers.Viewer)24 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 File (java.io.File)20 Date (java.util.Date)17 Iterator (java.util.Iterator)17 Shell (org.eclipse.swt.widgets.Shell)17 IMsn (de.janrufmonitor.framework.IMsn)16 Properties (java.util.Properties)15 ICip (de.janrufmonitor.framework.ICip)14