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;
}
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();
}
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();
}
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;
}
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;
}
Aggregations