Search in sources :

Example 1 with IName

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

the class IncomingCall method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    IPhonenumber pn = null;
    try {
        String phone = req.getParameter(IncomingCall.PARAMETER_NUMBER);
        if (phone == null || phone.length() == 0)
            pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
        else
            pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
        IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
        ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
        ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(IncomingCall.PARAMETER_CIP), "");
        IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(IncomingCall.PARAMETER_MSN), "");
        Date date = new Date(Long.parseLong(req.getParameter(IncomingCall.PARAMETER_DATE)));
        ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
        call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
        ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
        Thread sender = new Thread(new HandlerThread(call, this));
        sender.start();
        resp.getContentStreamForWrite().close();
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 2 with IName

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

the class EabFileCallerImporter method doImport.

public ICallerList doImport() {
    this.m_current = 0;
    m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    Date startDate = new Date();
    File db = new File(m_filename);
    try {
        FileInputStream in = new FileInputStream(db);
        Properties addressbook = new Properties();
        addressbook.load(in);
        in.close();
        m_total = Integer.parseInt(addressbook.getProperty("total", "1"));
        boolean hasMore = true;
        int i = 1;
        String key = null;
        while (hasMore && addressbook.size() > 0) {
            key = addressbook.getProperty(i + ".phonecount");
            addressbook.remove(i + ".phonecount");
            // found old format
            if (key == null) {
                key = addressbook.getProperty(i + ".phone");
                addressbook.remove(i + ".phone");
                if (key != null && key.length() > 0) {
                    IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
                    pn.setCallNumber(key);
                    pn.setAreaCode(addressbook.getProperty(i + ".area"));
                    addressbook.remove(i + ".area");
                    key = addressbook.getProperty(i + ".intarea");
                    addressbook.remove(i + ".intarea");
                    if (key == null || key.length() == 0)
                        key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
                    pn.setIntAreaCode(key);
                    IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
                    IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
                    Enumeration en = addressbook.keys();
                    List keys = new ArrayList();
                    while (en.hasMoreElements()) {
                        key = (String) en.nextElement();
                        if (key.startsWith(i + ".")) {
                            keys.add(key);
                            m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
                        }
                    }
                    if (keys.size() > 0) {
                        for (int j = 0; j < keys.size(); j++) {
                            addressbook.remove(keys.get(j));
                        }
                        keys.clear();
                        keys = null;
                    }
                    ICaller caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
                    caller.setAttributes(m);
                    this.m_callerList.add(caller);
                    i++;
                } else {
                    this.m_logger.info("Found no more valid keys. Left data: " + addressbook);
                    hasMore = false;
                }
            } else {
                // new format since 5.0.0
                int phonecount = Integer.parseInt(key);
                List phones = new ArrayList(1);
                ICaller caller = null;
                for (int a = 0; a < phonecount; a++) {
                    key = addressbook.getProperty(i + ".phone." + a);
                    addressbook.remove(i + ".phone." + a);
                    if (key != null && key.length() > 0) {
                        IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
                        pn.setCallNumber(key);
                        pn.setAreaCode(addressbook.getProperty(i + ".area." + a));
                        addressbook.remove(i + ".area." + a);
                        key = addressbook.getProperty(i + ".intarea." + a);
                        addressbook.remove(i + ".intarea." + a);
                        if (key == null || key.length() == 0)
                            key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
                        pn.setIntAreaCode(key);
                        phones.add(pn);
                    }
                }
                IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
                IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
                Enumeration en = addressbook.keys();
                List keys = new ArrayList();
                while (en.hasMoreElements()) {
                    key = (String) en.nextElement();
                    if (key.startsWith(i + ".")) {
                        keys.add(key);
                        m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
                    }
                }
                if (keys.size() > 0) {
                    for (int j = 0; j < keys.size(); j++) {
                        addressbook.remove(keys.get(j));
                    }
                    keys.clear();
                    keys = null;
                }
                caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phones);
                caller.setAttributes(m);
                this.m_callerList.add(caller);
                i++;
                this.m_current++;
            }
        }
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find caller backup file " + m_filename);
        return this.m_callerList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callerList;
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported caller file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callerList.size()).toString() + " caller items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return this.m_callerList;
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) FileInputStream(java.io.FileInputStream) ICaller(de.janrufmonitor.framework.ICaller) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) File(java.io.File) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 3 with IName

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

the class OldDatFileCallImporter method parseName.

private IName parseName(String caller) {
    String name = "";
    if (caller.indexOf("( -") > -1) {
        name = caller.substring(0, caller.indexOf("( -"));
    }
    if (caller.indexOf("(0") > -1) {
        name = caller.substring(0, caller.indexOf("(0"));
    }
    StringTokenizer st = new StringTokenizer(name, " ");
    if (st.countTokens() == 1) {
        return PIMRuntime.getInstance().getCallerFactory().createName("", "", st.nextToken());
    }
    if (st.countTokens() == 2) {
        return PIMRuntime.getInstance().getCallerFactory().createName(st.nextToken(), st.nextToken());
    }
    if (st.countTokens() == 3) {
        return PIMRuntime.getInstance().getCallerFactory().createName(st.nextToken(), st.nextToken(), st.nextToken());
    }
    if (st.countTokens() > 3) {
        IName n = PIMRuntime.getInstance().getCallerFactory().createName("", "");
        n.setFirstname(st.nextToken());
        n.setLastname(st.nextToken());
        n.setAdditional(st.nextToken());
        while (st.hasMoreTokens()) {
            n.setAdditional(n.getAdditional() + " " + st.nextToken());
        }
        return n;
    }
    return PIMRuntime.getInstance().getCallerFactory().createName("", "");
}
Also used : StringTokenizer(java.util.StringTokenizer) IName(de.janrufmonitor.framework.IName)

Example 4 with IName

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

the class Serializer method toCaller.

/**
 * Deserializes a byte array stream into an caller object.
 *
 * @param caller caller as a byte array representation.
 * @param runtime runtime to used
 * @return caller object
 * @throws SerializerException
 */
public static ICaller toCaller(byte[] caller, IRuntime runtime) throws SerializerException {
    if (runtime == null)
        throw new SerializerException("Runtime object is not set but required.");
    String callerString = new String(caller);
    // tokenize the input
    StringTokenizer st = new StringTokenizer(callerString, m_token);
    if (st.countTokens() < 8) {
        throw new SerializerException("Caller format is invalid: " + callerString);
    }
    try {
        // Check for new mpc format
        String test = st.nextToken().trim();
        List phones = null;
        if (test.equalsIgnoreCase("mpc")) {
            int phone_count = Integer.parseInt(st.nextToken().trim());
            phones = new ArrayList(phone_count);
            for (int i = 0; i < phone_count; i++) {
                // build number
                IPhonenumber pn = runtime.getCallerFactory().createPhonenumber(// token 1
                decode(st.nextToken().trim()), decode(st.nextToken().trim()), decode(st.nextToken().trim()));
                if (pn.getCallNumber().length() == 0) {
                    pn.setClired(true);
                }
                phones.add(pn);
            }
        } else {
            phones = new ArrayList(1);
            // build number
            IPhonenumber pn = runtime.getCallerFactory().createPhonenumber(// token 1
            test, // token 2
            decode(st.nextToken().trim()), // token 3
            decode(st.nextToken().trim()));
            if (pn.getCallNumber().length() == 0) {
                pn.setClired(true);
            }
            phones.add(pn);
        }
        // build name
        IName name = runtime.getCallerFactory().createName(// token 4
        decode(st.nextToken().trim()), // token 5
        decode(st.nextToken().trim()), // token 6
        decode(st.nextToken().trim()));
        // token 7
        String UUID = decode(st.nextToken().trim());
        // build attributes
        String attString = decode(st.nextToken().trim());
        IAttributeMap attList = runtime.getCallerFactory().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.getCallerFactory().createAttribute(decode(attrib.substring(0, attrib.indexOf(EQUAL))), decodeAttributeValue(attrib.substring(attrib.indexOf(EQUAL) + EQUAL.length())));
                    attList.add(att);
                }
            }
            // check for imagebinary
            if (attList.contains(IJAMConst.ATTRIBUTE_NAME_IMAGEBINARY)) {
                IAttribute imgbinary = attList.get(IJAMConst.ATTRIBUTE_NAME_IMAGEBINARY);
                if (imgbinary != null) {
                    imgbinary.setValue(StringUtils.replaceString(imgbinary.getValue(), IMGLFTOKEN_ESCAPE_SYMBOL, m_imglftoken));
                }
            }
        }
        // create an IMultiPhoneCaller object
        if (test.equalsIgnoreCase("mpc") || phones.size() > 1) {
            return runtime.getCallerFactory().createCaller(UUID, name, phones, attList);
        }
        // create an ICaller object
        return runtime.getCallerFactory().createCaller(UUID, name, (IPhonenumber) phones.get(0), attList);
    } catch (Exception e) {
        throw new SerializerException(e.toString());
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 5 with IName

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

the class CallSimulator method sendEvent.

protected void sendEvent(String number, String msn, String cip) {
    if (number != null && number.length() > 0)
        number = PhonenumberAnalyzer.getInstance(this.getRuntime()).toCallable(number);
    if (!number.startsWith("0") && isRaw) {
        number = "0" + number;
    }
    IEventBroker evtBroker = this.getRuntime().getEventBroker();
    evtBroker.register(this);
    evtBroker.register(this, evtBroker.createEvent(IEventConst.EVENT_TYPE_IDENTIFIED_CALL));
    IPhonenumber phone = PhonenumberAnalyzer.getInstance(this.getRuntime()).toClirPhonenumber(number);
    if (phone == null)
        phone = PhonenumberAnalyzer.getInstance(this.getRuntime()).toInternalPhonenumber(number, msn);
    if (phone == null)
        phone = PhonenumberAnalyzer.getInstance(this.getRuntime()).toPhonenumber(number, msn);
    IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
    ICaller aCaller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phone);
    ICip ocip = PIMRuntime.getInstance().getCallFactory().createCip(cip, "");
    IMsn omsn = PIMRuntime.getInstance().getCallFactory().createMsn(msn, "");
    ICall currentCall = PIMRuntime.getInstance().getCallFactory().createCall(aCaller, omsn, ocip);
    currentCall.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
    IEvent ev = evtBroker.createEvent(IEventConst.EVENT_TYPE_INCOMINGCALL, currentCall);
    evtBroker.send(this, ev);
    evtBroker.unregister(this);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IEvent(de.janrufmonitor.framework.event.IEvent) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) IEventBroker(de.janrufmonitor.framework.event.IEventBroker) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IName (de.janrufmonitor.framework.IName)15 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)12 ICaller (de.janrufmonitor.framework.ICaller)11 ICall (de.janrufmonitor.framework.ICall)6 ICip (de.janrufmonitor.framework.ICip)6 IMsn (de.janrufmonitor.framework.IMsn)6 IAttribute (de.janrufmonitor.framework.IAttribute)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 List (java.util.List)4 StringTokenizer (java.util.StringTokenizer)4 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)3 ICallerList (de.janrufmonitor.framework.ICallerList)3 IEvent (de.janrufmonitor.framework.event.IEvent)2 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)2 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)1