Search in sources :

Example 71 with ICall

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

the class CbcStatsAction method getStatisticItems.

public List getStatisticItems() {
    final List items = new ArrayList();
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                isCalculating = true;
                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "calculating", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                progressMonitor.worked(1);
                final Properties stat = new Properties();
                if (m_cl != null) {
                    ICall c = null;
                    for (int i = 0; i < m_cl.size(); i++) {
                        c = m_cl.get(i);
                        if (isOutgoingCall(c) && isCbcCall(c)) {
                            String key = getCbcCall(c);
                            String value = stat.getProperty(key, "");
                            if (value.length() == 0) {
                                stat.setProperty(key.trim(), "1");
                                stat.setProperty(key + ".cbc", key);
                            } else {
                                int val = new Integer(value).intValue();
                                val++;
                                stat.setProperty(key.trim(), new Integer(val).toString());
                                m_maxcount = Math.max(m_maxcount, val);
                            }
                            m_maxlistcount++;
                        }
                    }
                }
                progressMonitor.worked(1);
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "createstatistic", "label", getLanguage()));
                Iterator iter = stat.keySet().iterator();
                String key = null;
                String count = null;
                while (iter.hasNext()) {
                    key = (String) iter.next();
                    if (!(key.endsWith(".cbc"))) {
                        count = stat.getProperty(key, "");
                        items.add(new String[] { stat.getProperty(key + ".cbc"), count });
                    }
                }
                stat.clear();
                Collections.sort(items, new StatisticComparator());
                progressMonitor.done();
                isCalculating = false;
            }
        };
        pmd.setBlockOnOpen(false);
        pmd.run(true, false, r);
    // ModalContext.run(r, true, pmd.getProgressMonitor(),
    // DisplayManager.getDefaultDisplay());
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        isCalculating = false;
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        isCalculating = false;
    }
    while (isCalculating) try {
        Thread.sleep(1250);
    } catch (InterruptedException e) {
    }
    return items;
}
Also used : ICall(de.janrufmonitor.framework.ICall) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Properties(java.util.Properties) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 72 with ICall

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

the class AbstractCallDatabaseHandler method internalDeleteCallList.

private void internalDeleteCallList(ICallList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    PreparedStatement ps = this.getStatement("DELETE_CALL");
    PreparedStatement psa = this.getStatement("DELETE_ATTRIBUTE");
    ps.clearBatch();
    psa.clearBatch();
    ICall c = null;
    ICaller ca = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        ca = c.getCaller();
        ps.setString(1, c.getUUID());
        ps.addBatch();
        psa.setString(1, c.getUUID());
        psa.addBatch();
        if (!this.isCallerUsedElsewhere(ca.getUUID())) {
            psa.setString(1, ca.getUUID());
            psa.addBatch();
        }
        if (i % this.commit_count == 0) {
            ps.executeBatch();
            ps.clearBatch();
            this.m_logger.info("Executed prepared statement: " + ps.toString());
            psa.executeBatch();
            psa.clearBatch();
            this.m_logger.info("Executed prepared statement: " + psa.toString());
        }
    }
    // execute the rest batch content
    ps.executeBatch();
    psa.executeBatch();
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 73 with ICall

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

the class AbstractCallDatabaseHandler method updateCallList.

/**
 * Updates all calls in the submitted list. The select criterion of teh call is its UUID.
 * @param cl
 * @throws SQLException
 */
public void updateCallList(ICallList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    if (this.containsListAll(cl.size())) {
        this.createTables();
        this.setCallList(cl);
        return;
    }
    PreparedStatement ps = this.getStatement("UPDATE_CALL");
    PreparedStatement psa = this.getStatement("UPDATE_ATTRIBUTE");
    ps.clearBatch();
    psa.clearBatch();
    ICall c = null;
    IPhonenumber pn = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        pn = c.getCaller().getPhoneNumber();
        try {
            this.updateCall(ps, c.getUUID(), c.getCaller().getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), c.getMSN().getMSN(), c.getCIP().getCIP(), c.getDate().getTime(), Serializer.toByteArray(c));
            this.updateAttributes(psa, c.getUUID(), c.getAttributes());
            this.updateAttributes(psa, c.getCaller().getUUID(), c.getCaller().getAttributes());
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
        if (i % this.commit_count == 0) {
            ps.executeBatch();
            ps.clearBatch();
            this.m_logger.info("Executed prepared statement: " + ps.toString());
            psa.executeBatch();
            psa.clearBatch();
            this.m_logger.info("Executed prepared statement: " + psa.toString());
        }
    }
    // execute the rest batch content
    ps.executeBatch();
    psa.executeBatch();
}
Also used : ICall(de.janrufmonitor.framework.ICall) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 74 with ICall

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

the class AbstractCallDatabaseHandler method setCallList.

/**
 * Sets all calls in the submitted list to the database.
 *
 * @param cl
 * @throws SQLException
 */
public void setCallList(ICallList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    this.internalDeleteCallList(cl);
    List uuid_check = new ArrayList(cl.size());
    PreparedStatement ps = this.getStatement("INSERT_CALL");
    PreparedStatement psa = this.getStatement("INSERT_ATTRIBUTE");
    ps.clearBatch();
    psa.clearBatch();
    ICall c = null;
    IPhonenumber pn = null;
    String uuid = null;
    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);
        pn = c.getCaller().getPhoneNumber();
        try {
            this.createCall(ps, uuid, c.getCaller().getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), c.getMSN().getMSN(), c.getCIP().getCIP(), c.getDate().getTime(), Serializer.toByteArray(c));
            this.createAttributes(psa, uuid, c.getAttributes());
            this.createAttributes(psa, c.getCaller().getUUID(), c.getCaller().getAttributes());
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
        if (i % this.commit_count == 0) {
            try {
                ps.executeBatch();
                psa.executeBatch();
                ps.clearBatch();
                psa.clearBatch();
                this.m_logger.info("-------------------> executed Batch");
            } 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
    ps.executeBatch();
    psa.executeBatch();
    uuid_check.clear();
    uuid_check = null;
}
Also used : ICall(de.janrufmonitor.framework.ICall) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ICallList(de.janrufmonitor.framework.ICallList) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement) UUID(de.janrufmonitor.util.uuid.UUID) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 75 with ICall

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

the class AbstractFilterCallManager method filterCalls.

protected ICallList filterCalls(IFilter filter, ICallList cl) {
    if (cl == null) {
        cl = this.getInitialCallList(filter);
    }
    long start = System.currentTimeMillis();
    this.m_logger.info("Start filtering with filter: " + filter);
    this.m_logger.info("CallList size before filtering: " + cl.size());
    ICall c = null;
    if (filter != null) {
        if (filter.getType().equals(FilterType.DATE) || filter.getType().equals(FilterType.YEAR) || filter.getType().equals(FilterType.MONTH_YEAR)) {
            long from = 0;
            long to = 0;
            if (filter instanceof DateFilter) {
                DateFilter df = (DateFilter) filter;
                to = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
                from = df.getDateTo().getTime();
            }
            if (filter instanceof YearFilter) {
                YearFilter df = (YearFilter) filter;
                from = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
                to = df.getDateTo().getTime();
            }
            if (filter instanceof MonthYearFilter) {
                MonthYearFilter df = (MonthYearFilter) filter;
                from = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
                to = df.getDateTo().getTime();
            }
            long cdate = 0;
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                cdate = c.getDate().getTime();
                if (to > 0) {
                    if (cdate < from || cdate > to)
                        cl.remove(c);
                } else {
                    if (cdate < from)
                        cl.remove(c);
                }
            }
        }
        if (filter.getType().equals(FilterType.CALLER)) {
            ICaller cfilter = (ICaller) filter.getFilterObject();
            IPhonenumber pn = cfilter.getPhoneNumber();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getCaller().getPhoneNumber().equals(pn))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.PHONENUMBER)) {
            IPhonenumber pn = (IPhonenumber) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getCaller().getPhoneNumber().equals(pn))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.CIP)) {
            ICip cip = (ICip) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getCIP().equals(cip))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.MSN)) {
            IMsn msn = (IMsn) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getMSN().equals(msn))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.UUID)) {
            String[] uuids = (String[]) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                boolean hasUUID = false;
                for (int j = 0; j < uuids.length; j++) {
                    if (c.getUUID().equalsIgnoreCase(uuids[j]))
                        hasUUID = true;
                }
                if (!hasUUID)
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.ATTRIBUTE)) {
            IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
            if (m != null && m.size() > 0) {
                Iterator iter = m.iterator();
                IAttribute a = null;
                while (iter.hasNext()) {
                    a = (IAttribute) iter.next();
                    IAttribute ua = null;
                    for (int i = cl.size() - 1; i >= 0; i--) {
                        c = cl.get(i);
                        ua = c.getAttribute(a.getName());
                        if (ua == null || !ua.getValue().equalsIgnoreCase(a.getValue())) {
                            cl.remove(c);
                        }
                    }
                }
            }
        }
        if (filter.getType().equals(FilterType.ITEMCOUNT)) {
            int itemcount = ((ItemCountFilter) filter).getLimit();
            if (itemcount > 0) {
                ICallList tmpCl = this.getRuntime().getCallFactory().createCallList(itemcount);
                // added: 2006/04/20: just a work-a-round
                cl.sort(0, false);
                for (int i = 0, j = Math.min(cl.size(), itemcount); i < j; i++) {
                    tmpCl.add(cl.get(i));
                }
                cl.clear();
                cl.add(tmpCl);
            }
        }
    }
    this.m_logger.info("CallList size after filtering: " + cl.size());
    this.m_logger.info("Finished filtering with filter <" + filter + "> in " + Long.toString(System.currentTimeMillis() - start) + " msec.");
    return cl;
}
Also used : ICall(de.janrufmonitor.framework.ICall) ICip(de.janrufmonitor.framework.ICip) ICaller(de.janrufmonitor.framework.ICaller) ItemCountFilter(de.janrufmonitor.repository.filter.ItemCountFilter) ICallList(de.janrufmonitor.framework.ICallList) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) MonthYearFilter(de.janrufmonitor.repository.filter.MonthYearFilter) YearFilter(de.janrufmonitor.repository.filter.YearFilter) DateFilter(de.janrufmonitor.repository.filter.DateFilter) IMsn(de.janrufmonitor.framework.IMsn) MonthYearFilter(de.janrufmonitor.repository.filter.MonthYearFilter) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

ICall (de.janrufmonitor.framework.ICall)89 ICaller (de.janrufmonitor.framework.ICaller)41 List (java.util.List)23 Viewer (org.eclipse.jface.viewers.Viewer)20 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)19 ArrayList (java.util.ArrayList)19 IAttribute (de.janrufmonitor.framework.IAttribute)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 ICallList (de.janrufmonitor.framework.ICallList)17 IOException (java.io.IOException)14 Properties (java.util.Properties)14 Date (java.util.Date)13 Iterator (java.util.Iterator)13 Shell (org.eclipse.swt.widgets.Shell)13 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 ICip (de.janrufmonitor.framework.ICip)10 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)10