use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class GalSearchResultCallback method reset.
public void reset(GalSearchParams params) {
if (params.getSoapContext() != null) {
mResponse = params.getSoapContext().createElement(params.getResponseName());
mFormatter = new ItemIdFormatter(params.getSoapContext());
} else {
mResponse = Element.XMLElement.mFactory.createElement(params.getResponseName());
mFormatter = new ItemIdFormatter();
}
params.setGalResult(SearchGalResult.newSearchGalResult(this));
mIdOnly = params.isIdOnly();
try {
mAuthAcct = params.getAuthAccount();
} catch (ServiceException e) {
ZimbraLog.gal.warn("unable to get authed account", e);
}
mNeedCanExpand = params.getNeedCanExpand();
mNeedIsOwner = params.getNeedIsOwner();
mNeedIsMember = params.getNeedIsMember();
mNeedSMIMECerts = params.getNeedSMIMECerts();
}
use of com.zimbra.cs.service.util.ItemIdFormatter 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.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class ContactTest method testEncodeContact.
@Test
public void testEncodeContact() throws Exception {
Account account = Provisioning.getInstance().getAccountByName("testCont@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_userCertificate, "{\"ZMVAL\":[\"Cert1149638887753217\"]}");
Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
Element response = new Element.XMLElement(MailConstants.MODIFY_CONTACT_RESPONSE);
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "testCont@zimbra.com");
ToXML.encodeContact(response, new ItemIdFormatter(), new OperationContext(acct), contact, true, null);
Assert.assertEquals(response.getElement("cn").getElement("a").getText(), "Cert1149638887753217");
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class SaveDraftTest method updateRace.
@Test
public void updateRace() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
// create a draft via SOAP
Element request = new Element.JSONElement(MailConstants.SAVE_DRAFT_REQUEST);
Element m = request.addNonUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.E_SUBJECT, "dinner appt");
m.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, ORIGINAL_CONTENT);
Element response = new SaveDraft() {
@Override
protected Element generateResponse(ZimbraSoapContext zsc, ItemIdFormatter ifmt, OperationContext octxt, Mailbox mbox, Message msg, boolean wantImapUid, boolean wantModSeq) {
// trigger the failure case by re-saving the draft before it's serialized out
Message snapshotMsg = msg;
try {
snapshotMsg = (Message) msg.snapshotItem();
MimeMessage mm = new MimeMessage(JMSession.getSession());
mm.setText(MODIFIED_CONTENT);
mm.saveChanges();
mbox.saveDraft(null, new ParsedMessage(mm, false), snapshotMsg.getId());
} catch (Exception e) {
return null;
}
return super.generateResponse(zsc, ifmt, octxt, mbox, snapshotMsg, wantImapUid, wantModSeq);
}
}.handle(request, ServiceTestUtil.getRequestContext(acct));
// make sure the response has the correct message content
Assert.assertEquals("picked up modified content", MODIFIED_CONTENT, response.getElement(MailConstants.E_MSG).getElement(MailConstants.E_MIMEPART).getAttribute(MailConstants.E_CONTENT));
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class CreateContact method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
boolean verbose = request.getAttributeBool(MailConstants.A_VERBOSE, true);
boolean wantImapUid = request.getAttributeBool(MailConstants.A_WANT_IMAP_UID, false);
boolean wantModSeq = request.getAttributeBool(MailConstants.A_WANT_MODIFIED_SEQUENCE, false);
Element cn = request.getElement(MailConstants.E_CONTACT);
ItemId iidFolder = new ItemId(cn.getAttribute(MailConstants.A_FOLDER, DEFAULT_FOLDER), zsc);
String[] tags = TagUtil.parseTags(cn, mbox, octxt);
Element vcard = cn.getOptionalElement(MailConstants.E_VCARD);
List<ParsedContact> pclist;
if (vcard != null) {
pclist = parseAttachedVCard(zsc, octxt, mbox, vcard);
} else {
pclist = new ArrayList<ParsedContact>(1);
Pair<Map<String, Object>, List<Attachment>> cdata = parseContact(cn, zsc, octxt);
pclist.add(new ParsedContact(cdata.getFirst(), cdata.getSecond()));
}
if (needToMigrateDlist(zsc)) {
for (ParsedContact pc : pclist) {
migrateFromDlist(pc);
}
}
List<Contact> contacts = createContacts(octxt, mbox, iidFolder, pclist, tags);
Contact con = null;
if (contacts.size() > 0)
con = contacts.get(0);
Element response = zsc.createElement(MailConstants.CREATE_CONTACT_RESPONSE);
if (con != null) {
if (verbose) {
int fields = ToXML.NOTIFY_FIELDS;
if (wantImapUid) {
fields |= Change.IMAP_UID;
}
if (wantModSeq) {
fields |= Change.MODSEQ;
}
ToXML.encodeContact(response, ifmt, octxt, con, (ContactGroup) null, (Collection<String>) null, /* memberAttrFilter */
true, /* summary */
(Collection<String>) null, /* attrFilter */
fields, (String) null, /* migratedDList */
false, /* returnHiddenAttrs */
GetContacts.NO_LIMIT_MAX_MEMBERS, true);
} else {
Element contct = response.addNonUniqueElement(MailConstants.E_CONTACT);
contct.addAttribute(MailConstants.A_ID, con.getId());
if (wantImapUid) {
contct.addAttribute(MailConstants.A_IMAP_UID, con.getImapUid());
}
if (wantModSeq) {
contct.addAttribute(MailConstants.A_MODIFIED_SEQUENCE, con.getModifiedSequence());
}
}
}
return response;
}
Aggregations