Search in sources :

Example 1 with DomainBrowseTerm

use of com.zimbra.cs.index.DomainBrowseTerm in project zm-mailbox by Zimbra.

the class Browse method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    String browseBy = request.getAttribute(MailConstants.A_BROWSE_BY);
    BrowseBy parsedBrowseBy = BrowseBy.valueOf(browseBy.toLowerCase());
    String regex = request.getAttribute(MailConstants.A_REGEX, "").toLowerCase();
    int max = (int) (request.getAttributeLong(MailConstants.A_MAX_TO_RETURN, 0));
    List<BrowseTerm> terms;
    try {
        terms = mbox.browse(getOperationContext(zsc, context), parsedBrowseBy, regex, max);
    } catch (IOException e) {
        throw ServiceException.FAILURE("Failed to browse terms", e);
    }
    Element response = zsc.createElement(MailConstants.BROWSE_RESPONSE);
    for (BrowseTerm term : terms) {
        if (term instanceof DomainBrowseTerm) {
            DomainBrowseTerm domain = (DomainBrowseTerm) term;
            Element e = response.addElement(MailConstants.E_BROWSE_DATA).setText(domain.getText());
            String flags = domain.getHeaderFlags();
            if (!flags.isEmpty()) {
                e.addAttribute(MailConstants.A_BROWSE_DOMAIN_HEADER, flags);
            }
            e.addAttribute(MailConstants.A_FREQUENCY, domain.getFreq());
        } else {
            Element e = response.addElement(MailConstants.E_BROWSE_DATA).setText(term.getText());
            e.addAttribute(MailConstants.A_FREQUENCY, term.getFreq());
        }
    }
    return response;
}
Also used : BrowseBy(com.zimbra.cs.mailbox.Mailbox.BrowseBy) DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm) BrowseTerm(com.zimbra.cs.index.BrowseTerm) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm) Element(com.zimbra.common.soap.Element) IOException(java.io.IOException)

Example 2 with DomainBrowseTerm

use of com.zimbra.cs.index.DomainBrowseTerm in project zm-mailbox by Zimbra.

the class BrowseWrapper method browseBySender.

private List<DavResource> browseBySender(DavContext ctxt) throws IOException, ServiceException {
    ArrayList<DavResource> res = new ArrayList<DavResource>();
    String user = ctxt.getUser();
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    List<BrowseTerm> terms = mbox.browse(ctxt.getOperationContext(), Mailbox.BrowseBy.domains, "", 0);
    for (BrowseTerm term : terms) {
        if (term instanceof DomainBrowseTerm) {
            DomainBrowseTerm domain = (DomainBrowseTerm) term;
            if (domain.contains(DomainBrowseTerm.Field.FROM)) {
                res.add(new BrowseWrapper(generateUri(domain.getText()), getOwner()));
            }
        }
    }
    return res;
}
Also used : Account(com.zimbra.cs.account.Account) DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm) BrowseTerm(com.zimbra.cs.index.BrowseTerm) Mailbox(com.zimbra.cs.mailbox.Mailbox) DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning)

Example 3 with DomainBrowseTerm

use of com.zimbra.cs.index.DomainBrowseTerm in project zm-mailbox by Zimbra.

the class Mailbox method browse.

/**
     * Return a list of all the {attachments} or {doamins} or {objects} in this Mailbox, optionally with a prefix string
     * or limited by maximum number.
     *
     * @param max Maximum number of results to return.  0 means "return all results"  If more than max entries exist,
     * only the first max are returned, sorted by frequency.
     */
public List<BrowseTerm> browse(OperationContext octxt, BrowseBy browseBy, String regex, int max) throws IOException, ServiceException {
    boolean success = false;
    try {
        beginTransaction("browse", octxt);
        if (!hasFullAccess()) {
            throw ServiceException.PERM_DENIED("you do not have sufficient permissions on this mailbox");
        }
        List<BrowseTerm> result = null;
        switch(browseBy) {
            case attachments:
                result = index.getAttachmentTypes(regex);
                break;
            case domains:
                Map<String, DomainBrowseTerm> domains = new HashMap<String, DomainBrowseTerm>();
                for (BrowseTerm term : index.getDomains(LuceneFields.L_H_FROM, regex)) {
                    DomainBrowseTerm domain = domains.get(term.getText());
                    if (domain == null) {
                        domain = new DomainBrowseTerm(term);
                        domains.put(term.getText(), domain);
                    }
                    domain.addField(DomainBrowseTerm.Field.FROM);
                }
                for (BrowseTerm term : index.getDomains(LuceneFields.L_H_TO, regex)) {
                    DomainBrowseTerm domain = domains.get(term.getText());
                    if (domain == null) {
                        domain = new DomainBrowseTerm(term);
                        domains.put(term.getText(), domain);
                    }
                    domain.addField(DomainBrowseTerm.Field.TO);
                }
                for (BrowseTerm term : index.getDomains(LuceneFields.L_H_CC, regex)) {
                    DomainBrowseTerm domain = domains.get(term.getText());
                    if (domain == null) {
                        domain = new DomainBrowseTerm(term);
                        domains.put(term.getText(), domain);
                    }
                    domain.addField(DomainBrowseTerm.Field.CC);
                }
                result = new ArrayList<BrowseTerm>(domains.values());
                break;
            case objects:
                result = index.getObjects(regex);
                break;
            default:
                assert false : browseBy;
        }
        Collections.sort(result, new Comparator<BrowseTerm>() {

            @Override
            public int compare(BrowseTerm o1, BrowseTerm o2) {
                int retVal = o2.getFreq() - o1.getFreq();
                if (retVal == 0) {
                    retVal = o1.getText().compareTo(o2.getText());
                }
                return retVal;
            }
        });
        if (max > 0 && result.size() > max) {
            result = result.subList(0, max);
        }
        success = true;
        return result;
    } finally {
        endTransaction(success);
    }
}
Also used : DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm) BrowseTerm(com.zimbra.cs.index.BrowseTerm) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentLinkedHashMap(com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap) HashMap(java.util.HashMap) DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm)

Aggregations

BrowseTerm (com.zimbra.cs.index.BrowseTerm)3 DomainBrowseTerm (com.zimbra.cs.index.DomainBrowseTerm)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 ConcurrentLinkedHashMap (com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap)1 Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 BrowseBy (com.zimbra.cs.mailbox.Mailbox.BrowseBy)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1