Search in sources :

Example 46 with ICaller

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

the class AbstractMultiPhoneCallerDatabaseHandler method insertOrUpdateCallerList.

/**
 * Insert the callers in the list or update the callers if it already
 * exists.
 *
 * @param cl
 * @throws SQLException
 */
public void insertOrUpdateCallerList(ICallerList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    // check prepared statements
    PreparedStatement insert_caller = this.getStatement("INSERT_CALLER");
    PreparedStatement insert_attributes = this.getStatement("INSERT_ATTRIBUTE");
    PreparedStatement insert_phones = this.getStatement("INSERT_PHONE");
    PreparedStatement update_caller = this.getStatement("UPDATE_CALLER");
    PreparedStatement delete_phones = this.getStatement("DELETE_PHONE");
    PreparedStatement delete_phones2 = this.getStatement("DELETE_PHONE2");
    PreparedStatement delete_attributes = this.getStatement("DELETE_ATTRIBUTE");
    // clean up prpared statements
    insert_caller.clearBatch();
    insert_attributes.clearBatch();
    insert_phones.clearBatch();
    update_caller.clearBatch();
    delete_attributes.clearBatch();
    delete_phones.clearBatch();
    delete_phones2.clearBatch();
    // list for redundant UUIDs checks
    List uuid_check = new ArrayList(cl.size());
    ICaller c = null;
    String uuid = null;
    List phones = new ArrayList(1);
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        if (this.m_logger.isLoggable(Level.INFO) && c != null)
            this.m_logger.info("Adding to database: " + c.toString());
        // check if redundant uuid could occure
        uuid = c.getUUID();
        if (uuid_check.contains(uuid)) {
            this.m_logger.warning("Found duplicated UUID: " + c.toString());
            c.setUUID(new UUID().toString());
            uuid = c.getUUID();
        }
        uuid_check.add(uuid);
        // check which type of Interface the caller object implements
        if (!(c instanceof IMultiPhoneCaller)) {
            if (this.m_logger.isLoggable(Level.INFO) && c != null)
                this.m_logger.info("Caller is not type IMultiPhoneCaller. Transforming is triggered... : " + c.toString());
            c = this.getRuntime().getCallerFactory().toMultiPhoneCaller(c);
            // 2008/11/30: added to fix duplicated address book entries after category assignement
            c.setUUID(uuid);
        }
        phones.clear();
        phones.addAll(((IMultiPhoneCaller) c).getPhonenumbers());
        // check if single caller (uuid) is already in DB
        if (existsCaller(c)) {
            internalUpdate(c);
            if (this.m_logger.isLoggable(Level.INFO) && c != null)
                this.m_logger.info("Caller already exists in database. Update is triggered: " + c.toString());
            try {
                // update caller table
                this.updateCaller(update_caller, c.getUUID(), Serializer.toByteArray(c));
                // update attributes table
                this.deleteAttributes(delete_attributes, c.getUUID());
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                // update phones table
                this.deletePhone(delete_phones, c.getUUID());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else if (this.existsPhones(phones).size() > 0) {
            internalInsert(c);
            // check if phone numnbers are already in DB and overwrite them
            List existingPhones = this.existsPhones(phones);
            IPhonenumber pn = null;
            for (int a = 0, b = existingPhones.size(); a < b; a++) {
                pn = (IPhonenumber) existingPhones.get(a);
                if (this.m_logger.isLoggable(Level.INFO) && c != null)
                    this.m_logger.info("Phone already exists in database. Update is triggered: " + pn.toString());
                this.deletePhone(delete_phones2, pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber());
            }
            try {
                this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            internalInsert(c);
            // insert new caller
            try {
                this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        if (i % this.commit_count == 0) {
            try {
                delete_attributes.executeBatch();
                delete_attributes.clearBatch();
                this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
                delete_phones.executeBatch();
                delete_phones.clearBatch();
                this.m_logger.info("Batch DELETE_PHONES executed...");
                delete_phones2.executeBatch();
                delete_phones2.clearBatch();
                this.m_logger.info("Batch DELETE_PHONES2 executed...");
                insert_caller.executeBatch();
                insert_caller.clearBatch();
                this.m_logger.info("Batch INSERT_CALLER executed...");
                insert_attributes.executeBatch();
                insert_attributes.clearBatch();
                this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
                insert_phones.executeBatch();
                insert_phones.clearBatch();
                this.m_logger.info("Batch INSERT_PHONES executed...");
                update_caller.executeBatch();
                update_caller.clearBatch();
                this.m_logger.info("Batch UPDATE_CALLER executed...");
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage() + c.toString(), e);
            // throw new SQLException("Batch execution failed: ");
            }
        }
    }
    // execute the rest batch content
    delete_attributes.executeBatch();
    delete_attributes.clearBatch();
    this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
    delete_phones.executeBatch();
    delete_phones.clearBatch();
    this.m_logger.info("Batch DELETE_PHONES executed...");
    delete_phones2.executeBatch();
    delete_phones2.clearBatch();
    this.m_logger.info("Batch DELETE_PHONES2 executed...");
    insert_caller.executeBatch();
    insert_caller.clearBatch();
    this.m_logger.info("Batch INSERT_CALLER executed...");
    insert_attributes.executeBatch();
    insert_attributes.clearBatch();
    this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
    insert_phones.executeBatch();
    insert_phones.clearBatch();
    this.m_logger.info("Batch INSERT_PHONES executed...");
    update_caller.executeBatch();
    update_caller.clearBatch();
    this.m_logger.info("Batch UPDATE_CALLER executed...");
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 47 with ICaller

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

the class AbstractConfigurableCallerManager method applyFilters.

protected void applyFilters(ICallerList cl, IFilter[] filters) {
    if (cl == null)
        return;
    if (filters == null)
        return;
    IFilter f = null;
    for (int i = 0; i < filters.length; i++) {
        f = filters[i];
        if (f.getType() == FilterType.CHARACTER) {
            CharacterFilter cf = ((CharacterFilter) f);
            ICaller c = null;
            for (int j = cl.size() - 1; j >= 0; j--) {
                c = cl.get(j);
                if (!c.getAttributes().contains(cf.getAttributeName())) {
                    cl.remove(c);
                } else if (c.getAttributes().contains(cf.getAttributeName())) {
                    if (!c.getAttribute(cf.getAttributeName()).getValue().startsWith(cf.getCharacter())) {
                        cl.remove(c);
                    }
                }
            }
        }
        if (f.getType() == FilterType.PHONENUMBER) {
            PhonenumberFilter cf = ((PhonenumberFilter) f);
            ICaller c = null;
            for (int j = cl.size() - 1; j >= 0; j--) {
                c = cl.get(j);
                if (!c.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(cf.getPhonenumber().getIntAreaCode())) {
                    cl.remove(c);
                } else if (!c.getPhoneNumber().getAreaCode().equalsIgnoreCase(cf.getPhonenumber().getAreaCode())) {
                    cl.remove(c);
                }
            }
        }
        if (f.getType() == FilterType.ATTRIBUTE) {
            AttributeFilter cf = ((AttributeFilter) f);
            ICaller c = null;
            for (int j = cl.size() - 1; j >= 0; j--) {
                c = cl.get(j);
                IAttributeMap atts = cf.getAttributeMap();
                Iterator iter = atts.iterator();
                IAttribute a = null;
                while (iter.hasNext()) {
                    a = (IAttribute) iter.next();
                    if (!c.getAttributes().contains(a)) {
                        cl.remove(c);
                    } else if (c.getAttributes().contains(a) && !c.getAttribute(a.getName()).getValue().equalsIgnoreCase(a.getValue())) {
                        cl.remove(c);
                    }
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) IFilter(de.janrufmonitor.repository.filter.IFilter) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) PhonenumberFilter(de.janrufmonitor.repository.filter.PhonenumberFilter) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 48 with ICaller

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

the class AbstractDatabaseCallerManager method setCaller.

public synchronized void setCaller(ICallerList callerList) {
    try {
        ICaller c = null;
        for (int i = 0, j = callerList.size(); i < j; i++) {
            c = callerList.get(i);
            this.addCreationAttributes(c);
            this.addSystemAttributes(c);
        }
        m_isRunningProcess = true;
        getDatabaseHandler().insertOrUpdateCallerList(callerList);
        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);
        }
    }
    m_isRunningProcess = false;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException)

Example 49 with ICaller

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

the class DatFileCallerImporter method doImport.

public ICallerList doImport() {
    m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    Date startDate = new Date();
    File db = new File(m_filename);
    try {
        FileReader dbReader = new FileReader(db);
        BufferedReader bufReader = new BufferedReader(dbReader);
        ICaller aCaller = null;
        while (bufReader.ready()) {
            try {
                aCaller = Serializer.toCaller(bufReader.readLine().getBytes(), PIMRuntime.getInstance());
                if (aCaller == null) {
                    // file format is corrupted
                    return this.m_callerList;
                }
                this.m_callerList.add(aCaller);
            } catch (SerializerException e) {
                this.m_logger.warning("Caller was skipped: " + e.getMessage());
            }
        }
        bufReader.close();
        dbReader.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find caller backup file " + m_filename);
        return this.m_callerList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callerList;
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported caller file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callerList.size()).toString() + " caller items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return this.m_callerList;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) SerializerException(de.janrufmonitor.util.io.SerializerException) Date(java.util.Date)

Example 50 with ICaller

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

the class EabFileCallerExporter method doExport.

public boolean doExport() {
    File db = new File(m_filename);
    try {
        Properties addressbook = new Properties();
        FileOutputStream fo = new FileOutputStream(db);
        ICaller c = null;
        addressbook.setProperty("total", Integer.toString(this.m_callerList.size()));
        for (int i = 0; i < this.m_callerList.size(); i++) {
            c = this.m_callerList.get(i);
            if (c instanceof IMultiPhoneCaller) {
                List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
                addressbook.setProperty((i + 1) + ".phonecount", Integer.toString(phones.size()));
                for (int a = 0, b = phones.size(); a < b; a++) {
                    addressbook.setProperty((i + 1) + ".intarea." + a, ((IPhonenumber) phones.get(a)).getIntAreaCode());
                    addressbook.setProperty((i + 1) + ".area." + a, ((IPhonenumber) phones.get(a)).getAreaCode());
                    addressbook.setProperty((i + 1) + ".phone." + a, ((IPhonenumber) phones.get(a)).getCallNumber());
                }
            } else {
                addressbook.setProperty((i + 1) + ".intarea", c.getPhoneNumber().getIntAreaCode());
                addressbook.setProperty((i + 1) + ".area", c.getPhoneNumber().getAreaCode());
                addressbook.setProperty((i + 1) + ".phone", c.getPhoneNumber().getCallNumber());
            }
            IAttributeMap attributes = c.getAttributes();
            Iterator iter = attributes.iterator();
            IAttribute a = null;
            while (iter.hasNext()) {
                a = (IAttribute) iter.next();
                addressbook.setProperty((i + 1) + "." + a.getName(), a.getValue());
            }
        }
        addressbook.store(fo, "");
        fo.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.severe("File not found: " + m_filename);
        return false;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return false;
    }
    return true;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) FileNotFoundException(java.io.FileNotFoundException) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

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