Пример #1
0
  private Response getScheduleForLecturer(long lecturerId) {
    try {
      int currentMonth = Calendar.getInstance().get(Calendar.MONTH);
      int semester;
      if (currentMonth < Calendar.JULY) {
        semester = 0;
      } else {
        semester = 1;
      }
      List<Schedule> scheduleList = scheduleService.getSchedule(lecturerId, semester);
      List<ScheduleResponse> scheduleResponseList = new LinkedList<ScheduleResponse>();
      ScheduleGroupResponse groupResponse = new ScheduleGroupResponse();
      int currentWeek = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR) % 2;
      groupResponse.setCurrentWeek(currentWeek == 0 ? 2 : currentWeek);
      int day = 2;
      for (Schedule response : scheduleList) {
        if (day != response.getDayOfWeek()) {
          groupResponse.setSchedule(scheduleResponseList, day);
          scheduleResponseList.clear();
          day = response.getDayOfWeek();
        }
        response.setLecturer(lecturerService.get(response.getLecturerId()));
        scheduleResponseList.add(new ScheduleResponse(response));
      }
      groupResponse.setSchedule(scheduleResponseList, day);

      return Response.ok(groupResponse).header("Content-Encoding", "utf-8").build();
    } catch (BusinessServiceException e) {
      throw new RestServiceException(e.getErrorCode());
    }
  }
Пример #2
0
  private Response getScheduleForStudent(int course, int group, String subGroup) {
    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    int currentMonth = Calendar.getInstance().get(Calendar.MONTH);
    int semester;
    int yearOfEntrance;
    if (currentMonth < Calendar.JULY) {
      semester = course * 2;
      yearOfEntrance = currentYear - course;
    } else {
      semester = course * 2 - 1;
      yearOfEntrance = currentYear - course + 1;
    }
    String subGroupName = "".equals(subGroup) ? subGroup : String.valueOf(group) + subGroup;
    try {
      List<Schedule> scheduleList =
          scheduleService.getSchedule(
              semester, yearOfEntrance, String.valueOf(group), subGroupName);
      List<ScheduleResponse> scheduleResponseList = new LinkedList<ScheduleResponse>();
      ScheduleGroupResponse groupResponse = new ScheduleGroupResponse();
      int currentWeek = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR) % 2;
      groupResponse.setCurrentWeek(currentWeek == 0 ? 2 : currentWeek);
      int day = 2;
      for (Schedule response : scheduleList) {
        if (day != response.getDayOfWeek()) {
          groupResponse.setSchedule(scheduleResponseList, day);
          scheduleResponseList.clear();
          day = response.getDayOfWeek();
        }
        response.setLecturer(lecturerService.get(response.getLecturerId()));
        scheduleResponseList.add(new ScheduleResponse(response));
      }
      groupResponse.setSchedule(scheduleResponseList, day);

      return Response.ok(groupResponse).header("Content-Encoding", "utf-8").build();
    } catch (BusinessServiceException e) {
      throw new RestServiceException(e.getErrorCode());
    }
  }