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;
}
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;
}
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);
}
}
Aggregations