コード例 #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
 @Override
 protected void updateFields(Schedule domain, Schedule newDomain) {
   domain.setDayOfWeek(newDomain.getDayOfWeek());
   domain.setWeek(newDomain.getWeek());
   domain.setClassroomId(newDomain.getClassroomId());
   domain.setDisciplineTimeId(newDomain.getDisciplineTimeId());
   domain.setStudyId(newDomain.getStudyId());
 }
コード例 #3
0
 @Override
 protected void validate(Schedule domain) {
   try {
     DomainUtil.checkingForNotNull(domain.getWeek());
     DomainUtil.checkingForNotNull(domain.getDayOfWeek());
     DomainUtil.checkingForNotNull(domain.getStudyId());
     DomainUtil.checkingForNotNull(domain.getClassroomId());
     DomainUtil.checkingForNotNull(domain.getDisciplineTimeId());
   } catch (NullPropertyException e) {
     throw new RestServiceException(Response.Status.BAD_REQUEST.getStatusCode());
   }
 }
コード例 #4
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();
   }
 }
コード例 #5
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());
    }
  }