Search in sources :

Example 1 with EmailRecords

use of org.motechproject.email.domain.EmailRecords in project motech by motech.

the class EmailController method getEmails.

@RequestMapping(value = "/emails", method = RequestMethod.GET)
@PreAuthorize(EmailRolesConstants.HAS_ANY_EMAIL_ROLE)
@ResponseBody
public EmailRecords<? extends BasicEmailRecordDto> getEmails(GridSettings filter, HttpServletRequest request) {
    EmailRecordSearchCriteria criteria = prepareCriteria(filter);
    List<EmailRecord> filtered = auditService.findEmailRecords(criteria);
    List<? extends BasicEmailRecordDto> rows = hideColumns(filtered, filter);
    long total = auditService.countEmailRecords(criteria);
    if (filter.getRows() == null) {
        int defaultRowsAmount = 10;
        filter.setRows(defaultRowsAmount);
    }
    if (filter.getPage() == null) {
        int defaultPage = 1;
        filter.setPage(defaultPage);
    }
    int totalPages = (int) Math.ceil((double) total / filter.getRows());
    String username = getUsername(request);
    if (username != null) {
        lastFilter.put(username, filter);
    }
    return new EmailRecords<>((int) total, filter.getPage(), totalPages, rows);
}
Also used : EmailRecord(org.motechproject.email.domain.EmailRecord) EmailRecords(org.motechproject.email.domain.EmailRecords) EmailRecordSearchCriteria(org.motechproject.email.builder.EmailRecordSearchCriteria) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

EmailRecordSearchCriteria (org.motechproject.email.builder.EmailRecordSearchCriteria)1 EmailRecord (org.motechproject.email.domain.EmailRecord)1 EmailRecords (org.motechproject.email.domain.EmailRecords)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1