/* * Created on 8/Ago/2003 */ package net.sourceforge.fenixedu.presentationTier.Action.manager; import net.sourceforge.fenixedu.applicationTier.Servico.manager.InsertCurricularCourseAtDegreeCurricularPlan; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sourceforge.fenixedu.applicationTier.IUserView; import net.sourceforge.fenixedu.applicationTier.Filtro.exception.FenixFilterException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.ExistingServiceException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.FenixServiceException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.NonExistingServiceException; import net.sourceforge.fenixedu.dataTransferObject.InfoCurricularCourseEditor; import net.sourceforge.fenixedu.dataTransferObject.InfoDegreeCurricularPlan; import net.sourceforge.fenixedu.domain.DegreeCurricularPlan; import net.sourceforge.fenixedu.domain.GradeScale; import net.sourceforge.fenixedu.domain.curriculum.CurricularCourseType; import net.sourceforge.fenixedu.presentationTier.Action.base.FenixDispatchAction; import net.sourceforge.fenixedu.presentationTier.Action.exceptions.ExistingActionException; import net.sourceforge.fenixedu.presentationTier.Action.exceptions.FenixActionException; import net.sourceforge.fenixedu.presentationTier.Action.exceptions.NonExistingActionException; import net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.utils.ServiceUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.apache.struts.validator.DynaValidatorForm; import pt.ist.fenixWebFramework.security.UserView; /** * @author lmac1 */ public class InsertCurricularCourseDispatchAction extends FenixDispatchAction { public ActionForward prepareInsert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { return mapping.findForward("insertCurricularCourse"); } public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException, FenixServiceException, FenixFilterException { IUserView userView = UserView.getUser(); Integer degreeCurricularPlanId = Integer.valueOf(request.getParameter("degreeCurricularPlanId")); final DegreeCurricularPlan degreeCurricularPlan = rootDomainObject.readDegreeCurricularPlanByOID(degreeCurricularPlanId); DynaActionForm dynaForm = (DynaValidatorForm) form; String type = (String) dynaForm.get("type"); String mandatory = (String) dynaForm.get("mandatory"); String basic = (String) dynaForm.get("basic"); InfoDegreeCurricularPlan infoDegreeCurricularPlan = new InfoDegreeCurricularPlan(degreeCurricularPlan); InfoCurricularCourseEditor infoCurricularCourse = new InfoCurricularCourseEditor(); infoCurricularCourse.setBasic(Boolean.valueOf(basic)); infoCurricularCourse.setCode((String) dynaForm.get("code")); infoCurricularCourse.setInfoDegreeCurricularPlan(infoDegreeCurricularPlan); infoCurricularCourse.setMandatory(Boolean.valueOf(mandatory)); infoCurricularCourse.setName((String) dynaForm.get("name")); infoCurricularCourse.setNameEn((String) dynaForm.get("nameEn")); infoCurricularCourse.setType(CurricularCourseType.valueOf(type)); String credits = (String) dynaForm.get("credits"); if (credits.compareTo("") != 0) { infoCurricularCourse.setCredits(Double.valueOf(credits)); } String ectsCredits = (String) dynaForm.get("ectsCredits"); if (ectsCredits != null && ectsCredits.length() > 0) { infoCurricularCourse.setEctsCredits(Double.valueOf(ectsCredits)); } String labHours = (String) dynaForm.get("labHours"); if (labHours.compareTo("") != 0) { infoCurricularCourse.setLabHours(Double.valueOf(labHours)); } infoCurricularCourse.setMaximumValueForAcumulatedEnrollments(Integer.valueOf((String) dynaForm.get("maxIncrementNac"))); infoCurricularCourse.setMinimumValueForAcumulatedEnrollments(Integer.valueOf((String) dynaForm.get("minIncrementNac"))); String praticalHours = (String) dynaForm.get("praticalHours"); if (praticalHours.compareTo("") != 0) { infoCurricularCourse.setPraticalHours(Double.valueOf(praticalHours)); } String theoPratHours = (String) dynaForm.get("theoPratHours"); if (theoPratHours.compareTo("") != 0) { infoCurricularCourse.setTheoPratHours(Double.valueOf(theoPratHours)); } String theoreticalHours = (String) dynaForm.get("theoreticalHours"); if (theoreticalHours.compareTo("") != 0) { infoCurricularCourse.setTheoreticalHours(Double.valueOf(theoreticalHours)); } infoCurricularCourse.setWeigth(Double.valueOf((String) dynaForm.get("weight"))); infoCurricularCourse.setMandatoryEnrollment(Boolean.valueOf((String) dynaForm.get("mandatoryEnrollment"))); infoCurricularCourse.setEnrollmentAllowed(Boolean.valueOf((String) dynaForm.get("enrollmentAllowed"))); infoCurricularCourse.setEnrollmentWeigth(Integer.valueOf((String) dynaForm.get("enrollmentWeigth"))); infoCurricularCourse.setAcronym((String) dynaForm.get("acronym")); String gradeTypeString = (String) dynaForm.get("gradeType"); GradeScale gradeScale = null; if (gradeTypeString != null && gradeTypeString.length() > 0) { gradeScale = GradeScale.valueOf(gradeTypeString); } infoCurricularCourse.setGradeScale(gradeScale); try { InsertCurricularCourseAtDegreeCurricularPlan.run(infoCurricularCourse); } catch (ExistingServiceException ex) { throw new ExistingActionException(ex.getMessage(), ex); } catch (NonExistingServiceException exception) { throw new NonExistingActionException("message.nonExistingDegreeCurricularPlan", mapping.findForward("readDegree")); } return mapping.findForward("readDegreeCurricularPlan"); } }