public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean vertical = "1".equals(request.getParameter("v")); RequiredTimeTable rtt = null; if (request.getParameter("tp") != null) { TimePattern p = TimePatternDAO.getInstance().get(Long.valueOf(request.getParameter("tp"))); if (p != null) { TimeLocation t = null; if (request.getParameter("as") != null && request.getParameter("ad") != null) { t = new TimeLocation( Integer.parseInt(request.getParameter("ad")), Integer.parseInt(request.getParameter("as")), 1, 0, 0, null, null, null, 0); } rtt = new RequiredTimeTable(p.getTimePatternModel(t, true)); } } else if (request.getParameter("loc") != null) { Location location = LocationDAO.getInstance().get(Long.valueOf(request.getParameter("loc"))); if (location != null) { if (request.getParameter("xt") != null) { PeriodPreferenceModel px = new PeriodPreferenceModel( location.getSession(), Long.valueOf(request.getParameter("xt"))); px.load(location); rtt = new RequiredTimeTable(px); } else { if ("1".equals(request.getParameter("e"))) rtt = location.getEventAvailabilityTable(); else rtt = location.getRoomSharingTable(); } } } else if (request.getParameter("x") != null) { Exam exam = ExamDAO.getInstance().get(Long.valueOf(request.getParameter("x"))); if (exam != null) { ExamPeriod p = null; if (request.getParameter("ap") != null) p = ExamPeriodDAO.getInstance().get(Long.valueOf(request.getParameter("ap"))); PeriodPreferenceModel px = new PeriodPreferenceModel(exam.getSession(), p, exam.getExamType().getUniqueId()); px.load(exam); rtt = new RequiredTimeTable(px); } } else { rtt = new RequiredTimeTable(new TimePattern().getTimePatternModel()); } if (rtt != null) { if (request.getParameter("s") != null) { try { rtt.getModel().setDefaultSelection(Integer.parseInt(request.getParameter("s"))); } catch (NumberFormatException e) { rtt.getModel().setDefaultSelection(request.getParameter("s")); } } if (request.getParameter("p") != null) rtt.getModel().setPreferences(request.getParameter("p")); boolean hc = ("1".equals(request.getParameter("hc"))); response.setContentType("image/png"); response.setHeader("Content-Disposition", "attachment; filename=\"pattern.png\""); BufferedImage image = rtt.createBufferedImage(vertical, hc); if (image != null) ImageIO.write(image, "PNG", response.getOutputStream()); } }
public PdfWebTable getTable( boolean html, boolean color, ExamReportForm form, Collection<ExamInfo> exams) { if (exams == null || exams.isEmpty()) return null; boolean timeVertical = RequiredTimeTable.getTimeGridVertical(sessionContext.getUser()); boolean timeText = RequiredTimeTable.getTimeGridAsText(sessionContext.getUser()); String nl = (html ? "<br>" : "\n"); PdfWebTable table = new PdfWebTable( 9, "Not-assigned Examinations", "unassignedExams.do?ord=%%", new String[] { (form.getShowSections() ? "Classes / Courses" : "Examination"), "Length", "Seating" + nl + "Type", "Size", "Max" + nl + "Rooms", "Instructor", "Period" + nl + "Preferences", "Room" + nl + "Preferences", "Distribution" + nl + "Preferences" }, new String[] { "left", "right", "center", "right", "right", "left", "left", "left", "left" }, new boolean[] {true, true, true, false, false, true, true, true, true}); table.setRowStyle("white-space:nowrap"); try { for (ExamInfo exam : exams) { String perPref = "", roomPref = "", distPref = ""; if (html) { roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(RoomPref.class); if (roomPref.length() > 0) roomPref += nl; roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(BuildingPref.class); if (roomPref.length() > 0) roomPref += nl; roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(RoomFeaturePref.class); if (roomPref.length() > 0) roomPref += nl; roomPref += exam.getExam().getEffectivePrefHtmlForPrefType(RoomGroupPref.class); if (roomPref.endsWith(nl)) roomPref = roomPref.substring(0, roomPref.length() - nl.length()); if (timeText) { perPref += exam.getExam().getEffectivePrefHtmlForPrefType(ExamPeriodPref.class); } else { if (exam.getExam().getExamType().getType() == ExamType.sExamTypeMidterm) { MidtermPeriodPreferenceModel epx = new MidtermPeriodPreferenceModel( exam.getExam().getSession(), exam.getExam().getExamType()); epx.load(exam.getExam()); perPref += epx.toString(true); } else { PeriodPreferenceModel px = new PeriodPreferenceModel(exam.getExam().getSession(), exam.getExamTypeId()); px.load(exam.getExam()); perPref = "<img border='0' src='pattern?v=" + (timeVertical ? 1 : 0) + "&x=" + exam.getExamId() + "' title='" + px.toString() + "'>"; } } distPref += exam.getExam().getEffectivePrefHtmlForPrefType(DistributionPref.class); } else { for (Iterator j = exam.getExam().effectivePreferences(RoomPref.class).iterator(); j.hasNext(); ) { Preference pref = (Preference) j.next(); if (roomPref.length() > 0) roomPref += nl; roomPref += (color ? "@@COLOR " + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog()) + " " : "") + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + pref.preferenceText(); } for (Iterator j = exam.getExam().effectivePreferences(BuildingPref.class).iterator(); j.hasNext(); ) { Preference pref = (Preference) j.next(); if (roomPref.length() > 0) roomPref += nl; roomPref += (color ? "@@COLOR " + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog()) + " " : "") + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + pref.preferenceText(); } for (Iterator j = exam.getExam().effectivePreferences(RoomFeaturePref.class).iterator(); j.hasNext(); ) { Preference pref = (Preference) j.next(); if (roomPref.length() > 0) roomPref += nl; roomPref += (color ? "@@COLOR " + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog()) + " " : "") + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + pref.preferenceText(); } for (Iterator j = exam.getExam().effectivePreferences(RoomGroupPref.class).iterator(); j.hasNext(); ) { Preference pref = (Preference) j.next(); if (roomPref.length() > 0) roomPref += nl; roomPref += (color ? "@@COLOR " + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog()) + " " : "") + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + pref.preferenceText(); } if (ExamType.sExamTypeMidterm == exam.getExamType().getType()) { MidtermPeriodPreferenceModel epx = new MidtermPeriodPreferenceModel(exam.getExam().getSession(), exam.getExamType()); epx.load(exam.getExam()); perPref += epx.toString(false, true); } else { if (timeText || !color) { for (Iterator j = exam.getExam().effectivePreferences(ExamPeriodPref.class).iterator(); j.hasNext(); ) { Preference pref = (Preference) j.next(); if (perPref.length() > 0) perPref += nl; perPref += (color ? "@@COLOR " + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog()) + " " : "") + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + pref.preferenceText(); } } else { PeriodPreferenceModel px = new PeriodPreferenceModel( exam.getExam().getSession(), exam.getExamType().getUniqueId()); px.load(exam.getExam()); RequiredTimeTable rtt = new RequiredTimeTable(px); Image image = rtt.createBufferedImage(timeVertical); if (image != null) { table.addImage(exam.getExamId().toString(), image); perPref += "@@IMAGE " + exam.getExamId().toString() + " "; } else { for (Iterator j = exam.getExam().effectivePreferences(ExamPeriodPref.class).iterator(); j.hasNext(); ) { Preference pref = (Preference) j.next(); if (perPref.length() > 0) perPref += nl; perPref += (color ? "@@COLOR " + PreferenceLevel.prolog2color( pref.getPrefLevel().getPrefProlog()) + " " : "") + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + pref.preferenceText(); } } } } for (Iterator j = exam.getExam().effectivePreferences(DistributionPref.class).iterator(); j.hasNext(); ) { DistributionPref pref = (DistributionPref) j.next(); if (distPref.length() > 0) distPref += nl; distPref += (color ? "@@COLOR " + PreferenceLevel.prolog2color(pref.getPrefLevel().getPrefProlog()) + " " : "") + PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + pref.preferenceText(true, true, " (", ", ", ")") .replaceAll("<", "<") .replaceAll(">", ">"); } } String instructors = exam.getInstructorName(", "); table.addLine( "onClick=\"showGwtDialog('Examination Assignment', 'examInfo.do?examId=" + exam.getExamId() + "','900','90%');\"", new String[] { (html ? "<a name='" + exam.getExamId() + "'>" : "") + (form.getShowSections() ? exam.getSectionName(nl) : exam.getExamName()) + (html ? "</a>" : ""), String.valueOf(exam.getLength()), (Exam.sSeatingTypeNormal == exam.getSeatingType() ? "Normal" : "Exam"), String.valueOf(exam.getNrStudents()), String.valueOf(exam.getMaxRooms()), instructors, perPref, roomPref, distPref }, new Comparable[] { exam, exam.getLength(), exam.getSeatingType(), exam.getNrStudents(), exam.getMaxRooms(), instructors, perPref, roomPref, distPref }, exam.getExamId().toString()); } } catch (Exception e) { Debug.error(e); table.addLine(new String[] {"<font color='red'>ERROR:" + e.getMessage() + "</font>"}, null); } return table; }