Search in sources :

Example 6 with IAttribute

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

the class XMLSerializer method toXML.

private static synchronized String toXML(IAttributeMap l) {
    StringBuffer c = new StringBuffer();
    c.append("<attributes>");
    Iterator i = l.iterator();
    IAttribute a = null;
    while (i.hasNext()) {
        a = ((IAttribute) i.next());
        c.append("<attribute name=\"" + a.getName() + "\" value=\"" + encode(a.getValue()) + "\" />");
    }
    c.append("</attributes>");
    return c.toString();
}
Also used : Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute)

Example 7 with IAttribute

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

the class GoogleMapsDialogPlugin method buildRequestParameters.

private String buildRequestParameters(ICaller c) {
    StringBuffer params = new StringBuffer();
    IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    return params.toString();
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute)

Example 8 with IAttribute

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

the class EditorController method deleteElements.

public synchronized void deleteElements(Object list) {
    if (list != null && list instanceof ICallerList) {
        Map cms = new HashMap();
        ICallerList tmplist = null;
        ICaller c = null;
        for (int i = 0; i < ((ICallerList) list).size(); i++) {
            c = ((ICallerList) list).get(i);
            IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
            String cname = (att == null ? "all" : att.getValue());
            if (cms.containsKey(cname)) {
                tmplist = (ICallerList) cms.get(cname);
                tmplist.add(c);
            } else {
                tmplist = this.getRuntime().getCallerFactory().createCallerList(1);
                tmplist.add(c);
                cms.put(cname, tmplist);
            }
        }
        List managers = this.getActiveCallerManagers();
        ICallerManager mgr = null;
        for (int i = 0; i < managers.size(); i++) {
            mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
            if (mgr != null) {
                if (mgr.isSupported(IWriteCallerRepository.class)) {
                    tmplist = (ICallerList) cms.get("all");
                    if (tmplist != null) {
                        this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
                        ((IWriteCallerRepository) mgr).removeCaller(tmplist);
                    }
                    tmplist = (ICallerList) cms.get(mgr.getManagerID());
                    if (tmplist != null) {
                        this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
                        ((IWriteCallerRepository) mgr).removeCaller(tmplist);
                    }
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) Map(java.util.Map) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 9 with IAttribute

use of de.janrufmonitor.framework.IAttribute 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 10 with IAttribute

use of de.janrufmonitor.framework.IAttribute 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

IAttribute (de.janrufmonitor.framework.IAttribute)111 ICaller (de.janrufmonitor.framework.ICaller)44 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)40 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)39 List (java.util.List)34 ICallerList (de.janrufmonitor.framework.ICallerList)31 ArrayList (java.util.ArrayList)29 Iterator (java.util.Iterator)25 ICall (de.janrufmonitor.framework.ICall)19 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)15 SQLException (java.sql.SQLException)15 File (java.io.File)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)12 IOException (java.io.IOException)12 Message (de.janrufmonitor.exception.Message)11 ComFailException (com.jacob.com.ComFailException)10 Date (java.util.Date)10 IMsn (de.janrufmonitor.framework.IMsn)9 Dispatch (com.jacob.com.Dispatch)8 UUID (de.janrufmonitor.util.uuid.UUID)8