Search in sources :

Example 1 with StudentStudyPeriodDAO

use of fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO 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 StudentStudyPeriodDAO

use of fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO in project pyramus by otavanopisto.

the class EditStudentJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentActivityTypeDAO activityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
    StudentExaminationTypeDAO examinationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
    StudentEducationalLevelDAO educationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
    StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
    MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
    NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    StudentLodgingPeriodDAO lodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
    PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
    StudentStudyPeriodDAO studentStudyPeriodDAO = DAOFactory.getInstance().getStudentStudyPeriodDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
    Long personId = NumberUtils.createLong(requestContext.getRequest().getParameter("personId"));
    Person person = personDAO.findById(personId);
    Date birthday = requestContext.getDate("birthday");
    String ssecId = requestContext.getString("ssecId");
    Sex sex = (Sex) requestContext.getEnum("gender", Sex.class);
    String basicInfo = requestContext.getString("basicInfo");
    Long version = requestContext.getLong("version");
    Boolean secureInfo = requestContext.getBoolean("secureInfo");
    String username = requestContext.getString("username");
    String password = requestContext.getString("password1");
    String password2 = requestContext.getString("password2");
    if (UserUtils.allowEditCredentials(loggedUser, person)) {
        if (!person.getVersion().equals(version)) {
            throw new StaleObjectStateException(Person.class.getName(), person.getId());
        }
        boolean usernameBlank = StringUtils.isBlank(username);
        boolean passwordBlank = StringUtils.isBlank(password);
        UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson("internal", person);
        if (usernameBlank && passwordBlank) {
            // #1108: Existing credential deletion
            if (userIdentification != null && NumberUtils.isNumber(userIdentification.getExternalId())) {
                InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
                InternalAuth internalAuth = internalAuthDAO.findById(new Long(userIdentification.getExternalId()));
                if (internalAuth != null) {
                    internalAuthDAO.delete(internalAuth);
                }
                userIdentificationDAO.delete(userIdentification);
            }
        } else if (!usernameBlank || !passwordBlank) {
            if (!passwordBlank && !password.equals(password2)) {
                throw new SmvcRuntimeException(PyramusStatusCode.PASSWORD_MISMATCH, "Passwords don't match");
            }
            // #921: Check username
            InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
            InternalAuth internalAuth = internalAuthDAO.findByUsername(username);
            if (internalAuth != null) {
                userIdentification = userIdentificationDAO.findByAuthSourceAndExternalId("internal", internalAuth.getId().toString());
                if (userIdentification != null && !person.getId().equals(userIdentification.getPerson().getId())) {
                    throw new RuntimeException(Messages.getInstance().getText(requestContext.getRequest().getLocale(), "generic.errors.usernameInUse"));
                }
            } else if (!usernameBlank && passwordBlank) {
                throw new RuntimeException(Messages.getInstance().getText(requestContext.getRequest().getLocale(), "generic.errors.nopassword"));
            }
            // 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 = userIdentificationDAO.findByAuthSourceAndPerson(internalAuthenticationProvider.getName(), person);
                    if (internalAuthenticationProvider.canUpdateCredentials()) {
                        if (userIdentification == null) {
                            String externalId = internalAuthenticationProvider.createCredentials(username, password);
                            userIdentificationDAO.create(person, internalAuthenticationProvider.getName(), externalId);
                        } else {
                            if ("-1".equals(userIdentification.getExternalId())) {
                                String externalId = internalAuthenticationProvider.createCredentials(username, password);
                                userIdentificationDAO.updateExternalId(userIdentification, externalId);
                            } else {
                                if (!StringUtils.isBlank(username))
                                    internalAuthenticationProvider.updateUsername(userIdentification.getExternalId(), username);
                                if (!StringUtils.isBlank(password))
                                    internalAuthenticationProvider.updatePassword(userIdentification.getExternalId(), password);
                            }
                        }
                    }
                }
            }
        }
    }
    // Abstract student
    personDAO.update(person, birthday, ssecId, sex, basicInfo, secureInfo);
    // Person Variables
    Integer personVariableCount = requestContext.getInteger("personVariablesTable.rowCount");
    if (personVariableCount != null) {
        for (int i = 0; i < personVariableCount; i++) {
            String colPrefix = "personVariablesTable." + i;
            Long edited = requestContext.getLong(colPrefix + ".edited");
            if (Objects.equals(new Long(1), edited)) {
                String variableKey = requestContext.getString(colPrefix + ".key");
                String variableValue = requestContext.getString(colPrefix + ".value");
                personVariableDAO.setPersonVariable(person, variableKey, variableValue);
            }
        }
    }
    List<Student> students = UserUtils.canAccessAllOrganizations(loggedUser) ? studentDAO.listByPerson(person) : studentDAO.listByPersonAndOrganization(person, loggedUser.getOrganization());
    for (Student student : students) {
        int rowCount = requestContext.getInteger("emailTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "emailTable." + student.getId() + "." + i;
            String email = StringUtils.trim(requestContext.getString(colPrefix + ".email"));
            if (StringUtils.isNotBlank(email)) {
                ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
                if (!UserUtils.isAllowedEmail(email, contactType, person.getId()))
                    throw new RuntimeException(Messages.getInstance().getText(requestContext.getRequest().getLocale(), "generic.errors.emailInUse"));
            }
        }
    }
    for (Student student : students) {
        Long studentVersion = requestContext.getLong("studentVersion." + student.getId());
        if (!student.getVersion().equals(studentVersion))
            throw new StaleObjectStateException(Student.class.getName(), student.getId());
        String firstName = StringUtils.trim(requestContext.getString("firstName." + student.getId()));
        String lastName = StringUtils.trim(requestContext.getString("lastName." + student.getId()));
        String nickname = StringUtils.trim(requestContext.getString("nickname." + student.getId()));
        String additionalInfo = requestContext.getString("additionalInfo." + student.getId());
        String additionalContactInfo = requestContext.getString("otherContactInfo." + student.getId());
        String education = requestContext.getString("education." + student.getId());
        Double previousStudies = requestContext.getDouble("previousStudies." + student.getId());
        Date studyTimeEnd = requestContext.getDate("studyTimeEnd." + student.getId());
        Date studyStartDate = requestContext.getDate("studyStartDate." + student.getId());
        Date studyEndDate = requestContext.getDate("studyEndDate." + student.getId());
        String studyEndText = requestContext.getString("studyEndText." + student.getId());
        String tagsText = requestContext.getString("tags." + student.getId());
        StudentFunding funding = (StudentFunding) requestContext.getEnum("funding." + student.getId(), StudentFunding.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);
                }
            }
        }
        Long entityId = requestContext.getLong("language." + student.getId());
        Language language = entityId == null ? null : languageDAO.findById(entityId);
        entityId = requestContext.getLong("activityType." + student.getId());
        StudentActivityType activityType = entityId == null ? null : activityTypeDAO.findById(entityId);
        entityId = requestContext.getLong("examinationType." + student.getId());
        StudentExaminationType examinationType = entityId == null ? null : examinationTypeDAO.findById(entityId);
        entityId = requestContext.getLong("educationalLevel." + student.getId());
        StudentEducationalLevel educationalLevel = entityId == null ? null : educationalLevelDAO.findById(entityId);
        entityId = requestContext.getLong("nationality." + student.getId());
        Nationality nationality = entityId == null ? null : nationalityDAO.findById(entityId);
        entityId = requestContext.getLong("municipality." + student.getId());
        Municipality municipality = entityId == null ? null : municipalityDAO.findById(entityId);
        entityId = requestContext.getLong("school." + student.getId());
        School school = entityId != null && entityId > 0 ? schoolDAO.findById(entityId) : null;
        entityId = requestContext.getLong("studyEndReason." + student.getId());
        StudentStudyEndReason studyEndReason = entityId == null ? null : studyEndReasonDAO.findById(entityId);
        entityId = requestContext.getLong("curriculum." + student.getId());
        Curriculum curriculum = entityId == null ? null : curriculumDAO.findById(entityId);
        entityId = requestContext.getLong("studyApprover." + student.getId());
        StaffMember approver = entityId == null ? null : staffMemberDAO.findById(entityId);
        Integer variableCount = requestContext.getInteger("variablesTable." + student.getId() + ".rowCount");
        if (variableCount != null) {
            for (int i = 0; i < variableCount; i++) {
                String colPrefix = "variablesTable." + student.getId() + "." + i;
                Long edited = requestContext.getLong(colPrefix + ".edited");
                if (Objects.equals(new Long(1), edited)) {
                    String variableKey = requestContext.getString(colPrefix + ".key");
                    String variableValue = requestContext.getString(colPrefix + ".value");
                    userVariableDAO.setUserVariable(student, variableKey, variableValue);
                }
            }
        }
        Integer lodgingPeriodsCount = requestContext.getInteger("lodgingPeriodsTable." + student.getId() + ".rowCount");
        if (lodgingPeriodsCount != null) {
            Set<Long> remainingIds = new HashSet<>();
            for (int i = 0; i < lodgingPeriodsCount; i++) {
                String colPrefix = "lodgingPeriodsTable." + student.getId() + "." + i;
                Long id = requestContext.getLong(colPrefix + ".id");
                Date begin = requestContext.getDate(colPrefix + ".begin");
                Date end = requestContext.getDate(colPrefix + ".end");
                if (id == -1 && begin != null) {
                    StudentLodgingPeriod lodgingPeriod = lodgingPeriodDAO.create(student, begin, end);
                    remainingIds.add(lodgingPeriod.getId());
                } else if (id > 0) {
                    StudentLodgingPeriod lodgingPeriod = lodgingPeriodDAO.findById(id);
                    remainingIds.add(id);
                    if (begin != null) {
                        if (lodgingPeriod != null) {
                            lodgingPeriodDAO.update(lodgingPeriod, begin, end);
                        }
                    }
                }
            }
            List<StudentLodgingPeriod> periods = lodgingPeriodDAO.listByStudent(student);
            periods.removeIf(period -> remainingIds.contains(period.getId()));
            periods.forEach(period -> lodgingPeriodDAO.delete(period));
        }
        Integer studyPeriodsCount = requestContext.getInteger("studentStudyPeriodsTable." + student.getId() + ".rowCount");
        if (studyPeriodsCount != null) {
            Set<Long> remainingIds = new HashSet<>();
            for (int i = 0; i < studyPeriodsCount; i++) {
                String colPrefix = "studentStudyPeriodsTable." + student.getId() + "." + i;
                Long id = requestContext.getLong(colPrefix + ".id");
                StudentStudyPeriodType periodType = (StudentStudyPeriodType) requestContext.getEnum(colPrefix + ".type", StudentStudyPeriodType.class);
                Date begin = requestContext.getDate(colPrefix + ".begin");
                // Null out the end date when period type allows only begin dates
                Date end = !StudentStudyPeriodType.BEGINDATE_ONLY.contains(periodType) ? requestContext.getDate(colPrefix + ".end") : null;
                if (id == -1 && begin != null) {
                    StudentStudyPeriod studyPeriod = studentStudyPeriodDAO.create(student, begin, end, periodType);
                    remainingIds.add(studyPeriod.getId());
                } else if (id > 0) {
                    StudentStudyPeriod studyPeriod = studentStudyPeriodDAO.findById(id);
                    remainingIds.add(id);
                    if (begin != null) {
                        if (studyPeriod != null) {
                            studentStudyPeriodDAO.update(studyPeriod, begin, end, periodType);
                        }
                    }
                }
            }
            List<StudentStudyPeriod> periods = studentStudyPeriodDAO.listByStudent(student);
            periods.removeIf(period -> remainingIds.contains(period.getId()));
            periods.forEach(period -> studentStudyPeriodDAO.delete(period));
        }
        boolean studiesEnded = student.getStudyEndDate() == null && studyEndDate != null;
        // Student
        studentDAO.update(student, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityType, examinationType, educationalLevel, education, nationality, municipality, language, school, curriculum, previousStudies, studyStartDate, studyEndDate, studyEndReason, studyEndText);
        studentDAO.updateApprover(student, approver);
        studentDAO.updateFunding(student, funding);
        // Tags
        studentDAO.setStudentTags(student, tagEntities);
        // Contact info
        contactInfoDAO.update(student.getContactInfo(), additionalContactInfo);
        // Student addresses
        Set<Long> existingAddresses = new HashSet<>();
        int rowCount = requestContext.getInteger("addressTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "addressTable." + student.getId() + "." + i;
            Long addressId = requestContext.getLong(colPrefix + ".addressId");
            Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
            ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
            String name = requestContext.getString(colPrefix + ".name");
            String street = requestContext.getString(colPrefix + ".street");
            String postal = requestContext.getString(colPrefix + ".postal");
            String city = requestContext.getString(colPrefix + ".city");
            String country = requestContext.getString(colPrefix + ".country");
            boolean hasAddress = name != null || street != null || postal != null || city != null || country != null;
            if (addressId == -1 && hasAddress) {
                Address address = addressDAO.create(student.getContactInfo(), contactType, name, street, postal, city, country, defaultAddress);
                existingAddresses.add(address.getId());
            } else if (addressId > 0) {
                Address address = addressDAO.findById(addressId);
                if (hasAddress) {
                    existingAddresses.add(addressId);
                    addressDAO.update(address, defaultAddress, contactType, name, street, postal, city, country);
                }
            }
        }
        List<Address> addresses = student.getContactInfo().getAddresses();
        for (int i = addresses.size() - 1; i >= 0; i--) {
            Address address = addresses.get(i);
            if (!existingAddresses.contains(address.getId())) {
                addressDAO.delete(address);
            }
        }
        // Email addresses
        Set<Long> existingEmails = new HashSet<>();
        rowCount = requestContext.getInteger("emailTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "emailTable." + student.getId() + "." + i;
            Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
            ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
            String email = StringUtils.trim(requestContext.getString(colPrefix + ".email"));
            if (StringUtils.isNotBlank(email)) {
                Long emailId = requestContext.getLong(colPrefix + ".emailId");
                if (emailId == -1) {
                    emailId = emailDAO.create(student.getContactInfo(), contactType, defaultAddress, email).getId();
                } else {
                    emailDAO.update(emailDAO.findById(emailId), contactType, defaultAddress, email);
                }
                existingEmails.add(emailId);
            }
        }
        List<Email> emails = student.getContactInfo().getEmails();
        for (int i = emails.size() - 1; i >= 0; i--) {
            Email email = emails.get(i);
            if (!existingEmails.contains(email.getId())) {
                emailDAO.delete(email);
            }
        }
        // Phone numbers
        Set<Long> existingPhoneNumbers = new HashSet<>();
        rowCount = requestContext.getInteger("phoneTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "phoneTable." + student.getId() + "." + i;
            Boolean defaultNumber = requestContext.getBoolean(colPrefix + ".defaultNumber");
            ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
            String number = requestContext.getString(colPrefix + ".phone");
            Long phoneId = requestContext.getLong(colPrefix + ".phoneId");
            if (phoneId == -1 && number != null) {
                phoneId = phoneNumberDAO.create(student.getContactInfo(), contactType, defaultNumber, number).getId();
                existingPhoneNumbers.add(phoneId);
            } else if (phoneId > 0 && number != null) {
                phoneNumberDAO.update(phoneNumberDAO.findById(phoneId), contactType, defaultNumber, number);
                existingPhoneNumbers.add(phoneId);
            }
        }
        List<PhoneNumber> phoneNumbers = student.getContactInfo().getPhoneNumbers();
        for (int i = phoneNumbers.size() - 1; i >= 0; i--) {
            PhoneNumber phoneNumber = phoneNumbers.get(i);
            if (!existingPhoneNumbers.contains(phoneNumber.getId())) {
                phoneNumberDAO.delete(phoneNumber);
            }
        }
        Long studyProgrammeId = student.getStudyProgramme() != null ? student.getStudyProgramme().getId() : null;
        // #4226: Remove applications of nettipk/nettilukio students when their studies end
        if (studiesEnded && studyProgrammeId != null && (studyProgrammeId == 6L || studyProgrammeId == 7L)) {
            ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
            Application application = applicationDAO.findByStudent(student);
            if (application != null) {
                ApplicationUtils.deleteApplication(application);
            }
        }
    }
    // Contact information of a student won't be reflected to Person
    // used when searching students, so a manual re-index is needed
    person = personDAO.findById(person.getId());
    personDAO.forceReindex(person);
    requestContext.setRedirectURL(requestContext.getReferer(true));
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) 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) List(java.util.List) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO) HashSet(java.util.HashSet) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) LanguageDAO(fi.otavanopisto.pyramus.dao.base.LanguageDAO) NationalityDAO(fi.otavanopisto.pyramus.dao.base.NationalityDAO) StudentActivityTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentActivityTypeDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactInfoDAO(fi.otavanopisto.pyramus.dao.base.ContactInfoDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) StudentStudyPeriodType(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriodType) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) StaleObjectStateException(org.hibernate.StaleObjectStateException) Application(fi.otavanopisto.pyramus.domainmodel.application.Application) PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) Sex(fi.otavanopisto.pyramus.domainmodel.students.Sex) StudentStudyEndReasonDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO) ApplicationDAO(fi.otavanopisto.pyramus.dao.application.ApplicationDAO) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) 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) InternalAuth(fi.otavanopisto.pyramus.domainmodel.users.InternalAuth) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) StudentStudyPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO) StudentExaminationTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) StudentFunding(fi.otavanopisto.pyramus.domainmodel.students.StudentFunding) Date(java.util.Date) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) StudentLodgingPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentLodgingPeriod) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) InternalAuthDAO(fi.otavanopisto.pyramus.dao.users.InternalAuthDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentStudyPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod) UserIdentification(fi.otavanopisto.pyramus.domainmodel.users.UserIdentification)

Example 3 with StudentStudyPeriodDAO

use of fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO in project pyramus by otavanopisto.

the class ApplicationUtils method createPyramusStudent.

public static Student createPyramusStudent(Application application, Person person, StaffMember staffMember) {
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    ApplicationAttachmentDAO applicationAttachmentDAO = DAOFactory.getInstance().getApplicationAttachmentDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    StudentStudyPeriodDAO studentStudyPeriodDAO = DAOFactory.getInstance().getStudentStudyPeriodDAO();
    JSONObject formData = JSONObject.fromObject(application.getFormData());
    if (StringUtils.isNotBlank(getFormValue(formData, "field-nettilukio_compulsory_enddate"))) {
        try {
            new SimpleDateFormat("d.M.yyyy").parse(getFormValue(formData, "field-nettilukio_compulsory_enddate"));
        } catch (ParseException e) {
            logger.severe(String.format("Invalid compulsory end date format in application entity %d", application.getId()));
            return null;
        }
    }
    if (person == null) {
        String birthdayStr = getFormValue(formData, "field-birthday");
        String ssnEnd = getFormValue(formData, "field-ssn-end");
        try {
            Date birthday = StringUtils.isEmpty(birthdayStr) ? null : new SimpleDateFormat("d.M.yyyy").parse(birthdayStr);
            String ssn = StringUtils.isBlank(ssnEnd) ? null : ApplicationUtils.constructSSN(birthdayStr, ssnEnd);
            Sex sex = ApplicationUtils.resolveGender(getFormValue(formData, "field-sex"));
            person = personDAO.create(birthday, ssn, sex, null, Boolean.FALSE);
        } catch (ParseException e) {
            logger.severe(String.format("Invalid birthday format in application entity %d", application.getId()));
            return null;
        }
    }
    // Determine correct study programme
    StudyProgramme studyProgramme = ApplicationUtils.resolveStudyProgramme(getFormValue(formData, "field-line"), getFormValue(formData, "field-foreign-line"), EnumUtils.getEnum(AlternativeLine.class, getFormValue(formData, "field-nettilukio_alternativelines")));
    if (studyProgramme == null) {
        logger.severe(String.format("Unable to resolve study programme of application entity %d", application.getId()));
        return null;
    }
    // Study time end plus one year (for Internetix students)
    Date studyTimeEnd = null;
    if (StringUtils.equals(getFormValue(formData, "field-line"), "aineopiskelu")) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.YEAR, 1);
        studyTimeEnd = c.getTime();
    }
    // #868: Non-contract school information (for Internetix students, if exists)
    String additionalInfo = null;
    if (StringUtils.equals(getFormValue(formData, "field-line"), "aineopiskelu")) {
        String contractSchoolName = getFormValue(formData, "field-internetix-contract-school-name");
        String contractSchoolMunicipality = getFormValue(formData, "field-internetix-contract-school-municipality");
        String contractSchoolContact = getFormValue(formData, "field-internetix-contract-school-contact");
        if (!StringUtils.isAnyEmpty(contractSchoolName, contractSchoolMunicipality, contractSchoolContact)) {
            additionalInfo = String.format("<p><strong>Muun kuin sopimusoppilaitoksen yhteystiedot:</strong><br/>%s (%s)<br/>%s</p>", contractSchoolName, contractSchoolMunicipality, StringUtils.replace(contractSchoolContact, "\n", "<br/>"));
        }
    }
    Date studyStartDate = new Date();
    // Create student
    Student student = studentDAO.create(person, getFormValue(formData, "field-first-names"), getFormValue(formData, "field-last-name"), getFormValue(formData, "field-nickname"), additionalInfo, studyTimeEnd, ApplicationUtils.resolveStudentActivityType(getFormValue(formData, "field-job")), ApplicationUtils.resolveStudentExaminationType(getFormValue(formData, "field-internetix-contract-school-degree")), // student educational level (entity)
    null, // education (string)
    null, ApplicationUtils.resolveNationality(getFormValue(formData, "field-nationality")), ApplicationUtils.resolveMunicipality(getFormValue(formData, "field-municipality")), ApplicationUtils.resolveLanguage(getFormValue(formData, "field-language")), ApplicationUtils.resolveSchool(getFormValue(formData, "field-internetix-contract-school")), studyProgramme, // curriculum (TODO can this be resolved?)
    null, // previous studies (double)
    null, // study start date
    studyStartDate, // study end date
    null, // study end reason
    null, // study end text
    null, // archived
    Boolean.FALSE);
    userVariableDAO.createDefaultValueVariables(student);
    // StudyPeriods
    String compulsoryStudies = getFormValue(formData, "field-nettilukio_compulsory");
    if (StringUtils.isNotBlank(compulsoryStudies)) {
        if (StringUtils.equals(compulsoryStudies, "compulsory")) {
            studentStudyPeriodDAO.create(student, studyStartDate, null, StudentStudyPeriodType.COMPULSORY_EDUCATION);
            String compulsoryEndDateStr = getFormValue(formData, "field-nettilukio_compulsory_enddate");
            if (StringUtils.isNotBlank(compulsoryEndDateStr)) {
                try {
                    Date compulsoryEndDate = StringUtils.isEmpty(compulsoryEndDateStr) ? null : new SimpleDateFormat("d.M.yyyy").parse(compulsoryEndDateStr);
                    studentStudyPeriodDAO.create(student, compulsoryEndDate, null, StudentStudyPeriodType.NON_COMPULSORY_EDUCATION);
                } catch (ParseException e) {
                    logger.severe(String.format("Invalid compulsory end date format in application entity %d", application.getId()));
                    return null;
                }
            }
        } else if (StringUtils.equals(compulsoryStudies, "non_compulsory")) {
            studentStudyPeriodDAO.create(student, studyStartDate, null, StudentStudyPeriodType.NON_COMPULSORY_EDUCATION);
        }
    }
    // #1079: Aineopiskelu; yleissivistävä koulutustausta
    String internetixStudies = getFormValue(formData, "field-previous-studies-aineopiskelu");
    if (StringUtils.isNotBlank(internetixStudies)) {
        if (StringUtils.equals(internetixStudies, "perus")) {
            student = studentDAO.updateEducation(student, "Yleissivistävä koulutustausta: peruskoulu");
        } else if (StringUtils.equals(internetixStudies, "lukio")) {
            student = studentDAO.updateEducation(student, "Yleissivistävä koulutustausta: lukio");
        } else if (StringUtils.equals(internetixStudies, "ei")) {
            student = studentDAO.updateEducation(student, "Yleissivistävä koulutustausta: ei mitään");
        }
    }
    // Main contact type
    // Koti (unique)
    ContactType contactType = contactTypeDAO.findById(1L);
    // Attach email
    String email = StringUtils.lowerCase(StringUtils.trim(getFormValue(formData, "field-email")));
    logger.info(String.format("Attaching primary email %s", email));
    emailDAO.create(student.getContactInfo(), contactType, Boolean.TRUE, email);
    // Attach address
    addressDAO.create(student.getContactInfo(), contactType, String.format("%s %s", getFormValue(formData, "field-nickname"), getFormValue(formData, "field-last-name")), getFormValue(formData, "field-street-address"), getFormValue(formData, "field-zip-code"), getFormValue(formData, "field-city"), getFormValue(formData, "field-country"), Boolean.TRUE);
    // Attach phone
    phoneNumberDAO.create(student.getContactInfo(), contactType, Boolean.TRUE, getFormValue(formData, "field-phone"));
    // Guardian info (if email is present, all other fields are required and present, too)
    email = StringUtils.lowerCase(StringUtils.trim(getFormValue(formData, "field-underage-email")));
    if (!StringUtils.isBlank(email)) {
        // Attach email
        logger.info(String.format("Attaching guardian email %s", email));
        // Yhteyshenkilö (non-unique)
        contactType = contactTypeDAO.findById(5L);
        emailDAO.create(student.getContactInfo(), contactType, Boolean.FALSE, email);
        // Attach address
        addressDAO.create(student.getContactInfo(), contactType, String.format("%s %s", getFormValue(formData, "field-underage-first-name"), getFormValue(formData, "field-underage-last-name")), getFormValue(formData, "field-underage-street-address"), getFormValue(formData, "field-underage-zip-code"), getFormValue(formData, "field-underage-city"), getFormValue(formData, "field-underage-country"), Boolean.FALSE);
        // Attach phone
        phoneNumberDAO.create(student.getContactInfo(), contactType, Boolean.FALSE, getFormValue(formData, "field-underage-phone"));
    }
    // Contract school (Internetix students)
    String schoolId = getFormValue(formData, "field-internetix-contract-school");
    if (!NumberUtils.isNumber(schoolId)) {
        String customSchool = getFormValue(formData, "field-internetix-contract-school-name");
        if (!StringUtils.isBlank(customSchool)) {
            List<School> schools = schoolDAO.listByNameLowercaseAndArchived(customSchool, Boolean.FALSE);
            School school = schools.isEmpty() ? null : schools.get(0);
            if (school != null) {
                studentDAO.updateSchool(student, school);
                // #1003: add student to student group(s) based on school
                processSchoolStudentGroups(school, student);
            } else {
                String notification = "<b>Huom!</b> Opiskelijan ilmoittamaa oppilaitosta ei löydy vielä Pyramuksesta!";
                ApplicationLogDAO applicationLogDAO = DAOFactory.getInstance().getApplicationLogDAO();
                applicationLogDAO.create(application, ApplicationLogType.HTML, notification, null);
            }
        }
    }
    // Attachments
    List<ApplicationAttachment> attachments = applicationAttachmentDAO.listByApplicationId(application.getApplicationId());
    if (!attachments.isEmpty()) {
        String attachmentsFolder = SettingUtils.getSettingValue("applications.storagePath");
        if (StringUtils.isNotEmpty(attachmentsFolder)) {
            StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
            String applicationId = sanitizeFilename(application.getApplicationId());
            for (ApplicationAttachment attachment : attachments) {
                String attachmentFileName = sanitizeFilename(attachment.getName());
                try {
                    java.nio.file.Path path = Paths.get(attachmentsFolder, applicationId, attachmentFileName);
                    File file = path.toFile();
                    if (file.exists()) {
                        String fileId = null;
                        String contentType = Files.probeContentType(path);
                        byte[] data = FileUtils.readFileToByteArray(file);
                        if (PyramusFileUtils.isFileSystemStorageEnabled()) {
                            try {
                                fileId = PyramusFileUtils.generateFileId();
                                PyramusFileUtils.storeFile(student, fileId, data);
                                data = null;
                            } catch (IOException e) {
                                fileId = null;
                                logger.log(Level.WARNING, "Store user file to file system failed", e);
                            }
                        }
                        studentFileDAO.create(student, StringUtils.isBlank(attachment.getDescription()) ? attachmentFileName : attachment.getDescription(), attachmentFileName, fileId, // file type
                        null, contentType, data, staffMember);
                    }
                } catch (IOException e) {
                    logger.log(Level.WARNING, String.format("Exception processing attachment %s of application %d", attachment.getName(), application.getId()), e);
                }
            }
        }
    }
    return student;
}
Also used : ApplicationLogDAO(fi.otavanopisto.pyramus.dao.application.ApplicationLogDAO) PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) Sex(fi.otavanopisto.pyramus.domainmodel.students.Sex) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) StudentStudyPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ApplicationAttachmentDAO(fi.otavanopisto.pyramus.dao.application.ApplicationAttachmentDAO) IOException(java.io.IOException) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Date(java.util.Date) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) StudentGroupStudentDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupStudentDAO) JSONObject(net.sf.json.JSONObject) ApplicationAttachment(fi.otavanopisto.pyramus.domainmodel.application.ApplicationAttachment) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 4 with StudentStudyPeriodDAO

use of fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO in project pyramus by otavanopisto.

the class ViewStudentViewController method process.

/**
 * Processes the page request.
 *
 * In parameters
 * - student
 * - person
 *
 * Page parameters
 * - student - Student object
 * - nationalities - List of Nationality objects
 * - municipalities - List of Municipality objects
 * - languages - List of Language objects
 * - studentCourses - List of CourseStudent objects
 * - studentContactEntries - List of StudentContactLogEntry objects
 *
 * @param pageRequestContext pageRequestContext
 */
public void process(PageRequestContext pageRequestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentImageDAO imageDAO = DAOFactory.getInstance().getStudentImageDAO();
    StudentContactLogEntryDAO logEntryDAO = DAOFactory.getInstance().getStudentContactLogEntryDAO();
    StudentContactLogEntryCommentDAO entryCommentDAO = DAOFactory.getInstance().getStudentContactLogEntryCommentDAO();
    StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    CourseAssessmentRequestDAO courseAssessmentRequestDAO = DAOFactory.getInstance().getCourseAssessmentRequestDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    StudentLodgingPeriodDAO studentLodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
    PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
    PersonVariableKeyDAO personVariableKeyDAO = DAOFactory.getInstance().getPersonVariableKeyDAO();
    StudentStudyPeriodDAO studentStudyPeriodDAO = DAOFactory.getInstance().getStudentStudyPeriodDAO();
    MatriculationExamEnrollmentDAO matriculationExamEnrollmentDAO = DAOFactory.getInstance().getMatriculationExamEnrollmentDAO();
    Long loggedUserId = pageRequestContext.getLoggedUserId();
    StaffMember loggedUser = staffMemberDAO.findById(loggedUserId);
    Long personId = pageRequestContext.getLong("person");
    Person person = personDAO.findById(personId);
    pageRequestContext.getRequest().setAttribute("person", person);
    StaffMember staffMember = staffMemberDAO.findByPerson(person);
    pageRequestContext.getRequest().setAttribute("staffMember", staffMember);
    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, Boolean> studentHasImage = new HashMap<>();
    Map<Long, List<CourseStudent>> courseStudents = new HashMap<>();
    Map<Long, List<StudentContactLogEntry>> contactEntries = new HashMap<>();
    Map<Long, List<TransferCredit>> transferCredits = new HashMap<>();
    Map<Long, List<CourseAssessment>> courseAssessments = new HashMap<>();
    Map<Long, CourseAssessmentRequest> courseAssessmentRequests = new HashMap<>();
    Map<Long, List<StudentGroup>> studentGroups = new HashMap<>();
    Map<Long, List<StudentProjectBean>> studentProjects = new HashMap<>();
    Map<Long, CourseAssessment> courseAssessmentsByCourseStudent = new HashMap<>();
    // StudentProject.id -> List of module beans
    Map<Long, List<StudentProjectModuleBean>> studentProjectModules = new HashMap<>();
    final Map<Long, List<StudentContactLogEntryComment>> contactEntryComments = new HashMap<>();
    Map<Long, List<StudentLodgingPeriod>> studentLodgingPeriods = new HashMap<>();
    Map<Long, List<StudentStudyPeriod>> studentStudyPeriods = new HashMap<>();
    Map<Long, StudentTOR> subjectCredits = new HashMap<>();
    Map<Long, List<MatriculationExamEnrollment>> studentMatriculationEnrollments = new HashMap<>();
    JSONObject linkedCourseAssessments = new JSONObject();
    JSONObject linkedTransferCredits = new JSONObject();
    JSONObject studentFiles = new JSONObject();
    JSONObject studentVariablesJSON = new JSONObject();
    JSONArray studentReportsJSON = new JSONArray();
    JSONArray curriculumsJSON = new JSONArray();
    JSONObject studentAssessmentsJSON = new JSONObject();
    List<Report> studentReports = reportDAO.listByContextType(ReportContextType.Student);
    Collections.sort(studentReports, new StringAttributeComparator("getName"));
    for (Report report : studentReports) {
        JSONObject obj = new JSONObject();
        obj.put("id", report.getId().toString());
        obj.put("name", report.getName());
        studentReportsJSON.add(obj);
    }
    /* PersonVariables */
    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());
    /* Curriculums */
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    for (Curriculum curriculum : curriculums) {
        JSONObject obj = new JSONObject();
        obj.put("id", curriculum.getId().toString());
        obj.put("name", curriculum.getName());
        curriculumsJSON.add(obj);
    }
    for (Student student : students) {
        /**
         * Fetch courses this student is part of and sort the courses by course name
         */
        List<CourseStudent> courseStudentsByStudent = courseStudentDAO.listByStudent(student);
        Collections.sort(courseStudentsByStudent, new Comparator<CourseStudent>() {

            private String getCourseAssessmentCompareStr(CourseStudent courseStudent) {
                String result = "";
                if (courseStudent != null)
                    if (courseStudent.getCourse() != null)
                        result = courseStudent.getCourse().getName();
                return result;
            }

            @Override
            public int compare(CourseStudent o1, CourseStudent o2) {
                String s1 = getCourseAssessmentCompareStr(o1);
                String s2 = getCourseAssessmentCompareStr(o2);
                return s1.compareToIgnoreCase(s2);
            }
        });
        for (CourseStudent courseStudent : courseStudentsByStudent) {
            List<CourseAssessmentRequest> courseAssessmentRequestsByCourseStudent = courseAssessmentRequestDAO.listByCourseStudent(courseStudent);
            Collections.sort(courseAssessmentRequestsByCourseStudent, new Comparator<CourseAssessmentRequest>() {

                @Override
                public int compare(CourseAssessmentRequest o1, CourseAssessmentRequest o2) {
                    return o2.getCreated().compareTo(o1.getCreated());
                }
            });
            if (!courseAssessmentRequestsByCourseStudent.isEmpty()) {
                courseAssessmentRequests.put(courseStudent.getId(), courseAssessmentRequestsByCourseStudent.get(0));
            }
        }
        /**
         * Contact log entries
         */
        List<StudentContactLogEntry> listStudentContactEntries = logEntryDAO.listByStudent(student);
        for (int j = 0; j < listStudentContactEntries.size(); j++) {
            StudentContactLogEntry entry = listStudentContactEntries.get(j);
            List<StudentContactLogEntryComment> listComments = entryCommentDAO.listByEntry(entry);
            Collections.sort(listComments, new Comparator<StudentContactLogEntryComment>() {

                public int compare(StudentContactLogEntryComment o1, StudentContactLogEntryComment o2) {
                    Date d1 = o1.getCommentDate();
                    Date d2 = o2.getCommentDate();
                    int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d1.compareTo(d2);
                    if (val == 0)
                        return o1.getId().compareTo(o2.getId());
                    else
                        return val;
                }
            });
            contactEntryComments.put(entry.getId(), listComments);
        }
        // And then sort the entries by latest date of entry or its comments
        Collections.sort(listStudentContactEntries, new Comparator<StudentContactLogEntry>() {

            private Date getDateForEntry(StudentContactLogEntry entry) {
                Date d = entry.getEntryDate();
                List<StudentContactLogEntryComment> comments = contactEntryComments.get(entry.getId());
                for (int i = 0; i < comments.size(); i++) {
                    StudentContactLogEntryComment comment = comments.get(i);
                    if (d == null) {
                        d = comment.getCommentDate();
                    } else {
                        if (d.before(comment.getCommentDate()))
                            d = comment.getCommentDate();
                    }
                }
                return d;
            }

            public int compare(StudentContactLogEntry o1, StudentContactLogEntry o2) {
                Date d1 = getDateForEntry(o1);
                Date d2 = getDateForEntry(o2);
                int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d2.compareTo(d1);
                if (val == 0)
                    return o2.getId().compareTo(o1.getId());
                else
                    return val;
            }
        });
        /**
         * Students Course Assessments, sorted by course name
         */
        List<CourseAssessment> courseAssessmentsByStudent = courseAssessmentDAO.listByStudent(student);
        for (CourseAssessment courseAssessment : courseAssessmentsByStudent) {
            Long courseStudentId = courseAssessment.getCourseStudent().getId();
            courseAssessmentsByCourseStudent.put(courseStudentId, courseAssessment);
        }
        Collections.sort(courseAssessmentsByStudent, new Comparator<CourseAssessment>() {

            private String getCourseAssessmentCompareStr(CourseAssessment courseAssessment) {
                String result = "";
                if (courseAssessment != null)
                    if (courseAssessment.getCourseStudent() != null)
                        if (courseAssessment.getCourseStudent().getCourse() != null)
                            result = courseAssessment.getCourseStudent().getCourse().getName();
                return result;
            }

            @Override
            public int compare(CourseAssessment o1, CourseAssessment o2) {
                String s1 = getCourseAssessmentCompareStr(o1);
                String s2 = getCourseAssessmentCompareStr(o2);
                return s1.compareToIgnoreCase(s2);
            }
        });
        JSONArray jsonCourseStudentAssessments = new JSONArray();
        for (CourseStudent courseStudent : courseStudentsByStudent) {
            List<CourseAssessment> courseAssessmentList = courseAssessmentsByStudent.stream().filter(courseAssessment -> Objects.equals(courseStudent.getId(), courseAssessment.getCourseStudent().getId())).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(courseAssessmentList) && courseStudent.getCourse() != null) {
                Course course = courseStudent.getCourse();
                JSONObject obj = new JSONObject();
                obj.put("courseStudentId", courseStudent.getId());
                obj.put("courseName", course.getName());
                obj.put("subjectName", getSubjectText(course.getSubject(), pageRequestContext.getRequest().getLocale()));
                JSONArray jsonCurriculums = new JSONArray();
                for (Curriculum curriculum : course.getCurriculums()) {
                    JSONObject curobj = new JSONObject();
                    curobj.put("name", curriculum.getName());
                    jsonCurriculums.add(curobj);
                }
                obj.put("curriculums", jsonCurriculums);
                if (course.getCourseLength() != null) {
                    EducationalLength courseLength = course.getCourseLength();
                    obj.put("courseLength", courseLength.getUnits().toString());
                    if (courseLength.getUnit() != null) {
                        obj.put("courseLengthUnitName", courseLength.getUnit().getName());
                    }
                }
                JSONArray jsonCourseAssessments = new JSONArray();
                for (CourseAssessment ass : courseAssessmentList) {
                    JSONObject assobj = new JSONObject();
                    assobj.put("timestamp", ass.getDate() != null ? ass.getDate().getTime() : null);
                    assobj.put("gradeName", ass.getGrade() != null ? ass.getGrade().getName() : null);
                    assobj.put("gradingScaleName", (ass.getGrade() != null && ass.getGrade().getGradingScale() != null) ? ass.getGrade().getGradingScale().getName() : null);
                    assobj.put("assessorName", ass.getAssessor() != null ? ass.getAssessor().getFullName() : null);
                    jsonCourseAssessments.add(assobj);
                }
                obj.put("assessments", jsonCourseAssessments);
                jsonCourseStudentAssessments.add(obj);
            }
        }
        studentAssessmentsJSON.put(student.getId(), jsonCourseStudentAssessments);
        /**
         * Fetching and sorting of Transfer Credits
         */
        List<TransferCredit> transferCreditsByStudent = transferCreditDAO.listByStudent(student);
        Collections.sort(transferCreditsByStudent, new Comparator<TransferCredit>() {

            private String getCourseAssessmentCompareStr(TransferCredit tCredit) {
                String result = "";
                if (tCredit != null)
                    result = tCredit.getCourseName();
                return result;
            }

            @Override
            public int compare(TransferCredit o1, TransferCredit o2) {
                String s1 = getCourseAssessmentCompareStr(o1);
                String s2 = getCourseAssessmentCompareStr(o2);
                return s1.compareToIgnoreCase(s2);
            }
        });
        /**
         * Linked CourseAssessments
         */
        List<CreditLink> linkedCourseAssessmentByStudent = creditLinkDAO.listByStudentAndType(student, CreditType.CourseAssessment);
        Collections.sort(linkedCourseAssessmentByStudent, new Comparator<CreditLink>() {

            private String getCourseAssessmentCompareStr(CourseAssessment courseAssessment) {
                String result = "";
                if (courseAssessment != null)
                    if (courseAssessment.getCourseStudent() != null)
                        if (courseAssessment.getCourseStudent().getCourse() != null)
                            result = courseAssessment.getCourseStudent().getCourse().getName();
                return result;
            }

            @Override
            public int compare(CreditLink o1, CreditLink o2) {
                String s1 = getCourseAssessmentCompareStr((CourseAssessment) o1.getCredit());
                String s2 = getCourseAssessmentCompareStr((CourseAssessment) o2.getCredit());
                return s1.compareToIgnoreCase(s2);
            }
        });
        JSONArray arr = new JSONArray();
        for (CreditLink linkedCourseAssessment : linkedCourseAssessmentByStudent) {
            CourseAssessment courseAssessment = (CourseAssessment) linkedCourseAssessment.getCredit();
            String subjectName = getSubjectText(courseAssessment.getCourseStudent().getCourse().getSubject(), pageRequestContext.getRequest().getLocale());
            JSONObject obj = new JSONObject();
            obj.put("creditLinkId", linkedCourseAssessment.getId().toString());
            obj.put("courseStudentId", courseAssessment.getCourseStudent().getId().toString());
            obj.put("courseName", courseAssessment.getCourseStudent().getCourse().getName());
            obj.put("subjectName", subjectName);
            obj.put("creditDate", courseAssessment.getDate().getTime());
            obj.put("courseLength", courseAssessment.getCourseStudent().getCourse().getCourseLength().getUnits().toString());
            obj.put("courseLengthUnitName", courseAssessment.getCourseStudent().getCourse().getCourseLength().getUnit().getName());
            obj.put("gradeName", courseAssessment.getGrade() != null ? courseAssessment.getGrade().getName() : null);
            obj.put("gradingScaleName", courseAssessment.getGrade() != null ? courseAssessment.getGrade().getGradingScale().getName() : null);
            obj.put("assessingUserName", courseAssessment.getAssessor().getFullName());
            JSONArray courseCurriculums = new JSONArray();
            if (CollectionUtils.isNotEmpty(courseAssessment.getCourseStudent().getCourse().getCurriculums())) {
                for (Curriculum curriculum : courseAssessment.getCourseStudent().getCourse().getCurriculums()) {
                    JSONObject courseCurriculum = new JSONObject();
                    courseCurriculum.put("curriculumId", curriculum.getId());
                    courseCurriculum.put("curriculumName", curriculum.getName());
                    courseCurriculums.add(courseCurriculum);
                }
            }
            obj.put("curriculums", courseCurriculums);
            arr.add(obj);
        }
        if (!arr.isEmpty())
            linkedCourseAssessments.put(student.getId(), arr);
        /**
         * Linked TransferCredits
         */
        List<CreditLink> linkedTransferCreditsByStudent = creditLinkDAO.listByStudentAndType(student, CreditType.TransferCredit);
        Collections.sort(linkedTransferCreditsByStudent, new Comparator<CreditLink>() {

            private String getCourseAssessmentCompareStr(TransferCredit tCredit) {
                String result = "";
                if (tCredit != null)
                    result = tCredit.getCourseName();
                return result;
            }

            @Override
            public int compare(CreditLink o1, CreditLink o2) {
                String s1 = getCourseAssessmentCompareStr((TransferCredit) o1.getCredit());
                String s2 = getCourseAssessmentCompareStr((TransferCredit) o2.getCredit());
                return s1.compareToIgnoreCase(s2);
            }
        });
        arr = new JSONArray();
        for (CreditLink linkedTransferCredit : linkedTransferCreditsByStudent) {
            TransferCredit transferCredit = (TransferCredit) linkedTransferCredit.getCredit();
            String subjectName = getSubjectText(transferCredit.getSubject(), pageRequestContext.getRequest().getLocale());
            JSONObject obj = new JSONObject();
            obj.put("creditLinkId", linkedTransferCredit.getId().toString());
            obj.put("transferCreditId", transferCredit.getId().toString());
            obj.put("courseName", transferCredit.getCourseName());
            obj.put("subjectName", subjectName);
            obj.put("creditDate", transferCredit.getDate().getTime());
            obj.put("courseLength", transferCredit.getCourseLength().getUnits().toString());
            obj.put("courseLengthUnitName", transferCredit.getCourseLength().getUnit().getName());
            obj.put("gradeName", transferCredit.getGrade() != null ? transferCredit.getGrade().getName() : null);
            obj.put("gradingScaleName", transferCredit.getGrade() != null ? transferCredit.getGrade().getGradingScale().getName() : null);
            obj.put("assessingUserName", transferCredit.getAssessor().getFullName());
            if (transferCredit.getCurriculum() != null) {
                Curriculum curriculum = transferCredit.getCurriculum();
                obj.put("curriculumId", curriculum.getId());
                obj.put("curriculumName", curriculum.getName());
            }
            arr.add(obj);
        }
        if (!arr.isEmpty())
            linkedTransferCredits.put(student.getId(), arr);
        /**
         * Project beans setup
         */
        List<StudentProject> studentsStudentProjects = studentProjectDAO.listByStudent(student);
        List<StudentProjectBean> studentProjectBeans = new ArrayList<>();
        for (StudentProject studentProject : studentsStudentProjects) {
            int mandatoryModuleCount = 0;
            int optionalModuleCount = 0;
            int passedMandatoryModuleCount = 0;
            int passedOptionalModuleCount = 0;
            List<StudentProjectModuleBean> studentProjectModuleBeans = new ArrayList<>();
            /**
             * Go through project modules to
             *  a) count mandatory/optional modules
             *  b) count mandatory/optional modules that have passing grade on them
             *  c) create beans to be passed to jsp
             */
            List<CourseAssessment> allStudentCourseAssessments = courseAssessmentDAO.listByStudent(student);
            List<TransferCredit> allStudentTransferCredits = transferCreditDAO.listByStudent(student);
            List<CreditLink> allStudentCreditLinks = creditLinkDAO.listByStudent(student);
            for (CreditLink creditLink : allStudentCreditLinks) {
                switch(creditLink.getCredit().getCreditType()) {
                    case CourseAssessment:
                        allStudentCourseAssessments.add(((CourseAssessment) creditLink.getCredit()));
                        break;
                    case TransferCredit:
                        allStudentTransferCredits.add(((TransferCredit) creditLink.getCredit()));
                        break;
                    case ProjectAssessment:
                        break;
                }
            }
            for (StudentProjectModule studentProjectModule : studentProject.getStudentProjectModules()) {
                boolean hasPassingGrade = false;
                List<CourseStudent> projectCourseCourseStudentList = new ArrayList<>();
                List<TransferCredit> projectCourseTransferCreditList = new ArrayList<>();
                for (CourseAssessment assessment : allStudentCourseAssessments) {
                    if (assessment.getCourseStudent().getCourse().getModule().getId().equals(studentProjectModule.getModule().getId())) {
                        projectCourseCourseStudentList.add(assessment.getCourseStudent());
                        if (assessment.getGrade() != null && assessment.getGrade().getPassingGrade())
                            hasPassingGrade = true;
                    }
                }
                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())) {
                                projectCourseTransferCreditList.add(tc);
                                if (tc.getGrade() != null && tc.getGrade().getPassingGrade())
                                    hasPassingGrade = true;
                            }
                        }
                    }
                }
                if (studentProjectModule.getOptionality() == CourseOptionality.MANDATORY) {
                    mandatoryModuleCount++;
                    if (hasPassingGrade)
                        passedMandatoryModuleCount++;
                } else if (studentProjectModule.getOptionality() == CourseOptionality.OPTIONAL) {
                    optionalModuleCount++;
                    if (hasPassingGrade)
                        passedOptionalModuleCount++;
                }
                StudentProjectModuleBean moduleBean = new StudentProjectModuleBean(studentProjectModule, hasPassingGrade, projectCourseCourseStudentList, projectCourseTransferCreditList);
                studentProjectModuleBeans.add(moduleBean);
            }
            // Add ModuleBeans to response
            studentProjectModules.put(studentProject.getId(), studentProjectModuleBeans);
            List<ProjectAssessment> projectAssessments = projectAssessmentDAO.listByProjectAndArchived(studentProject, Boolean.FALSE);
            Collections.sort(projectAssessments, new Comparator<ProjectAssessment>() {

                @Override
                public int compare(ProjectAssessment o1, ProjectAssessment o2) {
                    return o2.getDate().compareTo(o1.getDate());
                }
            });
            StudentProjectBean bean = new StudentProjectBean(studentProject, mandatoryModuleCount, optionalModuleCount, passedMandatoryModuleCount, passedOptionalModuleCount, projectAssessments);
            studentProjectBeans.add(bean);
        }
        List<StudentFile> files = studentFileDAO.listByStudent(student);
        Collections.sort(files, new StringAttributeComparator("getName", true));
        arr = new JSONArray();
        for (StudentFile file : files) {
            JSONObject obj = new JSONObject();
            obj.put("id", file.getId());
            obj.put("name", file.getName());
            obj.put("fileTypeName", file.getFileType() != null ? file.getFileType().getName() : "");
            obj.put("created", file.getCreated().getTime());
            obj.put("lastModified", file.getLastModified().getTime());
            arr.add(obj);
        }
        if (!arr.isEmpty())
            studentFiles.put(student.getId(), arr);
        JSONArray variables = new JSONArray();
        for (UserVariable userVariable : userVariableDAO.listByUserAndUserEditable(student, true)) {
            JSONObject variable = new JSONObject();
            variable.put("type", userVariable.getKey().getVariableType());
            variable.put("name", userVariable.getKey().getVariableName());
            variable.put("key", userVariable.getKey().getVariableKey());
            variable.put("value", userVariable.getValue() != null ? userVariable.getValue() : "");
            variables.add(variable);
        }
        if (!variables.isEmpty())
            studentVariablesJSON.put(student.getId(), variables);
        // Student Image
        studentHasImage.put(student.getId(), imageDAO.findStudentHasImage(student));
        List<StudentLodgingPeriod> studentLodgingPeriodEntities = studentLodgingPeriodDAO.listByStudent(student);
        studentLodgingPeriodEntities.sort(Comparator.comparing(StudentLodgingPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
        List<StudentStudyPeriod> studentStudyPeriodEntities = studentStudyPeriodDAO.listByStudent(student);
        studentStudyPeriodEntities.sort(Comparator.comparing(StudentStudyPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
        courseStudents.put(student.getId(), courseStudentsByStudent);
        courseAssessments.put(student.getId(), courseAssessmentsByStudent);
        contactEntries.put(student.getId(), listStudentContactEntries);
        transferCredits.put(student.getId(), transferCreditsByStudent);
        studentGroups.put(student.getId(), studentGroupDAO.listByStudent(student, null, null, false));
        studentProjects.put(student.getId(), studentProjectBeans);
        studentLodgingPeriods.put(student.getId(), studentLodgingPeriodEntities);
        studentStudyPeriods.put(student.getId(), studentStudyPeriodEntities);
        studentMatriculationEnrollments.put(student.getId(), matriculationExamEnrollmentDAO.listByStudent(student));
        try {
            StudentTOR tor = StudentTORController.constructStudentTOR(student);
            subjectCredits.put(student.getId(), tor);
        } catch (Exception ex) {
            logger.log(Level.SEVERE, String.format("Failed to construct TOR for student %d", student.getId()), ex);
        }
    }
    ObjectMapper mapper = new ObjectMapper();
    StringWriter writer = new StringWriter();
    mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
    try {
        mapper.writeValue(writer, subjectCredits);
        String requestStr = writer.toString();
        setJsDataVariable(pageRequestContext, "subjectCredits", requestStr);
    } catch (JsonGenerationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    setJsDataVariable(pageRequestContext, "studentAssessments", studentAssessmentsJSON.toString());
    setJsDataVariable(pageRequestContext, "linkedCourseAssessments", linkedCourseAssessments.toString());
    setJsDataVariable(pageRequestContext, "linkedTransferCredits", linkedTransferCredits.toString());
    setJsDataVariable(pageRequestContext, "studentFiles", studentFiles.toString());
    setJsDataVariable(pageRequestContext, "studentReports", studentReportsJSON.toString());
    setJsDataVariable(pageRequestContext, "curriculums", curriculumsJSON.toString());
    setJsDataVariable(pageRequestContext, "studentVariables", studentVariablesJSON.toString());
    pageRequestContext.getRequest().setAttribute("students", students);
    pageRequestContext.getRequest().setAttribute("courses", courseStudents);
    pageRequestContext.getRequest().setAttribute("contactEntries", contactEntries);
    pageRequestContext.getRequest().setAttribute("contactEntryComments", contactEntryComments);
    pageRequestContext.getRequest().setAttribute("transferCredits", transferCredits);
    pageRequestContext.getRequest().setAttribute("courseAssessments", courseAssessments);
    pageRequestContext.getRequest().setAttribute("studentGroups", studentGroups);
    pageRequestContext.getRequest().setAttribute("studentProjects", studentProjects);
    pageRequestContext.getRequest().setAttribute("studentProjectModules", studentProjectModules);
    pageRequestContext.getRequest().setAttribute("courseAssessmentsByCourseStudent", courseAssessmentsByCourseStudent);
    pageRequestContext.getRequest().setAttribute("studentHasImage", studentHasImage);
    pageRequestContext.getRequest().setAttribute("courseAssessmentRequests", courseAssessmentRequests);
    pageRequestContext.getRequest().setAttribute("studentLodgingPeriods", studentLodgingPeriods);
    pageRequestContext.getRequest().setAttribute("studentStudyPeriods", studentStudyPeriods);
    pageRequestContext.getRequest().setAttribute("studentMatriculationEnrollments", studentMatriculationEnrollments);
    pageRequestContext.getRequest().setAttribute("hasPersonVariables", CollectionUtils.isNotEmpty(personVariableKeys));
    pageRequestContext.setIncludeJSP("/templates/students/viewstudent.jsp");
}
Also used : StudentTORController(fi.otavanopisto.pyramus.tor.StudentTORController) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) UserUtils(fi.otavanopisto.pyramus.framework.UserUtils) Date(java.util.Date) CreditType(fi.otavanopisto.pyramus.domainmodel.grading.CreditType) StringUtils(org.apache.commons.lang3.StringUtils) StudentLodgingPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentLodgingPeriod) StudentContactLogEntryComment(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntryComment) StudentStudyPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod) Locale(java.util.Locale) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) StudentStudyPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO) Map(java.util.Map) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) PyramusViewPermissions(fi.otavanopisto.pyramus.views.PyramusViewPermissions) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) RequestContext(fi.internetix.smvc.controllers.RequestContext) EducationalLength(fi.otavanopisto.pyramus.domainmodel.base.EducationalLength) Messages(fi.otavanopisto.pyramus.I18N.Messages) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) Breadcrumbable(fi.otavanopisto.pyramus.breadcrumbs.Breadcrumbable) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) PersonVariable(fi.otavanopisto.pyramus.domainmodel.users.PersonVariable) Objects(java.util.Objects) List(java.util.List) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) PersonVariableKey(fi.otavanopisto.pyramus.domainmodel.users.PersonVariableKey) JSONObject(net.sf.json.JSONObject) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) PyramusViewController2(fi.otavanopisto.pyramus.framework.PyramusViewController2) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) ReportContextType(fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) UserVariable(fi.otavanopisto.pyramus.domainmodel.users.UserVariable) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) UserDAO(fi.otavanopisto.pyramus.dao.users.UserDAO) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) StudentImageDAO(fi.otavanopisto.pyramus.dao.students.StudentImageDAO) PyramusRequestControllerAccess(fi.otavanopisto.pyramus.framework.PyramusRequestControllerAccess) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) User(fi.otavanopisto.pyramus.domainmodel.users.User) CollectionUtils(org.apache.commons.collections.CollectionUtils) StudentContactLogEntryCommentDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryCommentDAO) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) Permissions(fi.otavanopisto.pyramus.security.impl.Permissions) StudentFile(fi.otavanopisto.pyramus.domainmodel.file.StudentFile) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) StudentContactLogEntryDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO) StringWriter(java.io.StringWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) IOException(java.io.IOException) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) CourseAssessmentRequestDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO) PersonVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableKeyDAO) PageRequestContext(fi.internetix.smvc.controllers.PageRequestContext) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StudentLodgingPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) JSONArray(net.sf.json.JSONArray) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) Comparator(java.util.Comparator) Collections(java.util.Collections) DAOFactory(fi.otavanopisto.pyramus.dao.DAOFactory) StudentTOR(fi.otavanopisto.pyramus.tor.StudentTOR) ArrayList(java.util.ArrayList) UserVariable(fi.otavanopisto.pyramus.domainmodel.users.UserVariable) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) StudentImageDAO(fi.otavanopisto.pyramus.dao.students.StudentImageDAO) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) 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) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) StudentContactLogEntryCommentDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryCommentDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) StringWriter(java.io.StringWriter) PersonVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableKeyDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) PersonVariable(fi.otavanopisto.pyramus.domainmodel.users.PersonVariable) IOException(java.io.IOException) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) StudentTOR(fi.otavanopisto.pyramus.tor.StudentTOR) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) StudentStudyPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) StudentFile(fi.otavanopisto.pyramus.domainmodel.file.StudentFile) HashMap(java.util.HashMap) StudentContactLogEntryDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudentLodgingPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) List(java.util.List) ArrayList(java.util.ArrayList) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationalLength(fi.otavanopisto.pyramus.domainmodel.base.EducationalLength) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseAssessmentRequestDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO) StudentContactLogEntryComment(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntryComment) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) PersonVariableKey(fi.otavanopisto.pyramus.domainmodel.users.PersonVariableKey) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentStudyPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) JSONArray(net.sf.json.JSONArray) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) Date(java.util.Date) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException) StudentLodgingPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentLodgingPeriod) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)4 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)4 StudentStudyPeriodDAO (fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO)4 UserVariableDAO (fi.otavanopisto.pyramus.dao.users.UserVariableDAO)4 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)4 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)3 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)3 SchoolDAO (fi.otavanopisto.pyramus.dao.base.SchoolDAO)3 AddressDAO (fi.otavanopisto.pyramus.dao.base.AddressDAO)2 LanguageDAO (fi.otavanopisto.pyramus.dao.base.LanguageDAO)2 MunicipalityDAO (fi.otavanopisto.pyramus.dao.base.MunicipalityDAO)2 NationalityDAO (fi.otavanopisto.pyramus.dao.base.NationalityDAO)2 StudentFileDAO (fi.otavanopisto.pyramus.dao.file.StudentFileDAO)2 StudentActivityTypeDAO (fi.otavanopisto.pyramus.dao.students.StudentActivityTypeDAO)2 StudentEducationalLevelDAO (fi.otavanopisto.pyramus.dao.students.StudentEducationalLevelDAO)2 StudentExaminationTypeDAO (fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO)2 StudentLodgingPeriodDAO (fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO)2 StudentStudyEndReasonDAO (fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO)2 PersonVariableDAO (fi.otavanopisto.pyramus.dao.users.PersonVariableDAO)2 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)2