Exemplo n.º 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());
    }
  }
Exemplo n.º 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());
 }
Exemplo n.º 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());
   }
 }
Exemplo n.º 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();
   }
 }
Exemplo n.º 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());
    }
  }