Search in sources :

Example 71 with ICallerList

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

the class VcfParser30 method parse.

public ICallerList parse() throws VcfParserException {
    if (this.m_buffer == null)
        this.read();
    if (this.m_buffer.length() < 64)
        throw new VcfParserException("VCF file contains only " + this.m_buffer.length() + " characters.");
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    String[] entries = this.m_buffer.toString().split(BEGIN_VCARD);
    this.m_logger.info("Entries in generic VcfParser vcf file: " + entries.length);
    this.m_total = entries.length;
    for (int i = 0; i < entries.length; i++) {
        try {
            this.m_current++;
            IAttributeMap private_attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
            IAttributeMap bussiness_attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
            List private_phones = new ArrayList();
            List bussiness_phones = new ArrayList();
            String[] lines = entries[i].split(IJAMConst.CRLF);
            // parse single entry
            String line = null;
            String[] value = null;
            for (int j = 0; j < lines.length; j++) {
                line = lines[j];
                // check name
                if (line.toLowerCase().startsWith(N) || line.toLowerCase().startsWith(N2)) {
                    value = line.substring(line.indexOf(":") + 1).split(";");
                    if (value.length >= 2) {
                        this.m_logger.info("Set attribute name.");
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, value[1]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, value[1]));
                    }
                    if (value.length == 1) {
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                    }
                }
                if (line.toLowerCase().startsWith(ORG) || line.toLowerCase().startsWith(ORG2)) {
                    value = line.split(":");
                    if (value.length >= 2) {
                        this.m_logger.info("Set attribute organization.");
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, value[1]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, value[1]));
                    }
                }
                if (line.toLowerCase().startsWith(ADR)) {
                    String[] tokens = line.split(":");
                    if (tokens.length == 2) {
                        boolean isBusiness = false;
                        String[] attributes = tokens[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
                                String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(";");
                                for (int l = 0; l < values.length; l++) {
                                    if (values[l].equalsIgnoreCase(ADR_TYPES[1])) {
                                        isBusiness = true;
                                    }
                                }
                            }
                            if (attributes[k].toLowerCase().startsWith(ADR_TYPES[1])) {
                                isBusiness = true;
                            }
                        }
                        value = tokens[1].split(";");
                        if (value.length >= 6 && (value.length > 6 ? value[6].trim().length() > 0 : true) && value[3].trim().length() > 0) {
                            if (isBusiness) {
                                this.m_logger.info("Set attribute work address.");
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, value[2]));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, value[5]));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, value[3] + (value[4].trim().length() > 0 ? ", " + value[4] : "")));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, (value.length > 6 ? value[6] : "")));
                            } else {
                                this.m_logger.info("Set attribute home address.");
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, value[2]));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, value[5]));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, value[3] + (value[4].trim().length() > 0 ? ", " + value[4] : "")));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, (value.length > 6 ? value[6] : "")));
                            }
                        }
                    }
                }
                if (line.toLowerCase().startsWith(TEL)) {
                    value = line.split(":");
                    if (value.length == 2 && value[1].trim().length() > 0) {
                        boolean isBusiness = false;
                        boolean isFax = false;
                        boolean isCell = false;
                        String[] attributes = value[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
                                String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(",");
                                for (int l = 0; l < values.length; l++) {
                                    if (values[l].equalsIgnoreCase(TEL_TYPES[1])) {
                                        isBusiness = true;
                                    }
                                    if (values[l].equalsIgnoreCase(TEL_TYPES[3])) {
                                        isFax = true;
                                    }
                                    if (values[l].equalsIgnoreCase(TEL_TYPES[2])) {
                                        isCell = true;
                                    }
                                }
                            }
                            if (attributes[k].toLowerCase().startsWith(TEL_TYPES[1])) {
                                isBusiness = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(TEL_TYPES[3])) {
                                isFax = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(TEL_TYPES[2])) {
                                isCell = true;
                            }
                        }
                        try {
                            IPhonenumber pn = parsePhonenumber(value[1]);
                            if (pn != null && !bussiness_phones.contains(pn)) {
                                if (isBusiness) {
                                    this.m_logger.info("Set attribute work");
                                    bussiness_phones.add(pn);
                                    bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), (isFax ? IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE : (isCell ? IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE : IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))));
                                } else {
                                    this.m_logger.info("Set attribute home");
                                    private_phones.add(pn);
                                    private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), (isFax ? IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE : (isCell ? IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE : IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))));
                                }
                            }
                        } catch (Exception ex) {
                            this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                        }
                    }
                }
                if (line.toLowerCase().startsWith(EMAIL)) {
                    value = line.split(":");
                    if (value.length == 2 && value[1].trim().length() > 0) {
                        boolean isBusiness = false;
                        String[] attributes = value[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
                                String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(",");
                                for (int l = 0; l < values.length; l++) {
                                    if (values[l].equalsIgnoreCase(EMAIL_TYPES[1])) {
                                        isBusiness = true;
                                    }
                                }
                            }
                            if (attributes[k].toLowerCase().startsWith(EMAIL_TYPES[1])) {
                                isBusiness = true;
                            }
                        }
                        if (isBusiness) {
                            this.m_logger.info("Set attribute work");
                            bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL, value[1]));
                        } else {
                            this.m_logger.info("Set attribute home");
                            private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL, value[1]));
                        }
                    }
                }
                if (line.toLowerCase().startsWith(GEO)) {
                    value = line.split(":");
                    if (value.length == 2) {
                        value = value[1].split(";");
                        if (value.length == 2) {
                            bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, value[0]));
                            bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, value[1]));
                            private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, value[0]));
                            private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, value[1]));
                        }
                    }
                }
                if (line.toLowerCase().startsWith(PHOTO) || line.toLowerCase().startsWith(MS_CARDPICTURE)) {
                    value = new String[2];
                    value[0] = line.substring(0, line.indexOf(":"));
                    value[1] = line.substring(line.indexOf(":") + 1);
                    if (value.length == 2) {
                        boolean isUrl = false;
                        boolean isEncoding = false;
                        String img_type = null;
                        String[] attributes = value[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[0]) || attributes[k].toLowerCase().startsWith(PHOTO_TYPES[1])) {
                                isUrl = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[2])) {
                                isEncoding = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[3])) {
                                img_type = attributes[k].split("=")[1].toLowerCase();
                            }
                        }
                        if (isUrl) {
                            String img = getImageFromURL(value[1]);
                            if (img != null) {
                                this.m_logger.info("Set attribute photo.");
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                            }
                        }
                        if (isEncoding) {
                            try {
                                if (img_type == null || img_type.trim().length() == 0)
                                    img_type = "jpg";
                                StringBuffer img_content = new StringBuffer();
                                img_content.append(value[1]);
                                img_content.append("\n");
                                do {
                                    j++;
                                    value[1] = lines[j];
                                    if (value[1].startsWith(" "))
                                        value[1] = value[1].substring(1);
                                    img_content.append(value[1]);
                                    img_content.append("\n");
                                } while (value[1].indexOf("=") < 0);
                                String img = getImageFromBase64(img_content.toString(), img_type);
                                if (img != null) {
                                    this.m_logger.info("Set attribute photo.");
                                    private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                    bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                    private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                                    bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                                }
                            } catch (Exception ex) {
                                this.m_logger.log(Level.SEVERE, "VCF parsing error: PHOTO: " + ex.getMessage(), ex);
                            }
                        }
                    }
                }
            }
            // create ICaller objects
            IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
            if (private_phones.size() > 0 && private_attributes.size() > 0) {
                ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, private_phones);
                c.setAttributes(private_attributes);
                cl.add(c);
            }
            if (bussiness_phones.size() > 0 && bussiness_attributes.size() > 0) {
                ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, bussiness_phones);
                c.setAttributes(bussiness_attributes);
                cl.add(c);
            }
        } catch (Exception e) {
            this.m_logger.log(Level.SEVERE, "VCF parsing error: " + e.getMessage(), e);
        // throw new VcfParserException("parsing error: "+e.getMessage(), e);
        }
    }
    return cl;
}
Also used : ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 72 with ICallerList

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

the class ConsoleImport method execute.

public void execute() throws Exception {
    this.isExecuting = true;
    if (this.getExecuteParams().length != 1) {
        System.out.println("ERROR: Paramters are invalid. Please specify a valid module for installation.");
        this.isExecuting = false;
        return;
    }
    String filename = this.getExecuteParams()[0];
    IImExporter imp = ImExportFactory.getInstance().getImporter("OldDatFileCallerImporter");
    if (imp != null && imp instanceof ICallerImporter) {
        ((ICallerImporter) imp).setFilename(filename);
        ICallerList cl = ((ICallerImporter) imp).doImport();
        ICallerManager mgr = this.getRuntime().getCallerManagerFactory().getCallerManager("CallerDirectory");
        if (mgr != null && mgr.isActive() && mgr.isSupported(IWriteCallerRepository.class)) {
            ((IWriteCallerRepository) mgr).setCaller(cl);
            System.out.println("INFO: Successfully imported " + cl.size() + " caller entries.");
        } else {
            System.out.println("ERROR: Caller manager is missing.");
        }
    } else {
        System.out.println("ERROR: import filter for DAT files is missing.");
    }
    this.isExecuting = false;
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) ICallerImporter(de.janrufmonitor.repository.imexport.ICallerImporter) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 73 with ICallerList

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

the class CountryDirectory method importAreacodeCsvFiles.

private void importAreacodeCsvFiles() {
    String restart = System.getProperty(IJAMConst.SYSTEM_INSTALLER_RESTART);
    if (restart == null || restart.equalsIgnoreCase("true")) {
        this.m_logger.info("Detected jam.installer.restart flag as: " + System.getProperty(IJAMConst.SYSTEM_INSTALLER_RESTART));
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        restart = System.getProperty(IJAMConst.SYSTEM_INSTALLER_RESTART);
        if (restart != null && restart.equalsIgnoreCase("true")) {
            this.m_logger.info("Areacode update is not started, due to installation of new modules.");
            return;
        }
    }
    this.m_isMigrating = true;
    File areacodeFolder = new File(PathResolver.getInstance(this.getRuntime()).getDataDirectory() + File.separator + "areacodes");
    if (!areacodeFolder.exists())
        areacodeFolder.mkdirs();
    File[] areacodeCsvs = areacodeFolder.listFiles(new FilenameFilter() {

        public boolean accept(File f, String name) {
            return name.endsWith(".areacode.csv");
        }
    });
    if (areacodeCsvs.length > 0) {
        File areacodeCsv = null;
        ICallerList l = getRuntime().getCallerFactory().createCallerList();
        for (int i = 0; i < areacodeCsvs.length; i++) {
            areacodeCsv = areacodeCsvs[i];
            if (areacodeCsv.isFile() && areacodeCsv.exists()) {
                try {
                    // structure of file
                    // #intareacode;areacode;country;city
                    InputStream content = new FileInputStream(areacodeCsv);
                    if (content != null) {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(content, "ISO-8859-1"));
                        String[] entry = new String[4];
                        StringTokenizer st = null;
                        for (String line; (line = reader.readLine()) != null; ) {
                            if (line.startsWith("#")) {
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Skipping line from import (start comment line #): " + line);
                                continue;
                            }
                            st = new StringTokenizer(line, ";");
                            if (st.countTokens() == 2) {
                                entry[0] = st.nextToken().trim();
                                entry[1] = st.nextToken().trim();
                                IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(entry[0], "", "country");
                                IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                                if (entry[1].length() > 0)
                                    m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, entry[1]));
                                ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn, m);
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Adding intareacode entry: " + c);
                                l.add(c);
                            } else if (st.countTokens() == 4) {
                                entry[0] = st.nextToken().trim();
                                entry[1] = st.nextToken().trim();
                                entry[2] = st.nextToken().trim();
                                entry[3] = st.nextToken().trim();
                                IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(entry[0], entry[1], (entry[1].length() == 0 ? "country" : "area"));
                                IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                                if (entry[2].length() > 0)
                                    m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, entry[2]));
                                if (entry[3].length() > 0)
                                    m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, entry[3]));
                                ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn, m);
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Adding areacode entry: " + c);
                                l.add(c);
                            } else {
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Skipping line from import (invalid token count): " + line);
                            }
                        }
                        reader.close();
                    }
                    if (l.size() > 0)
                        this.storeCountryAreacodes(l);
                    l.clear();
                    if (!areacodeCsv.delete())
                        areacodeCsv.deleteOnExit();
                } catch (IOException e) {
                    this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    } else {
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("No .areacode.csv file found in path: " + areacodeFolder.getAbsolutePath());
    }
    this.m_isMigrating = false;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FilenameFilter(java.io.FilenameFilter) ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) ICallerList(de.janrufmonitor.framework.ICallerList) BufferedReader(java.io.BufferedReader) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 74 with ICallerList

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

the class FritzBoxPhonebookManager method createCallerListFromFritzBoxPhonebook.

private void createCallerListFromFritzBoxPhonebook() {
    Thread t = new Thread(new Runnable() {

        Logger m_logger;

        public void run() {
            isSyncing = true;
            this.m_logger = LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER);
            if (this.m_logger.isLoggable(Level.FINE))
                this.m_logger.fine("Starting JAM-FritzBoxPhonebookSync-Thread");
            File mso_cache = new File(FBP_CACHE_PATH);
            if (!mso_cache.exists())
                mso_cache.mkdirs();
            ICallerList cl = getRuntime().getCallerFactory().createCallerList();
            FirmwareManager fwm = FirmwareManager.getInstance();
            fwm.startup();
            try {
                if (!fwm.isLoggedIn())
                    fwm.login();
                if (this.m_logger.isLoggable(Level.INFO))
                    this.m_logger.info("FritzBox Firmware created.");
                if (this.m_logger.isLoggable(Level.INFO))
                    this.m_logger.info("Login to FritzBox successfull.");
                // check if phonebook is configured
                String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
                if (this.m_logger.isLoggable(Level.INFO))
                    this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
                int id = Integer.parseInt(abId);
                String name = null;
                try {
                    Map abs = fwm.getAddressbooks();
                    if (abs.containsKey(Integer.parseInt(abId))) {
                        name = (String) abs.get(Integer.parseInt(abId));
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("Getting FritzBox phonebook name: " + name);
                    }
                } catch (GetAddressbooksException e) {
                    this.m_logger.log(Level.WARNING, e.getMessage(), e);
                }
                List callers = null;
                if (name != null) {
                    callers = fwm.getCallerList(id, name);
                    if (this.m_logger.isLoggable(Level.INFO))
                        this.m_logger.info("Getting FritzBox phonebook callers: " + callers.size());
                } else {
                    callers = fwm.getCallerList();
                    if (this.m_logger.isLoggable(Level.INFO))
                        this.m_logger.info("Getting FritzBox default phonebook callers: " + callers.size());
                }
                if (callers.size() == 0) {
                    try {
                        getDatabaseHandler().deleteCallerList(getRuntime().getCallerFactory().createCallerList());
                        getDatabaseHandler().commit();
                    } catch (SQLException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                        try {
                            getDatabaseHandler().rollback();
                        } catch (SQLException e1) {
                            this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                        }
                    }
                    isSyncing = false;
                    return;
                }
                cl.add(FritzBoxMappingManager.getInstance().toCallerList(callers));
            } catch (FritzBoxLoginException e2) {
                this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
            } catch (GetCallerListException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            } catch (IOException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            } catch (Throwable e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
            try {
                getDatabaseHandler().deleteCallerList(getRuntime().getCallerFactory().createCallerList());
                getDatabaseHandler().insertOrUpdateCallerList(cl);
                getDatabaseHandler().commit();
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                try {
                    getDatabaseHandler().rollback();
                } catch (SQLException e1) {
                    this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                }
            }
            isSyncing = false;
            if (this.m_logger.isLoggable(Level.FINE))
                this.m_logger.fine("Stopping JAM-FritzBoxPhonebookSync-Thread");
        }
    });
    t.setName("JAM-FritzBoxPhonebookSync-Thread-(non-deamon)");
    t.start();
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) SQLException(java.sql.SQLException) IOException(java.io.IOException) Logger(java.util.logging.Logger) ICallerList(de.janrufmonitor.framework.ICallerList) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) GetAddressbooksException(de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) File(java.io.File) Map(java.util.Map)

Example 75 with ICallerList

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

the class FritzBoxPhonebookManager method removeCaller.

public void removeCaller(ICaller caller) {
    FirmwareManager fwm = FirmwareManager.getInstance();
    fwm.startup();
    try {
        if (!fwm.isLoggedIn())
            fwm.login();
        // check if phonebook is configured
        String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
        int id = Integer.parseInt(abId);
        IPhonebookEntry pe = FritzBoxMappingManager.getInstance().mapJamCallerToFritzBox(caller);
        fwm.deleteCaller(id, pe);
        ICallerList cl = getRuntime().getCallerFactory().createCallerList(1);
        cl.add(caller);
        try {
            getDatabaseHandler().deleteCallerList(cl);
            getDatabaseHandler().commit();
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            try {
                getDatabaseHandler().rollback();
            } catch (SQLException e1) {
                this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
            }
        }
    } catch (FritzBoxLoginException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (DeleteCallerException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    if (!this.isSyncing)
        this.createCallerListFromFritzBoxPhonebook();
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) ICallerList(de.janrufmonitor.framework.ICallerList) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) SQLException(java.sql.SQLException) DeleteCallerException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException) IPhonebookEntry(de.janrufmonitor.fritzbox.IPhonebookEntry) IOException(java.io.IOException)

Aggregations

ICallerList (de.janrufmonitor.framework.ICallerList)81 ICaller (de.janrufmonitor.framework.ICaller)40 List (java.util.List)36 ArrayList (java.util.ArrayList)32 IAttribute (de.janrufmonitor.framework.IAttribute)24 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)24 SQLException (java.sql.SQLException)24 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)18 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)17 IOException (java.io.IOException)15 Message (de.janrufmonitor.exception.Message)14 Iterator (java.util.Iterator)11 Map (java.util.Map)11 File (java.io.File)10 HashMap (java.util.HashMap)10 Viewer (org.eclipse.jface.viewers.Viewer)10 ICallerManager (de.janrufmonitor.repository.ICallerManager)9 ComFailException (com.jacob.com.ComFailException)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)7