Ejemplo n.º 1
0
 public boolean generateWeeklyEventForAllCourses() {
   HibernateSupport.beginTransaction();
   for (WeeklyEvent we : etm.getWeeklyEvents()) {
     we.deleteFromDB();
   }
   HibernateSupport.commitTransaction();
   etm.clearWeeklyEvents();
   List<Course> courses = bc.getCoc().getCourseTableModel().getAllCourses();
   boolean result = true;
   for (Course c : courses) {
     if (!generateWeeklyEventFor(c)) {
       LoggingFunctions.printError("Could not generate weekly event for " + c.getId(), "-");
       result = false;
     }
   }
   return result;
 }
Ejemplo n.º 2
0
  public boolean generateWeeklyEventFor(Course c) {
    List<Room> rooms = findRoomsForCourse(c);
    Room r = null;
    if (rooms.size() < 1) {
      LoggingFunctions.printError(
          "Could not generate weekly event for course " + c.getId(), "No suitable rooms found");
      return false;
    }
    Calendar cal = DateFunctions.calculateNextValidStartTime();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    int hours = (int) c.getSemesterHours();

    // While there is another valid start time
    while (DateFunctions.calculateNextValidStartTime(cal, hours)) {
      // If the course can be done on that start time
      if (isTimeslotFreeForCourse(c, cal, hours)) {
        r = getFreeRoomForTimeslot(rooms, cal, hours);
        // If there is a free room at that time
        if (r != null) {
          WeeklyEvent we = new WeeklyEvent();
          we.setEvent(cal, hours, c, r);
          etm.addWeeklyEvent(we);
          we.saveToDB();
          System.out.println("");
          System.out.println("Saved new weekly event:");
          System.out.println("Course: " + c.getName());
          System.out.println(
              "From: " + cal.get(Calendar.HOUR_OF_DAY) + "" + DateFunctions.getDayOfWeek(cal));
          System.out.println(
              "To: "
                  + cal.get(Calendar.HOUR_OF_DAY)
                  + hours
                  + ""
                  + DateFunctions.getDayOfWeek(cal));
          System.out.println("Room: " + r.getRoomName());
          System.out.println("");
          return true;
        }
      }
    }

    return false;
  }