Search in sources :

Example 1 with ReportDAO

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

the class EditReportJSONRequestController method process.

/**
 * Processes the request to edit a report.
 *
 * @param requestContext The JSON request context
 */
public void process(JSONRequestContext requestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
    ReportContextDAO reportContextDAO = DAOFactory.getInstance().getReportContextDAO();
    Long reportId = requestContext.getLong("reportId");
    Report report = reportDAO.findById(reportId);
    Long reportCategoryId = requestContext.getLong("category");
    ReportCategory category = reportCategoryId == null ? null : categoryDAO.findById(reportCategoryId);
    String name = requestContext.getString("name");
    reportDAO.update(report, name, category);
    for (ReportContextType contextType : ReportContextType.values()) {
        ReportContext context = reportContextDAO.findByReportAndContextType(report, contextType);
        boolean selected = requestContext.getBoolean("context." + contextType.toString());
        if (selected && context == null)
            reportContextDAO.create(report, contextType);
        else if (!selected && context != null)
            reportContextDAO.delete(context);
    }
    requestContext.setRedirectURL(requestContext.getReferer(true));
}
Also used : ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportContextDAO(fi.otavanopisto.pyramus.dao.reports.ReportContextDAO) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) ReportContextType(fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) ReportContext(fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)

Example 2 with ReportDAO

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

the class UploadReportDialogViewController 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) {
    FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    Long studentId = pageRequestContext.getLong("studentId");
    Long reportId = pageRequestContext.getLong("reportId");
    List<FileType> fileTypes = fileTypeDAO.listUnarchived();
    Collections.sort(fileTypes, new StringAttributeComparator("getName"));
    StringBuffer reportParameters = new StringBuffer();
    Map<String, String[]> parameterMap = pageRequestContext.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 {
                    reportParameters.append('&').append(entry.getKey()).append('=').append(URLEncoder.encode(value, "ISO-8859-1"));
                } catch (UnsupportedEncodingException e) {
                    throw new SmvcRuntimeException(e);
                }
            }
        }
    }
    pageRequestContext.getRequest().setAttribute("student", studentDAO.findById(studentId));
    pageRequestContext.getRequest().setAttribute("report", reportDAO.findById(reportId));
    pageRequestContext.getRequest().setAttribute("reportParameters", reportParameters);
    pageRequestContext.getRequest().setAttribute("fileTypes", fileTypes);
    pageRequestContext.setIncludeJSP("/templates/studentfiles/uploadreport.jsp");
}
Also used : FileTypeDAO(fi.otavanopisto.pyramus.dao.file.FileTypeDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) FileType(fi.otavanopisto.pyramus.domainmodel.file.FileType) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) Map(java.util.Map)

Example 3 with ReportDAO

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

the class ImportReportViewController method processForm.

@Override
public void processForm(PageRequestContext requestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
    ReportContextDAO reportContextDAO = DAOFactory.getInstance().getReportContextDAO();
    List<Report> reports = reportDAO.listAll();
    Collections.sort(reports, new StringAttributeComparator("getName"));
    JSONArray contextTypesJSON = new JSONArray();
    List<String> contextTypes = new ArrayList<>();
    for (ReportContextType contextType : ReportContextType.values()) {
        contextTypes.add(contextType.toString());
        contextTypesJSON.add(contextType.toString());
    }
    JSONArray reportsJSON = new JSONArray();
    for (Report report : reports) {
        JSONObject rObj = new JSONObject();
        List<ReportContext> contexts = reportContextDAO.listByReport(report);
        JSONArray rCtxs = new JSONArray();
        for (ReportContext ctx : contexts) {
            rCtxs.add(ctx.getContext().toString());
        }
        rObj.put("id", report.getId().toString());
        rObj.put("name", report.getName());
        rObj.put("category", report.getCategory() != null ? report.getCategory().getId() : "");
        rObj.put("contexts", rCtxs);
        reportsJSON.add(rObj);
    }
    List<ReportCategory> categories = categoryDAO.listAll();
    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());
            }
        }
    });
    setJsDataVariable(requestContext, "reports", reportsJSON.toString());
    setJsDataVariable(requestContext, "contextTypes", contextTypesJSON.toString());
    requestContext.getRequest().setAttribute("reports", reports);
    requestContext.getRequest().setAttribute("reportCategories", categories);
    requestContext.getRequest().setAttribute("contextTypes", contextTypes);
    requestContext.setIncludeJSP("/templates/system/importreport.jsp");
}
Also used : ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArray(net.sf.json.JSONArray) ArrayList(java.util.ArrayList) ReportContextType(fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType) JSONObject(net.sf.json.JSONObject) ReportContextDAO(fi.otavanopisto.pyramus.dao.reports.ReportContextDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) ReportContext(fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)

Example 4 with ReportDAO

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

the class UploadStudentReportJSONRequestController method process.

/**
 * Processes the request to edit a student group.
 *
 * @param requestContext
 *          The JSON request context
 */
public void process(JSONRequestContext requestContext) {
    StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
    FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    Long studentId = requestContext.getLong("studentId");
    Long reportId = requestContext.getLong("reportId");
    String reportParameters = requestContext.getString("reportParameters");
    Long userId = requestContext.getLoggedUserId();
    User loggedUser = userDAO.findById(userId);
    String name = requestContext.getString("fileName");
    Long fileTypeId = requestContext.getLong("fileType");
    String contentType;
    String format = requestContext.getString("reportFormat");
    if ("doc".equals(format)) {
        contentType = "application/msword";
    } else {
        format = "pdf";
        contentType = "application/pdf";
    }
    Student student = studentDAO.findById(studentId);
    FileType fileType = fileTypeId != null ? fileTypeDAO.findById(fileTypeId) : null;
    Report report = reportDAO.findById(reportId);
    MagicKeyDAO magicKeyDAO = DAOFactory.getInstance().getMagicKeyDAO();
    String reportsContextPath = System.getProperty("reports.contextPath");
    String reportsHost = System.getProperty("reports.host");
    String reportsProtocol = System.getProperty("reports.protocol");
    String reportsPort = System.getProperty("reports.port");
    // output or preview
    String outputMethod = "preview";
    MagicKey magicKey = magicKeyDAO.findByApplicationScope();
    StringBuilder urlBuilder = new StringBuilder().append(reportsProtocol).append("://").append(reportsHost).append(":").append(reportsPort).append(reportsContextPath).append("/").append(outputMethod).append("?magicKey=").append(magicKey.getName()).append("&__report=reports/").append(reportId).append(".rptdesign");
    urlBuilder.append("&__format=").append(format);
    urlBuilder.append(reportParameters);
    try {
        URL url = new URL(urlBuilder.toString());
        URLConnection urlConn = url.openConnection();
        InputStream inputStream = urlConn.getInputStream();
        String fileId = null;
        byte[] data = IOUtils.toByteArray(inputStream);
        if (PyramusFileUtils.isFileSystemStorageEnabled()) {
            try {
                fileId = PyramusFileUtils.generateFileId();
                PyramusFileUtils.storeFile(student, fileId, data);
                data = null;
            } catch (IOException e) {
                fileId = null;
                logger.log(Level.SEVERE, "Store user file to file system failed", e);
            }
        }
        String reportName = report.getName().toLowerCase().replaceAll("[^a-z0-9\\.]", "_");
        studentFileDAO.create(student, name, reportName + "." + format, fileId, fileType, contentType, data, loggedUser);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : FileTypeDAO(fi.otavanopisto.pyramus.dao.file.FileTypeDAO) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) MalformedURLException(java.net.MalformedURLException) User(fi.otavanopisto.pyramus.domainmodel.users.User) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) InputStream(java.io.InputStream) IOException(java.io.IOException) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) MagicKeyDAO(fi.otavanopisto.pyramus.dao.base.MagicKeyDAO) URL(java.net.URL) URLConnection(java.net.URLConnection) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) FileType(fi.otavanopisto.pyramus.domainmodel.file.FileType) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) MagicKey(fi.otavanopisto.pyramus.domainmodel.base.MagicKey)

Example 5 with ReportDAO

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

the class ViewCourseViewController 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) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    CourseComponentDAO courseComponentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    CourseAssessmentRequestDAO courseAssessmentRequestDAO = DAOFactory.getInstance().getCourseAssessmentRequestDAO();
    // The course to be edited
    Course course = courseDAO.findById(pageRequestContext.getLong("course"));
    pageRequestContext.getRequest().setAttribute("course", course);
    Map<Long, CourseAssessmentRequest> courseAssessmentRequests = new HashMap<>();
    List<CourseStudent> courseStudents = courseStudentDAO.listByCourse(course);
    Collections.sort(courseStudents, new Comparator<CourseStudent>() {

        @Override
        public int compare(CourseStudent o1, CourseStudent o2) {
            int cmp = o1.getStudent().getLastName().compareToIgnoreCase(o2.getStudent().getLastName());
            if (cmp == 0)
                cmp = o1.getStudent().getFirstName().compareToIgnoreCase(o2.getStudent().getFirstName());
            return cmp;
        }
    });
    List<CourseStaffMember> courseUsers = courseStaffMemberDAO.listByCourse(course);
    Collections.sort(courseUsers, new Comparator<CourseStaffMember>() {

        @Override
        public int compare(CourseStaffMember o1, CourseStaffMember o2) {
            int cmp = o1.getStaffMember().getLastName().compareToIgnoreCase(o2.getStaffMember().getLastName());
            if (cmp == 0)
                cmp = o1.getStaffMember().getFirstName().compareToIgnoreCase(o2.getStaffMember().getFirstName());
            return cmp;
        }
    });
    JSONArray courseReportsJSON = new JSONArray();
    List<Report> courseReports = reportDAO.listByContextType(ReportContextType.Course);
    Collections.sort(courseReports, new StringAttributeComparator("getName"));
    for (Report report : courseReports) {
        JSONObject obj = new JSONObject();
        obj.put("id", report.getId().toString());
        obj.put("name", report.getName());
        courseReportsJSON.add(obj);
    }
    for (CourseStudent courseStudent : courseStudents) {
        List<CourseAssessmentRequest> courseAssessmentRequestsByCourseStudent = courseAssessmentRequestDAO.listByCourseStudent(courseStudent);
        Collections.sort(courseAssessmentRequestsByCourseStudent, new Comparator<CourseAssessmentRequest>() {

            @Override
            public int compare(CourseAssessmentRequest o1, CourseAssessmentRequest o2) {
                return o2.getCreated().compareTo(o1.getCreated());
            }
        });
        if (!courseAssessmentRequestsByCourseStudent.isEmpty()) {
            courseAssessmentRequests.put(courseStudent.getId(), courseAssessmentRequestsByCourseStudent.get(0));
        }
    }
    setJsDataVariable(pageRequestContext, "courseReports", courseReportsJSON.toString());
    pageRequestContext.getRequest().setAttribute("courseStudents", courseStudents);
    pageRequestContext.getRequest().setAttribute("courseUsers", courseUsers);
    pageRequestContext.getRequest().setAttribute("courseComponents", courseComponentDAO.listByCourse(course));
    pageRequestContext.getRequest().setAttribute("courseDescriptions", descriptionDAO.listByCourseBase(course));
    pageRequestContext.getRequest().setAttribute("courseAssessmentRequests", courseAssessmentRequests);
    pageRequestContext.setIncludeJSP("/templates/courses/viewcourse.jsp");
}
Also used : HashMap(java.util.HashMap) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) JSONArray(net.sf.json.JSONArray) CourseAssessmentRequestDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO) JSONObject(net.sf.json.JSONObject) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO)

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