Search in sources :

Example 6 with Report

use of fi.otavanopisto.pyramus.domainmodel.reports.Report 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 Report

use of fi.otavanopisto.pyramus.domainmodel.reports.Report 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 Report

use of fi.otavanopisto.pyramus.domainmodel.reports.Report in project pyramus by otavanopisto.

the class ReportDAO method create.

public Report create(String name, String data, User creatingUser) {
    Date now = new Date(System.currentTimeMillis());
    Report report = new Report();
    report.setData(data);
    report.setName(name);
    report.setCreated(now);
    report.setCreator(creatingUser);
    report.setLastModified(now);
    report.setLastModifier(creatingUser);
    getEntityManager().persist(report);
    return report;
}
Also used : Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) Date(java.util.Date)

Example 9 with Report

use of fi.otavanopisto.pyramus.domainmodel.reports.Report in project pyramus by otavanopisto.

the class ReportDAO method listByContextType.

public List<Report> listByContextType(ReportContextType contextType) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Report> criteria = criteriaBuilder.createQuery(Report.class);
    Root<ReportContext> root = criteria.from(ReportContext.class);
    criteria.select(root.get(ReportContext_.report));
    criteria.where(criteriaBuilder.equal(root.get(ReportContext_.context), contextType));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportContext(fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)

Example 10 with Report

use of fi.otavanopisto.pyramus.domainmodel.reports.Report 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)

Aggregations

Report (fi.otavanopisto.pyramus.domainmodel.reports.Report)15 ReportDAO (fi.otavanopisto.pyramus.dao.reports.ReportDAO)12 ReportCategoryDAO (fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO)4 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)3 MagicKeyDAO (fi.otavanopisto.pyramus.dao.base.MagicKeyDAO)3 ReportContextDAO (fi.otavanopisto.pyramus.dao.reports.ReportContextDAO)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 IOException (java.io.IOException)3 Locale (java.util.Locale)3 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)2 StudentFileDAO (fi.otavanopisto.pyramus.dao.file.StudentFileDAO)2 CourseAssessmentRequestDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO)2 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)2 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2