Search in sources :

Example 1 with ProjectAssessmentDAO

use of fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO 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 ProjectAssessmentDAO

use of fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO in project pyramus by otavanopisto.

the class EditEnrollmentViewController method createOrUpdateStudentProject.

private void createOrUpdateStudentProject(MatriculationExamAttendance examAttendance, Student student, MatriculationExamSubject subject, boolean mandatory, StaffMember loggedUser) {
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
    MatriculationExamAttendanceDAO matriculationExamAttendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    MatriculationExamSubjectSettings subjectSettings = matriculationExamSubjectSettingsDAO.findBy(examAttendance.getEnrollment().getExam(), subject);
    if (subjectSettings == null || subjectSettings.getProject() == null) {
        // We cannot really do anything if the settings aren't in place
        return;
    }
    CourseOptionality projectOptionality = mandatory ? CourseOptionality.MANDATORY : CourseOptionality.OPTIONAL;
    Project project = subjectSettings.getProject();
    StudentProject studentProject;
    if (examAttendance != null && examAttendance.getProjectAssessment() != null && BooleanUtils.isFalse(examAttendance.getProjectAssessment().getArchived()) && examAttendance.getProjectAssessment().getStudentProject() != null && BooleanUtils.isFalse(examAttendance.getProjectAssessment().getStudentProject().getArchived())) {
        // Use the studentproject from the projectassessment if it exists
        studentProject = examAttendance.getProjectAssessment().getStudentProject();
    } else {
        // Resolve studentProject from the project in the settings
        List<StudentProject> studentProjects = studentProjectDAO.listBy(student, project, TSB.IGNORE);
        // Find first non-archived project
        studentProject = studentProjects.stream().filter(studentProject1 -> BooleanUtils.isFalse(studentProject1.getArchived())).findFirst().orElse(null);
        if (studentProject == null) {
            // No unarchived student project was found so try to use any other
            studentProject = studentProjects.isEmpty() ? null : studentProjects.get(0);
            if (studentProject != null && BooleanUtils.isTrue(studentProject.getArchived())) {
                studentProjectDAO.unarchive(studentProject);
            }
        }
    }
    if (studentProject == null) {
        // No matching student project was found so create a new one
        studentProject = studentProjectDAO.create(student, project.getName(), project.getDescription(), project.getOptionalStudiesLength().getUnits(), project.getOptionalStudiesLength().getUnit(), projectOptionality, loggedUser, project);
        Set<Tag> tags = new HashSet<>();
        for (Tag tag : project.getTags()) {
            tags.add(tag);
        }
        studentProjectDAO.updateTags(studentProject, tags);
        List<ProjectModule> projectModules = project.getProjectModules();
        for (ProjectModule projectModule : projectModules) {
            studentProjectModuleDAO.create(studentProject, projectModule.getModule(), null, CourseOptionality.getOptionality(projectModule.getOptionality().getValue()));
        }
    } else {
        studentProject = studentProjectDAO.updateOptionality(studentProject, projectOptionality);
    }
    MatriculationExam matriculationExam = examAttendance.getEnrollment().getExam();
    if (matriculationExam != null && matriculationExam.getSignupGrade() != null && subjectSettings.getExamDate() != null && examAttendance.getProjectAssessment() == null) {
        // Add the exam date
        ProjectAssessment projectAssessment = projectAssessmentDAO.create(studentProject, loggedUser, matriculationExam.getSignupGrade(), subjectSettings.getExamDate(), "");
        // Link the project assessment to this exam atten dance
        matriculationExamAttendanceDAO.updateProjectAssessment(examAttendance, projectAssessment);
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Arrays(java.util.Arrays) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) MatriculationExamAttendanceFunding(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceFunding) SchoolType(fi.otavanopisto.pyramus.domainmodel.matriculation.SchoolType) DegreeType(fi.otavanopisto.pyramus.domainmodel.matriculation.DegreeType) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) StringUtils(org.apache.commons.lang3.StringUtils) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamGrade(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamGrade) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BooleanUtils(org.apache.commons.lang.BooleanUtils) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) MatriculationExamAttendanceStatus(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceStatus) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) MatriculationExamEnrollmentState(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentState) Severity(fi.internetix.smvc.Severity) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) UserRole(fi.otavanopisto.pyramus.framework.UserRole) MatriculationExamEnrollmentDegreeStructure(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentDegreeStructure) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TSB(fi.otavanopisto.pyramus.domainmodel.TSB) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) MatriculationExamTerm(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm) PageRequestContext(fi.internetix.smvc.controllers.PageRequestContext) PyramusViewController(fi.otavanopisto.pyramus.framework.PyramusViewController) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance) List(java.util.List) DAOFactory(fi.otavanopisto.pyramus.dao.DAOFactory) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) HashSet(java.util.HashSet)

Example 3 with ProjectAssessmentDAO

use of fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO in project pyramus by otavanopisto.

the class ArchiveMatriculationAttendanceJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    MatriculationExamAttendanceDAO examAttendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    Long examAttendanceId = requestContext.getLong("examAttendanceId");
    MatriculationExamAttendance examAttendance = examAttendanceDAO.findById(examAttendanceId);
    if (examAttendance.getProjectAssessment() != null) {
        projectAssessmentDAO.archive(examAttendance.getProjectAssessment());
    }
    examAttendanceDAO.delete(examAttendance);
}
Also used : MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance)

Example 4 with ProjectAssessmentDAO

use of fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO in project pyramus by otavanopisto.

the class ListStudentProjectsJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    Long projectId = requestContext.getLong("project");
    Project project = projectDAO.findById(projectId);
    Integer page = requestContext.getInteger("page");
    page = page != null ? page : 0;
    Integer maxResults = requestContext.getInteger("maxResults");
    maxResults = maxResults != null ? maxResults : 25;
    int firstResult = page * maxResults;
    long numStudentProjectsTotal = studentProjectDAO.countByProject(project);
    int numPages = (int) Math.ceil((double) numStudentProjectsTotal / maxResults);
    List<StudentProject> studentProjectsByProjectPage = studentProjectDAO.listByProject(project, firstResult, maxResults);
    int resultsCount = studentProjectsByProjectPage.size();
    JSONArray studentProjectsJSON = new JSONArray();
    for (StudentProject sp : studentProjectsByProjectPage) {
        StudentProjectBean bean = beanify(sp, courseDAO, courseStudentDAO, transferCreditDAO, courseAssessmentDAO, projectAssessmentDAO);
        JSONObject spJSON = new JSONObject();
        JSONArray spDates = new JSONArray();
        StringBuilder gradeText = new StringBuilder();
        for (ProjectAssessment assessment : bean.getAssessments()) {
            spDates.add(assessment.getDate().getTime());
            if (gradeText.length() > 0)
                gradeText.append(", ");
            if (assessment.getGrade() != null)
                gradeText.append(assessment.getGrade().getName());
            else
                gradeText.append("-");
        }
        spJSON.put("personId", bean.getStudentProject().getStudent().getPerson().getId());
        spJSON.put("studentProjectId", bean.getStudentProject().getId());
        spJSON.put("studentName", bean.getStudentProject().getStudent().getLastName() + ", " + bean.getStudentProject().getStudent().getFirstName());
        spJSON.put("studyProgrammeName", bean.getStudentProject().getStudent().getStudyProgramme().getName());
        spJSON.put("optionality", bean.getStudentProject().getOptionality());
        spJSON.put("dates", spDates);
        spJSON.put("grade", gradeText.toString());
        spJSON.put("passedMandatory", bean.getPassedMandatoryModuleCount() + "/" + bean.getMandatoryModuleCount());
        spJSON.put("passedOptional", bean.getPassedOptionalModuleCount() + "/" + bean.getOptionalModuleCount());
        studentProjectsJSON.add(spJSON);
    }
    String statusMessage;
    Locale locale = requestContext.getRequest().getLocale();
    if (studentProjectsByProjectPage.size() > 0) {
        statusMessage = Messages.getInstance().getText(locale, "projects.viewProject.studentProjects.searchStatus", new Object[] { firstResult + 1, firstResult + resultsCount, numStudentProjectsTotal });
    } else {
        statusMessage = Messages.getInstance().getText(locale, "projects.viewProject.studentProjects.searchStatusNoMatches");
    }
    requestContext.addResponseParameter("studentProjects", studentProjectsJSON);
    requestContext.addResponseParameter("page", page);
    requestContext.addResponseParameter("pages", numPages);
    requestContext.addResponseParameter("statusMessage", statusMessage);
}
Also used : Locale(java.util.Locale) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) JSONArray(net.sf.json.JSONArray) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) JSONObject(net.sf.json.JSONObject) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) JSONObject(net.sf.json.JSONObject) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 5 with ProjectAssessmentDAO

use of fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO in project pyramus by otavanopisto.

the class EditStudentProjectViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    Long studentProjectId = pageRequestContext.getLong("studentproject");
    List<GradingScale> gradingScales = gradingScaleDAO.listUnarchived();
    StudentProject studentProject = studentProjectDAO.findById(studentProjectId);
    List<StudentProjectModule> studentProjectModules = studentProjectModuleDAO.listByStudentProject(studentProject);
    List<CourseStudent> courseStudents = courseStudentDAO.listByStudent(studentProject.getStudent());
    List<CourseAssessment> allStudentCourseAssessments = courseAssessmentDAO.listByStudent(studentProject.getStudent());
    List<TransferCredit> allStudentTransferCredits = transferCreditDAO.listByStudent(studentProject.getStudent());
    List<CreditLink> allStudentCreditLinks = creditLinkDAO.listByStudent(studentProject.getStudent());
    JSONArray studentProjectModulesJSON = new JSONArray();
    JSONArray courseStudentsJSON = new JSONArray();
    for (CreditLink creditLink : allStudentCreditLinks) {
        switch(creditLink.getCredit().getCreditType()) {
            case CourseAssessment:
                allStudentCourseAssessments.add((CourseAssessment) creditLink.getCredit());
                break;
            case TransferCredit:
                allStudentTransferCredits.add((TransferCredit) creditLink.getCredit());
                break;
        }
    }
    Collections.sort(studentProjectModules, new Comparator<StudentProjectModule>() {

        @Override
        public int compare(StudentProjectModule o1, StudentProjectModule o2) {
            return o1.getModule().getName().compareTo(o2.getModule().getName());
        }
    });
    for (StudentProjectModule studentProjectModule : studentProjectModules) {
        JSONArray moduleCourseStudents = new JSONArray();
        JSONArray moduleCredits = new JSONArray();
        boolean hasPassingGrade = false;
        List<CourseStudent> projectCourseCourseStudents = courseStudentDAO.listByModuleAndStudent(studentProjectModule.getModule(), studentProject.getStudent());
        for (CourseStudent courseStudent : projectCourseCourseStudents) {
            JSONObject courseStudentJson = new JSONObject();
            courseStudentJson.put("courseStudentParticipationType", courseStudent.getParticipationType().getName());
            // courseStudents.remove(courseStudent);
            moduleCourseStudents.add(courseStudentJson);
        }
        for (CourseAssessment assessment : allStudentCourseAssessments) {
            if (assessment.getCourseStudent().getCourse().getModule().getId().equals(studentProjectModule.getModule().getId())) {
                if (assessment.getGrade() != null) {
                    JSONObject courseAssessment = new JSONObject();
                    courseAssessment.put("creditType", assessment.getCreditType().toString());
                    courseAssessment.put("courseName", assessment.getCourseStudent().getCourse().getName());
                    courseAssessment.put("gradeName", assessment.getGrade().getName());
                    moduleCredits.add(courseAssessment);
                    hasPassingGrade = hasPassingGrade || assessment.getGrade().getPassingGrade();
                }
            }
        }
        if ((studentProjectModule.getModule().getCourseNumber() != null) && (studentProjectModule.getModule().getCourseNumber() != -1) && (studentProjectModule.getModule().getSubject() != null)) {
            for (TransferCredit tc : allStudentTransferCredits) {
                if ((tc.getCourseNumber() != null) && (tc.getCourseNumber() != -1) && (tc.getSubject() != null)) {
                    if (tc.getCourseNumber().equals(studentProjectModule.getModule().getCourseNumber()) && tc.getSubject().equals(studentProjectModule.getModule().getSubject())) {
                        if (tc.getGrade() != null) {
                            JSONObject transferCredit = new JSONObject();
                            transferCredit.put("creditType", tc.getCreditType().toString());
                            transferCredit.put("courseName", tc.getCourseName());
                            transferCredit.put("gradeName", tc.getGrade().getName());
                            moduleCredits.add(transferCredit);
                            hasPassingGrade = hasPassingGrade || tc.getGrade().getPassingGrade();
                        }
                    }
                }
            }
        }
        JSONObject obj = new JSONObject();
        obj.put("projectModuleId", studentProjectModule.getId().toString());
        obj.put("projectModuleOptionality", studentProjectModule.getOptionality().toString());
        obj.put("projectModuleAcademicTermId", studentProjectModule.getAcademicTerm() != null ? studentProjectModule.getAcademicTerm().getId().toString() : "");
        obj.put("projectModuleHasPassingGrade", hasPassingGrade ? "1" : "0");
        obj.put("moduleId", studentProjectModule.getModule().getId());
        obj.put("moduleName", studentProjectModule.getModule().getName());
        obj.put("moduleCourseStudents", moduleCourseStudents);
        obj.put("moduleCredits", moduleCredits);
        studentProjectModulesJSON.add(obj);
    }
    List<Student> students = studentDAO.listByPerson(studentProject.getStudent().getPerson());
    Collections.sort(students, new Comparator<Student>() {

        @Override
        public int compare(Student o1, Student o2) {
            /**
             * Ordering study programmes as follows
             *  1. studies that have start date but no end date (ongoing)
             *  2. studies that have no start nor end date
             *  3. studies that have ended
             *  4. studies that are archived
             *  5. other
             */
            int o1class = (o1.getArchived()) ? 4 : (o1.getStudyStartDate() != null && o1.getStudyEndDate() == null) ? 1 : (o1.getStudyStartDate() == null && o1.getStudyEndDate() == null) ? 2 : (o1.getStudyEndDate() != null) ? 3 : 5;
            int o2class = (o2.getArchived()) ? 4 : (o2.getStudyStartDate() != null && o2.getStudyEndDate() == null) ? 1 : (o2.getStudyStartDate() == null && o2.getStudyEndDate() == null) ? 2 : (o2.getStudyEndDate() != null) ? 3 : 5;
            if (o1class == o2class) {
                // classes are the same, we try to do last comparison from the start dates
                return ((o1.getStudyStartDate() != null) && (o2.getStudyStartDate() != null)) ? o2.getStudyStartDate().compareTo(o1.getStudyStartDate()) : 0;
            } else
                return o1class < o2class ? -1 : o1class == o2class ? 0 : 1;
        }
    });
    List<EducationalTimeUnit> educationalTimeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(educationalTimeUnits, new StringAttributeComparator("getName"));
    List<AcademicTerm> academicTerms = academicTermDAO.listUnarchived();
    Collections.sort(academicTerms, new Comparator<AcademicTerm>() {

        public int compare(AcademicTerm o1, AcademicTerm o2) {
            return o1.getStartDate() == null ? -1 : o2.getStartDate() == null ? 1 : o1.getStartDate().compareTo(o2.getStartDate());
        }
    });
    List<ProjectAssessment> assessments = projectAssessmentDAO.listByProjectAndArchived(studentProject, Boolean.FALSE);
    Collections.sort(assessments, new Comparator<ProjectAssessment>() {

        @Override
        public int compare(ProjectAssessment o1, ProjectAssessment o2) {
            return o2.getDate().compareTo(o1.getDate());
        }
    });
    Collections.sort(courseStudents, new Comparator<CourseStudent>() {

        @Override
        public int compare(CourseStudent o1, CourseStudent o2) {
            return o1.getCourse().getName().compareTo(o2.getCourse().getName());
        }
    });
    for (CourseStudent courseStudent : courseStudents) {
        CourseAssessment courseAssessment = courseAssessmentDAO.findLatestByCourseStudentAndArchived(courseStudent, Boolean.FALSE);
        Grade grade = courseAssessment != null ? courseAssessment.getGrade() : null;
        JSONObject obj = new JSONObject();
        String courseName = courseStudent.getCourse().getName();
        if (!StringUtils.isEmpty(courseStudent.getCourse().getNameExtension()))
            courseName = courseName + " (" + courseStudent.getCourse().getNameExtension() + ")";
        obj.put("courseName", courseName);
        if (courseStudent.getParticipationType() != null) {
            obj.put("participationType", courseStudent.getParticipationType().getName());
        }
        if (courseStudent.getCourse().getBeginDate() != null) {
            obj.put("courseBeginDate", courseStudent.getCourse().getBeginDate().getTime());
        }
        if (courseStudent.getCourse().getEndDate() != null) {
            obj.put("courseEndDate", courseStudent.getCourse().getEndDate().getTime());
        }
        obj.put("gradeName", grade != null ? grade.getName() : "");
        if (courseStudent.getOptionality() != null) {
            obj.put("optionality", courseStudent.getOptionality().toString());
        }
        obj.put("moduleId", courseStudent.getCourse().getModule().getId().toString());
        obj.put("courseId", courseStudent.getCourse().getId().toString());
        obj.put("courseStudentId", courseStudent.getId().toString());
        courseStudentsJSON.add(obj);
    }
    Map<Long, String> verbalAssessments = new HashMap<>();
    for (ProjectAssessment pAss : assessments) {
        // Shortened descriptions
        String description = pAss.getVerbalAssessment();
        if (description != null) {
            description = StringEscapeUtils.unescapeHtml(description.replaceAll("\\<.*?>", ""));
            description = description.replaceAll("\\n", "");
            verbalAssessments.put(pAss.getId(), description);
        }
    }
    /* Tags */
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = studentProject.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    pageRequestContext.getRequest().setAttribute("projectAssessments", assessments);
    pageRequestContext.getRequest().setAttribute("verbalAssessments", verbalAssessments);
    pageRequestContext.getRequest().setAttribute("studentProject", studentProject);
    pageRequestContext.getRequest().setAttribute("students", students);
    pageRequestContext.getRequest().setAttribute("optionalStudiesLengthTimeUnits", educationalTimeUnits);
    pageRequestContext.getRequest().setAttribute("academicTerms", academicTerms);
    pageRequestContext.getRequest().setAttribute("users", userDAO.listAll());
    pageRequestContext.getRequest().setAttribute("gradingScales", gradingScales);
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    setJsDataVariable(pageRequestContext, "studentProjectModules", studentProjectModulesJSON.toString());
    setJsDataVariable(pageRequestContext, "courseStudents", courseStudentsJSON.toString());
    pageRequestContext.setIncludeJSP("/templates/projects/editstudentproject.jsp");
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) HashMap(java.util.HashMap) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) JSONObject(net.sf.json.JSONObject) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) AcademicTermDAO(fi.otavanopisto.pyramus.dao.base.AcademicTermDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) JSONArray(net.sf.json.JSONArray) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) AcademicTerm(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)

Aggregations

ProjectAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO)6 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)5 ProjectAssessment (fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment)5 StudentProject (fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)5 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)4 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)4 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)4 CourseAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO)3 TransferCreditDAO (fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO)3 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)3 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)3 JSONArray (net.sf.json.JSONArray)3 JSONObject (net.sf.json.JSONObject)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 PageRequestContext (fi.internetix.smvc.controllers.PageRequestContext)2 DAOFactory (fi.otavanopisto.pyramus.dao.DAOFactory)2 AcademicTermDAO (fi.otavanopisto.pyramus.dao.base.AcademicTermDAO)2 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)2 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)2 CreditLinkDAO (fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO)2