Exemple #1
0
 public static boolean print(
     OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber)
     throws IOException, DocumentException {
   TreeSet courses =
       new TreeSet(
           new Comparator() {
             public int compare(Object o1, Object o2) {
               CourseOffering co1 = (CourseOffering) o1;
               CourseOffering co2 = (CourseOffering) o2;
               int cmp = co1.getCourseName().compareTo(co2.getCourseName());
               if (cmp != 0) return cmp;
               return co1.getUniqueId().compareTo(co2.getUniqueId());
             }
           });
   String subjectIds = "";
   for (SubjectArea sa : subjectAreas)
     subjectIds += (subjectIds.isEmpty() ? "" : ",") + sa.getUniqueId();
   String query =
       "select co from CourseOffering co where  co.subjectArea.uniqueId in (" + subjectIds + ")";
   if (courseNumber != null && !courseNumber.trim().isEmpty()) {
     query += " and co.courseNbr ";
     if (courseNumber.indexOf('*') >= 0)
       query += " like '" + courseNumber.trim().replace('*', '%').toUpperCase() + "'";
     else query += " = '" + courseNumber.trim().toUpperCase() + "'";
   }
   courses.addAll(new SessionDAO().getSession().createQuery(query).list());
   if (courses.isEmpty()) return false;
   PdfWorksheet w = new PdfWorksheet(out, subjectAreas, courseNumber);
   for (Iterator i = courses.iterator(); i.hasNext(); ) {
     w.print((CourseOffering) i.next());
   }
   w.lastPage();
   w.close();
   return true;
 }
Exemple #2
0
 public static boolean print(OutputStream out, Collection<SubjectArea> subjectAreas)
     throws IOException, DocumentException {
   TreeSet courses =
       new TreeSet(
           new Comparator() {
             public int compare(Object o1, Object o2) {
               CourseOffering co1 = (CourseOffering) o1;
               CourseOffering co2 = (CourseOffering) o2;
               int cmp = co1.getCourseName().compareTo(co2.getCourseName());
               if (cmp != 0) return cmp;
               return co1.getUniqueId().compareTo(co2.getUniqueId());
             }
           });
   String subjectIds = "";
   for (SubjectArea sa : subjectAreas)
     subjectIds += (subjectIds.isEmpty() ? "" : ",") + sa.getUniqueId();
   courses.addAll(
       SessionDAO.getInstance()
           .getSession()
           .createQuery(
               "select co from CourseOffering co where  co.subjectArea.uniqueId in ("
                   + subjectIds
                   + ")")
           .list());
   if (courses.isEmpty()) return false;
   PdfWorksheet w = new PdfWorksheet(out, subjectAreas, null);
   for (Iterator i = courses.iterator(); i.hasNext(); ) {
     w.print((CourseOffering) i.next());
   }
   w.lastPage();
   w.close();
   return true;
 }
Exemple #3
0
  public static void main(String[] args) {
    try {
      HibernateUtil.configureHibernate(ApplicationProperties.getProperties());

      Long sessionId =
          Long.valueOf(ApplicationProperties.getProperty("tmtbl.pdf.worksheet.session", "165924"));
      Session session = new SessionDAO().get(sessionId);
      if (session == null) {
        System.err.println(
            "Academic session "
                + sessionId
                + " not found, use property tmtbl.pdf.worksheet.session to set academic session.");
        System.exit(0);
      } else {
        System.out.println("Session: " + session);
      }
      TreeSet subjectAreas = null;
      if (args.length > 0) {
        subjectAreas = new TreeSet();
        for (int i = 0; i < args.length; i++) {
          SubjectArea sa = SubjectArea.findByAbbv(sessionId, args[i]);
          if (sa == null) System.err.println("Subject area " + args[i] + " not found.");
          else subjectAreas.add(sa);
        }
      } else {
        subjectAreas = new TreeSet(SubjectArea.getSubjectAreaList(sessionId));
      }

      for (Iterator i = subjectAreas.iterator(); i.hasNext(); ) {
        SubjectArea sa = (SubjectArea) i.next();
        System.out.println("Printing subject area " + sa.getSubjectAreaAbbreviation() + " ...");
        FileOutputStream out = new FileOutputStream(sa.getSubjectAreaAbbreviation() + ".pdf");
        List<SubjectArea> sas = new ArrayList<SubjectArea>();
        sas.add(sa);
        PdfWorksheet.print(out, sas);
        out.flush();
        out.close();
      }

      HibernateUtil.closeHibernate();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }