Search in sources :

Example 1 with NewSearchFolderSpec

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

the class ZMailbox method createSearchFolder.

/**
 * create a new sub folder of the specified parent folder.
 *
 * @param parentId parent folder id
 * @param name name of new folder
 * @param query search query (required)
 * @param types comma-sep list of types to search for.  Use null for default value.
 * @param sortBy how to sort the result. Use null for default value.
 * @see {@link ZSearchParams#TYPE_MESSAGE}
 * @return newly created search folder
 * @throws ServiceException on error
 * @param color color of folder
 */
public ZSearchFolder createSearchFolder(String parentId, String name, String query, String types, SearchSortBy sortBy, ZFolder.Color color) throws ServiceException {
    NewSearchFolderSpec spec = NewSearchFolderSpec.forNameQueryAndFolder(name, query, parentId);
    if (color != null) {
        if (StringUtil.equal(color.getName(), Color.RGBCOLOR)) {
            spec.setRgb(color.getRgbColorValue());
        } else {
            spec.setColor((byte) color.getValue());
        }
    }
    spec.setSearchTypes(types);
    if (sortBy != null) {
        spec.setSortBy(sortBy.name());
    }
    CreateSearchFolderResponse resp = this.invokeJaxb(new CreateSearchFolderRequest(spec));
    ZSearchFolder newSearch = getSearchFolderById(resp.getSearchFolder().getId());
    return newSearch != null ? newSearch : new ZSearchFolder(resp.getSearchFolder(), null, this);
}
Also used : CreateSearchFolderResponse(com.zimbra.soap.mail.message.CreateSearchFolderResponse) CreateSearchFolderRequest(com.zimbra.soap.mail.message.CreateSearchFolderRequest) NewSearchFolderSpec(com.zimbra.soap.mail.type.NewSearchFolderSpec)

Example 2 with NewSearchFolderSpec

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

the class CreateSearchFolder 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);
    CreateSearchFolderRequest req = zsc.elementToJaxb(request);
    NewSearchFolderSpec spec = req.getSearchFolder();
    Byte color = spec.getColor() != null ? spec.getColor() : MailItem.DEFAULT_COLOR;
    Color itemColor = spec.getRgb() != null ? new Color(spec.getRgb()) : new Color(color);
    ItemId iidParent = new ItemId(spec.getParentFolderId(), zsc);
    SearchFolder search = mbox.createSearchFolder(octxt, iidParent.getId(), spec.getName(), spec.getQuery(), spec.getSearchTypes(), spec.getSortBy(), Flag.toBitmask(spec.getFlags()), itemColor);
    Element response = zsc.createElement(MailConstants.CREATE_SEARCH_FOLDER_RESPONSE);
    if (search != null)
        ToXML.encodeSearchFolder(response, ifmt, search);
    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) Color(com.zimbra.common.mailbox.Color) Element(com.zimbra.common.soap.Element) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) CreateSearchFolderRequest(com.zimbra.soap.mail.message.CreateSearchFolderRequest) ItemId(com.zimbra.cs.service.util.ItemId) NewSearchFolderSpec(com.zimbra.soap.mail.type.NewSearchFolderSpec)

Aggregations

CreateSearchFolderRequest (com.zimbra.soap.mail.message.CreateSearchFolderRequest)2 NewSearchFolderSpec (com.zimbra.soap.mail.type.NewSearchFolderSpec)2 Color (com.zimbra.common.mailbox.Color)1 Element (com.zimbra.common.soap.Element)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)1 ItemId (com.zimbra.cs.service.util.ItemId)1 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 CreateSearchFolderResponse (com.zimbra.soap.mail.message.CreateSearchFolderResponse)1