Search in sources :

Example 1 with CreateDistributionListResponse

use of com.zimbra.soap.account.message.CreateDistributionListResponse in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method kvpForCreateDLResp_bug74371.

/*
# zmsoap -z -t account -m user1 GetDistributionListRequest/dl=grendl@coco.local @by=name
<GetDistributionListResponse xmlns="urn:zimbraAccount">
  <dl id="7a3e8ec5-4892-4b17-9225-cf17e8b3acc9" dynamic="1" name="grendl@coco.local" isOwner="1" isMember="1">
    <a n="mail">grendl@coco.local</a>
    <a n="zimbraMailStatus">enabled</a>
    <a n="zimbraMailAlias">grendl@coco.local</a>
    <a n="description">Wonder at that</a>
    <a n="displayName">Gren DLfun</a>
    <a n="zimbraDistributionListSubscriptionPolicy">ACCEPT</a>
    <a n="zimbraDistributionListUnsubscriptionPolicy">ACCEPT</a>
  </dl>
</GetDistributionListResponse>
# zmsoap --json -z -t account -m user1 GetDistributionListRequest/dl=grendl@coco.local @by=name
{
  "dl": [{
      "name": "grendl@coco.local",
      "id": "7a3e8ec5-4892-4b17-9225-cf17e8b3acc9",
      "dynamic": true,
      "isMember": true,
      "isOwner": true,
      "_attrs": {
        "mail": "grendl@coco.local",
        "zimbraMailStatus": "enabled",
        "zimbraMailAlias": "grendl@coco.local",
        "description": "Wonder at that",
        "displayName": "Gren DLfun",
        "zimbraDistributionListSubscriptionPolicy": "ACCEPT",
        "zimbraDistributionListUnsubscriptionPolicy": "ACCEPT"
      }
    }],
  "_jsns": "urn:zimbraAccount"
}

Extract from mailbox.log for creation of this DL by ZWC - demonstrating the different handling of attrs - See Bug 74371

      "CreateDistributionListResponse": [{
          "dl": [{
              "name": "grendl@coco.local",
              "id": "7a3e8ec5-4892-4b17-9225-cf17e8b3acc9",
              "dynamic": true,
              "a": [
                {
                  "n": "memberURL",
                  "_content": "ldap:///??sub?(|(zimbraMemberOf=7a3e8ec5-4892-4b17-9225-cf17e8b3acc9)(zimbraId=de47828e-94dd-45c3-9770-4dbd255564ca))"
                },
                {
                  "n": "mail",
                  "_content": "grendl@coco.local"
                },
                ...
     */
/**
     * Desired JSON
     */
// Re-enable when Bug 74371 is fixed? @Test
public void kvpForCreateDLResp_bug74371() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get(AccountConstants.E_CREATE_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateCreateDlResp(jsonElem);
    Element xmlElem = XMLElement.mFactory.createElement(QName.get(AccountConstants.E_CREATE_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateCreateDlResp(xmlElem);
    logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    List<KeyValuePair> attrs = Lists.newArrayList();
    attrs.add(new KeyValuePair("key1", "value1"));
    attrs.add(new KeyValuePair("key2", "value2"));
    DLInfo dl = new DLInfo("myId", "myRef", "my name", null, null, null, null, null);
    CreateDistributionListResponse jaxb = new CreateDistributionListResponse(dl);
    Element xmlJaxbElem = JaxbUtil.jaxbToElement(jaxb, XMLElement.mFactory);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    DLInfo roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, DLInfo.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    logDebug("XMLElement from JAXB ---> prettyPrint\n%1$s", xmlJaxbElem.prettyPrint());
    Element eDL = jsonJaxbElem.getElement(AdminConstants.E_DL);
    List<? extends KeyValuePair> kvps = roundtripped.getAttrList();
    Assert.assertEquals("roundtripped kvps num", 2, kvps.size());
    List<com.zimbra.common.soap.Element.KeyValuePair> elemKVPs = eDL.getElement("a").listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 2, elemKVPs.size());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) CreateDistributionListResponse(com.zimbra.soap.account.message.CreateDistributionListResponse) DLInfo(com.zimbra.soap.account.type.DLInfo)

Example 2 with CreateDistributionListResponse

use of com.zimbra.soap.account.message.CreateDistributionListResponse in project zm-mailbox by Zimbra.

the class TestDelegatedDL method createDelegatedGroup.

private static Group createDelegatedGroup(SoapTransport transport, String groupName, List<KeyValuePair> attrs) throws Exception {
    Group group = prov.getGroup(Key.DistributionListBy.name, groupName);
    assertNull(group);
    CreateDistributionListRequest req = new CreateDistributionListRequest(groupName, attrs, DYNAMIC);
    CreateDistributionListResponse resp = invokeJaxb(transport, req);
    group = prov.getGroup(Key.DistributionListBy.name, groupName);
    assertNotNull(group);
    assertEquals(groupName, group.getName());
    assertNotNull(group.getAttr(Provisioning.A_zimbraMailHost));
    return group;
}
Also used : Group(com.zimbra.cs.account.Group) CreateDistributionListRequest(com.zimbra.soap.account.message.CreateDistributionListRequest) CreateDistributionListResponse(com.zimbra.soap.account.message.CreateDistributionListResponse)

Example 3 with CreateDistributionListResponse

use of com.zimbra.soap.account.message.CreateDistributionListResponse in project zm-mailbox by Zimbra.

the class TestDelegatedDL method createDistributionListPermDenied.

@Test
public void createDistributionListPermDenied() throws Exception {
    String dlName = getAddress(genGroupNameLocalPart());
    SoapTransport transport = authUser(USER_OWNER);
    CreateDistributionListRequest req = new CreateDistributionListRequest(dlName, null, DYNAMIC);
    boolean caughtPermDenied = false;
    try {
        CreateDistributionListResponse resp = invokeJaxb(transport, req);
    } catch (SoapFaultException e) {
        String code = e.getCode();
        if (ServiceException.PERM_DENIED.equals(code)) {
            caughtPermDenied = true;
        }
    }
    assertTrue(caughtPermDenied);
}
Also used : CreateDistributionListRequest(com.zimbra.soap.account.message.CreateDistributionListRequest) CreateDistributionListResponse(com.zimbra.soap.account.message.CreateDistributionListResponse) SoapTransport(com.zimbra.common.soap.SoapTransport) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 4 with CreateDistributionListResponse

use of com.zimbra.soap.account.message.CreateDistributionListResponse in project zm-mailbox by Zimbra.

the class TestDelegatedDL method createDistributionList.

@Test
public void createDistributionList() throws Exception {
    String dlName = getAddress(genGroupNameLocalPart());
    SoapTransport transport = authUser(USER_CREATOR);
    CreateDistributionListRequest req = new CreateDistributionListRequest(dlName, null, DYNAMIC);
    List<KeyValuePair> attrsCreate = Lists.newArrayList(new KeyValuePair(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name()));
    req.setKeyValuePairs(attrsCreate);
    CreateDistributionListResponse resp = invokeJaxb(transport, req);
    DLInfo dlInfo = resp.getDl();
    String dlId = dlInfo.getId();
    Group group = prov.getGroup(Key.DistributionListBy.name, dlName);
    assertNotNull(group);
    assertEquals(group.getId(), dlId);
    boolean seenExpectedMail = false;
    boolean seenExpectedSubsPolicy = false;
    List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
    for (KeyValuePair attr : attrs) {
        String name = attr.getKey();
        String value = attr.getValue();
        if (Provisioning.A_mail.equals(name)) {
            assertEquals(group.getName(), value);
            seenExpectedMail = true;
        }
        if (Provisioning.A_zimbraDistributionListSubscriptionPolicy.equals(name)) {
            assertEquals(ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name(), value);
            seenExpectedSubsPolicy = true;
        }
    }
    assertTrue(seenExpectedMail);
    assertTrue(seenExpectedSubsPolicy);
}
Also used : Group(com.zimbra.cs.account.Group) CreateDistributionListRequest(com.zimbra.soap.account.message.CreateDistributionListRequest) KeyValuePair(com.zimbra.soap.type.KeyValuePair) CreateDistributionListResponse(com.zimbra.soap.account.message.CreateDistributionListResponse) DLInfo(com.zimbra.soap.account.type.DLInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 5 with CreateDistributionListResponse

use of com.zimbra.soap.account.message.CreateDistributionListResponse in project zm-mailbox by Zimbra.

the class TestDelegatedDL method createGroupAndAddOwner.

private static Group createGroupAndAddOwner(String groupName, Multimap<String, String> attrs, String ownerName) throws Exception {
    Group group = prov.getGroup(Key.DistributionListBy.name, groupName);
    assertNull(group);
    SoapTransport transport = authUser(USER_CREATOR);
    CreateDistributionListRequest req = new CreateDistributionListRequest(groupName, KeyValuePair.fromMultimap(attrs), DYNAMIC);
    CreateDistributionListResponse resp = invokeJaxb(transport, req);
    group = prov.getGroup(Key.DistributionListBy.name, groupName);
    assertNotNull(group);
    assertEquals(groupName, group.getName());
    assertNotNull(group.getAttr(Provisioning.A_zimbraMailHost));
    /*
         * USER_CREATOR is automatically an owner now.
         */
    // add ownerName as an owner
    addOwner(transport, groupName, ownerName);
    // remove USER_CREATOR from the owner list
    removeOwner(transport, groupName, USER_CREATOR);
    return group;
}
Also used : Group(com.zimbra.cs.account.Group) CreateDistributionListRequest(com.zimbra.soap.account.message.CreateDistributionListRequest) CreateDistributionListResponse(com.zimbra.soap.account.message.CreateDistributionListResponse) SoapTransport(com.zimbra.common.soap.SoapTransport)

Aggregations

CreateDistributionListResponse (com.zimbra.soap.account.message.CreateDistributionListResponse)5 CreateDistributionListRequest (com.zimbra.soap.account.message.CreateDistributionListRequest)4 SoapTransport (com.zimbra.common.soap.SoapTransport)3 Group (com.zimbra.cs.account.Group)3 DLInfo (com.zimbra.soap.account.type.DLInfo)2 KeyValuePair (com.zimbra.soap.type.KeyValuePair)2 Test (org.junit.Test)2 Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlElement (javax.xml.bind.annotation.XmlElement)1