Search in sources :

Example 81 with ICaller

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

the class Map method renderAsImage.

public Image renderAsImage() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICall) {
            this.m_o = ((ICall) this.m_o).getCaller();
        }
        if (this.m_o instanceof ICaller) {
            IAttribute lng = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG);
            IAttribute lat = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT);
            if (lng != null && lat != null) {
                String maptype = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "type");
                String zoom = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "zoom");
                try {
                    File dir = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getPhotoDirectory() + File.separator + "maps" + File.separator);
                    if (!dir.exists())
                        dir.mkdirs();
                    File img = new File(dir, lat.getValue() + lng.getValue() + maptype + zoom);
                    if (!img.exists()) {
                        URL url = new URL("http://maps.googleapis.com/maps/api/staticmap?center=" + lat.getValue() + "," + lng.getValue() + "&zoom=" + zoom + "&size=400x90&maptype=" + maptype + "&sensor=false&markers=color:blue%7Clabel:A%7C" + lat.getValue() + "," + lng.getValue());
                        URLConnection c = url.openConnection();
                        c.setDoInput(true);
                        c.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE; Windows NT)");
                        c.connect();
                        Object o = url.openStream();
                        if (o instanceof InputStream) {
                            BufferedInputStream bin = new BufferedInputStream((InputStream) o);
                            FileOutputStream fos = new FileOutputStream(img);
                            Stream.copy(bin, fos, true);
                            return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
                        }
                        return null;
                    }
                    return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
                } catch (MalformedURLException e) {
                } catch (IOException e) {
                }
            }
        }
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) ICall(de.janrufmonitor.framework.ICall) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) URLConnection(java.net.URLConnection) ICaller(de.janrufmonitor.framework.ICaller) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IAttribute(de.janrufmonitor.framework.IAttribute) File(java.io.File)

Example 82 with ICaller

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

the class JournalBuilder method parseCallerImage.

/**
 * Introduced for console version of html callmanager. Since no renderer are available on console,
 * a mechanism is needed for rendering caller images.
 *
 * @param text
 * @param call
 * @return
 * @throws IOException
 */
private static String parseCallerImage(String text, ICall call) throws IOException {
    String prefix = "<!-- start_caller_image:";
    String postfix = ":end_caller_image-->";
    while (text.indexOf(prefix) >= 0) {
        String token = text.substring(text.indexOf(prefix) + prefix.length(), text.indexOf(postfix));
        String[] elements = token.split(";");
        if (elements.length > 2) {
            continue;
        }
        ICaller c = call.getCaller();
        if (ImageHandler.getInstance().hasImage(c)) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Base64Encoder b64 = new Base64Encoder(bos);
            InputStream fin = ImageHandler.getInstance().getImageStream(c);
            Stream.copy(new BufferedInputStream(fin), b64, true);
            text = StringUtils.replaceString(text, prefix + token + postfix, "<img src=\"data:image/jpeg;base64," + bos.toString() + "\" " + (elements.length == 2 ? "width=\"" + elements[0] + "\" height=\"" + elements[1] + "\" " : "") + "/>");
        } else {
            text = StringUtils.replaceString(text, prefix + token + postfix, "");
        }
    }
    return text;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64Encoder(de.janrufmonitor.util.io.Base64Encoder)

Example 83 with ICaller

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

the class OutgoingCall method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    IPhonenumber pn = null;
    try {
        String phone = req.getParameter(OutgoingCall.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(OutgoingCall.PARAMETER_CIP), "");
        IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(OutgoingCall.PARAMETER_MSN), "");
        Date date = new Date(Long.parseLong(req.getParameter(OutgoingCall.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())));
        call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
        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 84 with ICaller

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

the class OutlookTransformer method createBusinessCallerList.

private ICallerList createBusinessCallerList(Dispatch contact) throws ComFailException {
    ICallerList callerList = getRuntime().getCallerFactory().createCallerList();
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "Firstname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, Dispatch.get(contact, "Lastname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    if (m.size() == 0) {
        attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "CompanyName").toString().trim());
        if (attribute != null)
            m.add(attribute);
    } else {
        attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, Dispatch.get(contact, "CompanyName").toString().trim());
        if (attribute != null)
            m.add(attribute);
    }
    // check if business caller exists
    if (m.size() > 0) {
        m.addAll(createBusinessAddressAttributes(contact));
        List phones = new ArrayList(businessPhones.length);
        IPhonenumber phone = getRuntime().getCallerFactory().createPhonenumber(false);
        String number = null;
        for (int i = 0; i < businessPhones.length; i++) {
            number = Dispatch.get(contact, businessPhones[i]).toString().trim();
            if (number != null && number.length() > 0) {
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer raw number: " + number);
                }
                phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer identified number: " + phone);
                }
                if (phone != null) {
                    if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                        m.add(getNumberTypeAttribute(businessPhones[i], phone.getTelephoneNumber()));
                        phones.add(phone);
                    }
                }
            }
        }
        if (phones.size() > 0) {
            ICaller outlookCaller = getRuntime().getCallerFactory().createCaller(null, phones, m);
            // outlookCaller.setAttributes(m);
            outlookCaller.setUUID(outlookCaller.getName().getLastname() + "_" + outlookCaller.getName().getFirstname() + "_" + outlookCaller.getPhoneNumber().getTelephoneNumber());
            this.setPictureAttribute(outlookCaller, contact);
            IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
            outlookCaller.setAttribute(cm);
            this.m_logger.fine("Created Outlook contact: " + outlookCaller.toString());
            callerList.add(outlookCaller);
        }
    }
    return callerList;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 85 with ICaller

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

the class OutlookTransformer method createPrivateCallerList.

private ICallerList createPrivateCallerList(Dispatch contact) throws ComFailException {
    ICallerList callerList = getRuntime().getCallerFactory().createCallerList();
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "Firstname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, Dispatch.get(contact, "Lastname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    // check if private caller exists
    if (m.size() > 0) {
        m.addAll(createPrivateAddressAttributes(contact));
        List phones = new ArrayList(businessPhones.length);
        IPhonenumber phone = getRuntime().getCallerFactory().createPhonenumber(false);
        String number = null;
        for (int i = 0; i < privatePhones.length; i++) {
            number = Dispatch.get(contact, privatePhones[i]).toString().trim();
            if (number != null && number.length() > 0) {
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer raw number: " + number);
                }
                phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer identified number: " + phone);
                }
                if (phone != null) {
                    if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                        m.add(getNumberTypeAttribute(privatePhones[i], phone.getTelephoneNumber()));
                        phones.add(phone);
                    }
                }
            }
        }
        if (phones.size() > 0) {
            ICaller outlookCaller = getRuntime().getCallerFactory().createCaller(null, phones, m);
            outlookCaller.setUUID(outlookCaller.getName().getLastname() + "_" + outlookCaller.getName().getFirstname() + "_" + outlookCaller.getPhoneNumber().getTelephoneNumber());
            this.setPictureAttribute(outlookCaller, contact);
            IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
            outlookCaller.setAttribute(cm);
            this.m_logger.fine("Created Outlook contact: " + outlookCaller.toString());
            callerList.add(outlookCaller);
        }
    }
    return callerList;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

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