Search in sources :

Example 1 with DLInfo

use of com.zimbra.soap.account.type.DLInfo 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 DLInfo

use of com.zimbra.soap.account.type.DLInfo in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method kvpForCreateDLRespBug74371.

/*
# 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 kvpForCreateDLRespBug74371() 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<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 3 with DLInfo

use of com.zimbra.soap.account.type.DLInfo 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 4 with DLInfo

use of com.zimbra.soap.account.type.DLInfo in project zm-mailbox by Zimbra.

the class TestDelegatedDL method getAccountDistributionLists.

@Test
public void getAccountDistributionLists() throws Exception {
    String GROUP_1_NAME = getAddress(genGroupNameLocalPart("1"));
    String GROUP_1_DISPLAY_NAME = "last";
    String GROUP_2_NAME = getAddress(genGroupNameLocalPart("2"));
    String GROUP_2_DISPLAY_NAME = "first";
    String GROUP_3_NAME = getAddress(genGroupNameLocalPart("3"));
    String GROUP_3_DISPLAY_NAME = "first";
    String GROUP_4_NAME = getAddress(genGroupNameLocalPart("4"));
    String GROUP_4_DISPLAY_NAME = "first";
    Group group1 = provUtil.createGroup(GROUP_1_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_1_DISPLAY_NAME), DYNAMIC);
    Group group2 = provUtil.createGroup(GROUP_2_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_2_DISPLAY_NAME), DYNAMIC);
    Group group3 = provUtil.createGroup(GROUP_3_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_3_DISPLAY_NAME), DYNAMIC);
    Group group4 = provUtil.createGroup(GROUP_4_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_4_DISPLAY_NAME), DYNAMIC);
    // create an account
    String ACCT_NAME = getAddress(genAcctNameLocalPart());
    Account acct = provUtil.createAccount(ACCT_NAME);
    // add the account in groups
    prov.addGroupMembers(group1, new String[] { ACCT_NAME });
    prov.addGroupMembers(group2, new String[] { ACCT_NAME });
    prov.addGroupMembers(group3, new String[] { ACCT_NAME });
    // make the account owner of groups
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group1.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group4.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    SoapTransport transport = authUser(ACCT_NAME);
    GetAccountDistributionListsRequest req = new GetAccountDistributionListsRequest(Boolean.TRUE, MemberOfSelector.all, Sets.newHashSet(Provisioning.A_zimbraMailStatus, Provisioning.A_zimbraDistributionListSubscriptionPolicy, Provisioning.A_zimbraDistributionListUnsubscriptionPolicy));
    GetAccountDistributionListsResponse resp = invokeJaxb(transport, req);
    List<String> result = Lists.newArrayList();
    List<DLInfo> groups = resp.getDlList();
    for (DLInfo dlInfo : groups) {
        String id = dlInfo.getId();
        String name = dlInfo.getName();
        String displayName = dlInfo.getDisplayName();
        Boolean isOwner = dlInfo.isOwner();
        Boolean isMember = dlInfo.isMember();
        List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
        List<String> attrValues = Lists.newArrayList();
        for (KeyValuePair attr : attrs) {
            String key = attr.getKey();
            String value = attr.getValue();
            attrValues.add(Verify.makeResultStr(key, value));
        }
        Collections.sort(attrValues);
        result.add(Verify.makeResultStr(id, name, displayName, isOwner, isMember, attrValues));
    }
    List<String> expectedAttrValuesOwner = Lists.newArrayList();
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.REJECT.name()));
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListUnsubscriptionPolicy, ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT.name()));
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraMailStatus, ZAttrProvisioning.MailStatus.enabled.name()));
    List<String> expectedAttrValuesNonOwner = Lists.newArrayList();
    expectedAttrValuesNonOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.REJECT.name()));
    expectedAttrValuesNonOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListUnsubscriptionPolicy, ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT.name()));
    // result should be sorted by displayName.
    // If displayName are the same, sorted by entry.getLabel()
    Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group4.getId(), group4.getName(), group4.getDisplayName(), Boolean.TRUE, Boolean.FALSE, expectedAttrValuesOwner), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName(), Boolean.TRUE, Boolean.TRUE, expectedAttrValuesOwner)), result);
    // rename group
    String GROUP_NEW_NAME = getAddress(genGroupNameLocalPart("new"));
    prov.renameGroup(group1.getId(), GROUP_NEW_NAME);
    // get membership again, should show the new name
    result.clear();
    groups = resp.getDlList();
    for (DLInfo dlInfo : groups) {
        String id = dlInfo.getId();
        String name = dlInfo.getName();
        String displayName = dlInfo.getDisplayName();
        Boolean isOwner = dlInfo.isOwner();
        Boolean isMember = dlInfo.isMember();
        List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
        List<String> attrValues = Lists.newArrayList();
        for (KeyValuePair attr : attrs) {
            String key = attr.getKey();
            String value = attr.getValue();
            attrValues.add(Verify.makeResultStr(key, value));
        }
        Collections.sort(attrValues);
        result.add(Verify.makeResultStr(id, name, displayName, isOwner, isMember, attrValues));
    }
    // result should be sorted by displayName
    Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group4.getId(), group4.getName(), group4.getDisplayName(), Boolean.TRUE, Boolean.FALSE, expectedAttrValuesOwner), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName(), Boolean.TRUE, Boolean.TRUE, expectedAttrValuesOwner)), result);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) KeyValuePair(com.zimbra.soap.type.KeyValuePair) GetAccountDistributionListsResponse(com.zimbra.soap.account.message.GetAccountDistributionListsResponse) GetAccountDistributionListsRequest(com.zimbra.soap.account.message.GetAccountDistributionListsRequest) DLInfo(com.zimbra.soap.account.type.DLInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Aggregations

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