use of com.zimbra.soap.admin.message.ReIndexRequest in project zm-mailbox by Zimbra.
the class ReIndex method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
ReIndexRequest req = JaxbUtil.elementToJaxb(request);
String action = req.getAction();
ReindexMailboxInfo reIndexMboxInfo = req.getMbox();
String accountId = reIndexMboxInfo.getAccountId();
Provisioning prov = Provisioning.getInstance();
Account account = prov.get(AccountBy.id, accountId, zsc.getAuthToken());
defendAgainstAccountOrCalendarResourceHarvesting(account, AccountBy.id, accountId, zsc, Admin.R_reindexMailbox, Admin.R_reindexCalendarResourceMailbox);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
if (mbox == null) {
throw ServiceException.FAILURE("mailbox not found for account " + accountId, null);
}
Element response = zsc.createElement(AdminConstants.REINDEX_RESPONSE);
if (ACTION_START.equalsIgnoreCase(action)) {
if (mbox.index.isReIndexInProgress()) {
response.addAttribute(AdminConstants.A_STATUS, STATUS_RUNNING);
} else {
String typesStr = reIndexMboxInfo.getTypes();
String idsStr = reIndexMboxInfo.getIds();
if (typesStr != null && idsStr != null) {
ServiceException.INVALID_REQUEST("Can't specify both 'types' and 'ids'", null);
}
if (typesStr != null) {
Set<MailItem.Type> types;
try {
types = MailItem.Type.setOf(typesStr);
} catch (IllegalArgumentException e) {
throw MailServiceException.INVALID_TYPE(e.getMessage());
}
mbox.index.startReIndexByType(types);
} else if (idsStr != null) {
Set<Integer> ids = new HashSet<Integer>();
for (String id : Splitter.on(',').trimResults().split(idsStr)) {
try {
ids.add(Integer.parseInt(id));
} catch (NumberFormatException e) {
ServiceException.INVALID_REQUEST("invalid item ID: " + id, e);
}
}
mbox.index.startReIndexById(ids);
} else {
mbox.index.startReIndex();
}
response.addAttribute(AdminConstants.A_STATUS, STATUS_STARTED);
}
} else if (ACTION_STATUS.equalsIgnoreCase(action)) {
MailboxIndex.ReIndexStatus status = mbox.index.getReIndexStatus();
if (status != null) {
addProgressInfo(response, status);
response.addAttribute(AdminConstants.A_STATUS, STATUS_RUNNING);
} else {
response.addAttribute(AdminConstants.A_STATUS, STATUS_IDLE);
}
} else if (ACTION_CANCEL.equalsIgnoreCase(action)) {
MailboxIndex.ReIndexStatus status = mbox.index.cancelReIndex();
if (status != null) {
response.addAttribute(AdminConstants.A_STATUS, STATUS_CANCELLED);
addProgressInfo(response, status);
} else {
response.addAttribute(AdminConstants.A_STATUS, STATUS_IDLE);
}
} else {
throw ServiceException.INVALID_REQUEST("Unknown action: " + action, null);
}
return response;
}
Aggregations