Search in sources :

Example 1 with Grade

use of fi.otavanopisto.pyramus.domainmodel.grading.Grade in project pyramus by otavanopisto.

the class EditStudentProjectJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Defaults defaults = defaultsDAO.getDefaults();
    // Project
    Long studentProjectId = jsonRequestContext.getLong("studentProject");
    StudentProject studentProject = studentProjectDAO.findById(studentProjectId);
    // Version check
    Long version = jsonRequestContext.getLong("version");
    if (!studentProject.getVersion().equals(version))
        throw new StaleObjectStateException(StudentProject.class.getName(), studentProject.getId());
    String name = jsonRequestContext.getString("name");
    String description = jsonRequestContext.getString("description");
    StaffMember staffMember = staffMemberDAO.findById(jsonRequestContext.getLoggedUserId());
    Long optionalStudiesLengthTimeUnitId = jsonRequestContext.getLong("optionalStudiesLengthTimeUnit");
    EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
    Double optionalStudiesLength = jsonRequestContext.getDouble("optionalStudiesLength");
    String tagsText = jsonRequestContext.getString("tags");
    Long studentId = jsonRequestContext.getLong("student");
    CourseOptionality projectOptionality = (CourseOptionality) jsonRequestContext.getEnum("projectOptionality", CourseOptionality.class);
    Set<Tag> tagEntities = new HashSet<>();
    if (!StringUtils.isBlank(tagsText)) {
        List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
        for (String tag : tags) {
            if (!StringUtils.isBlank(tag)) {
                Tag tagEntity = tagDAO.findByText(tag.trim());
                if (tagEntity == null)
                    tagEntity = tagDAO.create(tag);
                tagEntities.add(tagEntity);
            }
        }
    }
    Student student = studentDAO.findById(studentId);
    if (!studentProject.getStudent().equals(student)) {
        studentProjectDAO.updateStudent(studentProject, student, staffMember);
    }
    studentProjectDAO.update(studentProject, name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, projectOptionality, staffMember);
    // Tags
    studentProjectDAO.updateTags(studentProject, tagEntities);
    // ProjectAssessments
    int rowCount = jsonRequestContext.getInteger("assessmentsTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "assessmentsTable." + i;
        Long assessmentModified = jsonRequestContext.getLong(colPrefix + ".modified");
        if ((assessmentModified != null) && (assessmentModified.intValue() == 1)) {
            Long assessmentId = jsonRequestContext.getLong(colPrefix + ".assessmentId");
            ProjectAssessment projectAssessment = ((assessmentId != null) && (assessmentId.intValue() != -1)) ? projectAssessmentDAO.findById(assessmentId) : null;
            Long assessmentArchived = jsonRequestContext.getLong(colPrefix + ".deleted");
            if ((assessmentArchived != null) && (assessmentArchived.intValue() == 1)) {
                if (projectAssessment != null)
                    projectAssessmentDAO.archive(projectAssessment);
                else
                    throw new SmvcRuntimeException(PyramusStatusCode.OK, "Assessment marked for delete does not exist.");
            } else {
                Date assessmentDate = jsonRequestContext.getDate(colPrefix + ".date");
                Long assessmentGradeId = jsonRequestContext.getLong(colPrefix + ".grade");
                Grade grade = assessmentGradeId != null ? gradeDAO.findById(assessmentGradeId) : null;
                String verbalAssessment = projectAssessment != null ? projectAssessment.getVerbalAssessment() : null;
                Long verbalAssessmentModified = jsonRequestContext.getLong(colPrefix + ".verbalModified");
                if ((verbalAssessmentModified != null) && (verbalAssessmentModified.intValue() == 1))
                    verbalAssessment = jsonRequestContext.getString(colPrefix + ".verbalAssessment");
                if (projectAssessment == null) {
                    projectAssessmentDAO.create(studentProject, staffMember, grade, assessmentDate, verbalAssessment);
                } else {
                    projectAssessmentDAO.update(projectAssessment, staffMember, grade, assessmentDate, verbalAssessment);
                }
            }
        }
    }
    // Student project modules
    Set<Long> existingModuleIds = new HashSet<>();
    rowCount = jsonRequestContext.getInteger("modulesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "modulesTable." + i;
        Long studentProjectModuleId = jsonRequestContext.getLong(colPrefix + ".studentProjectModuleId");
        CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
        Long studyTermId = jsonRequestContext.getLong(colPrefix + ".academicTerm");
        AcademicTerm academicTerm = studyTermId == null ? null : academicTermDAO.findById(studyTermId);
        if (studentProjectModuleId == -1) {
            Long moduleId = jsonRequestContext.getLong(colPrefix + ".moduleId");
            Module module = moduleDAO.findById(moduleId);
            studentProjectModuleId = studentProjectModuleDAO.create(studentProject, module, academicTerm, optionality).getId();
        } else {
            studentProjectModuleDAO.update(studentProjectModuleDAO.findById(studentProjectModuleId), academicTerm, optionality);
        }
        existingModuleIds.add(studentProjectModuleId);
    }
    // Removed Student project modules
    List<StudentProjectModule> studentProjectModules = studentProjectModuleDAO.listByStudentProject(studentProject);
    for (StudentProjectModule studentProjectModule : studentProjectModules) {
        if (!existingModuleIds.contains(studentProjectModule.getId())) {
            studentProjectModuleDAO.delete(studentProjectModule);
        }
    }
    // Student project courses
    rowCount = jsonRequestContext.getInteger("coursesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "coursesTable." + i;
        Long courseId = jsonRequestContext.getLong(colPrefix + ".courseId");
        CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
        Course course = courseId == -1 ? null : courseDAO.findById(courseId);
        CourseStudent courseStudent = courseStudentDAO.findByCourseAndStudent(course, studentProject.getStudent());
        if (courseStudent == null) {
            CourseEnrolmentType courseEnrolmentType = defaults.getInitialCourseEnrolmentType();
            CourseParticipationType participationType = defaults.getInitialCourseParticipationType();
            Date enrolmentDate = new Date(System.currentTimeMillis());
            Boolean lodging = Boolean.FALSE;
            String organization = null;
            String additionalInfo = null;
            Room room = null;
            BigDecimal lodgingFee = null;
            Currency lodgingFeeCurrency = null;
            BigDecimal reservationFee = null;
            Currency reservationFeeCurrency = null;
            try {
                courseStudent = courseStudentDAO.create(course, studentProject.getStudent(), courseEnrolmentType, participationType, enrolmentDate, lodging, optionality, null, organization, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE);
            } catch (DuplicateCourseStudentException dcse) {
                Locale locale = jsonRequestContext.getRequest().getLocale();
                throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.duplicateCourseStudent", new Object[] { student.getFullName() }));
            }
        } else {
            courseStudentDAO.updateOptionality(courseStudent, optionality);
        }
    }
    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Also used : Locale(java.util.Locale) DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) AcademicTermDAO(fi.otavanopisto.pyramus.dao.base.AcademicTermDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Currency(java.util.Currency) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) HashSet(java.util.HashSet) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) AcademicTerm(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) StaleObjectStateException(org.hibernate.StaleObjectStateException) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)

Example 2 with Grade

use of fi.otavanopisto.pyramus.domainmodel.grading.Grade in project pyramus by otavanopisto.

the class GradingService method updateGrade.

public void updateGrade(@WebParam(name = "gradeId") Long gradeId, @WebParam(name = "name") String name, @WebParam(name = "description") String description, @WebParam(name = "passingGrade") Boolean passingGrade, @WebParam(name = "GPA") Double GPA, @WebParam(name = "qualification") String qualification) {
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    Grade grade = gradeDAO.findById(gradeId);
    gradeDAO.update(grade, name, description, passingGrade, GPA, qualification);
    validateEntity(grade);
}
Also used : Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO)

Example 3 with Grade

use of fi.otavanopisto.pyramus.domainmodel.grading.Grade in project pyramus by otavanopisto.

the class GradingService method createGrade.

public GradeEntity createGrade(@WebParam(name = "gradingScaleId") Long gradingScaleId, @WebParam(name = "name") String name, @WebParam(name = "description") String description, @WebParam(name = "passingGrade") Boolean passingGrade, @WebParam(name = "GPA") Double GPA, @WebParam(name = "qualification") String qualification) {
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    Grade grade = gradeDAO.create(gradingScaleDAO.findById(gradingScaleId), name, description, passingGrade, GPA, qualification);
    validateEntity(grade);
    return EntityFactoryVault.buildFromDomainObject(grade);
}
Also used : GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO)

Example 4 with Grade

use of fi.otavanopisto.pyramus.domainmodel.grading.Grade in project pyramus by otavanopisto.

the class EditGradingScaleJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    Long gradingScaleId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("gradingScaleId"));
    String name = jsonRequestContext.getRequest().getParameter("name");
    String description = jsonRequestContext.getRequest().getParameter("description");
    GradingScale gradingScale = gradingScaleDAO.findById(gradingScaleId);
    gradingScaleDAO.update(gradingScale, name, description);
    Set<Long> existingGrades = new HashSet<>();
    int rowCount = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("gradesTable.rowCount")).intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "gradesTable." + i;
        String gradeIdParam = jsonRequestContext.getRequest().getParameter(colPrefix + ".gradeId");
        Long gradeId = StringUtils.isBlank(gradeIdParam) ? null : NumberUtils.createLong(gradeIdParam);
        String gradeName = jsonRequestContext.getRequest().getParameter(colPrefix + ".name");
        String gradeQualification = jsonRequestContext.getRequest().getParameter(colPrefix + ".qualification");
        String gradeGPAParam = jsonRequestContext.getRequest().getParameter(colPrefix + ".GPA");
        String gradeDescription = jsonRequestContext.getRequest().getParameter(colPrefix + ".description");
        Boolean passingGrade = "1".equals(jsonRequestContext.getRequest().getParameter(colPrefix + ".passingGrade"));
        Double gradeGPA = StringUtils.isBlank(gradeGPAParam) ? null : NumberUtils.createDouble(gradeGPAParam);
        if (gradeId != null) {
            Grade grade = gradeDAO.findById(gradeId);
            gradeDAO.update(grade, gradeName, gradeDescription, passingGrade, gradeGPA, gradeQualification);
            existingGrades.add(grade.getId());
        } else {
            Grade grade = gradeDAO.create(gradingScale, gradeName, gradeDescription, passingGrade, gradeGPA, gradeQualification);
            existingGrades.add(grade.getId());
        }
    }
    List<Grade> grades = gradingScale.getGrades();
    for (int i = grades.size() - 1; i >= 0; i--) {
        Grade grade = grades.get(i);
        if (!existingGrades.contains(grade.getId()))
            gradingScale.removeGrade(grade);
    }
    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO) HashSet(java.util.HashSet)

Example 5 with Grade

use of fi.otavanopisto.pyramus.domainmodel.grading.Grade in project pyramus by otavanopisto.

the class CommonRESTService method deleteGrade.

@Path("/gradingScales/{SCALEID:[0-9]*}/grades/{ID:[0-9]*}")
@DELETE
@RESTPermit(CommonPermissions.DELETE_GRADE)
public Response deleteGrade(@PathParam("SCALEID") Long gradingScaleId, @PathParam("ID") Long id, @DefaultValue("false") @QueryParam("permanent") Boolean permanent) {
    GradingScale gradingScale = commonController.findGradingScaleById(gradingScaleId);
    if (gradingScale == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (gradingScale.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Grade grade = commonController.findGradeByIdId(id);
    if (grade == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (permanent) {
        commonController.deleteGrade(grade);
    } else {
        commonController.archiveGrade(grade, sessionController.getUser());
    }
    return Response.noContent().build();
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit)

Aggregations

Grade (fi.otavanopisto.pyramus.domainmodel.grading.Grade)25 GradeDAO (fi.otavanopisto.pyramus.dao.grading.GradeDAO)12 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)11 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)11 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)10 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)9 Date (java.util.Date)9 GradingScale (fi.otavanopisto.pyramus.domainmodel.grading.GradingScale)8 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)8 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)7 Path (javax.ws.rs.Path)7 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)6 CourseAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO)6 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)6 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)5 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)5 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)5 TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)5 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)4 TransferCreditDAO (fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO)4