Search in sources :

Example 6 with ReportDAO

use of fi.otavanopisto.pyramus.dao.reports.ReportDAO in project pyramus by otavanopisto.

the class EditReportViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
    ReportContextDAO reportContextDAO = DAOFactory.getInstance().getReportContextDAO();
    Long reportId = pageRequestContext.getLong("reportId");
    Report report = reportDAO.findById(reportId);
    List<ReportCategory> categories = categoryDAO.listAll();
    List<ReportContext> reportContexts = reportContextDAO.listByReport(report);
    Collections.sort(categories, new Comparator<ReportCategory>() {

        public int compare(ReportCategory o1, ReportCategory o2) {
            if (o1.getIndexColumn() == o2.getIndexColumn() || o1.getIndexColumn().equals(o2.getIndexColumn())) {
                return o1.getName() == null ? -1 : o2.getName() == null ? 1 : o1.getName().compareTo(o2.getName());
            } else {
                return o1.getIndexColumn() == null ? -1 : o2.getIndexColumn() == null ? 1 : o1.getIndexColumn().compareTo(o2.getIndexColumn());
            }
        }
    });
    Map<String, Boolean> selectedContexts = new HashMap<>();
    for (ReportContext context : reportContexts) selectedContexts.put(context.getContext().toString(), Boolean.TRUE);
    List<String> contextTypes = new ArrayList<>();
    for (ReportContextType contextType : ReportContextType.values()) contextTypes.add(contextType.toString());
    pageRequestContext.getRequest().setAttribute("report", report);
    pageRequestContext.getRequest().setAttribute("reportCategories", categories);
    pageRequestContext.getRequest().setAttribute("reportContexts", selectedContexts);
    pageRequestContext.getRequest().setAttribute("contextTypes", contextTypes);
    pageRequestContext.setIncludeJSP("/templates/reports/editreport.jsp");
}
Also used : ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) HashMap(java.util.HashMap) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) ArrayList(java.util.ArrayList) ReportContextType(fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType) ReportContextDAO(fi.otavanopisto.pyramus.dao.reports.ReportContextDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) ReportContext(fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)

Example 7 with ReportDAO

use of fi.otavanopisto.pyramus.dao.reports.ReportDAO in project pyramus by otavanopisto.

the class ListReportsViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    List<Report> reports = reportDAO.listByContextType(ReportContextType.Common);
    Collections.sort(reports, new Comparator<Report>() {

        @Override
        public int compare(Report o1, Report o2) {
            String s1 = o1.getCategory() == null ? null : o1.getCategory().getName();
            String s2 = o2.getCategory() == null ? null : o2.getCategory().getName();
            int cmp = s1 == null ? 1 : s2 == null ? -1 : s1.compareToIgnoreCase(s2);
            if (cmp == 0) {
                cmp = o1.getName().compareToIgnoreCase(o2.getName());
            }
            return cmp;
        }
    });
    pageRequestContext.getRequest().setAttribute("reports", reports);
    pageRequestContext.setIncludeJSP("/templates/reports/listreports.jsp");
}
Also used : Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO)

Example 8 with ReportDAO

use of fi.otavanopisto.pyramus.dao.reports.ReportDAO in project pyramus by otavanopisto.

the class ViewReportParametersViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    MagicKeyDAO magicKeyDAO = DAOFactory.getInstance().getMagicKeyDAO();
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    Long reportId = pageRequestContext.getLong("reportId");
    Report report = reportDAO.findById(reportId);
    StringBuilder magicKeyBuilder = new StringBuilder().append(Long.toHexString(reportId)).append('-').append(Long.toHexString(System.currentTimeMillis())).append('-').append(Long.toHexString(Thread.currentThread().getId()));
    MagicKey magicKey = magicKeyDAO.create(magicKeyBuilder.toString(), MagicKeyScope.REQUEST);
    String localeAdd = "";
    Locale locale = pageRequestContext.getRequest().getLocale();
    if (locale != null) {
        localeAdd = "&__locale=";
        localeAdd += locale.getLanguage();
        if (!StringUtils.isEmpty(locale.getCountry())) {
            localeAdd += "_";
            localeAdd += locale.getCountry();
        }
    }
    StringBuilder urlBuilder = new StringBuilder().append(ReportUtils.getReportsUrl(pageRequestContext.getRequest())).append("/parameter?magicKey=").append(magicKey.getName()).append(localeAdd).append("&__report=reports/").append(reportId).append(".rptdesign").append("&__masterpage=true&__nocache");
    handleContextParameters(pageRequestContext, report, urlBuilder);
    pageRequestContext.setIncludeUrl(urlBuilder.toString());
}
Also used : Locale(java.util.Locale) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) MagicKeyDAO(fi.otavanopisto.pyramus.dao.base.MagicKeyDAO) MagicKey(fi.otavanopisto.pyramus.domainmodel.base.MagicKey)

Example 9 with ReportDAO

use of fi.otavanopisto.pyramus.dao.reports.ReportDAO in project pyramus by otavanopisto.

the class ViewReportViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    Long reportId = pageRequestContext.getLong("reportId");
    Report report = reportDAO.findById(reportId);
    handleContextParameters(pageRequestContext, report);
    pageRequestContext.getRequest().setAttribute("report", report);
    pageRequestContext.setIncludeJSP("/templates/reports/viewreport.jsp");
}
Also used : Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO)

Example 10 with ReportDAO

use of fi.otavanopisto.pyramus.dao.reports.ReportDAO in project pyramus by otavanopisto.

the class DownloadReportBinaryRequestController method process.

/**
 * Processes a binary request for a report in binary format.
 * The request should contain the following parameters:
 * <dl>
 *   <dt><code>reportId</code></dt>
 *   <dd>The ID of the report to download.</dd>
 *   <dt><code>format</code></dt>
 *   <dd>The file format of the report. Possible values:
 *     <ul>
 *       <li><code>html</code></li>
 *       <li><code>pdf</code></li>
 *       <li><code>rtf</code></li>
 *       <li><code>doc</code></li>
 *       <li><code>xml</code></li>
 *     </ul>
 *   </dd>
 * </dl>
 *
 * @param binaryRequestContext The context of the binary request.
 */
public void process(BinaryRequestContext binaryRequestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    MagicKeyDAO magicKeyDAO = DAOFactory.getInstance().getMagicKeyDAO();
    Long reportId = binaryRequestContext.getLong("reportId");
    String formatParameter = binaryRequestContext.getString("format");
    ReportOutputFormat outputFormat = Enum.valueOf(ReportOutputFormat.class, formatParameter);
    StringBuilder magicKeyBuilder = new StringBuilder().append(Long.toHexString(reportId)).append('-').append(Long.toHexString(System.currentTimeMillis())).append('-').append(Long.toHexString(Thread.currentThread().getId()));
    MagicKey magicKey = magicKeyDAO.create(magicKeyBuilder.toString(), MagicKeyScope.REQUEST);
    Report report = reportDAO.findById(reportId);
    String reportName = report.getName().toLowerCase().replaceAll("[^a-z0-9\\.]", "_");
    String localeAdd = "";
    Locale locale = binaryRequestContext.getRequest().getLocale();
    if (locale != null) {
        localeAdd = "&__locale=";
        localeAdd += locale.getLanguage();
        if (!StringUtils.isEmpty(locale.getCountry())) {
            localeAdd += "_";
            localeAdd += locale.getCountry();
        }
    }
    StringBuilder urlBuilder = new StringBuilder().append(ReportUtils.getReportsUrl(binaryRequestContext.getRequest())).append("/preview").append("?magicKey=").append(magicKey.getName()).append(localeAdd).append("&__report=reports/").append(reportId).append(".rptdesign").append("&__format=").append(outputFormat.name());
    Map<String, String[]> parameterMap = binaryRequestContext.getRequest().getParameterMap();
    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        if (!reservedParameters.contains(entry.getKey())) {
            String[] values = entry.getValue();
            for (String value : values) {
                // TODO ISO-8859-1 should be UTF-8, once Birt's parameter dialog form has its accept-charset="UTF-8" set
                try {
                    urlBuilder.append('&').append(entry.getKey()).append('=').append(URLEncoder.encode(value, "ISO-8859-1"));
                } catch (UnsupportedEncodingException e) {
                    throw new SmvcRuntimeException(e);
                }
            }
        }
    }
    binaryRequestContext.setFileName(reportName + '.' + outputFormat.getExt());
    binaryRequestContext.setContentUrl(urlBuilder.toString());
}
Also used : Locale(java.util.Locale) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) MagicKeyDAO(fi.otavanopisto.pyramus.dao.base.MagicKeyDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) MagicKey(fi.otavanopisto.pyramus.domainmodel.base.MagicKey) Map(java.util.Map)

Aggregations

ReportDAO (fi.otavanopisto.pyramus.dao.reports.ReportDAO)13 Report (fi.otavanopisto.pyramus.domainmodel.reports.Report)12 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)4 ReportCategoryDAO (fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO)4 MagicKeyDAO (fi.otavanopisto.pyramus.dao.base.MagicKeyDAO)3 ReportContextDAO (fi.otavanopisto.pyramus.dao.reports.ReportContextDAO)3 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)3 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)3 MagicKey (fi.otavanopisto.pyramus.domainmodel.base.MagicKey)3 ReportCategory (fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory)3 ReportContext (fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)3 ReportContextType (fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType)3 User (fi.otavanopisto.pyramus.domainmodel.users.User)3 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)3 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Locale (java.util.Locale)3 Map (java.util.Map)3 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)2 FileTypeDAO (fi.otavanopisto.pyramus.dao.file.FileTypeDAO)2