Search in sources :

Example 1 with ContactEntry

use of com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry in project zm-mailbox by Zimbra.

the class ContactRankings method dump.

private void dump(String action) {
    if (ZimbraLog.gal.isDebugEnabled()) {
        StringBuilder buf = new StringBuilder(action + " contact rankings");
        buf.append("\n");
        for (ContactEntry entry : getSortedSet()) {
            entry.toString(buf);
            buf.append("\n");
        }
        ZimbraLog.gal.debug(buf.toString());
    }
}
Also used : ContactEntry(com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry)

Example 2 with ContactEntry

use of com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry in project zm-mailbox by Zimbra.

the class ContactRankings method increment.

public synchronized void increment(String email, String displayName) {
    long now = System.currentTimeMillis();
    email = email.toLowerCase();
    ContactEntry entry = mEntries.get(email.toLowerCase());
    if (entry == null) {
        entry = new ContactEntry();
        entry.mEmail = email;
        entry.setName(displayName);
        entry.mRanking = 1;
        entry.mFolderId = ContactAutoComplete.FOLDER_ID_UNKNOWN;
        entry.mLastAccessed = now;
        if (mEntries.size() >= mTableSize) {
            ContactEntry lastEntry = getSortedSet().last();
            if (lastEntry.mRanking < 1)
                remove(lastEntry);
        }
        if (mEntries.size() < mTableSize) {
            add(entry);
        } else {
            for (ContactEntry e : mEntries.values()) {
                int weeksOld = (int) ((now - e.mLastAccessed) / Constants.MILLIS_PER_WEEK) + 1;
                e.mRanking -= weeksOld;
                if (e.mRanking < 0)
                    e.mRanking = 0;
            }
        }
    } else {
        entry.mRanking++;
        if (entry.mRanking <= 0)
            entry.mRanking = 1;
        if (displayName != null && displayName.length() > 0)
            entry.setName(displayName);
        entry.mLastAccessed = now;
    }
}
Also used : ContactEntry(com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry)

Example 3 with ContactEntry

use of com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry in project zm-mailbox by Zimbra.

the class AutoComplete method toXML.

protected void toXML(Element response, AutoCompleteResult result, String authAccountId) {
    response.addAttribute(MailConstants.A_CANBECACHED, result.canBeCached);
    for (ContactEntry entry : result.entries) {
        Element cn = response.addElement(MailConstants.E_MATCH);
        // separately on user request
        if (!entry.isContactGroup()) {
            cn.addAttribute(MailConstants.A_EMAIL, entry.getEmail());
        }
        cn.addAttribute(MailConstants.A_MATCH_TYPE, getType(entry));
        cn.addAttribute(MailConstants.A_RANKING, Integer.toString(entry.getRanking()));
        cn.addAttribute(MailConstants.A_IS_GROUP, entry.isGroup());
        if (entry.isGroup() && entry.canExpandGroupMembers()) {
            cn.addAttribute(MailConstants.A_EXP, true);
        }
        ItemId id = entry.getId();
        if (id != null) {
            cn.addAttribute(MailConstants.A_ID, id.toString(authAccountId));
        }
        int folderId = entry.getFolderId();
        if (folderId > 0) {
            cn.addAttribute(MailConstants.A_FOLDER, Integer.toString(folderId));
        }
        if (entry.isContactGroup()) {
            cn.addAttribute(MailConstants.A_DISPLAYNAME, entry.getDisplayName());
        }
        String firstName = entry.getFirstName();
        if (firstName != null) {
            cn.addAttribute(MailConstants.A_FIRSTNAME, firstName);
        }
        String middleName = entry.getMiddleName();
        if (middleName != null) {
            cn.addAttribute(MailConstants.A_MIDDLENAME, middleName);
        }
        String lastName = entry.getLastName();
        if (lastName != null) {
            cn.addAttribute(MailConstants.A_LASTNAME, lastName);
        }
        String fullName = entry.getFullName();
        if (fullName != null) {
            cn.addAttribute(MailConstants.A_FULLNAME, fullName);
        }
        String nickname = entry.getNickname();
        if (nickname != null) {
            cn.addAttribute(MailConstants.A_NICKNAME, nickname);
        }
        String company = entry.getCompany();
        if (company != null) {
            cn.addAttribute(MailConstants.A_COMPANY, company);
        }
        String fileAs = entry.getFileAs();
        if (fileAs != null) {
            cn.addAttribute(MailConstants.A_FILEAS, fileAs);
        }
    }
}
Also used : ContactEntry(com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId)

Example 4 with ContactEntry

use of com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry in project zm-mailbox by Zimbra.

the class ContactAutoCompleteTest method rankingTestContactWithSameEmailDifferentDisplayName.

@Test
public void rankingTestContactWithSameEmailDifferentDisplayName() throws Exception {
    // Autocomplete should show same ranking for a email address present in difference contacts.
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, "Pal");
    fields.put(ContactConstants.A_lastName, "One");
    fields.put(ContactConstants.A_email, "testauto@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    Map<String, Object> fields1 = new HashMap<String, Object>();
    fields1.put(ContactConstants.A_email, "testauto@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields1), Mailbox.ID_FOLDER_CONTACTS, null);
    ContactRankings.increment(mbox.getAccountId(), Collections.singleton(new InternetAddress("testauto@zimbra.com")));
    ContactRankings.increment(mbox.getAccountId(), Collections.singleton(new InternetAddress("testauto@zimbra.com")));
    ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox));
    AutoCompleteResult result = autocomplete.query("Pal", null, 10);
    Assert.assertEquals(1, result.entries.size());
    for (ContactEntry ce : result.entries) {
        Assert.assertEquals(2, ce.mRanking);
    }
    result.clear();
    result = autocomplete.query("testauto", null, 10);
    Assert.assertEquals(2, result.entries.size());
    for (ContactEntry ce : result.entries) {
        Assert.assertEquals(2, ce.mRanking);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) ParsedContact(com.zimbra.cs.mime.ParsedContact) AutoCompleteResult(com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult) HashMap(java.util.HashMap) ContactEntry(com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry) Test(org.junit.Test)

Example 5 with ContactEntry

use of com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry in project zm-mailbox by Zimbra.

the class ContactRankings method writeToDatabase.

private synchronized void writeToDatabase() throws ServiceException {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(mAccountId);
    Metadata config = new Metadata();
    for (ContactEntry entry : getSortedSet()) {
        Metadata m = new Metadata();
        m.put(KEY_RANKING, entry.mRanking);
        if (entry.mDisplayName != null)
            m.put(KEY_NAME, entry.mDisplayName);
        m.put(KEY_LAST_ACCESSED, entry.mLastAccessed);
        config.put(entry.mEmail, m);
    }
    mbox.setConfig(null, CONFIG_KEY_CONTACT_RANKINGS, config);
    dump("writing");
}
Also used : ContactEntry(com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry)

Aggregations

ContactEntry (com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry)7 HashMap (java.util.HashMap)2 Element (com.zimbra.common.soap.Element)1 AutoCompleteResult (com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult)1 ParsedContact (com.zimbra.cs.mime.ParsedContact)1 ItemId (com.zimbra.cs.service.util.ItemId)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 InternetAddress (javax.mail.internet.InternetAddress)1 Test (org.junit.Test)1