Search in sources :

Example 1 with AutoCompleteResult

use of com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult 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 2 with AutoCompleteResult

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

the class AutoComplete method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(getZimbraSoapContext(context));
    OperationContext octxt = getOperationContext(zsc, context);
    String name = request.getAttribute(MailConstants.A_NAME);
    // remove commas (bug 46540)
    name = name.replace(",", " ").trim();
    if (StringUtils.isEmpty(name)) {
        throw ServiceException.INVALID_REQUEST("name parameter is empty", null);
    }
    GalSearchType type = GalSearchType.fromString(request.getAttribute(MailConstants.A_TYPE, "account"));
    int limit = account.getContactAutoCompleteMaxResults();
    boolean needCanExpand = request.getAttributeBool(MailConstants.A_NEED_EXP, false);
    AutoCompleteResult result = query(request, zsc, account, false, name, limit, type, needCanExpand, octxt);
    Element response = zsc.createElement(MailConstants.AUTO_COMPLETE_RESPONSE);
    toXML(response, result, zsc.getAuthtokenAccountId());
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) AutoCompleteResult(com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) GalSearchType(com.zimbra.soap.type.GalSearchType)

Aggregations

AutoCompleteResult (com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult)2 Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 ContactEntry (com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ParsedContact (com.zimbra.cs.mime.ParsedContact)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GalSearchType (com.zimbra.soap.type.GalSearchType)1 HashMap (java.util.HashMap)1 InternetAddress (javax.mail.internet.InternetAddress)1 Test (org.junit.Test)1