fim.setTimeInMillis(inicio.getTimeInMillis());
    public ActionForward createEditLesson(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response) throws Exception {        DynaActionForm manageLessonForm = (DynaActionForm) form;        request.setAttribute("manageLessonForm", manageLessonForm);        ContextUtils.setExecutionPeriodContext(request);        DiaSemana weekDay = new DiaSemana(new Integer(formDay2EnumerateDay((String) manageLessonForm                .get("diaSemana"))));        Boolean quinzenal = (Boolean) manageLessonForm.get("quinzenal");        if (quinzenal == null) {            quinzenal = new Boolean(false);        }        Calendar inicio = Calendar.getInstance();        inicio.set(Calendar.HOUR_OF_DAY, Integer.parseInt((String) manageLessonForm.get("horaInicio")));        inicio.set(Calendar.MINUTE, Integer.parseInt((String) manageLessonForm.get("minutosInicio")));        inicio.set(Calendar.SECOND, 0);        Calendar fim = Calendar.getInstance();        fim.set(Calendar.HOUR_OF_DAY, Integer.parseInt((String) manageLessonForm.get("horaFim")));        fim.set(Calendar.MINUTE, Integer.parseInt((String) manageLessonForm.get("minutosFim")));        fim.set(Calendar.SECOND, 0);        InfoRoom infoSala = new InfoRoom();        infoSala.setNome((String) manageLessonForm.get("nomeSala"));        ActionErrors actionErrors = checkTimeIntervalAndWeekDay(inicio, fim, weekDay);        if (actionErrors.isEmpty()) {            InfoRoom infoRoom = new InfoRoom();            infoRoom.setCapacidadeNormal(new Integer(0));            infoRoom.setCapacidadeExame(new Integer(0));            InfoLesson infoLessonToCreateOrEdited = new InfoLesson();            infoLessonToCreateOrEdited.setDiaSemana(weekDay);            infoLessonToCreateOrEdited.setInicio(inicio);            infoLessonToCreateOrEdited.setFim(fim);            InfoShift infoShift = (InfoShift) (request.getAttribute(SessionConstants.SHIFT));            infoLessonToCreateOrEdited.setInfoShift(infoShift);            infoLessonToCreateOrEdited.setTipo(infoShift.getTipo());            infoLessonToCreateOrEdited.setInfoSala(infoSala);            InfoRoomOccupation infoRoomOccupation = new InfoRoomOccupation();            infoRoomOccupation.setDayOfWeek(weekDay);            infoRoomOccupation.setEndTime(fim);            infoRoomOccupation.setStartTime(inicio);            infoRoomOccupation.setInfoRoom(infoSala);            if (quinzenal.booleanValue()) {                infoRoomOccupation.setFrequency(RoomOccupation.QUINZENAL);                if (manageLessonForm.get("week") == null || manageLessonForm.get("week").equals("")) {                    ActionError actionError = new ActionError("errors.emptyField.checkBoxTrue");                    ActionErrors newActionErrors = new ActionErrors();                    newActionErrors.add("errors.emptyField.checkBoxTrue", actionError);                    saveErrors(request, newActionErrors);                    return prepareEdit(mapping, form, request, response);                }                infoRoomOccupation.setWeekOfQuinzenalStart(new Integer(Integer                        .parseInt((String) manageLessonForm.get("week"))));            } else {                infoRoomOccupation.setFrequency(RoomOccupation.SEMANAL);            }            InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) request                    .getAttribute(SessionConstants.EXECUTION_PERIOD);            InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) request                    .getAttribute(SessionConstants.EXECUTION_DEGREE);            InfoPeriod infoPeriod = null;            if (infoExecutionPeriod.getSemester().equals(new Integer(1))) {                infoPeriod = infoExecutionDegree.getInfoPeriodLessonsFirstSemester();            } else {                infoPeriod = infoExecutionDegree.getInfoPeriodLessonsSecondSemester();            }            infoRoomOccupation.setInfoPeriod(infoPeriod);            infoLessonToCreateOrEdited.setInfoRoomOccupation(infoRoomOccupation);            String action = request.getParameter("action");            if (action != null && action.equals("edit")) {                InfoLesson infoLessonOld = (InfoLesson) request.getAttribute(SessionConstants.LESSON);                Object argsEditLesson[] = { infoLessonOld, infoLessonToCreateOrEdited, infoShift };                try {                    ServiceUtils.executeService(SessionUtils.getUserView(request), "EditLesson",                            argsEditLesson);                } catch (EditLesson.InvalidLoadException ex) {                    if (ex.getMessage().endsWith("REACHED")) {                        actionErrors.add("errors.shift.hours.limit.reached", new ActionError(                                "errors.shift.hours.limit.reached"));                    } else {                        actionErrors.add("errors.shift.hours.limit.exceeded", new ActionError(                                "errors.shift.hours.limit.exceeded"));                    }                    saveErrors(request, actionErrors);                    return mapping.getInputForward();                } catch (ExistingServiceException ex) {                    throw new ExistingActionException("A aula", ex);                } catch (InterceptingServiceException ex) {                    throw new InterceptingActionException(infoSala.getNome(), ex);                } catch (InvalidTimeIntervalServiceException ex) {                    throw new InvalidTimeIntervalActionException(ex);                }            } else {                Object argsCreateLesson[] = { infoLessonToCreateOrEdited, infoShift };                try {                    ServiceUtils.executeService(SessionUtils.getUserView(request), "CreateLesson",                            argsCreateLesson);                } catch (CreateLesson.InvalidLoadException ex) {                    if (ex.getMessage().endsWith("REACHED")) {                        actionErrors.add("errors.shift.hours.limit.reached", new ActionError(                                "errors.shift.hours.limit.reached"));                    } else {                        actionErrors.add("errors.shift.hours.limit.exceeded", new ActionError(                                "errors.shift.hours.limit.exceeded"));                    }                    saveErrors(request, actionErrors);                    return mapping.getInputForward();                }            }            return mapping.findForward("EditShift");        }        saveErrors(request, actionErrors);        return mapping.getInputForward();    }