Search in sources :

Example 1 with CreateContactRequest

use of com.zimbra.soap.mail.message.CreateContactRequest in project zm-mailbox by Zimbra.

the class TestContactGroup method createAndGetContactGroup.

@Test
@Bug(bug = 70558)
public void createAndGetContactGroup() throws Exception {
    SoapTransport transport = authUser(acct.getName());
    /*
         * search gal to get ref of the member account in GAL
         */
    SearchGalRequest searchGalReq = new SearchGalRequest();
    searchGalReq.setName(memberAcct.getName());
    SearchGalResponse searchGalResp = invokeJaxb(transport, searchGalReq);
    List<ContactInfo> entries = searchGalResp.getContacts();
    assertEquals(1, entries.size());
    ContactInfo galEntry = entries.get(0);
    String galMemberRef = galEntry.getReference();
    /*
         * create a contact group
         */
    NewContactGroupMember contactGroupMemer = NewContactGroupMember.createForTypeAndValue(ContactGroup.Member.Type.GAL_REF.getSoapEncoded(), galMemberRef);
    NewContactAttr contactAttr = new NewContactAttr(ContactConstants.A_type);
    contactAttr.setValue(ContactConstants.TYPE_GROUP);
    ContactSpec contactSpec = new ContactSpec();
    contactSpec.addAttr(contactAttr);
    contactSpec.addContactGroupMember(contactGroupMemer);
    CreateContactRequest createContactReq = new CreateContactRequest(contactSpec);
    CreateContactResponse createContactResp = invokeJaxb(transport, createContactReq);
    String contactGroupId = createContactResp.getContact().getId();
    /*
         * get the contact group, derefed
         */
    GetContactsRequest getContactsReq = new GetContactsRequest();
    getContactsReq.addContact(new Id(contactGroupId));
    getContactsReq.setDerefGroupMember(Boolean.TRUE);
    GetContactsResponse getContactsResp = invokeJaxb(transport, getContactsReq, SoapProtocol.SoapJS);
    List<com.zimbra.soap.mail.type.ContactInfo> contacts = getContactsResp.getContacts();
    assertEquals(1, contacts.size());
    com.zimbra.soap.mail.type.ContactInfo contact = contacts.get(0);
    List<ContactGroupMember> members = contact.getContactGroupMembers();
    assertEquals(1, members.size());
    ContactGroupMember member = members.get(0);
    String memberType = member.getType();
    String memberValue = member.getValue();
    assertEquals(ContactGroup.Member.Type.GAL_REF.getSoapEncoded(), memberType);
    assertEquals(galMemberRef, memberValue);
}
Also used : ContactSpec(com.zimbra.soap.mail.type.ContactSpec) ContactGroupMember(com.zimbra.soap.mail.type.ContactGroupMember) NewContactGroupMember(com.zimbra.soap.mail.type.NewContactGroupMember) SearchGalResponse(com.zimbra.soap.account.message.SearchGalResponse) CreateContactResponse(com.zimbra.soap.mail.message.CreateContactResponse) SearchGalRequest(com.zimbra.soap.account.message.SearchGalRequest) CreateContactRequest(com.zimbra.soap.mail.message.CreateContactRequest) GetContactsResponse(com.zimbra.soap.mail.message.GetContactsResponse) GetContactsRequest(com.zimbra.soap.mail.message.GetContactsRequest) NewContactAttr(com.zimbra.soap.mail.type.NewContactAttr) ContactInfo(com.zimbra.soap.account.type.ContactInfo) NewContactGroupMember(com.zimbra.soap.mail.type.NewContactGroupMember) Id(com.zimbra.soap.type.Id) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 2 with CreateContactRequest

use of com.zimbra.soap.mail.message.CreateContactRequest in project zm-mailbox by Zimbra.

the class TestGetContactsRequest method createContact.

public ContactInfo createContact(SoapTransport soapTrans, String fullName) throws ServiceException, IOException, HttpException {
    ContactSpec contactSpec = new ContactSpec();
    contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_fullName, fullName));
    CreateContactResponse resp = invokeJaxb(soapTrans, new CreateContactRequest(contactSpec));
    assertNotNull(String.format("CreateContactResponse when creating %s should not be null", fullName), resp);
    ContactInfo contact = resp.getContact();
    assertNotNull(String.format("CreateContactResponse/cn when creating %s should not be null", fullName), contact);
    return contact;
}
Also used : CreateContactRequest(com.zimbra.soap.mail.message.CreateContactRequest) ContactSpec(com.zimbra.soap.mail.type.ContactSpec) CreateContactResponse(com.zimbra.soap.mail.message.CreateContactResponse) ContactInfo(com.zimbra.soap.mail.type.ContactInfo)

Example 3 with CreateContactRequest

use of com.zimbra.soap.mail.message.CreateContactRequest in project zm-mailbox by Zimbra.

the class TestGetContactsRequest method createContactGroup.

public ContactInfo createContactGroup(SoapTransport soapTrans, String fullName, String... memberIds) throws ServiceException, IOException, HttpException {
    ContactSpec contactSpec = new ContactSpec();
    contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_fullName, fullName));
    contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_type, ContactConstants.TYPE_GROUP));
    for (String id : memberIds) {
        contactSpec.addContactGroupMember(NewContactGroupMember.createForTypeAndValue(ContactGroup.Member.Type.CONTACT_REF.getSoapEncoded(), id));
    }
    CreateContactResponse resp = invokeJaxb(soapTrans, new CreateContactRequest(contactSpec));
    assertNotNull(String.format("CreateContactResponse when creating ContactGroup %s should not be null", fullName), resp);
    ContactInfo contact = resp.getContact();
    assertNotNull(String.format("CreateContactResponse/cn when creating ContactGroup %s should not be null", fullName), contact);
    return contact;
}
Also used : CreateContactRequest(com.zimbra.soap.mail.message.CreateContactRequest) ContactSpec(com.zimbra.soap.mail.type.ContactSpec) CreateContactResponse(com.zimbra.soap.mail.message.CreateContactResponse) ContactInfo(com.zimbra.soap.mail.type.ContactInfo)

Example 4 with CreateContactRequest

use of com.zimbra.soap.mail.message.CreateContactRequest in project zm-mailbox by Zimbra.

the class ZMailbox method createContact.

/**
 * Creates a new contact.
 * @param folderId the new contact's folder id
 * @param tags tags to set on the contact, or <tt>null</tt>
 * @param attrs contact attributes (key/value)
 * @param attachments contact attachments (key/upload id) or <tt>null</tt>
 * @param verbose <tt>false</tt> to only initialize the <tt>id</tt> of the return <tt>ZContact</tt> object
 * @return the new contact
 * @throws ServiceException
 */
public ZContact createContact(String folderId, String tags, Map<String, String> attrs, Map<String, ZAttachmentInfo> attachments, Map<String, String> members) throws ServiceException {
    ContactSpec contactSpec = new ContactSpec();
    CreateContactRequest ccReq = new CreateContactRequest(contactSpec);
    ccReq.setWantImapUid(true);
    ccReq.setWantModifiedSequence(true);
    if (folderId != null) {
        contactSpec.setFolder(folderId);
    }
    if (tags != null) {
        contactSpec.setTags(tags);
    }
    addAttrsAndAttachmentsToContact(contactSpec, attrs, attachments);
    if (members != null) {
        for (Map.Entry<String, String> entry : members.entrySet()) {
            contactSpec.addContactGroupMemberWithTypeAndValue(entry.getValue(), entry.getKey());
        }
    }
    return new ZContact(invokeJaxbToElement(ccReq).getElement(MailConstants.E_CONTACT), this);
}
Also used : CreateContactRequest(com.zimbra.soap.mail.message.CreateContactRequest) ModifyContactSpec(com.zimbra.soap.mail.type.ModifyContactSpec) ContactSpec(com.zimbra.soap.mail.type.ContactSpec) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Aggregations

CreateContactRequest (com.zimbra.soap.mail.message.CreateContactRequest)4 ContactSpec (com.zimbra.soap.mail.type.ContactSpec)4 CreateContactResponse (com.zimbra.soap.mail.message.CreateContactResponse)3 ContactInfo (com.zimbra.soap.mail.type.ContactInfo)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SoapTransport (com.zimbra.common.soap.SoapTransport)1 Bug (com.zimbra.qa.QA.Bug)1 SearchGalRequest (com.zimbra.soap.account.message.SearchGalRequest)1 SearchGalResponse (com.zimbra.soap.account.message.SearchGalResponse)1 ContactInfo (com.zimbra.soap.account.type.ContactInfo)1 GetContactsRequest (com.zimbra.soap.mail.message.GetContactsRequest)1 GetContactsResponse (com.zimbra.soap.mail.message.GetContactsResponse)1 ContactGroupMember (com.zimbra.soap.mail.type.ContactGroupMember)1 ModifyContactSpec (com.zimbra.soap.mail.type.ModifyContactSpec)1 NewContactAttr (com.zimbra.soap.mail.type.NewContactAttr)1 NewContactGroupMember (com.zimbra.soap.mail.type.NewContactGroupMember)1 Id (com.zimbra.soap.type.Id)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1