コード例 #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
 @GET
 @Path("/{id}/classroom")
 @Produces(MediaType.APPLICATION_JSON)
 public Response getClassroom(@PathParam("id") long id) {
   try {
     Schedule domain = getService().get(id);
     DomainUtil.checkingForNotNull(domain);
     return Response.ok(domain.getClassroom()).header("Content-Encoding", "utf-8").build();
   } catch (BusinessServiceException e) {
     throw new RestServiceException(e.getErrorCode());
   } catch (NullPropertyException e) {
     return Response.noContent().build();
   }
 }
コード例 #3
0
 @Override
 @GET
 @Path("/list")
 @Produces(MediaType.APPLICATION_JSON)
 public Response list() {
   try {
     List<ScheduleResponse> scheduleResponses = new LinkedList<ScheduleResponse>();
     for (Schedule schedule : getService().list()) {
       scheduleResponses.add(new ScheduleResponse(schedule));
     }
     return Response.ok(scheduleResponses).header("Content-Encoding", "utf-8").build();
   } catch (BusinessServiceException e) {
     throw new RestServiceException(e.getErrorCode());
   }
 }
コード例 #4
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());
    }
  }