Search in sources :

Example 1 with Attr

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

the class ToXML method encodeHabGroup.

/**
 * @param parent parent element of XML response
 * @param grp the group to encode
 * @param parentId id of the parent group
 */
public static void encodeHabGroup(Element parent, HABGroup grp, String parentId) {
    Element habGroup = parent.addNonUniqueElement(AccountConstants.E_HAB_GROUP);
    habGroup.addAttribute(AccountConstants.A_NAME, grp.getName());
    for (Attr attr : grp.getAttrs()) {
        if (!skipAttrs.contains(attr.getKey())) {
            ToXML.encodeAttr(habGroup, attr.getKey(), attr.getValue());
        }
    }
    if (parentId != null) {
        habGroup.addAttribute(AccountConstants.A_PARENT_HAB_GROUP_ID, parentId);
    }
    habGroup.addAttribute(AdminConstants.A_ID, grp.getId());
    habGroup.addAttribute(AccountConstants.A_HAB_SENIORITY_INDEX, grp.getSeniorityIndex());
    for (HABGroup habGrp : grp.getChildGroups()) {
        if (habGrp.getId() != null) {
            encodeHabGroup(habGroup, habGrp, grp.getId());
        }
    }
}
Also used : HABGroup(com.zimbra.soap.account.type.HABGroup) Element(com.zimbra.common.soap.Element) Attr(com.zimbra.soap.account.type.Attr)

Example 2 with Attr

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

the class JaxbToJsonTest method zimbraOddKeyValuePairsAnnotation.

/**
 * Check that JSON can be deserialised into a JAXB object when some of the JSON represents Zimbra KeyValuePairs
 * (i.e. An "_attrs" array).
 * In this case, the target objects for each keyvalue pair do NOT use the defaults of "a" for the element name and
 * "n" for the attribute name in the XML form.
 * Desired XML :<br />
 * &lt;key-value-pairs-tester xmlns="urn:zimbraTest">
 *   &lt;oddElemName name="key1">value1&lt;/oddElemName>
 *   &lt;oddElemName name="key2">value2-a&lt;/oddElemName>
 *   &lt;oddElemName name="key2">value2-b&lt;/oddElemName>
 * &lt;/key-value-pairs-tester>
 *<br />
 * Desired JSON :<br />
 * {
 *   "_attrs": {
 *     "key1": "value1",
 *     "key2": [
 *       "value2-a",
 *       "value2-b"]
 *   },
 *   "_jsns": "urn:zimbraTest"
 * }
 */
@Test
public void zimbraOddKeyValuePairsAnnotation() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("key-value-pairs", "urn:zimbraTest"));
    jsonElem.addKeyValuePair("key1", "value1", "oddElemName", "name");
    jsonElem.addKeyValuePair("key2", "value2-a", "oddElemName", "name");
    jsonElem.addKeyValuePair("key2", "value2-b", "oddElemName", "name");
    List<Attr> attrs = Lists.newArrayList();
    attrs.add(new Attr("key1", "value1"));
    attrs.add(new Attr("key2", "value2-a"));
    attrs.add(new Attr("key2", "value2-b"));
    OddKeyValuePairsTester jaxb = new OddKeyValuePairsTester(attrs);
    logDebug("XMLElement (from JAXB) ---> prettyPrint\n%1$s", JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false).prettyPrint());
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    String origJson = jsonJaxbElem.prettyPrint();
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", origJson);
    OddKeyValuePairsTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, OddKeyValuePairsTester.class);
    List<Element.KeyValuePair> elemKVPs = jsonJaxbElem.listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 3, elemKVPs.size());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
    List<Attr> kvps = roundtripped.getAttrList();
    Assert.assertEquals("roundtripped kvps num", 3, kvps.size());
    jsonJaxbElem = JacksonUtil.jaxbToJSONElement(roundtripped);
    String finalJson = jsonJaxbElem.prettyPrint();
    if (!origJson.equals(finalJson)) {
        logDebug("JSONElement from roundtripped JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
        Assert.assertEquals("roundtripped JSON pretty print", origJson, finalJson);
    }
}
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) XmlElemJsonAttr(com.zimbra.soap.jaxb.XmlElemJsonAttr) Attr(com.zimbra.soap.account.type.Attr) OddKeyValuePairsTester(com.zimbra.soap.jaxb.OddKeyValuePairsTester) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 3 with Attr

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

the class TestAuth method attrsReturnedInAuthResponse.

@Test
public void attrsReturnedInAuthResponse() throws Exception {
    String ATTR_NAME = Provisioning.A_zimbraFeatureExternalFeedbackEnabled;
    String ATTR_VALUE = ProvisioningConstants.TRUE;
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(ATTR_NAME, ATTR_VALUE);
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain, attrs);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(new SoapDebugListener());
    com.zimbra.soap.type.AccountSelector acctSel = new com.zimbra.soap.type.AccountSelector(com.zimbra.soap.type.AccountBy.name, acct.getName());
    AuthRequest req = new AuthRequest(acctSel, "test123");
    req.addAttr(ATTR_NAME);
    AuthResponse resp = invokeJaxb(transport, req);
    Set<String> result = Sets.newHashSet();
    for (Attr attr : resp.getAttrs()) {
        String attrName = attr.getName();
        String attrValue = attr.getValue();
        result.add(Verify.makeResultStr(attrName, attrValue));
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(ATTR_NAME, ATTR_VALUE)), result);
    /*
         * test the auth by auth toke npath
         */
    String authTokenStr = resp.getAuthToken();
    AuthToken authToken = new AuthToken(authTokenStr, Boolean.FALSE);
    req = new AuthRequest();
    req.setAuthToken(authToken);
    req.addAttr(ATTR_NAME);
    transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(new SoapDebugListener());
    resp = invokeJaxb(transport, req);
    result = Sets.newHashSet();
    for (Attr attr : resp.getAttrs()) {
        String attrName = attr.getName();
        String attrValue = attr.getValue();
        result.add(Verify.makeResultStr(attrName, attrValue));
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(ATTR_NAME, ATTR_VALUE)), result);
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) AccountSelector(com.zimbra.soap.type.AccountSelector) Attr(com.zimbra.soap.account.type.Attr) AuthResponse(com.zimbra.soap.account.message.AuthResponse) AccountSelector(com.zimbra.soap.type.AccountSelector) ZAuthToken(com.zimbra.common.auth.ZAuthToken) AuthToken(com.zimbra.soap.account.type.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Aggregations

Attr (com.zimbra.soap.account.type.Attr)3 Element (com.zimbra.common.soap.Element)2 Test (org.junit.Test)2 ZAuthToken (com.zimbra.common.auth.ZAuthToken)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)1 Account (com.zimbra.cs.account.Account)1 AuthRequest (com.zimbra.soap.account.message.AuthRequest)1 AuthResponse (com.zimbra.soap.account.message.AuthResponse)1 AuthToken (com.zimbra.soap.account.type.AuthToken)1 HABGroup (com.zimbra.soap.account.type.HABGroup)1 OddKeyValuePairsTester (com.zimbra.soap.jaxb.OddKeyValuePairsTester)1 XmlElemJsonAttr (com.zimbra.soap.jaxb.XmlElemJsonAttr)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 AccountSelector (com.zimbra.soap.type.AccountSelector)1 KeyValuePair (com.zimbra.soap.type.KeyValuePair)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlElement (javax.xml.bind.annotation.XmlElement)1