use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class GetTag method handle.
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);
List<Tag> tags = null;
try {
tags = mbox.getTagList(octxt);
} catch (ServiceException e) {
// just return no tags in the perm denied case (not considered an error here)...
if (!e.getCode().equals(ServiceException.PERM_DENIED))
throw e;
}
Element response = zsc.createElement(MailConstants.GET_TAG_RESPONSE);
if (tags != null) {
for (Tag tag : tags) {
if (tag == null || tag instanceof Flag)
continue;
ToXML.encodeTag(response, ifmt, octxt, tag);
}
}
return response;
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class GetMsgMetadata 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);
String ids = request.getElement(MailConstants.E_MSG).getAttribute(MailConstants.A_IDS);
ArrayList<Integer> local = new ArrayList<Integer>();
HashMap<String, StringBuilder> remote = new HashMap<String, StringBuilder>();
ItemAction.partitionItems(zsc, ids, local, remote);
Element response = zsc.createElement(MailConstants.GET_MSG_METADATA_RESPONSE);
if (remote.size() > 0) {
List<Element> responses = proxyRemote(request, remote, context);
for (Element e : responses) {
response.addElement(e);
}
}
if (local.size() > 0) {
List<Message> msgs = GetMsg.getMsgs(octxt, mbox, local, false);
for (Message msg : msgs) {
if (msg != null) {
ToXML.encodeMessageSummary(response, ifmt, octxt, msg, null, SUMMARY_FIELDS);
}
}
}
return response;
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class SoapSession method putQueuedNotifications.
/** Write a single instance of the PendingModifications structure into the
* passed-in <ctxt> block. */
protected void putQueuedNotifications(Mailbox mbox, QueuedNotifications ntfn, Element parent, ZimbraSoapContext zsc) {
// create the base "notify" block: <notify seq="6"/>
Element eNotify = parent.addElement(ZimbraNamespace.E_NOTIFY);
if (ntfn.getSequence() > 0) {
eNotify.addAttribute(HeaderConstants.A_SEQNO, ntfn.getSequence());
}
OperationContext octxt = null;
try {
octxt = DocumentHandler.getOperationContext(zsc, this);
} catch (ServiceException e) {
ZimbraLog.session.warn("error fetching operation context for: " + zsc.getAuthtokenAccountId(), e);
return;
}
boolean debug = ZimbraLog.session.isDebugEnabled();
PendingModifications pms = ntfn.mMailboxChanges;
RemoteNotifications rns = ntfn.mRemoteChanges;
Element eDeleted = eNotify.addUniqueElement(ZimbraNamespace.E_DELETED);
StringBuilder deletedIds = new StringBuilder();
if (pms != null && pms.deleted != null && pms.deleted.size() > 0) {
for (ModificationKey mkey : pms.deleted.keySet()) {
addDeletedNotification(mkey, deletedIds);
}
}
if (rns != null && rns.deleted != null) {
deletedIds.append(deletedIds.length() == 0 ? "" : ",").append(rns.deleted);
}
boolean hasLocalCreates = pms != null && pms.created != null && !pms.created.isEmpty();
boolean hasRemoteCreates = rns != null && rns.created != null && !rns.created.isEmpty();
if (hasLocalCreates || hasRemoteCreates) {
Element eCreated = eNotify.addUniqueElement(ZimbraNamespace.E_CREATED);
if (hasLocalCreates) {
for (MailItem item : pms.created.values()) {
ItemIdFormatter ifmt = new ItemIdFormatter(mAuthenticatedAccountId, item.getMailbox(), false);
try {
Element elem = ToXML.encodeItem(eCreated, ifmt, octxt, item, ToXML.NOTIFY_FIELDS);
// special-case notifications for new mountpoints in the authenticated user's mailbox
if (item instanceof Mountpoint && mbox == item.getMailbox()) {
Map<ItemId, Pair<Boolean, Element>> mountpoints = new HashMap<ItemId, Pair<Boolean, Element>>(2);
expandLocalMountpoint(octxt, (Mountpoint) item, eCreated.getFactory(), mountpoints);
expandRemoteMountpoints(octxt, zsc, mountpoints);
transferMountpointContents(elem, octxt, mountpoints);
}
} catch (ServiceException e) {
ZimbraLog.session.warn("error encoding item " + item.getId(), e);
return;
}
}
// sanity-check the returned element
if (!eCreated.hasChildren() && debug) {
ZimbraLog.session.debug("no serialied creates for item set: %s", pms.created.keySet());
}
}
if (hasRemoteCreates) {
if (debug) {
ZimbraLog.session.debug("adding %d proxied creates", rns.created.size());
}
for (Element elt : rns.created) {
if (encodingMatches(parent, elt)) {
eCreated.addElement(elt.clone().detach());
} else {
ZimbraLog.session.warn("unable to add remote notification due to mismatched SOAP protocol");
}
}
}
}
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
boolean hasLocalModifies = pms != null && pms.modified != null && !pms.modified.isEmpty();
boolean hasRemoteModifies = rns != null && rns.modified != null && !rns.modified.isEmpty();
if (hasLocalModifies || hasRemoteModifies) {
Element eModified = eNotify.addUniqueElement(ZimbraNamespace.E_MODIFIED);
if (hasLocalModifies) {
for (Change chg : pms.modified.values()) {
if (chg.why != 0 && chg.what instanceof MailItem) {
MailItem item = (MailItem) chg.what;
try {
Element elt = ToXML.encodeItem(eModified, ifmt, octxt, item, chg.why);
if (elt == null) {
ModificationKey mkey = new ModificationKey(item);
addDeletedNotification(mkey, deletedIds);
if (debug) {
ZimbraLog.session.debug("marking nonserialized item as a delete: %s", mkey);
}
}
} catch (ServiceException e) {
ZimbraLog.session.warn("error encoding item " + item.getId(), e);
return;
}
} else if (chg.why != 0 && chg.what instanceof Mailbox) {
ToXML.encodeMailbox(eModified, octxt, (Mailbox) chg.what, chg.why);
}
}
// sanity-check the returned element
if (!eModified.hasChildren() && debug) {
ZimbraLog.session.debug("no serialied modifies for item set: %s", pms.modified.keySet());
}
}
if (hasRemoteModifies) {
if (debug) {
ZimbraLog.session.debug("adding %d proxied modifies", rns.modified.size());
}
for (Element elt : rns.modified) {
if (encodingMatches(parent, elt)) {
eModified.addElement(elt.clone().detach());
} else {
ZimbraLog.session.warn("unable to add remote notification due to mismatched SOAP protocol");
}
}
}
}
if (rns != null && rns.activities != null && !rns.activities.isEmpty()) {
for (Element elt : rns.activities) {
if (encodingMatches(parent, elt)) {
eNotify.addElement(elt.clone().detach());
} else {
ZimbraLog.session.warn("unable to add remote notification due to mismatched SOAP protocol");
}
}
}
putExtraNotifications(ntfn, eNotify, ifmt);
if (deletedIds == null || deletedIds.length() == 0) {
eDeleted.detach();
} else {
eDeleted.addAttribute(A_ID, deletedIds.toString());
}
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class SoapSession method expandLocalMountpoint.
private void expandLocalMountpoint(OperationContext octxt, Mountpoint mpt, Element.ElementFactory factory, Map<ItemId, Pair<Boolean, Element>> mountpoints) {
// don't bother generating the subhierarchy more than once
ItemId iidTarget = mpt.getTarget();
if (mountpoints.containsKey(iidTarget)) {
return;
}
try {
Provisioning prov = Provisioning.getInstance();
Account owner = prov.get(Key.AccountBy.id, mpt.getOwnerId(), octxt.getAuthToken());
if (owner == null || owner.getId().equals(mAuthenticatedAccountId)) {
mountpoints.put(iidTarget, new Pair<Boolean, Element>(true, null));
return;
}
// if we're non-admin and it's not active
if (Provisioning.ACCOUNT_STATUS_MAINTENANCE.equals(owner.getAccountStatus(prov)) || (!Provisioning.ACCOUNT_STATUS_ACTIVE.equals(owner.getAccountStatus(prov)) && (!octxt.isUsingAdminPrivileges() || !AccessManager.getInstance().canAccessAccount(octxt.getAuthenticatedUser(), owner)))) {
mountpoints.put(iidTarget, new Pair<Boolean, Element>(true, null));
return;
}
// handle mountpoints pointing to a different server later
if (!Provisioning.onLocalServer(owner)) {
mountpoints.put(iidTarget, null);
return;
}
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(owner);
FolderNode remote = mbox.getFolderTree(octxt, new ItemId(mbox, mpt.getRemoteId()), false);
if (remote != null && remote.mFolder != null && !remote.mFolder.isHidden()) {
ItemIdFormatter ifmt = new ItemIdFormatter(octxt.getAuthenticatedUser(), mbox, false);
if (OperationContextData.getNeedGranteeName(octxt)) {
OperationContextData.addGranteeNames(octxt, remote);
}
Element subhierarchy = GetFolder.encodeFolderNode(remote, factory.createElement("ignored"), ifmt, octxt).detach();
mountpoints.put(iidTarget, new Pair<Boolean, Element>(false, subhierarchy));
// fault in a delegate session because there's actually something to listen on...
getDelegateSession(mpt.getOwnerId());
}
} catch (ServiceException e) {
mountpoints.put(iidTarget, new Pair<Boolean, Element>(true, null));
}
}
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();
}
Aggregations