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