use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.
the class SoapProvisioning method autoCompleteGal.
@Override
public SearchGalResult autoCompleteGal(Domain d, String query, GalSearchType type, int limit, GalContact.Visitor visitor) throws ServiceException {
String typeStr = type == null ? GalSearchType.all.name() : type.name();
XMLElement req = new XMLElement(AdminConstants.AUTO_COMPLETE_GAL_REQUEST);
req.addElement(AdminConstants.E_NAME).setText(query);
req.addAttribute(AdminConstants.A_DOMAIN, d.getName());
req.addAttribute(AdminConstants.A_TYPE, typeStr);
req.addAttribute(AdminConstants.A_LIMIT, limit);
Element resp = invoke(req);
SearchGalResult result = SearchGalResult.newSearchGalResult(visitor);
result.setHadMore(resp.getAttributeBool(AdminConstants.A_MORE, false));
result.setTokenizeKey(resp.getAttribute(AccountConstants.A_TOKENIZE_KEY, null));
for (Element e : resp.listElements(AdminConstants.E_CN)) {
result.addMatch(new GalContact(e.getAttribute(AdminConstants.A_ID), getAttrs(e)));
}
return result;
}
use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.
the class TestSearchGal method searchWithOffsetLimit.
private void searchWithOffsetLimit(boolean ldap, String domainName) throws Exception {
SoapTransport transport = authUser(TestUtil.getAddress(AUTHED_USER, domainName));
Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_GAL_REQUEST);
request.addElement(AccountConstants.E_NAME).setText(".");
int offset = 5;
int limit = 3;
request.addAttribute(MailConstants.A_QUERY_OFFSET, offset);
request.addAttribute(MailConstants.A_QUERY_LIMIT, limit);
request.addAttribute(MailConstants.A_SORTBY, "nameAsc");
Element response = transport.invoke(request);
boolean paginationSupported = response.getAttributeBool(AccountConstants.A_PAGINATION_SUPPORTED);
List<GalContact> result = new ArrayList<GalContact>();
for (Element e : response.listElements(AdminConstants.E_CN)) {
result.add(new GalContact(AdminConstants.A_ID, SoapProvisioning.getAttrs(e)));
}
if (ldap) {
// pagination is not supported
assertFalse(paginationSupported);
// limit is ignored, ldap search is limited by zimbraGalMaxResults
// should find all objects, plus the authed user
assertEquals(NUM_ALL_OBJECTS + 1, result.size());
} else {
// pagination is supported
assertTrue(paginationSupported);
assertEquals(limit, result.size());
for (int i = 0; i < limit; i++) {
assertEquals(getAcctEmail(offset + i, domainName), result.get(i).getSingleAttr(ContactConstants.A_email));
}
}
}
use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.
the class TestSearchGal method binaryDataInEntry.
private void binaryDataInEntry(boolean ldap, String domainName, boolean wantSMIMECert) throws Exception {
SoapTransport transport = authUser(TestUtil.getAddress(AUTHED_USER, domainName));
Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_GAL_REQUEST);
if (wantSMIMECert) {
request.addAttribute(AccountConstants.A_NEED_SMIME_CERTS, true);
}
request.addElement(AccountConstants.E_NAME).setText(getAcctEmail(ACCOUNT_CONTAINS_BINARY_DATA, domainName));
Element response = transport.invoke(request);
List<GalContact> result = new ArrayList<GalContact>();
for (Element e : response.listElements(AdminConstants.E_CN)) {
result.add(new GalContact(AdminConstants.A_ID, SoapProvisioning.getAttrs(e)));
}
assertEquals(1, result.size());
GalContact galContact = result.get(0);
Map<String, Object> fields = galContact.getAttrs();
Object value = fields.get(BINARY_GALCONTACT_FIELD);
if (!wantSMIMECert) {
assertNull(value);
return;
}
assertTrue(value instanceof String[]);
String[] values = (String[]) value;
assertEquals(2, values.length);
boolean foundContent1 = false;
boolean foundContent2 = false;
for (String valueAsString : values) {
if (BINARY_CONTENT_1.equals(valueAsString)) {
foundContent1 = true;
}
if (BINARY_CONTENT_2.equals(valueAsString)) {
foundContent2 = true;
}
}
assertTrue(foundContent1);
assertTrue(foundContent2);
}
use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.
the class TestGal method tokenizeTest.
private void tokenizeTest(GalOp galOp, String tokenizeKey, String key, String[] expectedUsers) throws Exception {
Domain domain = mProv.get(Key.DomainBy.name, TOKENIZE_TEST_DOMAIN_NAME);
SearchGalResult galResult = null;
if (galOp == GalOp.GOP_AUTOCOMPLETE)
galResult = mProv.autoCompleteGal(domain, key, // Provisioning.GAL_SEARCH_TYPE.ALL,
GalSearchType.account, 10, null);
else if (galOp == GalOp.GOP_SEARCH)
galResult = mProv.searchGal(domain, key, GalSearchType.account, 0, null);
else
fail();
System.out.println("tokenizeTest: key=" + key);
assertEquals(galResult.getTokenizeKey(), tokenizeKey);
Set<String> results = new HashSet<String>();
for (GalContact gc : galResult.getMatches()) {
String r = (String) gc.getAttrs().get(ContactConstants.A_email);
System.out.println(" " + r);
results.add(r);
}
for (String mail : expectedUsers) assertTrue(results.contains(mail + "@" + TOKENIZE_TEST_DOMAIN_NAME));
List<String> expectedUsersList = Arrays.asList(expectedUsers);
for (String mail : results) assertTrue(expectedUsersList.contains((mail.split("@"))[0]));
assertEquals(expectedUsers.length, galResult.getNumMatches());
}
use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.
the class ToXML method encodeContactGroup.
private static void encodeContactGroup(Element elem, ContactGroup contactGroup, Collection<String> memberAttrFilter, ItemIdFormatter ifmt, OperationContext octxt, boolean summary, int fields) throws ServiceException {
for (ContactGroup.Member member : contactGroup.getMembers(true)) {
Element eMember = elem.addElement(MailConstants.E_CONTACT_GROUP_MEMBER);
encodeContactGroupMemberBasic(eMember, member);
Object derefedMember = member.getDerefedObj();
if (derefedMember != null) {
if (derefedMember instanceof String) {
// inline member, do nothing
} else if (derefedMember instanceof Contact) {
// only expand one level for now.
// If this member is a group, do not create/pass down a ContactGroup object from the member.
encodeContact(eMember, ifmt, octxt, (Contact) derefedMember, summary, memberAttrFilter, fields);
} else if (derefedMember instanceof GalContact) {
encodeGalContact(eMember, (GalContact) derefedMember, memberAttrFilter);
} else if (derefedMember instanceof Element) {
// proxied GAL or Contact entry
Element eContact = (Element) derefedMember;
if (memberAttrFilter != null) {
for (Element eAttr : eContact.listElements()) {
String name = eAttr.getAttribute(MailConstants.A_ATTRIBUTE_NAME, null);
if (!memberAttrFilter.contains(name)) {
eAttr.detach();
}
}
}
eMember.addElement(eContact);
}
}
}
}
Aggregations