Search in sources :

Example 31 with XMLElement

use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method enumElemList.

/**
 *  Testing form:
 *      {@code @XmlElement(name="enum-entry", required=false)
 *      private List<ViewEnum> entries = Lists.newArrayList();}
 * Desired JSON :
 *      {
 *        "enum-entry": [
 *          {
 *            "_content": "appointment"
 *          },
 *          {
 *            "_content": ""
 *          },
 *          {
 *            "_content": "document"
 *          }],
 *        "_jsns": "urn:zimbraTest"
 */
@Test
public void enumElemList() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("enum-elem-list", "urn:zimbraTest"));
    jsonElem.addNonUniqueElement("enum-entry").addText(ViewEnum.APPOINTMENT.toString());
    jsonElem.addNonUniqueElement("enum-entry").addText(ViewEnum.UNKNOWN.toString());
    jsonElem.addNonUniqueElement("enum-entry").addText(ViewEnum.DOCUMENT.toString());
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    EnumElemList tstr = new EnumElemList();
    tstr.addEntry(ViewEnum.APPOINTMENT);
    tstr.addEntry(ViewEnum.UNKNOWN);
    tstr.addEntry(ViewEnum.DOCUMENT);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
    EnumElemList roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumElemList.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    List<Element> jsonElems = jsonJaxbElem.listElements();
    List<ViewEnum> entries = roundtripped.getEntries();
    Assert.assertEquals("jsonElems num", 3, jsonElems.size());
    Assert.assertEquals("entries num", 3, entries.size());
    Assert.assertTrue("has APPOINTMENT", entries.contains(ViewEnum.APPOINTMENT));
    Assert.assertTrue("has UNKNOWN", entries.contains(ViewEnum.UNKNOWN));
    Assert.assertTrue("has DOCUMENT", entries.contains(ViewEnum.DOCUMENT));
}
Also used : EnumElemList(com.zimbra.soap.jaxb.EnumElemList) WrappedEnumElemList(com.zimbra.soap.jaxb.WrappedEnumElemList) 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) ViewEnum(com.zimbra.soap.jaxb.ViewEnum) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 32 with XMLElement

use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.

the class DocumentTest method note.

/**
 * Verifies setting the {@code Note} flag on a document.
 */
@Test
public void note() throws Exception {
    // Create document and note.
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Document doc = createDocument(mbox, "doc.txt", "This is a document", false);
    Document note = createDocument(mbox, "note.txt", "This is a note", true);
    // Validate flag.
    doc = mbox.getDocumentById(null, doc.getId());
    note = mbox.getDocumentById(null, note.getId());
    assertTrue((note.getFlagBitmask() & Flag.FlagInfo.NOTE.toBitmask()) != 0);
    // Search by flag.
    List<Integer> ids = TestUtil.search(mbox, "tag:\\note", MailItem.Type.DOCUMENT);
    Assert.assertEquals(1, ids.size());
    Assert.assertEquals(note.getId(), ids.get(0).intValue());
    // Make sure that the note flag is serialized to XML.
    Element eDoc = ToXML.encodeDocument(new XMLElement("test"), new ItemIdFormatter(), null, doc);
    Assert.assertEquals(null, Strings.emptyToNull(eDoc.getAttribute(MailConstants.A_FLAGS, null)));
    Element eNote = ToXML.encodeDocument(new XMLElement("test"), new ItemIdFormatter(), null, note);
    Assert.assertEquals("t", eNote.getAttribute(MailConstants.A_FLAGS));
}
Also used : ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) XMLElement(com.zimbra.common.soap.Element.XMLElement) Test(org.junit.Test)

Example 33 with XMLElement

use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.

the class SoapProvisioning method autoCompleteGal.

@Override
public SearchGalResult autoCompleteGal(Domain d, String query, GalSearchType type, int limit, GalContact.Visitor visitor) throws ServiceException {
    String typeStr = type == null ? GalSearchType.all.name() : type.name();
    XMLElement req = new XMLElement(AdminConstants.AUTO_COMPLETE_GAL_REQUEST);
    req.addElement(AdminConstants.E_NAME).setText(query);
    req.addAttribute(AdminConstants.A_DOMAIN, d.getName());
    req.addAttribute(AdminConstants.A_TYPE, typeStr);
    req.addAttribute(AdminConstants.A_LIMIT, limit);
    Element resp = invoke(req);
    SearchGalResult result = SearchGalResult.newSearchGalResult(visitor);
    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 34 with XMLElement

use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.

the class SoapProvisioning method removeConfigSMIMEConfig.

@Override
public void removeConfigSMIMEConfig(String configName) throws ServiceException {
    XMLElement req = new XMLElement(AdminConstants.MODIFY_SMIME_CONFIG_REQUEST);
    Element eConfig = req.addElement(AdminConstants.E_CONFIG);
    eConfig.addAttribute(AdminConstants.A_NAME, configName);
    eConfig.addAttribute(AdminConstants.A_OP, AdminConstants.OP_REMOVE);
    invoke(req);
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 35 with XMLElement

use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.

the class SoapProvisioning method revokeRight.

@Override
public void revokeRight(String targetType, TargetBy targetBy, String target, String granteeType, GranteeBy granteeBy, String grantee, String right, RightModifier rightModifier) throws ServiceException {
    XMLElement req = new XMLElement(AdminConstants.REVOKE_RIGHT_REQUEST);
    toXML(req, targetType, targetBy, target);
    toXML(req, granteeType, granteeBy, grantee);
    toXML(req, right, rightModifier);
    invoke(req);
}
Also used : XMLElement(com.zimbra.common.soap.Element.XMLElement)

Aggregations

XMLElement (com.zimbra.common.soap.Element.XMLElement)146 Element (com.zimbra.common.soap.Element)116 JSONElement (com.zimbra.common.soap.Element.JSONElement)33 Test (org.junit.Test)32 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)28 XmlElement (javax.xml.bind.annotation.XmlElement)28 FilterTest (com.zimbra.soap.mail.type.FilterTest)26 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)9 HashMap (java.util.HashMap)8 KeyValuePair (com.zimbra.soap.type.KeyValuePair)7 ArrayList (java.util.ArrayList)7 Account (com.zimbra.cs.account.Account)6 ZAuthToken (com.zimbra.common.auth.ZAuthToken)5 ByteBuilder (com.zimbra.common.mime.HeaderUtils.ByteBuilder)4 ServiceException (com.zimbra.common.service.ServiceException)4 DataSource (com.zimbra.cs.account.DataSource)4 Auth (com.zimbra.cs.service.account.Auth)4 URL (java.net.URL)4 Cookie (javax.servlet.http.Cookie)4 HttpException (org.apache.http.HttpException)4