Search in sources :

Example 1 with ContactURLType

use of fi.otavanopisto.pyramus.domainmodel.base.ContactURLType in project pyramus by otavanopisto.

the class ContactURLTypeDAO method create.

public ContactURLType create(String name) {
    EntityManager entityManager = getEntityManager();
    ContactURLType contactURLType = new ContactURLType();
    contactURLType.setName(name);
    entityManager.persist(contactURLType);
    return contactURLType;
}
Also used : EntityManager(javax.persistence.EntityManager) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType)

Example 2 with ContactURLType

use of fi.otavanopisto.pyramus.domainmodel.base.ContactURLType 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 3 with ContactURLType

use of fi.otavanopisto.pyramus.domainmodel.base.ContactURLType in project pyramus by otavanopisto.

the class CreateStudentViewController method process.

public void process(PageRequestContext pageRequestContext) {
    StudentActivityTypeDAO studentActivityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
    StudentEducationalLevelDAO studentEducationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
    StudentExaminationTypeDAO studentExaminationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
    StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
    UserVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO();
    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();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    User loggedUser = staffMemberDAO.findById(pageRequestContext.getLoggedUserId());
    Long personId = pageRequestContext.getLong("personId");
    if (personId != null) {
        Person person = personDAO.findById(personId);
        StaffMember staffMember = staffMemberDAO.findByPerson(person);
        pageRequestContext.getRequest().setAttribute("person", person);
        pageRequestContext.getRequest().setAttribute("staffMember", staffMember);
        String emails = new JSONArrayExtractor("defaultAddress", "contactType", "address").extractString(staffMember.getContactInfo().getEmails());
        String addresses = new JSONArrayExtractor("defaultAddress", "name", "contactType", "streetAddress", "postalCode", "city", "country").extractString(staffMember.getContactInfo().getAddresses());
        String phones = new JSONArrayExtractor("defaultNumber", "contactType", "number").extractString(staffMember.getContactInfo().getPhoneNumbers());
        setJsDataVariable(pageRequestContext, "createstudent_emails", emails);
        setJsDataVariable(pageRequestContext, "createstudent_addresses", addresses);
        setJsDataVariable(pageRequestContext, "createstudent_phones", phones);
    }
    List<StudyProgramme> studyProgrammes = UserUtils.canAccessAllOrganizations(loggedUser) ? studyProgrammeDAO.listUnarchived() : studyProgrammeDAO.listByOrganization(loggedUser.getOrganization(), Archived.UNARCHIVED);
    Collections.sort(studyProgrammes, new StringAttributeComparator("getName"));
    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"));
    List<UserVariableKey> userVariableKeys = variableKeyDAO.listByUserEditable(Boolean.TRUE);
    Collections.sort(userVariableKeys, new StringAttributeComparator("getVariableName"));
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    String jsonContactTypes = new JSONArrayExtractor("name", "id").extractString(contactTypes);
    String jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extractString(userVariableKeys);
    setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
    setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys);
    pageRequestContext.getRequest().setAttribute("schools", schools);
    pageRequestContext.getRequest().setAttribute("activityTypes", studentActivityTypeDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
    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("studyProgrammes", studyProgrammes);
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.getRequest().setAttribute("studyEndReasons", studyEndReasonDAO.listByParentReason(null));
    pageRequestContext.getRequest().setAttribute("variableKeys", userVariableKeys);
    pageRequestContext.setIncludeJSP("/templates/students/createstudent.jsp");
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) UserVariableKey(fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) StudentStudyEndReasonDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StudentEducationalLevelDAO(fi.otavanopisto.pyramus.dao.students.StudentEducationalLevelDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) StudentExaminationTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) NationalityDAO(fi.otavanopisto.pyramus.dao.base.NationalityDAO) LanguageDAO(fi.otavanopisto.pyramus.dao.base.LanguageDAO) StudentActivityTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentActivityTypeDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) UserVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.UserVariableKeyDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 4 with ContactURLType

use of fi.otavanopisto.pyramus.domainmodel.base.ContactURLType in project pyramus by otavanopisto.

the class EditSchoolViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
    SchoolVariableDAO schoolVariableDAO = DAOFactory.getInstance().getSchoolVariableDAO();
    SchoolVariableKeyDAO schoolVariableKeyDAO = DAOFactory.getInstance().getSchoolVariableKeyDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    Long schoolId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("school"));
    School school = schoolDAO.findById(schoolId);
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = school.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
    Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
    List<SchoolVariableKey> schoolUserEditableVariableKeys = schoolVariableKeyDAO.listUserEditableVariableKeys();
    Collections.sort(schoolUserEditableVariableKeys, new StringAttributeComparator("getVariableName"));
    List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    String jsonContactTypes = new JSONArrayExtractor("id", "name").extractString(contactTypes);
    List<Address> addresses = school.getContactInfo().getAddresses();
    JSONArray jsonAddresses = new JSONArrayExtractor("id", "defaultAddress", "name", "streetAddress", "postalCode", "city", "country").extract(addresses);
    for (int i = 0; i < jsonAddresses.size(); i++) {
        JSONObject jsonAddress = jsonAddresses.getJSONObject(i);
        if (addresses.get(i).getContactType() != null) {
            jsonAddress.put("contactTypeId", addresses.get(i).getContactType().getId());
        }
    }
    List<Email> emails = school.getContactInfo().getEmails();
    JSONArray jsonEmails = new JSONArrayExtractor("id", "defaultAddress", "address").extract(emails);
    for (int i = 0; i < jsonEmails.size(); i++) {
        JSONObject jsonEmail = jsonEmails.getJSONObject(i);
        if (emails.get(i).getContactType() != null) {
            jsonEmail.put("contactTypeId", emails.get(i).getContactType().getId());
        }
    }
    List<PhoneNumber> phoneNumbers = school.getContactInfo().getPhoneNumbers();
    JSONArray jsonPhoneNumbers = new JSONArrayExtractor("id", "defaultNumber", "number").extract(phoneNumbers);
    for (int i = 0; i < jsonPhoneNumbers.size(); i++) {
        JSONObject jsonPhoneNumber = jsonPhoneNumbers.getJSONObject(i);
        if (phoneNumbers.get(i).getContactType() != null) {
            jsonPhoneNumber.put("contactTypeId", phoneNumbers.get(i).getContactType().getId());
        }
    }
    JSONArray jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extract(schoolUserEditableVariableKeys);
    for (int i = 0; i < jsonVariableKeys.size(); i++) {
        JSONObject jsonVariableKey = jsonVariableKeys.getJSONObject(i);
        String key = jsonVariableKey.getString("variableKey");
        String value = schoolVariableDAO.findValueBySchoolAndKey(school, key);
        if (value != null)
            jsonVariableKey.put("variableValue", value);
    }
    this.setJsDataVariable(pageRequestContext, "addresses", jsonAddresses.toString());
    this.setJsDataVariable(pageRequestContext, "emails", jsonEmails.toString());
    this.setJsDataVariable(pageRequestContext, "phoneNumbers", jsonPhoneNumbers.toString());
    this.setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
    this.setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys.toString());
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("school", school);
    pageRequestContext.getRequest().setAttribute("variableKeys", schoolUserEditableVariableKeys);
    pageRequestContext.getRequest().setAttribute("schoolFields", schoolFieldDAO.listUnarchived());
    pageRequestContext.setIncludeJSP("/templates/settings/editschool.jsp");
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) SchoolVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableKeyDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) SchoolVariableDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableDAO) JSONArray(net.sf.json.JSONArray) SchoolVariableKey(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariableKey) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) JSONObject(net.sf.json.JSONObject) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 5 with ContactURLType

use of fi.otavanopisto.pyramus.domainmodel.base.ContactURLType in project pyramus by otavanopisto.

the class StudentRESTService method createStudentContactURL.

@Path("/students/{STUDENTID:[0-9]*}/contactURLs")
@POST
@RESTPermit(StudentPermissions.CREATE_STUDENTCONTACTURL)
public Response createStudentContactURL(@PathParam("STUDENTID") Long studentId, fi.otavanopisto.pyramus.rest.model.ContactURL contactURL) {
    if (contactURL == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Long contactURLTypeId = contactURL.getContactURLTypeId();
    String url = contactURL.getUrl();
    if (contactURLTypeId == null || StringUtils.isBlank(url)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    ContactURLType contactURLType = commonController.findContactURLTypeById(contactURLTypeId);
    if (contactURLType == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    return Response.ok(objectFactory.createModel(studentController.addStudentContactURL(student, contactURLType, url))).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Aggregations

ContactURLType (fi.otavanopisto.pyramus.domainmodel.base.ContactURLType)11 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)7 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)6 ContactURLTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO)6 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)6 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)5 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)4 School (fi.otavanopisto.pyramus.domainmodel.base.School)4 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)4 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)4 UserVariableKey (fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey)4 JSONArrayExtractor (fi.otavanopisto.pyramus.util.JSONArrayExtractor)4 SchoolDAO (fi.otavanopisto.pyramus.dao.base.SchoolDAO)3 UserVariableKeyDAO (fi.otavanopisto.pyramus.dao.users.UserVariableKeyDAO)3 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)3 Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)3 Nationality (fi.otavanopisto.pyramus.domainmodel.base.Nationality)3 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)3 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)3 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)2