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));
}
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));
}
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;
}
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);
}
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);
}
Aggregations