Search in sources :

Example 6 with GalContact

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());
}
Also used : GalContact(com.zimbra.cs.account.GalContact) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Domain(com.zimbra.cs.account.Domain) HashSet(java.util.HashSet)

Example 7 with GalContact

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);
            }
        }
    }
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) GalContact(com.zimbra.cs.account.GalContact) Contact(com.zimbra.cs.mailbox.Contact)

Example 8 with GalContact

use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.

the class SoapProvisioning method searchGal.

public SearchGalResult searchGal(Domain d, String query, GalSearchType type, String token, int limit, int offset, String sortBy) throws ServiceException {
    String typeStr = type == null ? GalSearchType.all.name() : type.name();
    XMLElement req = new XMLElement(AdminConstants.SEARCH_GAL_REQUEST);
    req.addElement(AdminConstants.E_NAME).setText(query);
    req.addAttribute(AdminConstants.A_DOMAIN, d.getName());
    req.addAttribute(AdminConstants.A_TYPE, typeStr);
    if (limit > 0)
        req.addAttribute(AdminConstants.A_LIMIT, limit);
    if (offset > 0)
        req.addAttribute(AdminConstants.A_OFFSET, limit);
    if (sortBy != null)
        req.addAttribute(AdminConstants.A_SORT_BY, sortBy);
    if (token != null)
        req.addAttribute(AdminConstants.A_TOKEN, token);
    Element resp = invoke(req);
    SearchGalResult result = SearchGalResult.newSearchGalResult(null);
    result.setToken(resp.getAttribute(AdminConstants.A_TOKEN, null));
    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;
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 9 with GalContact

use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.

the class TestSearchGal method searchWithDot.

/*
    static void authAdmin(SoapTransport transport, String acctName) throws Exception {
        
        Element request = Element.create(transport.getRequestProtocol(), AdminConstants.AUTH_REQUEST);
        request.addElement(AccountConstants.E_ACCOUNT).addAttribute(AccountConstants.A_BY, AccountBy.name.name()).setText(acctName);
        request.addElement(AccountConstants.E_PASSWORD).setText("test123");
        
        Element response = transport.invoke(request);
        String authToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
        transport.setAuthToken(authToken);
    }
    */
private void searchWithDot(boolean ldap, String domainName, int expectedNumEntries) 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(".");
    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);
    } else {
        // pagination is supported
        assertTrue(paginationSupported);
    }
    // should find all objects, plus the authed user
    assertEquals(expectedNumEntries, result.size());
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 10 with GalContact

use of com.zimbra.cs.account.GalContact in project zm-mailbox by Zimbra.

the class TestSearchGal method searchByName.

private void searchByName(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(KEY_FOR_SEARCH_BY_NAME);
    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(NUM_ACCOUNTS, result.size());
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) SoapTransport(com.zimbra.common.soap.SoapTransport)

Aggregations

GalContact (com.zimbra.cs.account.GalContact)12 Element (com.zimbra.common.soap.Element)9 ArrayList (java.util.ArrayList)6 SoapTransport (com.zimbra.common.soap.SoapTransport)5 SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)3 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 Account (com.zimbra.cs.account.Account)2 Domain (com.zimbra.cs.account.Domain)2 Provisioning (com.zimbra.cs.account.Provisioning)2 GalOp (com.zimbra.cs.account.gal.GalOp)1 DavResource (com.zimbra.cs.dav.resource.DavResource)1 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)1 Contact (com.zimbra.cs.mailbox.Contact)1 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GalSearchType (com.zimbra.soap.type.GalSearchType)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1