Search in sources :

Example 21 with IAttribute

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

the class CommentCallerHandler method storeComments.

private void storeComments(List comments, String directory) {
    // clean up old comments
    File[] oldComments = new File(directory).listFiles(new FileFilter() {

        public boolean accept(File pathname) {
            if (pathname.getAbsolutePath().endsWith(getCommentFilenameExtension())) {
                return true;
            }
            return false;
        }
    });
    for (int i = 0; i < oldComments.length; i++) oldComments[i].delete();
    for (int i = 0; i < comments.size(); i++) {
        IComment comment = (IComment) comments.get(i);
        File commentFile = new File(directory + comment.getID() + this.getCommentFilenameExtension());
        try {
            FileWriter commentWriter = new FileWriter(commentFile);
            BufferedWriter bufWriter = new BufferedWriter(commentWriter);
            bufWriter.write(comment.getText());
            bufWriter.flush();
            bufWriter.close();
            commentWriter.close();
        } catch (FileNotFoundException ex) {
            this.m_logger.severe("File not found: " + directory + comment.getID());
        } catch (IOException ex) {
            this.m_logger.severe("IOException on file " + directory + comment.getID());
        }
        commentFile.setLastModified(comment.getDate().getTime());
        Properties commentAttributes = new Properties();
        IAttributeMap m = comment.getAttributes();
        Iterator it = m.iterator();
        IAttribute a = null;
        while (it.hasNext()) {
            a = (IAttribute) it.next();
            commentAttributes.setProperty(a.getName(), a.getValue());
        }
        File commentAttributesFile = new File(commentFile.getAbsolutePath() + ".attributes");
        try {
            FileOutputStream fos = new FileOutputStream(commentAttributesFile);
            commentAttributes.store(fos, "");
            fos.flush();
            fos.close();
        } catch (FileNotFoundException ex) {
            this.m_logger.severe("File not found: " + directory + comment.getID());
        } catch (IOException ex) {
            this.m_logger.severe("IOException on file " + directory + comment.getID());
        }
        commentAttributesFile.setLastModified(comment.getDate().getTime());
    // TODO: removed due to performance reasons
    // this.storeAttachments(comment.getAttachments(), directory + comment.getID());
    }
}
Also used : IComment(de.janrufmonitor.service.comment.api.IComment) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) FileFilter(java.io.FileFilter) File(java.io.File)

Example 22 with IAttribute

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

the class CommentDialog method okPressed.

protected void okPressed() {
    this.m_comment.setText(m_textField.getText());
    IAttribute a = getRuntime().getCallerFactory().createAttribute(IComment.COMMENT_ATTRIBUTE_STATUS, this.m_status.getItem(this.m_status.getSelectionIndex()));
    this.m_comment.addAttribute(a);
    a = getRuntime().getCallerFactory().createAttribute(IComment.COMMENT_ATTRIBUTE_FOLLOWUP, (this.m_followup.getSelection() ? IJAMConst.ATTRIBUTE_VALUE_YES : IJAMConst.ATTRIBUTE_VALUE_NO));
    this.m_comment.addAttribute(a);
    a = getRuntime().getCallerFactory().createAttribute(IComment.COMMENT_ATTRIBUTE_MODIFIED, Long.toString(System.currentTimeMillis()));
    this.m_comment.addAttribute(a);
    a = getRuntime().getCallerFactory().createAttribute(IComment.COMMENT_ATTRIBUTE_SUBJECT, m_subject.getText());
    this.m_comment.addAttribute(a);
    super.okPressed();
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute)

Example 23 with IAttribute

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

the class CallStatistic method run.

public void run() {
    Object[] o = this.m_app.getController().getElementArray();
    if (o != null && o.length > 0 && o[0] instanceof ICall) {
        Map msnStats = new HashMap();
        int count = o.length;
        int accumated = 0;
        ICall c = null;
        IAttribute att = null;
        for (int i = 0; i < o.length; i++) {
            c = (ICall) o[i];
            att = c.getAttribute("fritzbox.duration");
            if (att != null) {
                int call_dur = 0;
                try {
                    call_dur = Integer.parseInt(att.getValue());
                } catch (Exception e) {
                    this.m_logger.log(Level.SEVERE, e.toString(), e);
                }
                accumated += call_dur;
                if (msnStats.containsKey(c.getMSN().getMSN())) {
                    int d = ((Integer) msnStats.get(c.getMSN().getMSN())).intValue();
                    d += call_dur;
                    msnStats.put(c.getMSN().getMSN(), new Integer(d));
                } else {
                    msnStats.put(c.getMSN().getMSN(), new Integer(call_dur));
                }
            }
        }
        accumated = accumated / 60;
        int h = accumated / 60;
        int min = accumated % 60;
        Iterator iter = msnStats.keySet().iterator();
        StringBuffer sb = new StringBuffer();
        String msn = null;
        Formatter f = Formatter.getInstance(getRuntime());
        String CRLF = "\n";
        while (iter.hasNext()) {
            msn = (String) iter.next();
            int value = ((Integer) msnStats.get(msn)).intValue() / 60;
            sb.append("\t");
            sb.append(f.parse(IJAMConst.GLOBAL_VARIABLE_MSNFORMAT, getRuntime().getMsnManager().createMsn(msn)));
            sb.append(": ");
            sb.append((value / 60));
            sb.append("h ");
            sb.append((value % 60));
            sb.append("min ");
            if (iter.hasNext())
                sb.append(CRLF);
        }
        String text = this.getI18nManager().getString(this.getNamespace(), "stat", "description", this.getLanguage());
        text = StringUtils.replaceString(text, "{%1}", Integer.toString(count));
        text = StringUtils.replaceString(text, "{%2}", Integer.toString(h) + "h " + Integer.toString(min) + "min");
        text = StringUtils.replaceString(text, "{%3}", sb.toString());
        MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "stat", "label", this.getLanguage()), text);
        this.m_app.updateViews(false);
        return;
    }
}
Also used : ICall(de.janrufmonitor.framework.ICall) HashMap(java.util.HashMap) Formatter(de.janrufmonitor.util.formatter.Formatter) Shell(org.eclipse.swt.widgets.Shell) IAttribute(de.janrufmonitor.framework.IAttribute) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with IAttribute

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

the class HsqldbCallDatabaseHandler method prepareStatement.

private String prepareStatement(IFilter[] filters, int count, int offset, boolean isCounter, ISearchTerm[] searchTerms) {
    StringBuffer sql = new StringBuffer();
    // build SQL statement
    sql.append("SELECT");
    if (filters.length == 1 && filters[0] == null)
        filters = null;
    // 2008/11/28: optimized attribute filter call
    if (filters != null && filters.length > 0 && hasOnlyAttributeFilter(filters)) {
        if (isCounter) {
            sql.append(" COUNT(calls.uuid) ");
        } else {
            sql.append(" content ");
        }
        sql.append("FROM attributes LEFT JOIN calls ON calls.uuid=attributes.ref AND ");
        IFilter f = null;
        for (int i = 0; i < filters.length; i++) {
            f = filters[i];
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("(");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
        }
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" AND");
            sql.append(createSearchTerm(searchTerms));
        }
    } else if (filters != null && filters.length > 0) {
        int limit = -1;
        for (int i = 0; i < filters.length; i++) {
            if (filters[i] != null && filters[i].getType() == FilterType.ITEMCOUNT) {
                limit = ((ItemCountFilter) filters[i]).getLimit();
                if (!isCounter) {
                    // 2008/05/19: to be done since offset was introduced !!
                    count = limit;
                    offset = 0;
                }
            }
        }
        if (isCounter) {
            sql.append(" COUNT(calls.uuid) ");
        } else {
            sql.append(" content ");
        }
        sql.append("FROM calls");
        if (hasAttributeFilter(filters))
            sql.append(", attributes");
        if (filters.length == 1 && filters[0] != null && filters[0].getType() == FilterType.ITEMCOUNT)
            sql.append("");
        else
            sql.append(" WHERE ");
        IFilter f = null;
        boolean isCallerFilter = false;
        boolean isMsnFilter = false;
        for (int i = 0; i < filters.length; i++) {
            if (filters[i] != null && filters[i].getType() == FilterType.ITEMCOUNT) {
                // limit=((ItemCountFilter)filters[i]).getLimit();
                continue;
            }
            f = filters[i];
            if (f == null)
                continue;
            if (isCallerFilter && (f.getType() == FilterType.CALLER || f.getType() == FilterType.PHONENUMBER)) {
                if (i > 0)
                    sql.append(" OR ");
            } else if (isMsnFilter && f.getType() == FilterType.MSN) {
                if (i > 0)
                    sql.append(" OR ");
            } else {
                if (i > 0 && filters[i - 1].getType() != FilterType.ITEMCOUNT)
                    sql.append(" AND ");
            }
            if (f.getType() == FilterType.DATE) {
                DateFilter df = (DateFilter) f;
                sql.append("(calls.cdate>");
                sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
                sql.append(" AND calls.cdate<");
                sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
                sql.append(")");
            }
            if (f.getType() == FilterType.YEAR) {
                YearFilter df = (YearFilter) f;
                sql.append("(calls.cdate>");
                sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
                sql.append(" AND calls.cdate<");
                sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
                sql.append(")");
            }
            if (f.getType() == FilterType.MONTH_YEAR) {
                MonthYearFilter df = (MonthYearFilter) f;
                sql.append("(calls.cdate>");
                sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
                sql.append(" AND calls.cdate<");
                sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
                sql.append(")");
            }
            if (f.getType() == FilterType.CALLER) {
                if (!isCallerFilter)
                    sql.append("(");
                isCallerFilter = true;
                ICaller c = (ICaller) f.getFilterObject();
                IPhonenumber pn = c.getPhoneNumber();
                sql.append("(calls.country='");
                sql.append(pn.getIntAreaCode());
                sql.append("' AND calls.areacode='");
                sql.append(pn.getAreaCode());
                sql.append("' AND calls.number='");
                sql.append(pn.getCallNumber());
                sql.append("')");
                if (isCallerFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.CALLER))))
                    sql.append(")");
            }
            if (f.getType() == FilterType.PHONENUMBER) {
                if (!isCallerFilter)
                    sql.append("(");
                isCallerFilter = true;
                IPhonenumber pn = (IPhonenumber) f.getFilterObject();
                sql.append("(calls.country='");
                sql.append(pn.getIntAreaCode());
                sql.append("' AND calls.areacode='");
                sql.append(pn.getAreaCode());
                sql.append("' AND calls.number='");
                sql.append(pn.getCallNumber());
                sql.append("')");
                if (isCallerFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.PHONENUMBER))))
                    sql.append(")");
            }
            if (f.getType() == FilterType.CIP) {
                ICip cip = (ICip) f.getFilterObject();
                sql.append("calls.cip='");
                sql.append(cip.getCIP());
                sql.append("'");
            }
            if (f.getType() == FilterType.MSN) {
                IMsn[] msn = (IMsn[]) f.getFilterObject();
                if (msn != null && msn.length > 0) {
                    if (!isMsnFilter)
                        sql.append("(");
                    isMsnFilter = true;
                    sql.append("(");
                    for (int j = 0; j < msn.length; j++) {
                        if (j > 0)
                            sql.append(" OR ");
                        sql.append("calls.msn='");
                        sql.append(msn[j].getMSN());
                        sql.append("'");
                    }
                    sql.append(")");
                    if (isMsnFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.MSN))))
                        sql.append(")");
                }
            }
            if (f.getType() == FilterType.UUID) {
                String[] uuids = (String[]) f.getFilterObject();
                if (uuids != null && uuids.length > 0) {
                    sql.append("(");
                    for (int j = 0; j < uuids.length; j++) {
                        if (j > 0)
                            sql.append(" OR ");
                        sql.append("calls.uuid='");
                        sql.append(uuids[i]);
                        sql.append("'");
                    }
                    sql.append(")");
                }
            }
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("calls.uuid=attributes.ref AND (");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
        }
        if (searchTerms != null && searchTerms.length > 0) {
            if (filters.length == 1 && filters[0] != null && filters[0].getType() == FilterType.ITEMCOUNT)
                sql.append(" WHERE");
            else
                sql.append(" AND");
            sql.append(createSearchTerm(searchTerms));
        }
        if (limit > 0 && !isCounter) {
            sql.append(" ORDER BY cdate DESC");
        }
    } else {
        if (isCounter) {
            sql.append(" COUNT(calls.uuid) ");
        } else {
            sql.append(" content ");
        }
        sql.append("FROM calls");
        if (count > 0 && offset >= 0) {
            sql.append(" AS rtable");
        }
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" WHERE");
            sql.append(createSearchTerm(searchTerms));
        }
    }
    if (count > 0 && offset >= 0) {
        sql.append(" LIMIT ");
        sql.append(count);
        sql.append(" OFFSET ");
        sql.append(offset);
    }
    sql.append(";");
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info(sql.toString());
    return sql.toString();
}
Also used : ICip(de.janrufmonitor.framework.ICip) Date(java.util.Date) ICaller(de.janrufmonitor.framework.ICaller) IFilter(de.janrufmonitor.repository.filter.IFilter) ItemCountFilter(de.janrufmonitor.repository.filter.ItemCountFilter) 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)

Example 25 with IAttribute

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

the class HsqldbCallerDatabaseHandler method buildCallerList.

protected ICallerList buildCallerList(IFilter[] filters) throws SQLException {
    ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
    if (!isConnected())
        return cl;
    StringBuffer sql = new StringBuffer();
    Statement stmt = m_con.createStatement();
    // build SQL statement
    sql.append("SELECT content FROM callers");
    if (hasAttributeFilter(filters))
        sql.append(", attributes");
    if (filters != null && filters.length > 0 && filters[0] != null) {
        IFilter f = null;
        sql.append(" WHERE ");
        for (int i = 0; i < filters.length; i++) {
            f = filters[i];
            if (i > 0)
                sql.append(" AND ");
            if (f.getType() == FilterType.PHONENUMBER) {
                IPhonenumber pn = (IPhonenumber) f.getFilterObject();
                sql.append("country='" + pn.getIntAreaCode() + "' AND areacode='" + pn.getAreaCode() + "'");
            }
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("callers.uuid=attributes.ref AND (");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
            if (f.getType() == FilterType.CHARACTER) {
                sql.append("(");
                sql.append("callers.uuid=attributes.ref AND (");
                sql.append("attributes.name='");
                sql.append(((CharacterFilter) f).getAttributeName());
                sql.append("'");
                sql.append(" AND ");
                sql.append("(attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toUpperCase());
                sql.append("%'");
                sql.append(" OR attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toLowerCase());
                sql.append("%'");
                sql.append(")))");
            }
        }
    }
    sql.append(";");
    ResultSet rs = stmt.executeQuery(sql.toString());
    while (rs.next()) {
        try {
            cl.add(Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime()));
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    return cl;
}
Also used : CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) Statement(java.sql.Statement) SerializerException(de.janrufmonitor.util.io.SerializerException) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) ResultSet(java.sql.ResultSet) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IAttribute (de.janrufmonitor.framework.IAttribute)111 ICaller (de.janrufmonitor.framework.ICaller)44 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)40 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)39 List (java.util.List)34 ICallerList (de.janrufmonitor.framework.ICallerList)31 ArrayList (java.util.ArrayList)29 Iterator (java.util.Iterator)25 ICall (de.janrufmonitor.framework.ICall)19 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)15 SQLException (java.sql.SQLException)15 File (java.io.File)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)12 IOException (java.io.IOException)12 Message (de.janrufmonitor.exception.Message)11 ComFailException (com.jacob.com.ComFailException)10 Date (java.util.Date)10 IMsn (de.janrufmonitor.framework.IMsn)9 Dispatch (com.jacob.com.Dispatch)8 UUID (de.janrufmonitor.util.uuid.UUID)8