Search in sources :

Example 76 with ICaller

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

the class PIMCapiData method createCallObject.

private ICall createCallObject(String number, String msn, int cip) {
    IPhonenumber phone = PhonenumberAnalyzer.getInstance(getRuntime()).toClirPhonenumber(number);
    if (phone == null)
        phone = PhonenumberAnalyzer.getInstance(getRuntime()).toInternalPhonenumber(number, msn);
    if (phone == null)
        phone = PhonenumberAnalyzer.getInstance(getRuntime()).toPhonenumber("0" + number, msn);
    IName name = this.getRuntime().getCallerFactory().createName("", "");
    ICaller aCaller = this.getRuntime().getCallerFactory().createCaller(name, phone);
    ICip cipObj = this.getRuntime().getCallFactory().createCip(Integer.toString(cip), "");
    IMsn msnObj = this.getRuntime().getCallFactory().createMsn(msn, "");
    ICall c = this.getRuntime().getCallFactory().createCall(aCaller, msnObj, cipObj);
    c.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_BCHANNEL, this.m_plci.toString()));
    c.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_RAW_NUMBER, number));
    c.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
    return c;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 77 with ICaller

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

the class GosPage method createControl.

public void createControl(Composite c) {
    Composite co = new Composite(c, SWT.NONE);
    co.setLayout(new GridLayout(2, false));
    co.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    int operations = DND.DROP_MOVE;
    Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
    DropTarget target = new DropTarget(co, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {

        public void drop(DropTargetEvent event) {
            // A drop has occurred, copy over the data
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            File f = new File(((String[]) event.data)[0]);
            m_logger.info("Detected drag action with file: " + f.getAbsolutePath());
            if (f.exists() && f.getName().toLowerCase().endsWith(".jam.zip")) {
                ZipArchive zip = new ZipArchive(f, false);
                try {
                    zip.open();
                    List files = zip.list(new FilenameFilter() {

                        public boolean accept(File f, String name) {
                            return name.toLowerCase().startsWith("install/repository.") && name.toLowerCase().endsWith(".inf");
                        }
                    });
                    if (files.size() == 1) {
                        m_logger.info("Found a valid generic online module.");
                        Properties inf = new Properties();
                        inf.load(zip.get((String) files.get(0)));
                        String ns = ((String) files.get(0)).substring("install/repository.".length(), ((String) files.get(0)).length() - 4);
                        name.setText(ns);
                        url.setText(inf.getProperty("repository." + ns + ":url:value", ""));
                        offset.setText(inf.getProperty("repository." + ns + ":skipbytes:value", "0"));
                        lastname.setText(inf.getProperty("repository." + ns + ":regexp.lastname:value", ""));
                        firstname.setText(inf.getProperty("repository." + ns + ":regexp.firstname:value", ""));
                        street.setText(inf.getProperty("repository." + ns + ":regexp.street:value", ""));
                        streetno.setText(inf.getProperty("repository." + ns + ":regexp.streetno:value", ""));
                        postal.setText(inf.getProperty("repository." + ns + ":regexp.pcode:value", ""));
                        city.setText(inf.getProperty("repository." + ns + ":regexp.city:value", ""));
                        area.setText(inf.getProperty("repository." + ns + ":regexp.areacode:value", ""));
                        number.setText(inf.getProperty("repository." + ns + ":regexp.phone:value", ""));
                        intarea.setText(inf.getProperty("repository." + ns + ":intareacode:value", ""));
                    }
                    zip.close();
                } catch (ZipArchiveException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                } catch (IOException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    });
    Label l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "name", "label", this.m_language));
    GridData gd = new GridData();
    gd.widthHint = 150;
    name = new Text(co, SWT.BORDER);
    name.setLayoutData(gd);
    name.setText("");
    name.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "version", "label", this.m_language));
    gd = new GridData();
    gd.widthHint = 50;
    version = new Text(co, SWT.BORDER);
    version.setLayoutData(gd);
    version.setText("1.0.0");
    version.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "url", "label", this.m_language));
    url = new Text(co, SWT.BORDER);
    gd.widthHint = 300;
    url.setLayoutData(gd);
    url.setText("");
    url.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "offset", "label", this.m_language));
    offset = new Text(co, SWT.BORDER);
    offset.setText("");
    offset.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "lastname", "label", this.m_language));
    lastname = new Text(co, SWT.BORDER);
    lastname.setLayoutData(gd);
    lastname.setText("");
    lastname.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            lastname.setForeground(new Color(lastname.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "firstname", "label", this.m_language));
    firstname = new Text(co, SWT.BORDER);
    firstname.setText("");
    firstname.setLayoutData(gd);
    firstname.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            firstname.setForeground(new Color(firstname.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "street", "label", this.m_language));
    street = new Text(co, SWT.BORDER);
    street.setLayoutData(gd);
    street.setText("");
    street.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            street.setForeground(new Color(street.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "streetno", "label", this.m_language));
    streetno = new Text(co, SWT.BORDER);
    streetno.setLayoutData(gd);
    streetno.setText("");
    streetno.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            streetno.setForeground(new Color(streetno.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "postal", "label", this.m_language));
    postal = new Text(co, SWT.BORDER);
    postal.setLayoutData(gd);
    postal.setText("");
    postal.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            postal.setForeground(new Color(postal.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "city", "label", this.m_language));
    city = new Text(co, SWT.BORDER);
    city.setLayoutData(gd);
    city.setText("");
    city.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            city.setForeground(new Color(city.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "area", "label", this.m_language));
    area = new Text(co, SWT.BORDER);
    area.setLayoutData(gd);
    area.setText("");
    area.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            area.setForeground(new Color(area.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "number", "label", this.m_language));
    number = new Text(co, SWT.BORDER);
    number.setLayoutData(gd);
    number.setText("");
    number.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
            number.setForeground(new Color(number.getDisplay(), 0, 0, 0));
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "intarea", "label", this.m_language));
    intarea = new Text(co, SWT.BORDER);
    intarea.setText("49");
    intarea.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "locale", "label", this.m_language));
    Locale[] locales = Locale.getAvailableLocales();
    List localeList = new ArrayList(locales.length);
    Locale lo = null;
    for (int i = 0; i < locales.length; i++) {
        lo = locales[i];
        if (lo.toString().indexOf("_") > 0)
            localeList.add(lo);
    }
    Collections.sort(localeList, new Comparator() {

        public int compare(Object l1, Object l2) {
            if (l1 instanceof Locale && l2 instanceof Locale) {
                return ((Locale) l1).getDisplayCountry().compareTo(((Locale) l2).getDisplayCountry());
            }
            return 0;
        }
    });
    String[] countryNames = new String[localeList.size()];
    for (int i = 0; i < localeList.size(); i++) {
        countryNames[i] = ((Locale) localeList.get(i)).getDisplayCountry() + " (" + ((Locale) localeList.get(i)).getDisplayLanguage() + ")";
    }
    locale = new Combo(co, SWT.READ_ONLY);
    locale.setItems(countryNames);
    for (int i = 0; i < countryNames.length; i++) {
        locale.setData(countryNames[i], localeList.get(i));
    }
    locale.select(0);
    locale.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    l = new Label(co, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "encoding", "label", this.m_language));
    String[] encodings = new String[] { "ISO-8859-1", "UTF-8", "UTF-16" };
    encoding = new Combo(co, SWT.READ_ONLY);
    encoding.setItems(encodings);
    for (int i = 0; i < encodings.length; i++) {
        encoding.setData(encodings[i], encodings[i]);
    }
    encoding.select(0);
    locale.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setPageComplete(isComplete());
        }
    });
    Composite dco2 = new Composite(co, SWT.NONE);
    dco2.setLayout(new GridLayout(1, false));
    gd = new GridData();
    gd.horizontalSpan = 2;
    dco2.setLayoutData(gd);
    ffe = new FileFieldEditor(this.m_i18n.getString(this.getNamespace(), "fname", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "flabel", "label", this.m_language), dco2);
    ffe.setFileExtensions(new String[] { "*.png" });
    l = new Label(co, SWT.LEFT);
    l = new Label(co, SWT.LEFT);
    Composite dco = new Composite(co, SWT.NONE);
    dco.setLayout(new GridLayout(1, false));
    gd = new GridData();
    gd.horizontalSpan = 2;
    dco.setLayoutData(gd);
    dfe = new DirectoryFieldEditor(this.m_i18n.getString(this.getNamespace(), "dname", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "dlabel", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "dmessage", "label", this.m_language), dco);
    dfe.setStringValue(PathResolver.getInstance().getTempDirectory());
    Group c2 = new Group(co, SWT.SHADOW_ETCHED_IN);
    c2.setLayout(new GridLayout(2, false));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = GridData.FILL_HORIZONTAL;
    c2.setLayoutData(gd);
    l = new Label(c2, SWT.LEFT);
    l.setText(this.m_i18n.getString(this.getNamespace(), "testnumber", "label", this.m_language));
    l = new Label(c2, SWT.LEFT);
    final Text testnum = new Text(c2, SWT.BORDER);
    testnum.setText("");
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    // gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
    testnum.setLayoutData(gd);
    final Button test = new Button(c2, SWT.PUSH);
    test.setEnabled(false);
    test.setText(this.m_i18n.getString(this.getNamespace(), "test", "label", this.m_language));
    test.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(testnum.getText().startsWith("0") ? testnum.getText().substring(1) : testnum.getText());
            pn.setIntAreaCode(intarea.getText());
            Properties config = new Properties();
            config.setProperty("version", version.getText());
            config.setProperty("skipbytes", offset.getText());
            config.setProperty("url", url.getText());
            config.setProperty("regexp.lastname", lastname.getText());
            config.setProperty("regexp.firstname", firstname.getText());
            config.setProperty("regexp.street", street.getText());
            config.setProperty("regexp.streetno", streetno.getText());
            config.setProperty("regexp.pcode", postal.getText());
            config.setProperty("regexp.city", city.getText());
            config.setProperty("regexp.areacode", area.getText());
            config.setProperty("regexp.phone", number.getText());
            config.setProperty("intareacode", intarea.getText());
            config.setProperty("locale", ((Locale) locale.getData(locale.getText())).toString());
            config.setProperty("encoding", encoding.getText());
            config.setProperty("icon", ffe.getStringValue());
            TestWebCallerManager twcm = new TestWebCallerManager(config);
            try {
                ICaller c = twcm.getCaller(pn);
                IService dialog = getRuntime().getServiceFactory().getService("DefaultCallDialogService");
                if (dialog != null) {
                    ICall call = getRuntime().getCallFactory().createCall(c, getRuntime().getMsnManager().createMsn("12345"), getRuntime().getCipManager().createCip("1"));
                    if (dialog instanceof AbstractReceiverConfigurableService) {
                        ((AbstractReceiverConfigurableService) dialog).receivedValidRule(call);
                    }
                    lastname.setForeground(new Color(lastname.getDisplay(), 0, 0, 0));
                    firstname.setForeground(new Color(firstname.getDisplay(), 0, 0, 0));
                    street.setForeground(new Color(street.getDisplay(), 0, 0, 0));
                    streetno.setForeground(new Color(streetno.getDisplay(), 0, 0, 0));
                    postal.setForeground(new Color(postal.getDisplay(), 0, 0, 0));
                    city.setForeground(new Color(city.getDisplay(), 0, 0, 0));
                    area.setForeground(new Color(area.getDisplay(), 0, 0, 0));
                    number.setForeground(new Color(number.getDisplay(), 0, 0, 0));
                }
            } catch (CallerNotFoundException ex) {
                PropagationFactory.getInstance().fire(new Message(Message.INFO, getNamespace(), "notidentified", new String[] { pn.getTelephoneNumber() }, ex));
                // first CallerNotFoundException
                Throwable cause = ex.getCause();
                if (cause != null && !(cause instanceof RegExpURLRequesterException)) {
                    cause = cause.getCause();
                }
                if (cause != null && cause instanceof RegExpURLRequesterException) {
                    List failure = ((RegExpURLRequesterException) cause).getFailures();
                    String c = null;
                    for (int i = 0; i < failure.size(); i++) {
                        c = (String) failure.get(i);
                        if (c.equalsIgnoreCase("regexp.lastname")) {
                            lastname.setForeground(new Color(lastname.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.firstname")) {
                            firstname.setForeground(new Color(firstname.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.street")) {
                            street.setForeground(new Color(street.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.streetno")) {
                            streetno.setForeground(new Color(streetno.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.pcode")) {
                            postal.setForeground(new Color(postal.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.city")) {
                            city.setForeground(new Color(city.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.areacode")) {
                            area.setForeground(new Color(area.getDisplay(), 255, 0, 0));
                        }
                        if (c.equalsIgnoreCase("regexp.phone")) {
                            number.setForeground(new Color(number.getDisplay(), 255, 0, 0));
                        }
                    }
                }
            } finally {
                twcm = null;
            }
        }
    });
    testnum.addKeyListener(new KeyListener() {

        public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
            if (testnum.getText().length() > 0 && url.getText().length() > 0 && number.getText().length() > 0)
                test.setEnabled(true);
            else
                test.setEnabled(false);
        }

        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
        }
    });
    this.setPageComplete(isComplete());
    this.setControl(co);
}
Also used : ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) Locale(java.util.Locale) RegExpURLRequesterException(de.janrufmonitor.repository.web.RegExpURLRequesterException) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) ZipArchive(de.janrufmonitor.repository.zip.ZipArchive) Combo(org.eclipse.swt.widgets.Combo) Comparator(java.util.Comparator) FileFieldEditor(org.eclipse.jface.preference.FileFieldEditor) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) IService(de.janrufmonitor.service.IService) AbstractReceiverConfigurableService(de.janrufmonitor.service.AbstractReceiverConfigurableService) Color(org.eclipse.swt.graphics.Color) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) ICaller(de.janrufmonitor.framework.ICaller) Transfer(org.eclipse.swt.dnd.Transfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) DropTarget(org.eclipse.swt.dnd.DropTarget) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber) Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) Message(de.janrufmonitor.exception.Message) DirectoryFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.DirectoryFieldEditor) Properties(java.util.Properties) FilenameFilter(java.io.FilenameFilter) GridLayout(org.eclipse.swt.layout.GridLayout) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) ICall(de.janrufmonitor.framework.ICall) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) GridData(org.eclipse.swt.layout.GridData) KeyListener(org.eclipse.swt.events.KeyListener)

Example 78 with ICaller

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

the class GoogleContactsProxy method createContacts.

public synchronized void createContacts(ICallerList cl) throws GoogleContactsException {
    this.m_current = 0;
    this.m_total = 0;
    this.m_total = cl.size();
    try {
        fetchCategories();
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    }
    if (cl.size() == 0)
        return;
    ContactsService cs = login();
    ICaller caller = null;
    ContactEntry entry = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        this.m_current++;
        caller = cl.get(i);
        IAttributeMap m = caller.getAttributes();
        try {
            entry = new ContactEntry();
            Name name = new Name();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME))
                name.setFamilyName(new FamilyName((m.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().length() == 0 ? " " : m.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue()), null));
            else
                name.setFamilyName(new FamilyName(" ", null));
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME))
                name.setGivenName(new GivenName((m.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue().length() == 0 ? " " : m.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue()), null));
            else
                name.setGivenName(new GivenName(" ", null));
            name.setFullName(new FullName(Formatter.getInstance(getRuntime()).parse("%a:ln%, %a:fn%", m), null));
            entry.setName(name);
            entry.addStructuredPostalAddress(createPostalAddress(m));
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
                String emails = m.get(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue();
                Email email = new Email();
                email.setAddress(emails);
                entry.addEmailAddress(email);
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                String cat = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY).getValue();
                if (this.m_reverseCategories.containsKey(cat)) {
                    GroupMembershipInfo gmi = new GroupMembershipInfo();
                    gmi.setHref((String) this.m_reverseCategories.get(cat));
                    entry.addGroupMembershipInfo(gmi);
                }
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_GEO_ACC)) {
                ExtendedProperty acc = new ExtendedProperty();
                acc.setName(IJAMConst.ATTRIBUTE_NAME_GEO_ACC);
                acc.setValue(m.get(IJAMConst.ATTRIBUTE_NAME_GEO_ACC).getValue());
                entry.addExtendedProperty(acc);
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LNG)) {
                ExtendedProperty acc = new ExtendedProperty();
                acc.setName(IJAMConst.ATTRIBUTE_NAME_GEO_LNG);
                acc.setValue(m.get(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
                entry.addExtendedProperty(acc);
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LAT)) {
                ExtendedProperty acc = new ExtendedProperty();
                acc.setName(IJAMConst.ATTRIBUTE_NAME_GEO_LAT);
                acc.setValue(m.get(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
                entry.addExtendedProperty(acc);
            }
            PhoneNumber pn = null;
            if (caller instanceof IMultiPhoneCaller) {
                List phones = ((IMultiPhoneCaller) caller).getPhonenumbers();
                IPhonenumber p = null;
                for (int k = 0, l = phones.size(); k < l; k++) {
                    p = (IPhonenumber) phones.get(k);
                    pn = new PhoneNumber();
                    pn.setPrimary(k == 0);
                    IAttribute type = m.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + p.getTelephoneNumber());
                    if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
                        pn.setRel(PhoneNumber.Rel.MOBILE);
                    } else if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
                        pn.setRel(PhoneNumber.Rel.HOME_FAX);
                    } else {
                        pn.setRel(PhoneNumber.Rel.HOME);
                    }
                    pn.setPhoneNumber(Formatter.getInstance(getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, p));
                    entry.addPhoneNumber(pn);
                }
            } else {
                pn = new PhoneNumber();
                IAttribute type = m.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + caller.getPhoneNumber().getTelephoneNumber());
                if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
                    pn.setRel(PhoneNumber.Rel.MOBILE);
                } else if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
                    pn.setRel(PhoneNumber.Rel.HOME_FAX);
                } else {
                    pn.setRel(PhoneNumber.Rel.HOME);
                }
                pn.setPhoneNumber(Formatter.getInstance(getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, caller.getPhoneNumber()));
                entry.addPhoneNumber(pn);
            }
            URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/" + getLoginUser() + "/full");
            entry = (ContactEntry) cs.insert(postUrl, entry);
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
                String file = PathResolver.getInstance(getRuntime()).resolve(m.get(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH).getValue());
                if (new File(file).exists()) {
                    FileInputStream in = new FileInputStream(file);
                    Link photoLink = entry.getContactPhotoLink();
                    URL photoUrl = new URL(photoLink.getHref());
                    GDataRequest request = cs.createRequest(GDataRequest.RequestType.UPDATE, photoUrl, new ContentType("image/jpeg"));
                    Stream.copy(in, request.getRequestStream());
                    request.execute();
                }
            }
            if (entry != null && this.m_dbh != null) {
                try {
                    if (caller instanceof IMultiPhoneCaller) {
                        List phones = ((IMultiPhoneCaller) caller).getPhonenumbers();
                        IPhonenumber p = null;
                        for (int k = 0; k < phones.size(); k++) {
                            p = (IPhonenumber) phones.get(k);
                            this.m_dbh.insert(caller.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber());
                        }
                    } else {
                        IPhonenumber p = caller.getPhoneNumber();
                        this.m_dbh.insert(caller.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber());
                    }
                } catch (SQLException e) {
                    throw new GoogleContactsException(e.getMessage(), e);
                }
            } else {
                this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
            }
        } catch (MalformedURLException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        } catch (IOException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        } catch (ServiceException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Email(com.google.gdata.data.extensions.Email) ContentType(com.google.gdata.util.ContentType) FamilyName(com.google.gdata.data.extensions.FamilyName) SQLException(java.sql.SQLException) GivenName(com.google.gdata.data.extensions.GivenName) GDataRequest(com.google.gdata.client.Service.GDataRequest) URL(java.net.URL) FamilyName(com.google.gdata.data.extensions.FamilyName) Name(com.google.gdata.data.extensions.Name) GivenName(com.google.gdata.data.extensions.GivenName) FullName(com.google.gdata.data.extensions.FullName) ContactsService(com.google.gdata.client.contacts.ContactsService) ContactEntry(com.google.gdata.data.contacts.ContactEntry) GroupMembershipInfo(com.google.gdata.data.contacts.GroupMembershipInfo) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) IOException(java.io.IOException) ExtendedProperty(com.google.gdata.data.extensions.ExtendedProperty) FileInputStream(java.io.FileInputStream) ICaller(de.janrufmonitor.framework.ICaller) ServiceException(com.google.gdata.util.ServiceException) FullName(com.google.gdata.data.extensions.FullName) IAttribute(de.janrufmonitor.framework.IAttribute) PhoneNumber(com.google.gdata.data.extensions.PhoneNumber) File(java.io.File) Link(com.google.gdata.data.Link) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 79 with ICaller

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

the class GoogleContactsProxy method preload.

public void preload() throws GoogleContactsException {
    try {
        fetchCategories();
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    }
    ICallerList cl = getRuntime().getCallerFactory().createCallerList(getMaxResults());
    ContactsService cs = login();
    try {
        URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/" + getLoginUser() + "/full");
        Query q = new Query(feedUrl);
        q.setMaxResults(getMaxResults());
        ContactFeed resultFeed = (ContactFeed) cs.getFeed(q, ContactFeed.class);
        List entries = resultFeed.getEntries();
        this.m_total = entries.size();
        this.m_logger.info("Fetched " + entries.size() + " entries from google account " + getLoginUser());
        Object o = null;
        for (int i = 0, j = entries.size(); i < j; i++) {
            o = entries.get(i);
            if (o instanceof ContactEntry) {
                // && (category==null || matchCategory(category, (ContactEntry) o))) {
                ICaller c = this.parse(cs, (ContactEntry) o);
                if (c != null) {
                    cl.add(c);
                }
            }
        }
    } catch (MalformedURLException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    }
    // 
    if (this.m_dbh != null) {
        try {
            ICaller c = null;
            for (int i = 0, j = cl.size(); i < j; i++) {
                c = cl.get(i);
                if (c instanceof IMultiPhoneCaller) {
                    List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
                    IPhonenumber pn = null;
                    this.m_dbh.delete(c.getUUID());
                    for (int k = 0; k < phones.size(); k++) {
                        pn = (IPhonenumber) phones.get(k);
                        this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                    }
                } else {
                    IPhonenumber pn = c.getPhoneNumber();
                    this.m_dbh.delete(c.getUUID());
                    this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                }
            }
            this.m_dbh.commit();
        } catch (SQLException e) {
            throw new GoogleContactsException(e.getMessage(), e);
        }
    } else {
        this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Query(com.google.gdata.client.Query) SQLException(java.sql.SQLException) IOException(java.io.IOException) ContactFeed(com.google.gdata.data.contacts.ContactFeed) URL(java.net.URL) ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) ServiceException(com.google.gdata.util.ServiceException) ContactsService(com.google.gdata.client.contacts.ContactsService) ContactEntry(com.google.gdata.data.contacts.ContactEntry) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 80 with ICaller

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

the class GoogleMapsLocalize 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) {
                // check if maps.google.com service is enabled
                IService googlemap = getRuntime().getServiceFactory().getService(Maps.ID);
                if (googlemap != null && googlemap.isEnabled()) {
                    Properties configuration = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(Maps.NAMESPACE);
                    String url = configuration.getProperty("url");
                    if (url == null || url.trim().length() == 0) {
                        MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "nourl", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "nourl", "description", this.getLanguage()));
                        return;
                    }
                    IAttribute postalCode = ((ICaller) o).getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY);
                    if (postalCode == null || postalCode.getValue().trim().length() == 0) {
                        MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "less", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "less", "description", this.getLanguage()));
                        return;
                    }
                    IAttribute city = ((ICaller) o).getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
                    if (city == null || city.getValue().trim().length() == 0) {
                        MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "less", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "less", "description", this.getLanguage()));
                        return;
                    }
                    StringBuffer googlemapUrl = new StringBuffer();
                    googlemapUrl.append(url);
                    googlemapUrl.append(buildRequestParameters((ICaller) o));
                    this.m_logger.info("Requesting maps.google.com URL: " + googlemapUrl.toString());
                    Program.launch(googlemapUrl.toString());
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Properties(java.util.Properties) IService(de.janrufmonitor.service.IService)

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