Search in sources :

Example 6 with IPhonenumber

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

the class MacAddressBookProxy method getContactsByAreaCode.

@SuppressWarnings("unchecked")
public synchronized ICallerList getContactsByAreaCode(String countrycode, String areacode) throws MacAddressBookProxyException {
    this.m_total = 0;
    this.m_current = 0;
    final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    if (this.m_dbh != null) {
        try {
            List uuids = this.m_dbh.select(countrycode, areacode);
            if (uuids.size() > 0) {
                List contacts = getRecordsByUIDs(uuids);
                if (contacts.size() > 0) {
                    this.m_total = contacts.size();
                    ICaller businessCaller, privateCaller = null;
                    for (Object contact : contacts) {
                        if (contact instanceof Map<?, ?>) {
                            this.m_current++;
                            privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
                            businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
                            if (privateCaller == null && businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
                                callers.add(businessCaller);
                            }
                            if (privateCaller != null && businessCaller == null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
                                callers.add(privateCaller);
                            }
                            if (privateCaller != null && businessCaller != null) {
                                if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
                                    // only one entry available
                                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
                                    IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
                                        this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
                                        businessCaller = null;
                                    }
                                }
                                if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
                                    // only one entry available
                                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
                                    IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
                                        this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
                                        privateCaller = null;
                                    }
                                }
                                if (privateCaller != null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
                                    callers.add(privateCaller);
                                }
                                if (businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
                                    callers.add(businessCaller);
                                }
                            }
                        }
                    }
                }
            }
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    if (callers.size() > 0) {
        Thread updateDbhThread = new Thread() {

            public void run() {
                updateProxyDatabase(callers);
            }
        };
        updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
        updateDbhThread.start();
    }
    return callers;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) PrivateMacAddressBookMapping(de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping) SQLException(java.sql.SQLException) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) BusinessMacAddressBookMapping(de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping) HashMap(java.util.HashMap) Map(java.util.Map) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 7 with IPhonenumber

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

the class Callto method generateHtml.

private StringBuffer generateHtml(Object o, String dial, String ext) {
    StringBuffer html = new StringBuffer();
    html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" + IJAMConst.CRLF);
    html.append("<html>" + IJAMConst.CRLF);
    html.append("<head>" + IJAMConst.CRLF);
    html.append("<title>");
    html.append("Callto");
    html.append("</title>" + IJAMConst.CRLF);
    html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + IJAMConst.CRLF);
    html.append("<link rel=\"stylesheet\" href=\"/config/web-config/styles/jam-styles.css\" type=\"text/css\">" + IJAMConst.CRLF);
    html.append("<link rel=\"SHORTCUT ICON\" href=\"/config/web-config/images/favicon.ico\" type=\"image/ico\" />");
    html.append("</head>" + IJAMConst.CRLF);
    html.append("<body>" + IJAMConst.CRLF);
    if (dial != null && dial.length() > 1) {
        dial = PhonenumberAnalyzer.getInstance(getRuntime()).toCallable(dial);
        IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(dial);
        try {
            Method m = o.getClass().getMethod("dial", new Class[] { IPhonenumber.class, String.class });
            if (ext != null) {
                ext = URLDecoder.decode(ext, "UTF-8");
            }
            m.invoke(o, new Object[] { pn, ext });
            html.append("Call to 0");
            html.append(pn.getTelephoneNumber());
            html.append(" successfully established" + (ext != null ? " on line " + ext : "") + ". Take the head phone...");
            html.append(IJAMConst.CRLF);
        } catch (Exception ex) {
            html.append(ex.getMessage());
            html.append(IJAMConst.CRLF);
        }
    } else {
        html.append("Wrong callto syntax: http://&lt;server&gt;:&lt;port&gt;/callto?dial=&lt;number&gt;[&ext=&lt;extension&gt;]");
        html.append(IJAMConst.CRLF);
    }
    html.append("</body>" + IJAMConst.CRLF);
    html.append("</html>" + IJAMConst.CRLF);
    return html;
}
Also used : Method(java.lang.reflect.Method) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 8 with IPhonenumber

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

the class XMLSerializer method toXML.

private static synchronized String toXML(List phones) {
    StringBuffer c = new StringBuffer();
    c.append("<phonenumbers>");
    Iterator i = phones.iterator();
    IPhonenumber a = null;
    while (i.hasNext()) {
        a = ((IPhonenumber) i.next());
        c.append("<phonenumber intarea=\"" + encode(a.getIntAreaCode()) + "\" area=\"" + encode(a.getAreaCode()) + "\" callnumber=\"" + encode(a.getCallNumber()) + "\" telephonenumber=\"" + encode(a.getTelephoneNumber()) + "\" />");
    }
    c.append("</phonenumbers>");
    return c.toString();
}
Also used : Iterator(java.util.Iterator) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 9 with IPhonenumber

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

the class GetCaller method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(GetCaller.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IIdentifyCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    String number = null;
    try {
        number = req.getParameter(GetCaller.PARAMETER_NUMBER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (number == null || number.length() == 0) {
        this.m_logger.severe("Parameter &number= was empty or not set.");
        throw new HandlerException("Parameter &number= was empty or not set.", 404);
    }
    IPhonenumber pn = null;
    StringTokenizer st = new StringTokenizer(number, ";");
    if (st.countTokens() == 3) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
    }
    if (st.countTokens() == 2) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
    }
    if (st.countTokens() == 1) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
    }
    try {
        ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
        String xml = XMLSerializer.toXML(caller, false);
        resp.setParameter("Content-Type", "text/xml");
        resp.setParameter("Content-Length", Long.toString(xml.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(xml.getBytes());
        ps.flush();
        ps.close();
    } catch (CallerNotFoundException e) {
        throw new HandlerException(e.getMessage(), 404);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) StringTokenizer(java.util.StringTokenizer) OutputStream(java.io.OutputStream) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 10 with IPhonenumber

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

the class Image method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(Image.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IIdentifyCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    String number = null;
    try {
        number = req.getParameter(Image.PARAMETER_NUMBER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (number == null || number.length() == 0) {
        this.m_logger.severe("Parameter &number= was empty or not set.");
        throw new HandlerException("Parameter &number= was empty or not set.", 404);
    }
    IPhonenumber pn = null;
    StringTokenizer st = new StringTokenizer(number, ";");
    if (st.countTokens() == 3) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
    }
    if (st.countTokens() == 2) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
    }
    if (st.countTokens() == 1) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
    }
    try {
        ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
        IAttribute imageAtt = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH);
        if (ImageHandler.getInstance().hasImage(caller)) {
            InputStream in = ImageHandler.getInstance().getImageStream(caller);
            if (in != null) {
                resp.setParameter("Content-Type", this.getMimetype("jpg"));
                OutputStream ps = resp.getContentStreamForWrite();
                byte[] buffer = new byte[8092];
                int bytesRead;
                while ((bytesRead = in.read(buffer)) != -1) {
                    ps.write(buffer, 0, bytesRead);
                }
                in.close();
                ps.flush();
                ps.close();
            }
        } else if (imageAtt != null) {
            String pathToImage = PathResolver.getInstance(getRuntime()).resolve(imageAtt.getValue());
            File image = new File(pathToImage);
            if (image.exists()) {
                resp.setParameter("Content-Type", this.getMimetype(pathToImage));
                resp.setParameter("Content-Length", Long.toString(image.length()));
                OutputStream ps = resp.getContentStreamForWrite();
                FileInputStream in = new FileInputStream(image);
                byte[] buffer = new byte[8092];
                int bytesRead;
                while ((bytesRead = in.read(buffer)) != -1) {
                    ps.write(buffer, 0, bytesRead);
                }
                in.close();
                ps.flush();
                ps.close();
            } else {
                throw new CallerNotFoundException("Image " + pathToImage + " not found");
            }
        } else {
            throw new CallerNotFoundException("No image assigned for caller " + caller);
        }
    } catch (CallerNotFoundException e) {
        throw new HandlerException(e.getMessage(), 404);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) FileInputStream(java.io.FileInputStream) ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) IAttribute(de.janrufmonitor.framework.IAttribute) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IPhonenumber (de.janrufmonitor.framework.IPhonenumber)99 ICaller (de.janrufmonitor.framework.ICaller)62 List (java.util.List)49 ArrayList (java.util.ArrayList)44 IAttribute (de.janrufmonitor.framework.IAttribute)38 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)37 ICallerList (de.janrufmonitor.framework.ICallerList)36 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)26 ICall (de.janrufmonitor.framework.ICall)19 SQLException (java.sql.SQLException)19 IMsn (de.janrufmonitor.framework.IMsn)17 Date (java.util.Date)17 IOException (java.io.IOException)16 ICip (de.janrufmonitor.framework.ICip)13 IName (de.janrufmonitor.framework.IName)13 File (java.io.File)13 Iterator (java.util.Iterator)13 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)9 UUID (de.janrufmonitor.util.uuid.UUID)9 FileInputStream (java.io.FileInputStream)9