Search in sources :

Example 1 with CreditLinkDAO

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

the class EditStudentViewController method process.

public void process(PageRequestContext pageRequestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentActivityTypeDAO studentActivityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
    StudentEducationalLevelDAO studentEducationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
    StudentExaminationTypeDAO studentExaminationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
    StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
    UserVariableKeyDAO userVariableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
    MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
    NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    StudentLodgingPeriodDAO studentLodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
    PersonVariableKeyDAO personVariableKeyDAO = DAOFactory.getInstance().getPersonVariableKeyDAO();
    PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
    StudentStudyPeriodDAO studentStudyPeriodDAO = DAOFactory.getInstance().getStudentStudyPeriodDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    Locale locale = pageRequestContext.getRequest().getLocale();
    User loggedUser = userDAO.findById(pageRequestContext.getLoggedUserId());
    Long personId = pageRequestContext.getLong("person");
    Person person = personDAO.findById(personId);
    List<Student> students = UserUtils.canAccessAllOrganizations(loggedUser) ? studentDAO.listByPerson(person) : studentDAO.listByPersonAndOrganization(person, loggedUser.getOrganization());
    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;
        }
    });
    Map<Long, String> studentTags = new HashMap<>();
    Map<Long, Boolean> studentHasCredits = new HashMap<>();
    List<UserVariableKey> userVariableKeys = userVariableKeyDAO.listByUserEditable(Boolean.TRUE);
    Collections.sort(userVariableKeys, new StringAttributeComparator("getVariableName"));
    JSONObject studentLodgingPeriods = new JSONObject();
    JSONObject studentStudyPeriodsJSON = new JSONObject();
    for (Student student : students) {
        StringBuilder tagsBuilder = new StringBuilder();
        Iterator<Tag> tagIterator = student.getTags().iterator();
        while (tagIterator.hasNext()) {
            Tag tag = tagIterator.next();
            tagsBuilder.append(tag.getText());
            if (tagIterator.hasNext())
                tagsBuilder.append(' ');
        }
        studentTags.put(student.getId(), tagsBuilder.toString());
        studentHasCredits.put(student.getId(), creditLinkDAO.countByStudent(student) + courseAssessmentDAO.countByStudent(student) + transferCreditDAO.countByStudent(student) > 0);
        JSONArray variables = new JSONArray();
        for (UserVariableKey userVariableKey : userVariableKeys) {
            UserVariable userVariable = userVariableDAO.findByUserAndVariableKey(student, userVariableKey);
            JSONObject variable = new JSONObject();
            variable.put("type", userVariableKey.getVariableType());
            variable.put("name", userVariableKey.getVariableName());
            variable.put("key", userVariableKey.getVariableKey());
            variable.put("value", userVariable != null ? userVariable.getValue() : "");
            variables.add(variable);
        }
        setJsDataVariable(pageRequestContext, "variables." + student.getId(), variables.toString());
        List<StudentLodgingPeriod> studentLodgingPeriodEntities = studentLodgingPeriodDAO.listByStudent(student);
        studentLodgingPeriodEntities.sort(Comparator.comparing(StudentLodgingPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
        JSONArray lodgingPeriods = new JSONArray();
        for (StudentLodgingPeriod period : studentLodgingPeriodEntities) {
            JSONObject periodJSON = new JSONObject();
            periodJSON.put("id", period.getId());
            periodJSON.put("begin", period.getBegin() != null ? period.getBegin().getTime() : null);
            periodJSON.put("end", period.getEnd() != null ? period.getEnd().getTime() : null);
            lodgingPeriods.add(periodJSON);
        }
        if (!lodgingPeriods.isEmpty()) {
            studentLodgingPeriods.put(student.getId(), lodgingPeriods);
        }
        List<StudentStudyPeriod> studyPeriods = studentStudyPeriodDAO.listByStudent(student);
        studyPeriods.sort(Comparator.comparing(StudentStudyPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
        JSONArray studyPeriodsJSON = new JSONArray();
        for (StudentStudyPeriod studyPeriod : studyPeriods) {
            JSONObject periodJSON = new JSONObject();
            periodJSON.put("id", studyPeriod.getId());
            periodJSON.put("begin", studyPeriod.getBegin() != null ? studyPeriod.getBegin().getTime() : null);
            periodJSON.put("end", studyPeriod.getEnd() != null ? studyPeriod.getEnd().getTime() : null);
            periodJSON.put("type", studyPeriod.getPeriodType());
            studyPeriodsJSON.add(periodJSON);
        }
        if (!studyPeriodsJSON.isEmpty()) {
            studentStudyPeriodsJSON.put(student.getId(), studyPeriodsJSON);
        }
    }
    setJsDataVariable(pageRequestContext, "studentLodgingPeriods", studentLodgingPeriods.toString());
    setJsDataVariable(pageRequestContext, "studentStudyPeriods", studentStudyPeriodsJSON.toString());
    List<PersonVariableKey> personVariableKeys = personVariableKeyDAO.listUserEditablePersonVariableKeys();
    Collections.sort(personVariableKeys, new StringAttributeComparator("getVariableName"));
    JSONArray personVariablesJSON = new JSONArray();
    for (PersonVariableKey personVariableKey : personVariableKeys) {
        PersonVariable personVariable = personVariableDAO.findByPersonAndVariableKey(person, personVariableKey);
        JSONObject personVariableJSON = new JSONObject();
        personVariableJSON.put("type", personVariableKey.getVariableType());
        personVariableJSON.put("name", personVariableKey.getVariableName());
        personVariableJSON.put("key", personVariableKey.getVariableKey());
        personVariableJSON.put("value", personVariable != null ? personVariable.getValue() : "");
        personVariablesJSON.add(personVariableJSON);
    }
    setJsDataVariable(pageRequestContext, "personVariables", personVariablesJSON.toString());
    List<Nationality> nationalities = nationalityDAO.listUnarchived();
    Collections.sort(nationalities, new StringAttributeComparator("getName"));
    List<Municipality> municipalities = municipalityDAO.listUnarchived();
    Collections.sort(municipalities, new StringAttributeComparator("getName"));
    List<Language> languages = languageDAO.listUnarchived();
    Collections.sort(languages, new StringAttributeComparator("getName"));
    List<School> schools = schoolDAO.listUnarchived();
    Collections.sort(schools, new StringAttributeComparator("getName"));
    List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
    Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
    List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    String username = "";
    boolean hasInternalAuthenticationStrategies = AuthenticationProviderVault.getInstance().hasInternalStrategies();
    if (UserUtils.allowEditCredentials(loggedUser, person)) {
        if (hasInternalAuthenticationStrategies) {
            // TODO: Support for multiple internal authentication providers
            List<InternalAuthenticationProvider> internalAuthenticationProviders = AuthenticationProviderVault.getInstance().getInternalAuthenticationProviders();
            if (internalAuthenticationProviders.size() == 1) {
                InternalAuthenticationProvider internalAuthenticationProvider = internalAuthenticationProviders.get(0);
                if (internalAuthenticationProvider != null) {
                    UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson(internalAuthenticationProvider.getName(), person);
                    if (internalAuthenticationProvider.canUpdateCredentials()) {
                        if (userIdentification != null) {
                            username = internalAuthenticationProvider.getUsername(userIdentification.getExternalId());
                        }
                    }
                }
            }
        }
    }
    JSONArray studentStudyPeriodTypesJSON = new JSONArray();
    for (StudentStudyPeriodType studentStudyPeriodType : StudentStudyPeriodType.values()) {
        JSONObject studyPeriodType = new JSONObject();
        studyPeriodType.put("id", studentStudyPeriodType.toString());
        studyPeriodType.put("displayName", Messages.getInstance().getText(locale, String.format("generic.studentStudyPeriods.%s", studentStudyPeriodType)));
        studyPeriodType.put("beginOnly", StudentStudyPeriodType.BEGINDATE_ONLY.contains(studentStudyPeriodType));
        studentStudyPeriodTypesJSON.add(studyPeriodType);
    }
    setJsDataVariable(pageRequestContext, "studentStudyPeriodTypes", studentStudyPeriodTypesJSON.toString());
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    List<StudyProgramme> studyProgrammes = UserUtils.canAccessAllOrganizations(loggedUser) ? studyProgrammeDAO.listUnarchived() : studyProgrammeDAO.listByOrganization(loggedUser.getOrganization(), Archived.UNARCHIVED);
    Collections.sort(studyProgrammes, new StringAttributeComparator("getName"));
    List<StaffMember> studyApprovers = staffMemberDAO.listByProperty(StaffMemberProperties.STUDY_APPROVER.getKey(), "1");
    // Add study approvers to the list that have been used before so the selections can be persisted
    List<StaffMember> selectedStudyApprovers = students.stream().map(student -> student.getStudyApprover()).filter(Objects::nonNull).collect(Collectors.toList());
    for (StaffMember selectedStudyApprover : selectedStudyApprovers) {
        Long selectedStudyApproverId = selectedStudyApprover.getId();
        boolean isSelectedInList = studyApprovers.stream().map(StaffMember::getId).anyMatch(selectedStudyApproverId::equals);
        if (!isSelectedInList) {
            studyApprovers.add(selectedStudyApprover);
        }
    }
    studyApprovers.sort(Comparator.comparing(StaffMember::getLastName).thenComparing(StaffMember::getFirstName));
    readUserVariablePresets(pageRequestContext);
    pageRequestContext.getRequest().setAttribute("tags", studentTags);
    pageRequestContext.getRequest().setAttribute("person", person);
    pageRequestContext.getRequest().setAttribute("students", students);
    pageRequestContext.getRequest().setAttribute("activityTypes", studentActivityTypeDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
    pageRequestContext.getRequest().setAttribute("contactTypes", contactTypes);
    pageRequestContext.getRequest().setAttribute("examinationTypes", studentExaminationTypeDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("educationalLevels", studentEducationalLevelDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("nationalities", nationalities);
    pageRequestContext.getRequest().setAttribute("municipalities", municipalities);
    pageRequestContext.getRequest().setAttribute("languages", languages);
    pageRequestContext.getRequest().setAttribute("schools", schools);
    pageRequestContext.getRequest().setAttribute("studyProgrammes", studyProgrammes);
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.getRequest().setAttribute("studyEndReasons", studyEndReasonDAO.listByParentReason(null));
    pageRequestContext.getRequest().setAttribute("variableKeys", userVariableKeys);
    pageRequestContext.getRequest().setAttribute("personVariableKeys", personVariableKeys);
    pageRequestContext.getRequest().setAttribute("studentHasCredits", studentHasCredits);
    pageRequestContext.getRequest().setAttribute("hasInternalAuthenticationStrategies", hasInternalAuthenticationStrategies);
    pageRequestContext.getRequest().setAttribute("username", username);
    pageRequestContext.getRequest().setAttribute("allowEditCredentials", UserUtils.allowEditCredentials(loggedUser, person));
    pageRequestContext.getRequest().setAttribute("studyApprovers", studyApprovers);
    pageRequestContext.setIncludeJSP("/templates/students/editstudent.jsp");
}
Also used : Locale(java.util.Locale) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) HashMap(java.util.HashMap) UserVariableKey(fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) UserVariable(fi.otavanopisto.pyramus.domainmodel.users.UserVariable) StudentLodgingPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) InternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StudentEducationalLevelDAO(fi.otavanopisto.pyramus.dao.students.StudentEducationalLevelDAO) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) NationalityDAO(fi.otavanopisto.pyramus.dao.base.NationalityDAO) LanguageDAO(fi.otavanopisto.pyramus.dao.base.LanguageDAO) StudentActivityTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentActivityTypeDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) UserVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.UserVariableKeyDAO) JSONObject(net.sf.json.JSONObject) StudentStudyPeriodType(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriodType) PersonVariableKey(fi.otavanopisto.pyramus.domainmodel.users.PersonVariableKey) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) User(fi.otavanopisto.pyramus.domainmodel.users.User) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) StudentStudyEndReasonDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) UserDAO(fi.otavanopisto.pyramus.dao.users.UserDAO) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) PersonVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableKeyDAO) StudentStudyPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO) StudentExaminationTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) PersonVariable(fi.otavanopisto.pyramus.domainmodel.users.PersonVariable) JSONArray(net.sf.json.JSONArray) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) StudentLodgingPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentLodgingPeriod) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentStudyPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod) UserIdentification(fi.otavanopisto.pyramus.domainmodel.users.UserIdentification)

Example 2 with CreditLinkDAO

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

the class CopyStudentStudyProgrammeJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    Long studentId = requestContext.getLong("studentId");
    Student oldStudent = studentDAO.findById(studentId);
    StaffMember loggedUser = userDAO.findById(requestContext.getLoggedUserId());
    if (!UserUtils.canAccessOrganization(loggedUser, oldStudent.getOrganization())) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Cannot access specified student");
    }
    Long newStudyProgrammeId = requestContext.getLong("newStudyProgrammeId");
    StudyProgramme newStudyProgramme = studyProgrammeDAO.findById(newStudyProgrammeId);
    if (newStudyProgramme == null) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "New Study Programme not defined");
    }
    if (!UserUtils.canAccessOrganization(loggedUser, newStudyProgramme.getOrganization())) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Cannot access specified study programme");
    }
    Boolean linkCredits = requestContext.getBoolean("linkCredits");
    Boolean setAsDefaultUser = requestContext.getBoolean("setAsDefaultUser");
    Person person = oldStudent.getPerson();
    String firstName = oldStudent.getFirstName();
    String lastName = oldStudent.getLastName();
    String nickname = oldStudent.getNickname();
    String additionalInfo = oldStudent.getAdditionalInfo();
    // student.getPreviousStudies();
    Double previousStudies = null;
    // student.getStudyTimeEnd();
    Date studyTimeEnd = null;
    // student.getStudyStartDate();
    Date studyStartTime = null;
    // student.getStudyEndDate();
    Date studyEndTime = null;
    // student.getStudyEndText();
    String studyEndText = null;
    Language language = oldStudent.getLanguage();
    Municipality municipality = oldStudent.getMunicipality();
    StudentActivityType activityType = oldStudent.getActivityType();
    StudentExaminationType examinationType = oldStudent.getExaminationType();
    StudentEducationalLevel educationalLevel = oldStudent.getEducationalLevel();
    String education = oldStudent.getEducation();
    Nationality nationality = oldStudent.getNationality();
    School school = oldStudent.getSchool();
    // oldStudent.getStudyProgramme();
    StudyProgramme studyProgramme = newStudyProgramme;
    // student.getStudyEndReason();
    StudentStudyEndReason studyEndReason = null;
    Curriculum curriculum = oldStudent.getCurriculum();
    Student newStudent = studentDAO.create(person, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityType, examinationType, educationalLevel, education, nationality, municipality, language, school, studyProgramme, curriculum, previousStudies, studyStartTime, studyEndTime, studyEndReason, studyEndText, false);
    // Variables are not copied, but the default values are applied
    userVariableDAO.createDefaultValueVariables(newStudent);
    // Contact info
    contactInfoDAO.update(newStudent.getContactInfo(), oldStudent.getContactInfo().getAdditionalInfo());
    if (person.getDefaultUser() == null || Boolean.TRUE.equals(setAsDefaultUser)) {
        personDAO.updateDefaultUser(person, newStudent);
    }
    // Addresses
    List<Address> addresses = oldStudent.getContactInfo().getAddresses();
    for (int i = 0; i < addresses.size(); i++) {
        Address add = addresses.get(i);
        addressDAO.create(newStudent.getContactInfo(), add.getContactType(), add.getName(), add.getStreetAddress(), add.getPostalCode(), add.getCity(), add.getCountry(), add.getDefaultAddress());
    }
    // Email addresses
    List<Email> emails = oldStudent.getContactInfo().getEmails();
    for (int i = 0; i < emails.size(); i++) {
        Email email = emails.get(i);
        emailDAO.create(newStudent.getContactInfo(), email.getContactType(), email.getDefaultAddress(), email.getAddress());
    }
    // Phone numbers
    List<PhoneNumber> phoneNumbers = oldStudent.getContactInfo().getPhoneNumbers();
    for (int i = 0; i < phoneNumbers.size(); i++) {
        PhoneNumber phoneNumber = phoneNumbers.get(i);
        phoneNumberDAO.create(newStudent.getContactInfo(), phoneNumber.getContactType(), phoneNumber.getDefaultNumber(), phoneNumber.getNumber());
    }
    if (linkCredits) {
        List<CourseAssessment> assessments = courseAssessmentDAO.listByStudent(oldStudent);
        for (CourseAssessment assessment : assessments) {
            creditLinkDAO.create(assessment, newStudent, loggedUser);
        }
        List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(oldStudent);
        for (TransferCredit transferCredit : transferCredits) {
            creditLinkDAO.create(transferCredit, newStudent, loggedUser);
        }
        List<CreditLink> creditLinks = creditLinkDAO.listByStudent(oldStudent);
        for (CreditLink creditLink : creditLinks) {
            creditLinkDAO.create(creditLink.getCredit(), newStudent, loggedUser);
        }
    }
    String redirectURL = requestContext.getRequest().getContextPath() + "/students/editstudent.page?student=" + newStudent.getPerson().getId();
    String refererAnchor = requestContext.getRefererAnchor();
    if (!StringUtils.isBlank(refererAnchor))
        redirectURL += "#" + refererAnchor;
    requestContext.setRedirectURL(redirectURL);
}
Also used : PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Date(java.util.Date) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactInfoDAO(fi.otavanopisto.pyramus.dao.base.ContactInfoDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 3 with CreditLinkDAO

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

the class ImportStudentCreditsJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    Long studentId = requestContext.getLong("studentId");
    Student baseStudent = studentDAO.findById(studentId);
    List<Student> students = studentDAO.listByPerson(baseStudent.getPerson());
    students.remove(baseStudent);
    User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
    // LinkedCourseAssessments for baseStudent
    int rowCount = requestContext.getLong("linkedCourseAssessmentsTable." + baseStudent.getId() + ".rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String paramName = "linkedCourseAssessmentsTable." + baseStudent.getId() + "." + i + ".selected";
        boolean selected = new Long(1).equals(requestContext.getLong(paramName));
        if (selected) {
            Long creditLinkId = requestContext.getLong("linkedCourseAssessmentsTable." + baseStudent.getId() + "." + i + ".creditLinkId");
            CreditLink creditLink = creditLinkDAO.findById(creditLinkId);
            creditLinkDAO.archive(creditLink, loggedUser);
        }
    }
    // LinkedTransferCredits for baseStudent
    rowCount = requestContext.getLong("linkedTransferCreditsTable." + baseStudent.getId() + ".rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String paramName = "linkedTransferCreditsTable." + baseStudent.getId() + "." + i + ".selected";
        boolean selected = new Long(1).equals(requestContext.getLong(paramName));
        if (selected) {
            Long creditLinkId = requestContext.getLong("linkedTransferCreditsTable." + baseStudent.getId() + "." + i + ".creditLinkId");
            CreditLink creditLink = creditLinkDAO.findById(creditLinkId);
            creditLinkDAO.archive(creditLink, loggedUser);
        }
    }
    for (Student student : students) {
        // CourseAssessments
        rowCount = requestContext.getLong("courseAssessmentsTable." + student.getId() + ".rowCount").intValue();
        for (int i = 0; i < rowCount; i++) {
            String paramName = "courseAssessmentsTable." + student.getId() + "." + i + ".selected";
            boolean selected = new Long(1).equals(requestContext.getLong(paramName));
            if (selected) {
                Long courseAssessmentId = requestContext.getLong("courseAssessmentsTable." + student.getId() + "." + i + ".courseAssessmentId");
                CourseAssessment courseAssessment = courseAssessmentDAO.findById(courseAssessmentId);
                CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, courseAssessment);
                if (creditLink == null)
                    creditLinkDAO.create(courseAssessment, baseStudent, loggedUser);
            }
        }
        // TransferCredits
        rowCount = requestContext.getLong("transferCreditsTable." + student.getId() + ".rowCount").intValue();
        for (int i = 0; i < rowCount; i++) {
            String paramName = "transferCreditsTable." + student.getId() + "." + i + ".selected";
            boolean selected = new Long(1).equals(requestContext.getLong(paramName));
            if (selected) {
                Long transferCreditId = requestContext.getLong("transferCreditsTable." + student.getId() + "." + i + ".transferCreditId");
                TransferCredit transferCredit = transferCreditDAO.findById(transferCreditId);
                CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, transferCredit);
                if (creditLink == null)
                    creditLinkDAO.create(transferCredit, baseStudent, loggedUser);
            }
        }
        // LinkedCourseAssessments
        rowCount = requestContext.getLong("linkedCourseAssessmentsTable." + student.getId() + ".rowCount").intValue();
        for (int i = 0; i < rowCount; i++) {
            String paramName = "linkedCourseAssessmentsTable." + student.getId() + "." + i + ".selected";
            boolean selected = new Long(1).equals(requestContext.getLong(paramName));
            if (selected) {
                Long courseAssessmentId = requestContext.getLong("linkedCourseAssessmentsTable." + student.getId() + "." + i + ".courseAssessmentId");
                CourseAssessment courseAssessment = courseAssessmentDAO.findById(courseAssessmentId);
                CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, courseAssessment);
                if (creditLink == null)
                    creditLinkDAO.create(courseAssessment, baseStudent, loggedUser);
            }
        }
        // LinkedTransferCredits
        rowCount = requestContext.getLong("linkedTransferCreditsTable." + student.getId() + ".rowCount").intValue();
        for (int i = 0; i < rowCount; i++) {
            String paramName = "linkedTransferCreditsTable." + student.getId() + "." + i + ".selected";
            boolean selected = new Long(1).equals(requestContext.getLong(paramName));
            if (selected) {
                Long transferCreditId = requestContext.getLong("linkedTransferCreditsTable." + student.getId() + "." + i + ".transferCreditId");
                TransferCredit transferCredit = transferCreditDAO.findById(transferCreditId);
                CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, transferCredit);
                if (creditLink == null)
                    creditLinkDAO.create(transferCredit, baseStudent, loggedUser);
            }
        }
    }
    String redirectURL = requestContext.getRequest().getContextPath() + "/students/importstudentcredits.page?studentId=" + baseStudent.getId();
    // String refererAnchor = requestContext.getRefererAnchor();
    // if (!StringUtils.isBlank(refererAnchor))
    // redirectURL += "#" + refererAnchor;
    requestContext.setRedirectURL(redirectURL);
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)

Example 4 with CreditLinkDAO

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

Example 5 with CreditLinkDAO

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

the class StudentTORController method constructStudentTOR.

public static StudentTOR constructStudentTOR(Student student) throws Exception {
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    List<CourseAssessment> courseAssessmentsByStudent = courseAssessmentDAO.listByStudent(student);
    List<TransferCredit> transferCreditsByStudent = transferCreditDAO.listByStudent(student);
    List<CreditLink> linkedCourseAssessmentByStudent = creditLinkDAO.listByStudentAndType(student, CreditType.CourseAssessment);
    List<CreditLink> linkedTransferCreditsByStudent = creditLinkDAO.listByStudentAndType(student, CreditType.TransferCredit);
    StudentTOR tor = new StudentTOR();
    TORProblems problems = tor.getProblems();
    for (CourseAssessment courseAssessment : courseAssessmentsByStudent) {
        if (courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
            Subject subject = courseAssessment.getCourseStudent().getCourse().getSubject();
            Integer courseNumber = courseAssessment.getCourseStudent().getCourse().getCourseNumber();
            Set<Curriculum> creditCurriculums = courseAssessment.getCourseStudent().getCourse().getCurriculums();
            EducationalLength courseEducationalLength = courseAssessment.getCourseStudent().getCourse().getCourseLength();
            Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
            TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
            addTORCredit(tor, student, subject, courseAssessment, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
        }
    }
    for (TransferCredit transferCredit : transferCreditsByStudent) {
        Subject subject = transferCredit.getSubject();
        Integer courseNumber = transferCredit.getCourseNumber();
        Set<Curriculum> creditCurriculums = transferCredit.getCurriculum() != null ? new HashSet<>(Arrays.asList(transferCredit.getCurriculum())) : Collections.emptySet();
        EducationalLength courseEducationalLength = transferCredit.getCourseLength();
        Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
        TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
        addTORCredit(tor, student, subject, transferCredit, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
    }
    for (CreditLink linkedCourseAssessment : linkedCourseAssessmentByStudent) {
        CourseAssessment courseAssessment = (CourseAssessment) linkedCourseAssessment.getCredit();
        if (courseAssessment != null && courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
            Subject subject = courseAssessment.getCourseStudent().getCourse().getSubject();
            Integer courseNumber = courseAssessment.getCourseStudent().getCourse().getCourseNumber();
            Set<Curriculum> creditCurriculums = courseAssessment.getCourseStudent().getCourse().getCurriculums();
            EducationalLength courseEducationalLength = courseAssessment.getCourseStudent().getCourse().getCourseLength();
            Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
            TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
            addTORCredit(tor, student, subject, courseAssessment, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
        }
    }
    for (CreditLink linkedTransferCredit : linkedTransferCreditsByStudent) {
        TransferCredit transferCredit = (TransferCredit) linkedTransferCredit.getCredit();
        if (transferCredit != null) {
            Subject subject = transferCredit.getSubject();
            Integer courseNumber = transferCredit.getCourseNumber();
            Set<Curriculum> creditCurriculums = transferCredit.getCurriculum() != null ? new HashSet<>(Arrays.asList(transferCredit.getCurriculum())) : Collections.emptySet();
            EducationalLength courseEducationalLength = transferCredit.getCourseLength();
            Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
            TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
            addTORCredit(tor, student, subject, transferCredit, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
        }
    }
    tor.postProcess();
    return tor;
}
Also used : CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) EducationalLength(fi.otavanopisto.pyramus.domainmodel.base.EducationalLength)

Aggregations

CourseAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO)8 CreditLinkDAO (fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO)8 TransferCreditDAO (fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO)8 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)7 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)7 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)6 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)6 CreditLink (fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)6 TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)6 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)4 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)4 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)3 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)3 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)3 JSONArray (net.sf.json.JSONArray)3 JSONObject (net.sf.json.JSONObject)3 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)2 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)2 ProjectAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO)2 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)2