Search in sources :

Example 21 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class GetSystemRetentionPolicy method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    GetSystemRetentionPolicyRequest req = JaxbUtil.elementToJaxb(request);
    Provisioning prov = Provisioning.getInstance();
    // assume default retention policy to be set in globalConfig (for backward compatibility)
    Entry entry = prov.getConfig();
    // check if cos is specified
    CosSelector cosSelector = req.getCos();
    if (cosSelector != null) {
        entry = prov.get(Key.CosBy.fromString(cosSelector.getBy().name()), cosSelector.getKey());
        if (entry == null)
            throw AccountServiceException.NO_SUCH_COS(cosSelector.getKey());
    }
    // check right
    checkGetRight(entry, zsc, context);
    RetentionPolicy rp = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(entry);
    GetSystemRetentionPolicyResponse res = new GetSystemRetentionPolicyResponse(rp);
    return JaxbUtil.jaxbToElement(res, zsc.getResponseProtocol().getFactory());
}
Also used : Entry(com.zimbra.cs.account.Entry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CosSelector(com.zimbra.soap.admin.type.CosSelector) GetSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse) GetSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.GetSystemRetentionPolicyRequest) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Provisioning(com.zimbra.cs.account.Provisioning)

Example 22 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class TagAction 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);
    Element action = request.getElement(MailConstants.E_ACTION);
    String opAttr = action.getAttribute(MailConstants.A_OPERATION).toLowerCase();
    String operation = getOperation(opAttr);
    if (operation.equals(OP_TAG) || operation.equals(OP_FLAG)) {
        throw ServiceException.INVALID_REQUEST("cannot tag/flag a tag", null);
    }
    if (!TAG_ACTIONS.contains(operation)) {
        throw ServiceException.INVALID_REQUEST("invalid operation on tag: " + opAttr, null);
    }
    String tn = action.getAttribute(MailConstants.A_TAG_NAMES, null);
    if (tn != null) {
        // switch tag names to tag IDs, because that's what ItemAction expects
        StringBuilder tagids = new StringBuilder();
        for (String name : TagUtil.decodeTags(tn)) {
            tagids.append(tagids.length() == 0 ? "" : ",").append(mbox.getTagByName(octxt, name).getId());
        }
        action.addAttribute(MailConstants.A_ID, tagids.toString());
    }
    String successes;
    if (operation.equals(OP_RETENTION_POLICY)) {
        ItemId iid = new ItemId(action.getAttribute(MailConstants.A_ID), zsc);
        RetentionPolicy rp = new RetentionPolicy(action.getElement(MailConstants.E_RETENTION_POLICY));
        mbox.setRetentionPolicy(octxt, iid.getId(), MailItem.Type.TAG, rp);
        successes = new ItemIdFormatter(zsc).formatItemId(iid);
    } else {
        successes = handleCommon(context, request, opAttr, MailItem.Type.TAG);
    }
    Element response = zsc.createElement(MailConstants.TAG_ACTION_RESPONSE);
    Element result = response.addUniqueElement(MailConstants.E_ACTION);
    result.addAttribute(MailConstants.A_ID, successes);
    result.addAttribute(MailConstants.A_TAG_NAMES, tn);
    result.addAttribute(MailConstants.A_OPERATION, opAttr);
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 23 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class ToXML method encodeFolder.

public static Element encodeFolder(Element parent, ItemIdFormatter ifmt, OperationContext octxt, Folder folder, int fields, boolean exposeAclAccessKey) throws ServiceException {
    if (folder instanceof SearchFolder) {
        return encodeSearchFolder(parent, ifmt, (SearchFolder) folder, fields);
    } else if (folder instanceof Mountpoint) {
        return encodeMountpoint(parent, ifmt, octxt, (Mountpoint) folder, fields);
    }
    Element elem = parent.addElement(MailConstants.E_FOLDER);
    encodeFolderCommon(elem, ifmt, folder, fields);
    if (needToOutput(fields, Change.SIZE)) {
        int deleted = folder.getDeletedCount();
        elem.addAttribute(MailConstants.A_NUM, folder.getItemCount() - deleted);
        if (deleted > 0) {
            elem.addAttribute(MailConstants.A_IMAP_NUM, folder.getItemCount());
        }
        elem.addAttribute(MailConstants.A_SIZE, folder.getTotalSize());
        elem.addAttribute(MailConstants.A_IMAP_MODSEQ, folder.getImapMODSEQ());
        elem.addAttribute(MailConstants.A_IMAP_UIDNEXT, folder.getImapUIDNEXT());
    }
    if (needToOutput(fields, Change.URL)) {
        String url = folder.getUrl();
        if (!url.isEmpty() || fields != NOTIFY_FIELDS) {
            // Note: in this case, a url on a folder object
            // is not a url to the folder, but the url to another item that's
            // external of the mail system. In most cases this is a 'synced' folder
            // that is either RSS or a remote calendar object
            elem.addAttribute(MailConstants.A_URL, HttpUtil.sanitizeURL(url));
        }
    }
    Mailbox mbox = folder.getMailbox();
    boolean remote = octxt != null && octxt.isDelegatedRequest(mbox);
    boolean canAdminister = !remote;
    boolean canDelete = canAdminister;
    if (remote) {
        // return effective permissions only for remote folders
        String perms = encodeEffectivePermissions(folder, octxt);
        elem.addAttribute(MailConstants.A_RIGHTS, perms);
        canAdminister = perms != null && perms.indexOf(ACL.ABBR_ADMIN) != -1;
        // Need to know retention policy if grantees can delete from a folder so clients can warn
        // them when they try to delete something within the retention period
        canDelete = canAdminister || (perms != null && perms.indexOf(ACL.ABBR_DELETE) != -1);
    }
    if (canAdminister) {
        // return full ACLs for folders we have admin rights on
        if (needToOutput(fields, Change.ACL)) {
            if (fields != NOTIFY_FIELDS || folder.isTagged(Flag.FlagInfo.NO_INHERIT)) {
                encodeACL(octxt, elem, folder.getEffectiveACL(), exposeAclAccessKey);
            }
        }
    }
    if (canDelete) {
        if (needToOutput(fields, Change.RETENTION_POLICY)) {
            RetentionPolicy rp = folder.getRetentionPolicy();
            if (fields != NOTIFY_FIELDS || rp.isSet()) {
                // Only output retention policy if it's being modified, or if we're returning all
                // folder data and policy is set.
                encodeRetentionPolicy(elem, RetentionPolicyManager.getInstance().getCompleteRetentionPolicy(folder.getAccount(), rp));
            }
        }
    }
    return elem;
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Element(com.zimbra.common.soap.Element) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 24 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class Folder method decodeMetadata.

@Override
void decodeMetadata(Metadata meta) throws ServiceException {
    super.decodeMetadata(meta);
    // avoid a painful data migration...
    Type view;
    switch(mId) {
        case Mailbox.ID_FOLDER_INBOX:
        case Mailbox.ID_FOLDER_SPAM:
        case Mailbox.ID_FOLDER_SENT:
        case Mailbox.ID_FOLDER_DRAFTS:
            view = Type.MESSAGE;
            break;
        case Mailbox.ID_FOLDER_CALENDAR:
            view = Type.APPOINTMENT;
            break;
        case Mailbox.ID_FOLDER_TASKS:
            view = Type.TASK;
            break;
        case Mailbox.ID_FOLDER_AUTO_CONTACTS:
        case Mailbox.ID_FOLDER_CONTACTS:
            view = Type.CONTACT;
            break;
        case Mailbox.ID_FOLDER_IM_LOGS:
            view = Type.MESSAGE;
            break;
        default:
            view = Type.UNKNOWN;
            break;
    }
    byte bview = (byte) meta.getLong(Metadata.FN_VIEW, -1);
    defaultView = bview >= 0 ? Type.of(bview) : view;
    attributes = (byte) meta.getLong(Metadata.FN_ATTRS, 0);
    totalSize = meta.getLong(Metadata.FN_TOTAL_SIZE, 0L);
    imapUIDNEXT = (int) meta.getLong(Metadata.FN_UIDNEXT, 0);
    imapMODSEQ = (int) meta.getLong(Metadata.FN_MODSEQ, 0);
    imapRECENT = (int) meta.getLong(Metadata.FN_RECENT, -1);
    imapRECENTCutoff = (int) meta.getLong(Metadata.FN_RECENT_CUTOFF, 0);
    deletedCount = (int) meta.getLong(Metadata.FN_DELETED, 0);
    deletedUnreadCount = (int) meta.getLong(Metadata.FN_DELETED_UNREAD, 0);
    if (meta.containsKey(Metadata.FN_URL) || meta.containsKey(Metadata.FN_SYNC_DATE)) {
        syncData = new SyncData(meta.get(Metadata.FN_URL, null), meta.get(Metadata.FN_SYNC_GUID, null), meta.getLong(Metadata.FN_SYNC_DATE, 0));
    }
    Metadata rp = meta.getMap(Metadata.FN_RETENTION_POLICY, true);
    if (rp != null) {
        retentionPolicy = RetentionPolicyManager.retentionPolicyFromMetadata(rp, true);
    } else {
        retentionPolicy = new RetentionPolicy();
    }
    activeSyncDisabled = meta.getBool(Metadata.FN_DISABLE_ACTIVESYNC, false);
    webOfflineSyncDays = meta.getInt(Metadata.FN_WEB_OFFLINE_SYNC_DAYS, -1);
}
Also used : RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 25 with RetentionPolicy

use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.

the class JaxbToElementTest method standalonElementToJaxbTest.

@Test
public void standalonElementToJaxbTest() throws Exception {
    InputStream is = getClass().getResourceAsStream("retentionPolicy.xml");
    Element elem = Element.parseXML(is);
    String eXml = elem.toString();
    ZimbraLog.test.debug("retentionPolicy.xml from Element:\n%s", eXml);
    RetentionPolicy rp = JaxbUtil.elementToJaxb(elem, RetentionPolicy.class);
    Assert.assertNotNull("elementToJaxb RetentionPolicy returned object", rp);
    Element elem2 = JaxbUtil.jaxbToElement(rp, XMLElement.mFactory);
    String eXml2 = elem2.toString();
    ZimbraLog.test.debug("Round tripped retentionPolicy.xml from Element:\n%s", eXml2);
    XMLAssert.assertXMLEqual(eXml, eXml2);
}
Also used : InputStream(java.io.InputStream) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Aggregations

RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)37 Policy (com.zimbra.soap.mail.type.Policy)22 Test (org.junit.Test)15 Config (com.zimbra.cs.account.Config)7 Element (com.zimbra.common.soap.Element)6 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 ServiceException (com.zimbra.common.service.ServiceException)4 Cos (com.zimbra.cs.account.Cos)4 ZFolder (com.zimbra.client.ZFolder)3 ZMailbox (com.zimbra.client.ZMailbox)3 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 Color (com.zimbra.common.mailbox.Color)2 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Provisioning (com.zimbra.cs.account.Provisioning)2 DbTag (com.zimbra.cs.db.DbTag)2 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 AlterItemTag (com.zimbra.cs.redolog.op.AlterItemTag)2