Search in sources :

Example 1 with MailServiceException

use of org.opencastproject.messages.MailServiceException in project opencast by opencast.

the class EmailListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
    Map<String, String> result = new HashMap<String, String>();
    if (getListNameFromFilter(EmailFilterList.TEMPLATE_NAMES).equals(listName)) {
        String nameText = null;
        if (query.hasFilter(NAME) && query.getFilter(NAME).getValue().isSome() && query.getFilter(NAME).getValue().get() instanceof String) {
            nameText = (String) query.getFilter(NAME).getValue().get();
        }
        String startsWithText = null;
        if (query.hasFilter(STARTS_WITH_TEXT) && query.getFilter(STARTS_WITH_TEXT).getValue().isSome() && query.getFilter(STARTS_WITH_TEXT).getValue().get() instanceof String) {
            startsWithText = (String) query.getFilter(STARTS_WITH_TEXT).getValue().get();
        }
        List<MessageTemplate> messageTemplateList;
        try {
            if (nameText != null) {
                logger.debug("Searching for a template with name '{}'", nameText);
                messageTemplateList = mailService.getMessageTemplateByName(nameText);
            } else if (startsWithText != null) {
                logger.debug("Searching for templates that start with '{}'", startsWithText);
                messageTemplateList = mailService.getMessageTemplatesStartingWith(startsWithText);
            } else {
                logger.debug("Getting all templates");
                messageTemplateList = mailService.getMessageTemplates();
            }
        } catch (MailServiceException e) {
            logger.error("Error retreiving message templates from mail service: {}", ExceptionUtils.getStackTrace(e));
            throw new ListProviderException("Error retreiving message templates from mail service", e);
        }
        for (MessageTemplate messageTemplate : messageTemplateList) {
            result.put(Long.toString(messageTemplate.getId()), messageTemplate.getName());
        }
    } else {
        logger.warn("No email list for list name {} found", listName);
        throw new ListProviderException("No email list for list name " + listName + " found!");
    }
    return ListProviderUtil.filterMap(result, query);
}
Also used : MessageTemplate(org.opencastproject.messages.MessageTemplate) HashMap(java.util.HashMap) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) MailServiceException(org.opencastproject.messages.MailServiceException)

Aggregations

HashMap (java.util.HashMap)1 ListProviderException (org.opencastproject.index.service.exception.ListProviderException)1 MailServiceException (org.opencastproject.messages.MailServiceException)1 MessageTemplate (org.opencastproject.messages.MessageTemplate)1